成功支付条纹后,获取最后4位数的信用卡

时间:2014-02-01 02:20:02

标签: php stripe-payments

我有以下代码使用Stripe处理用户信用卡上的费用。

// Create the charge on Stripe's servers - this will charge the user's card
    try {
        $charge = Stripe_Charge::create(array(
          "amount" => $grandTotal, // amount in cents, again
          "currency" => "usd",
          "card" => $token,
          "description" => "Candy Kingdom Order")
        );
    } catch(Stripe_CardError $e) {
      // The card has been declined
    }

现在我希望能够显示订单确认页面上使用的卡的最后4位数字。但我想以一种不存储完整卡号的方式来做。只是最后的4.我不知道如何检索这些信息,如果它甚至可能的话。请帮忙吗?

1 个答案:

答案 0 :(得分:19)

API Documentation有您正在寻找的答案。 $ charge-> card-> last4应该具有您要查找的值。使用您的示例,以下内容将起作用:

$last4 = null;
try {
    $charge = Stripe_Charge::create(array(
      "amount" => $grandTotal, // amount in cents, again
      "currency" => "usd",
      "card" => $token,
      "description" => "Candy Kingdom Order")
    );
    $last4 = $charge->card->last4;
} catch(Stripe_CardError $e) {
  // The card has been declined
}