#nid11 - bancontact incomplete payments
1 messages ยท Page 1 of 1 (latest)
I don't think this would be expected. Can you share details of your integration, eg how you create payment intents and confirm them?
`$bancontact_source = \Stripe\Source::create([
"type" => "bancontact",
"amount" => $totalPrice * 100,
"currency" => "eur",
"owner" => [
"email" => $email,
"name" => $name
],
"redirect" => [
"return_url" => route('bancontactRedirect'),
]
]); `
` if ($bancontact_source) {
$order = new Order();
$order->user_id = $userID;
$order->restaurant_id = $restaurant_id;
$order->comment = $request->note;
$order->address = $request->address;
$order->city = $request->city;
$order->phone = $request->phone;
$order->delivery_schedule = $request->delivery_schedule;
if ($request->delivery_schedule == 'scheduled') {
$order->time = $deliveryDateTime;
}
/$order->time = $deliveryDateTime;/
if ($discount > 0) {
$order->promo_code = $request->promo_code;
$order->discount = $discount;
}
$order->postal_code = $request->postal_code;
$order->delivery_price = 0;
$order->order_price = 0;
$order->payment_method = 'Bancontact';
$order->payment_status = "Pending";
$order->stripe_payment_id = $bancontact_source['id'];
$order->save();
$orderStatus = new OrderStatus();
$orderStatus->order_id = $order->id;
$orderStatus->user_id = $userID;
$orderStatus->save();
$cartItems = \Cart::getContent();
if ($order) {
session(['orderId' => $order->id]);
foreach ($cartItems as $product) {
}
}
} }
}
return response()->json(['status' => '200', 'message' => 'success', 'result' => $bancontact_source], 200);
} catch (\Stripe\Exception\CardException $e) {
// Since it's a decline, \Stripe\Exception\CardException will be caught
return redirect()->back()->with('error', $e->getError()->message);
}
}
`
`public function bancontactRedirect(Request $request)
{
$userID = Auth::user()->id;
\Stripe\Stripe::setApiKey(config('services.stripe_secret_key'));
$source = \Stripe\Source::retrieve(
$request->source
);
if ($source->status == 'chargeable' && !empty($source)) {
\Stripe\Stripe::setApiKey(config('services.stripe_secret_key'));
try {
$charge = \Stripe\Charge::create([
"amount" => $source->amount,
"currency" => "eur",
"source" => $source->id,
"description" => "Paiement de "
]);
// Use Stripe's library to make requests...
} catch (\Stripe\Exception\CardException $e) {
session()->forget('OrderId');
// Since it's a decline, \Stripe\Exception\CardException will be caught
// return response()->json(['status'=>'400','message'=>$e->getError()->message],200);
return redirect('/Failed');
}
if ($charge) {
$order = Order::where('id', session()->get('orderId'))->first();
$order->payment_status = 'Success';
$order->order_price = $source->amount / 100;
$order->save();
return redirect()->route('tracker.one', $order)->with('success_message', 'Your payment has been successfully accepted by Bancontact payment method !');
}
} `
`else {
if (session('orderId')) {
$order = Order::where('id', session()->get('orderId'))->first();
if (session('bancontact_success')) {
$order->payment_status = 'Success';
$order->save();
} else {
$order->payment_status = 'Declined';
$order->order_price = 0;
$order->total_tax_amount = 0;
$order->save();
}
}
return redirect()->route('checkout')->with('paymentfailed', 'paymentFailed');
}`
thank you so much for the help ๐
It Aah, it looks like you're using the legacy sources & charges integration, so upon failure you end up creating a new charge to retry. I'd suggest looking at update this to use our newer Payment Intent integration that allows you to confirm the payment intent with authentication support in a single flow, and no need to create another:
https://stripe.com/docs/payments/bancontact/accept-a-payment#create-payment-intent
i'll check that
thank you so much for the help ๐
NP!