Answers for "how to prevent user to add duplicate card in stripe using laravel"

PHP
0

how to prevent user to add duplicate card in stripe using laravel

$stripe = new StripeClient('STRIPE_SECRET_KEY');

$cards = $stripe->paymentMethods->all(['customer' => '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;
   }
}
Posted by: Guest on April-14-2021
0

how to prevent user to add duplicate card in stripe using laravel

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,
    ]);
  }
Posted by: Guest on September-07-2021

Code answers related to "how to prevent user to add duplicate card in stripe using laravel"

Browse Popular Code Answers by Language