📜  如何防止用户使用 laravel 在条带中添加重复卡 - PHP 代码示例

📅  最后修改于: 2022-03-11 14:54:41.402000             🧑  作者: Mango

代码示例1
public function checkBankingDetailsAlert()
  {
    $user = Auth::user();
    $stripe = new \Stripe\StripeClient(env('STRIPE_SECRET'));
    $cards = $stripe->paymentMethods->all(['customer' => $user->stripe_customer_id, 'type' => 'card']);
    $fingerprints = [];
    foreach ($cards as $card) {
       $fingerprint = $card['card']['fingerprint'];
        if (in_array($fingerprint, $fingerprints, true)) {
          $stripe->paymentMethods->detach($card['id']);
       } else {
         $fingerprints[] = $fingerprint;
       }
    }
    return response()->json([
      'status' => 'Success',
      'fingerprint' => $fingerprints,
    ]);
  }