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

Mit*_*ans 10 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
    }
Run Code Online (Sandbox Code Playgroud)

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

小智 20

API文档有您正在寻找的答案.$ 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
}
Run Code Online (Sandbox Code Playgroud)

  • 它现在是`$ charge-> source-> last4` (7认同)