having an issue with stripe at the moment. I believe I'm missing something incredibly simple here.
So on a project of mine customers can buy products and all the payments are handled with stripe. When a customer first uses stripe to make a payment i create a customer within stripe and store their id in my db. If they already exist i retrieve the customer and update the card (or try to)
This is my code
// check if we already have their stripe info
if ($customer->stripe_id != NULL) {
$stripe_customer = \Stripe\Customer::retrieve($customer->stripe_id);
$stripe_customer->card = $input['stripe_token'];
} else {
$stripe_customer = \Stripe\Customer::create([
'card' => $input['stripe_token'],
'email' => $customer->email,
'description' => 'Customer #' . $customer->id,
]);
$this->customersRepo->update($customer->id, ['stripe_id' => $stripe_customer->id]);
}
// charge accordingly
$charge = \Stripe\Charge::create([
'customer' => $stripe_customer->id,
'amount' => $order->order_total * 100,
'description' => 'Payment for order #' . $order->order_ref . ' from ' . route('home'),
'currency' => 'gbp',
'metadata' => [
'order_ref' => '#' . $order->order_ref,
'customer_id' => $customer->id,
'customer_name' => $customer->user->present()->fullName,
'customer_email' => $customer->user->email
]
]);
Which all works perfectly fine but when I try to pay with a different card it uses the card previously supplied so the customer doesn't seem to be updating?
For example, I am using the test card number 4242424242424242 to simulate a normal payment which is fine and works correctly.
But when I try to use 4000000000000002 to simulate a card error on the same customer it still goes through as paid, which leads me to believe the previous card is being used.
Any way around this or am I missing something?
Thanks,
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire