【问题标题】:Get last 4 digits of credit card after successful Stripe paymentStripe 支付成功后获取信用卡的最后 4 位数字
【发布时间】:2014-02-24 22:23:30
【问题描述】:

我有以下代码使用 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 个。我不确定如何检索此信息,如果可能的话。请帮忙?

【问题讨论】:

  • 您不知道如何提取任何数据
  • substr($cardNumber, -4);

标签: php stripe-payments


【解决方案1】:

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
}

【讨论】:

  • 现在是$charge->source->last4
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-11
  • 2020-08-01
  • 2015-08-07
  • 1970-01-01
  • 2016-02-02
  • 2010-09-25
相关资源
最近更新 更多