Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 成功付款后获取信用卡的最后4位数字_Php_Stripe Payments - Fatal编程技术网

Php 成功付款后获取信用卡的最后4位数字

Php 成功付款后获取信用卡的最后4位数字,php,stripe-payments,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" =&g

我有下面的代码,它使用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个。如果可能的话,我不知道如何检索这些信息。请帮忙?

有你想要的答案$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
}

您不知道如何将任何数据拉入
substr($cardNumber,-4)现在是
$charge->source->last4