I’ve written the following php code in my web app to check for this.
# Retrieve the customer we’re adding this token to
$customer = \Stripe\Customer::retrieve($customer_id)
            ->sources->all(array('limit'=>15, 'object' => 'card'));
# Retrieve the submitted token
$stripe_token =\Stripe\Token::retrieve($_POST['stripeToken']);
# The fingerprint of the card is stored in ['card']['fingerprint']
$key = searcharray($fingerprint, 'fingerprint',$customer);
# Check if the card fingerprint submitted matches one of the customer’s current sources
if($fingerprint==$key){
   echo 'That card already exists on your account.';
}
# add the search array function given below
function searcharray($value, $key, $array) {
   foreach ($array->data as $k => $val) {
       if ($val[$key] == $value) {
           return $val[$key];
       }
   }
   return null;
}
 

 
 
 
No comments:
Post a Comment