Reputation: 2220
Good day all. I'm developing a payment module on Prestashop 1.7. the payment process is external, and before the redirection I had to make a POST on their server in order to create a token, then redirect to them and "wait" for the user to come back on the store.
I'm trying to figure out the best approach to this and the correct loop to be done with cart and order.
1) the user arrive on the checkout page (he has a cart, but not an order)
2) the user choose the payment method.
3) upon clicking the button, the user is sent to the "preparation" controller (still has a cart and no order)
4) the front controller called "preparation" will execute a POST to the payment gateway, and with the response, will redirect the user to their gateway (and I will pass them a "returnUrl" that point to my "confirmation" controller).
5) the user is on their gateway, he will do some gateway things.
6) the user is sent back to Prestashop, on the returnUrl I had given before, some data will be attached to this.
7) here it is my concern: to confirm the order, I have to redirect the user to:
Tools::redirect('index.php?controller=order-confirmation&id_cart='.$cart->id.'&id_module='.$this->module->id.'&id_order='.$this->module->currentOrder.'&key='.$customer->secure_key);
but actually I don't have a "id_order" right? I didn't confirmed the cart and trasfromed it into an order yet... right?
Do I have to make a:
$this->module->validateOrder($cart->id, Configuration::get('PS_OS_BANKWIRE'), $total, $this->module->displayName, NULL, $mailVars, (int)$currency->id, false, $customer->secure_key);
before redirecting the user to the order-confirmation? is all of this true, or I didn't understand nothing about the transformation of the cart into an order?
thanks in advance.
Upvotes: 1
Views: 1539
Reputation: 4337
Yes you have to call validateOrder()
method to transform cart into order.
On step 4 you pass a redirectUrl
to your own controller in shop which will validate an order and then redirect to success page.
One thing you have to be careful about is cart manipulation while the user is on payment gateway page. When a user is redirected to payment gateway, the cart is still active and he can open the shop in another tab and manipulate his cart (add, remove, choose different shipping etc.) and then click Pay
button on the gateway page, so before redirecting the user to the payment gateway, make sure you store cart total value in your custom table and before you validate an order, make sure that the amount is the same or I think Prestashop will do that for you in validateOrder()
by comparing cart amount and paid amount and set the Payment error
status on the order if the amounts don't match (It's been a while since I touched prestashop so I'm not sure).
Upvotes: 2