cancel
Showing results for 
Search instead for 
Did you mean: 

Payment Provider Gateway: set Order statuses

SOLVED

Payment Provider Gateway: set Order statuses

Hello,

I am trying to develop an extension based on new Payment Provider Gateway. My service provider, like many, requires redirect to it's page. But the thing is, that it's based on cryptocurrency, so payment itself may take hours. For this reason the payment should be considered complete only after callback is received.

I based extension on sample-module-payment-gateway.

My current order processing logic:

1. Authorise Command Success Handler gets payment page URL from payment service and save it to the AdditionalInformation, than change state of created Transaction to Pending, so Order itself has Payment Review status now:

$payment->setAdditionalInformation('redirect_url', $url);
$payment->setIsTransactionClosed(false);
$payment->setIsTransactionPending(true);


2. After that customer is redirected to the service provider's page with the afterPlaceOrder() method, which gets new URL from Controller, which gets it from AdditionalInformation:

$order = $this->checkoutSession->getLastRealOrder();
$payment = $order->getPayment();
$payment->getAdditionalInformation('redirect_url');


3. When callback received by appropriate Controller method, I call registerAuthorizationNotification and registerCaptureNotification methods to return Order to the Processing status:

$order = $this->orderRepository->get($orderId);
$payment = $order->getPayment();

$payment->registerAuthorizationNotification($amount);
$payment->registerCaptureNotification($amount);


The question is: is it the right way to handle Order statuses or I should implement another approach?

 

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Payment Provider Gateway: set Order statuses

Looks like just changing order statuses don't trigger all necessary events, like creating invoice and update Total Paid value.
So I stop with the

$payment->registerAuthorizationNotification($amount);
$payment->registerCaptureNotification($amount);

 

View solution in original post

4 REPLIES 4

Re: Payment Provider Gateway: set Order statuses

Hello @alebedev

 

Basically, magento custom payment gateway development are mainly depends on payment gateway API, how it work and how it return different value. In your payment gateway you must be handling some error or success URL. So you can also use that controller method to change order status accordingly.

 

Was my answer helpful? You can accept it as a solution.
175+ Professional Extensions for M1 & M2
Need a developer?Just visit Contact Us Now

Re: Payment Provider Gateway: set Order statuses

Hello, @theMageComp

Thank you for reply, but I believe there is some misunderstanding. I'll try to rewrite my question.

 

I need to suspend order to some status while payment is pending and than update order triggering all success payment events.

Can I do it with:

$payment->setIsTransactionClosed(false);
$payment->setIsTransactionPending(true);

and than (after successfull payment):

$payment->registerAuthorizationNotification($amount);
$payment->registerCaptureNotification($amount);

or I should only change order status and state like this:

$order->setState(Order::STATE_PROCESSING, true);
$order->setStatus(Order::STATE_PROCESSING);
$order->addStatusToHistory($order->getStatus(), 'Order processed successfully with reference');
$order->save();

All solutions are seems to work, but I don't know which is correct one.

Re: Payment Provider Gateway: set Order statuses

Hello @alebedev

 

Yes, better way is.

$order->setState(Order::STATE_PROCESSING, true);
$order->setStatus(Order::STATE_PROCESSING);
$order->addStatusToHistory($order->getStatus(), 'Order processed successfully with reference');
$order->save();
Was my answer helpful? You can accept it as a solution.
175+ Professional Extensions for M1 & M2
Need a developer?Just visit Contact Us Now

Re: Payment Provider Gateway: set Order statuses

Looks like just changing order statuses don't trigger all necessary events, like creating invoice and update Total Paid value.
So I stop with the

$payment->registerAuthorizationNotification($amount);
$payment->registerCaptureNotification($amount);