zipMoney / zip.magento2

Zip Payment Extension for Magento2 that support global zip products
MIT License
4 stars 9 forks source link

Approved payments erroneously cancelled #44

Open simonworkhouse opened 3 years ago

simonworkhouse commented 3 years ago

Approved payments erroneously cancelled

An approved payment will be erroneously cancelled if a user has two tabs open on the Zip pay hosted page and chooses to return to the store in one of those tabs and then completes the payment process in the other tab.

Steps to reproduce

This issue is easiest to replicate using two browser tabs and these steps assume that the user is at the payment step of the checkout.

  1. Select Zip as the payment method and proceed to the Zip hosted payment page.
  2. In a second tab, select Zip again and proceed to the Zip hosted payment page.
  3. In the second tab, click the "Back to Store" link. (Logs indicate a call to /zippayment/complete/?result=cancelled...).
  4. In the first tab, proceed through the payment steps on the Zip hosted payment page.
  5. Upon returning to the store a payment error will be encountered.

After completing the payment and returning to the store, logs will first show a call to /zippayment/complete/?result=approved..., then a charge request is attempted with logged Charge Payload:- {"authority":{... which will receive a 403 with the message Authority request - xxxxxxx is not approved.

Upon receiving the 403, the approved order is then erroneously cancelled and the user is shown a generic error page, which likely states something along the lines of "General Error An error occurred while processing your request.".

The cause

The charge request uses the incorrect Zip checkout ID due to Zip\ZipPayment\Helper\Payload::getAuthority() fetching this from the additional_information field in the quote payment object, which may have changed since the user initially proceeded to the Zip hosted payment page.

This incorrect Zip checkout ID is used in the charge payload and results in an error after which the module cancels the order.

The fix

Either use the checkout ID returned by the Zip hosted payment page instead of fetching it from the quote payment, or alternatively, track multiple payments against a quote instead of assuming that there will be only one.

Example logs

[2021-06-21 10:35:27] zipMoneyLog.INFO: Starting Checkout [] []
[2021-06-21 10:35:27] zipMoneyLog.DEBUG: Checkout Method:- guest [] []
[2021-06-21 10:35:27] zipMoneyLog.DEBUG: Is Allowed Guest Checkout :- 1 [] []
[2021-06-21 10:35:27] zipMoneyLog.DEBUG: Is Customer Logged In :-  [] []
[2021-06-21 10:35:27] zipMoneyLog.DEBUG: Shipping Required:- Yes [] []
[2021-06-21 10:35:27] zipMoneyLog.DEBUG: Gift Card Amount:- 0 [] []
[2021-06-21 10:35:27] zipMoneyLog.DEBUG: 499-0-0-499 [] []
[2021-06-21 10:35:27] zipMoneyLog.DEBUG: Checkout Request:- {"type":"standard","shopper":{"first_name":"Testee","last_name":"Tester","phone":"+61412123123","email":"test@test.com","billing_address":{"line1":"2 Beans St","city":"PERTH","state":"WA","postal_code":"6000","country":"AU","first_name":"Testee","last_name":"Tester"}},"order":{"reference":"67000000078","amount":499,"currency":"AUD","shipping":{"pickup":false,"address":{"line1":"2 Beans St","city":"PERTH","state":"WA","postal_code":"6000","country":"AU","first_name":"Testee","last_name":"Tester"}},"items":[{"name":"Gnarly Bedside","amount":499,"reference":"62263","description":"The Gnarly two-drawer bedside is just gnarly.","quantity":1,"type":"sku","image_uri":"http:\/\/blah.localhost\/static\/version1623719616\/frontend\/Testing\/blah\/en_AU\/Magento_Catalog\/images\/product\/placeholder\/.jpg","item_uri":"http:\/\/blah.localhost\/Gnarly-bedside","product_code":"123363"}],"cart_reference":"265392"},"metadata":{},"config":{"redirect_uri":"http:\/\/blah.localhost\/zippayment\/complete\/"}} [] []
[2021-06-21 10:35:30] zipMoneyLog.DEBUG: Checkout Response:- {"id":"au-co_FZCvATHzEw9VPTxxxxxxxx","uri":"https:\/\/account.sandbox.zipmoney.com.au\/?co=co_FZCvATHzEw9VPTxxxxxxxx&m=6c998223-aaaa-bbbb-cccc-xxxxxxxxxxxxx","type":"standard","shopper":{"first_name":"Testee","last_name":"Tester","phone":"+61412123123","email":"test@test.com","birth_date":"0001-01-01T00:00:00+00:00","gender":"Other","statistics":{"sales_total_count":0,"sales_total_amount":0,"sales_avg_amount":0,"sales_max_amount":0,"refunds_total_amount":0,"previous_chargeback":false,"currency":"AUD"},"billing_address":{"line1":"2 Beans St","city":"PERTH","state":"WA","postal_code":"6000","country":"AU","first_name":"Testee","last_name":"Tester"}},"order":{"reference":"67000000078","amount":499,"currency":"AUD","shipping":{"pickup":false,"address":{"line1":"2 Beans St","city":"PERTH","state":"WA","postal_code":"6000","country":"AU","first_name":"Testee","last_name":"Tester"}},"items":[{"name":"Gnarly Bedside","amount":499,"reference":"62263","description":"The Gnarly two-drawer bedside is just gnarly.","quantity":1,"type":"sku","image_uri":"http:\/\/blah.localhost\/static\/version1623719616\/frontend\/Testing\/blah\/en_AU\/Magento_Catalog\/images\/product\/placeholder\/.jpg","item_uri":"http:\/\/blah.localhost\/Gnarly-bedside","product_code":"123363"}],"cart_reference":"265392"},"config":{"redirect_uri":"http:\/\/blah.localhost\/zippayment\/complete\/"},"created":"2021-06-21T10:35:30+00:00","state":"created","metadata":{}} [] []
[2021-06-21 10:35:30] zipMoneyLog.INFO: Successful to get redirect url [ https://account.sandbox.zipmoney.com.au/?co=co_FZCvATHzEw9VPTxxxxxxxx&m=6c998223-aaaa-bbbb-cccc-xxxxxxxxxxxxx ]  [] []
[2021-06-21 10:36:05] zipMoneyLog.INFO: Starting Checkout [] []
[2021-06-21 10:36:05] zipMoneyLog.DEBUG: Checkout Method:- guest [] []
[2021-06-21 10:36:05] zipMoneyLog.DEBUG: Is Allowed Guest Checkout :- 1 [] []
[2021-06-21 10:36:05] zipMoneyLog.DEBUG: Is Customer Logged In :-  [] []
[2021-06-21 10:36:05] zipMoneyLog.DEBUG: Shipping Required:- Yes [] []
[2021-06-21 10:36:05] zipMoneyLog.DEBUG: Gift Card Amount:- 0 [] []
[2021-06-21 10:36:05] zipMoneyLog.DEBUG: 499-0-0-499 [] []
[2021-06-21 10:36:05] zipMoneyLog.DEBUG: Checkout Request:- {"type":"standard","shopper":{"first_name":"Testee","last_name":"Tester","phone":"+61412123123","email":"test@test.com","billing_address":{"line1":"2 Beans St","city":"PERTH","state":"WA","postal_code":"6000","country":"AU","first_name":"Testee","last_name":"Tester"}},"order":{"reference":"67000000078","amount":499,"currency":"AUD","shipping":{"pickup":false,"address":{"line1":"2 Beans St","city":"PERTH","state":"WA","postal_code":"6000","country":"AU","first_name":"Testee","last_name":"Tester"}},"items":[{"name":"Gnarly Bedside","amount":499,"reference":"62263","description":"The Gnarly two-drawer bedside is just gnarly.","quantity":1,"type":"sku","image_uri":"http:\/\/blah.localhost\/static\/version1623719616\/frontend\/Testing\/blah\/en_AU\/Magento_Catalog\/images\/product\/placeholder\/.jpg","item_uri":"http:\/\/blah.localhost\/Gnarly-bedside","product_code":"123363"}],"cart_reference":"265392"},"metadata":{},"config":{"redirect_uri":"http:\/\/blah.localhost\/zippayment\/complete\/"}} [] []
[2021-06-21 10:36:06] zipMoneyLog.DEBUG: Checkout Response:- {"id":"au-co_qQSg86sBKq291yxxxxxxxx","uri":"https:\/\/account.sandbox.zipmoney.com.au\/?co=co_qQSg86sBKq291yxxxxxxxx&m=6c998223-aaaa-bbbb-cccc-xxxxxxxxxxxxx","type":"standard","shopper":{"first_name":"Testee","last_name":"Tester","phone":"+61412123123","email":"test@test.com","birth_date":"0001-01-01T00:00:00+00:00","gender":"Other","statistics":{"sales_total_count":0,"sales_total_amount":0,"sales_avg_amount":0,"sales_max_amount":0,"refunds_total_amount":0,"previous_chargeback":false,"currency":"AUD"},"billing_address":{"line1":"2 Beans St","city":"PERTH","state":"WA","postal_code":"6000","country":"AU","first_name":"Testee","last_name":"Tester"}},"order":{"reference":"67000000078","amount":499,"currency":"AUD","shipping":{"pickup":false,"address":{"line1":"2 Beans St","city":"PERTH","state":"WA","postal_code":"6000","country":"AU","first_name":"Testee","last_name":"Tester"}},"items":[{"name":"Gnarly Bedside","amount":499,"reference":"62263","description":"The Gnarly two-drawer bedside is just gnarly.","quantity":1,"type":"sku","image_uri":"http:\/\/blah.localhost\/static\/version1623719616\/frontend\/Testing\/blah\/en_AU\/Magento_Catalog\/images\/product\/placeholder\/.jpg","item_uri":"http:\/\/blah.localhost\/Gnarly-bedside","product_code":"123363"}],"cart_reference":"265392"},"config":{"redirect_uri":"http:\/\/blah.localhost\/zippayment\/complete\/"},"created":"2021-06-21T10:36:05+00:00","state":"created","metadata":{}} [] []
[2021-06-21 10:36:06] zipMoneyLog.INFO: Successful to get redirect url [ https://account.sandbox.zipmoney.com.au/?co=co_qQSg86sBKq291yxxxxxxxx&m=6c998223-aaaa-bbbb-cccc-xxxxxxxxxxxxx ]  [] []
[2021-06-21 10:36:47] zipMoneyLog.DEBUG: On Complete Controller [] []
[2021-06-21 10:36:47] zipMoneyLog.DEBUG: /zippayment/complete/?result=cancelled&checkoutId=au-co_qQSg86sBKq291yxxxxxxxx [] []
[2021-06-21 10:36:47] zipMoneyLog.DEBUG: Result:- %s [] []
[2021-06-21 10:36:47] zipMoneyLog.DEBUG: Current Customer Id:- %s Quote Customer Id:- %s Quote checkout method:- %s [] []
[2021-06-21 10:36:47] zipMoneyLog.DEBUG: Calling cancelledAction [] []
[2021-06-21 10:38:48] zipMoneyLog.DEBUG: On Complete Controller [] []
[2021-06-21 10:38:48] zipMoneyLog.DEBUG: /zippayment/complete/?result=approved&checkoutId=au-co_FZCvATHzEw9VPTxxxxxxxx [] []
[2021-06-21 10:38:48] zipMoneyLog.DEBUG: Result:- %s [] []
[2021-06-21 10:38:48] zipMoneyLog.ERROR: Checkout Id does not match with the session quote. [] []
[2021-06-21 10:38:51] zipMoneyLog.INFO: Loading Quote by using zip checkout get api [] []
[2021-06-21 10:38:51] zipMoneyLog.DEBUG: Current Customer Id:- %s Quote Customer Id:- %s Quote checkout method:- %s [] []
[2021-06-21 10:38:52] zipMoneyLog.DEBUG: Quote Grand Total:- 499.0000 Quote Customer Id:-  Checkout Method:- guest [] []
[2021-06-21 10:38:55] zipMoneyLog.INFO: Successfull to place the order [] []
[2021-06-21 10:38:56] zipMoneyLog.DEBUG: Shipping Required:- Yes [] []
[2021-06-21 10:38:56] zipMoneyLog.DEBUG: Gift Card Amount:- 0 [] []
[2021-06-21 10:38:56] zipMoneyLog.DEBUG: 499-0-0-499 [] []
[2021-06-21 10:38:56] zipMoneyLog.DEBUG: Charge Payload:- {"authority":{"type":"checkout_id","value":"au-co_qQSg86sBKq291yxxxxxxxx"},"reference":"67000000078","amount":499,"currency":"AUD","capture":true,"order":{"reference":"67000000078","shipping":{"pickup":false,"address":{"line1":"2 Beans St","city":"PERTH","state":"WA","postal_code":"6000","country":"AU","first_name":"Testee","last_name":"Tester"}},"items":[{"name":"Gnarly Bedside","amount":499,"reference":"4729","description":"The Gnarly two-drawer bedside is just gnarly.","quantity":1,"type":"sku","image_uri":"http:\/\/blah.localhost\/static\/version1623719616\/frontend\/Testing\/blah\/en_AU\/Magento_Catalog\/images\/product\/placeholder\/.jpg","item_uri":"http:\/\/blah.localhost\/Gnarly-bedside","product_code":"123363"}]},"metadata":{}} [] []
[2021-06-21 10:38:59] zipMoneyLog.DEBUG: ApiError:- [403] Error connecting to the API (https://global-api.sand.au.edge.zip.co/merchant/charges)-{"error":{"code":"unauthorised_operation","message":"Authority request - co_qQSg86sBKq291yxxxxxxxx is not approved.  Check that request is not expired or completed."}} [] []
[2021-06-21 10:38:59] zipMoneyLog.DEBUG: Cancelling the order [] []
[2021-06-21 10:38:59] zipMoneyLog.DEBUG: Could not process the payment [] []
[2021-06-21 10:38:59] zipMoneyLog.INFO: In errorAction [] []
[2021-06-21 10:38:59] zipMoneyLog.INFO: An error occurred. [] []
mahbub-zip commented 3 years ago

Hi Simon,

I can't able to replicate the issue. I am able to place the order .please see the below log file.

[2021-06-24 23:19:00] zipMoneyLog.DEBUG: Checkout Method:- guest [] []
[2021-06-24 23:19:00] zipMoneyLog.DEBUG: Is Allowed Guest Checkout :- 1 [] []
[2021-06-24 23:19:00] zipMoneyLog.DEBUG: Is Customer Logged In :-  [] []
[2021-06-24 23:19:00] zipMoneyLog.DEBUG: Shipping Required:- Yes [] []
[2021-06-24 23:19:00] zipMoneyLog.DEBUG: Gift Card Amount:- 0 [] []
[2021-06-24 23:19:00] zipMoneyLog.DEBUG: 5--5-5-5 [] []
[2021-06-24 23:19:00] zipMoneyLog.DEBUG: Checkout Request:- {"type":"standard","shopper":{"first_name":"zip","last_name":"test","phone":"400000","email":"mahbubur.rahman@zip.co","billing_address":{"line1":"10 spring st","city":"sydney","state":"NSW","postal_code":"2000","country":"AU","first_name":"zip","last_name":"test"}},"order":{"reference":"AU141020000000088","amount":5,"currency":"AUD","shipping":{"pickup":false,"address":{"line1":"10 spring st","city":"sydney","state":"NSW","postal_code":"2000","country":"AU","first_name":"zip","last_name":"test"}},"items":[{"name":"Argus All-Weather Tank","amount":5,"reference":"507","quantity":1,"type":"sku","image_uri":"http:\/\/127.0.0.1\/magento240\/pub\/static\/version1623885585\/frontend\/Magento\/luma\/en_AU\/Magento_Catalog\/images\/product\/placeholder\/.jpg","item_uri":"http:\/\/127.0.0.1\/magento240\/default\/argus-all-weather-tank.html","product_code":"MT07-M-Gray"},{"name":"Discount","amount":-5,"reference":"Discount","quantity":1,"type":"discount"},{"name":"Shipping","amount":5,"reference":"Shipping","quantity":1,"type":"shipping"}],"cart_reference":"183"},"metadata":{},"config":{"redirect_uri":"http:\/\/127.0.0.1\/magento240\/default\/zippayment\/complete\/"}} [] []
[2021-06-24 23:19:00] zipMoneyLog.DEBUG: Checkout Response:- {"id":"au-co_W84Xx2fj04zAwqB1VyeCj6","uri":"https:\/\/sandbox.zip.co\/customer\/account-selector?co=co_W84Xx2fj04zAwqB1VyeCj6&m=52ca96a6-3286-4e2e-a085-06918554fc4f","type":"standard","shopper":{"first_name":"zip","last_name":"test","phone":"400000","email":"mahbubur.rahman@zip.co","birth_date":"0001-01-01T00:00:00+00:00","gender":"Other","statistics":{"sales_total_count":0,"sales_total_amount":0,"sales_avg_amount":0,"sales_max_amount":0,"refunds_total_amount":0,"previous_chargeback":false,"currency":"AUD"},"billing_address":{"line1":"10 spring st","city":"sydney","state":"NSW","postal_code":"2000","country":"AU","first_name":"zip","last_name":"test"}},"order":{"reference":"AU141020000000088","amount":5,"currency":"AUD","shipping":{"pickup":false,"address":{"line1":"10 spring st","city":"sydney","state":"NSW","postal_code":"2000","country":"AU","first_name":"zip","last_name":"test"}},"items":[{"name":"Argus All-Weather Tank","amount":5,"reference":"507","quantity":1,"type":"sku","image_uri":"http:\/\/127.0.0.1\/magento240\/pub\/static\/version1623885585\/frontend\/Magento\/luma\/en_AU\/Magento_Catalog\/images\/product\/placeholder\/.jpg","item_uri":"http:\/\/127.0.0.1\/magento240\/default\/argus-all-weather-tank.html","product_code":"MT07-M-Gray"},{"name":"Discount","amount":-5,"reference":"Discount","quantity":1,"type":"discount"},{"name":"Shipping","amount":5,"reference":"Shipping","quantity":1,"type":"shipping"}],"cart_reference":"183"},"config":{"redirect_uri":"http:\/\/127.0.0.1\/magento240\/default\/zippayment\/complete\/"},"created":"2021-06-24T23:19:00+00:00","state":"created","metadata":{}} [] []
[2021-06-24 23:19:00] zipMoneyLog.INFO: Successful to get redirect url [ https://sandbox.zip.co/customer/account-selector?co=co_W84Xx2fj04zAwqB1VyeCj6&m=52ca96a6-3286-4e2e-a085-06918554fc4f ]  [] []
[2021-06-24 23:19:37] zipMoneyLog.INFO: Starting Checkout [] []
[2021-06-24 23:19:37] zipMoneyLog.DEBUG: Checkout Method:- guest [] []
[2021-06-24 23:19:37] zipMoneyLog.DEBUG: Is Allowed Guest Checkout :- 1 [] []
[2021-06-24 23:19:37] zipMoneyLog.DEBUG: Is Customer Logged In :-  [] []
[2021-06-24 23:19:37] zipMoneyLog.DEBUG: Shipping Required:- Yes [] []
[2021-06-24 23:19:37] zipMoneyLog.DEBUG: Gift Card Amount:- 0 [] []
[2021-06-24 23:19:37] zipMoneyLog.DEBUG: 5--5-5-5 [] []
[2021-06-24 23:19:37] zipMoneyLog.DEBUG: Checkout Request:- {"type":"standard","shopper":{"first_name":"zip","last_name":"test","phone":"400000","email":"mahbubur.rahman@zip.co","billing_address":{"line1":"10 spring st","city":"sydney","state":"NSW","postal_code":"2000","country":"AU","first_name":"zip","last_name":"test"}},"order":{"reference":"AU141020000000088","amount":5,"currency":"AUD","shipping":{"pickup":false,"address":{"line1":"10 spring st","city":"sydney","state":"NSW","postal_code":"2000","country":"AU","first_name":"zip","last_name":"test"}},"items":[{"name":"Argus All-Weather Tank","amount":5,"reference":"507","quantity":1,"type":"sku","image_uri":"http:\/\/127.0.0.1\/magento240\/pub\/static\/version1623885585\/frontend\/Magento\/luma\/en_AU\/Magento_Catalog\/images\/product\/placeholder\/.jpg","item_uri":"http:\/\/127.0.0.1\/magento240\/default\/argus-all-weather-tank.html","product_code":"MT07-M-Gray"},{"name":"Discount","amount":-5,"reference":"Discount","quantity":1,"type":"discount"},{"name":"Shipping","amount":5,"reference":"Shipping","quantity":1,"type":"shipping"}],"cart_reference":"183"},"metadata":{},"config":{"redirect_uri":"http:\/\/127.0.0.1\/magento240\/default\/zippayment\/complete\/"}} [] []
[2021-06-24 23:19:38] zipMoneyLog.DEBUG: Checkout Response:- {"id":"au-co_E7Q0mwyWFo5A0JPcG6lF24","uri":"https:\/\/sandbox.zip.co\/customer\/account-selector?co=co_E7Q0mwyWFo5A0JPcG6lF24&m=52ca96a6-3286-4e2e-a085-06918554fc4f","type":"standard","shopper":{"first_name":"zip","last_name":"test","phone":"400000","email":"mahbubur.rahman@zip.co","birth_date":"0001-01-01T00:00:00+00:00","gender":"Other","statistics":{"sales_total_count":0,"sales_total_amount":0,"sales_avg_amount":0,"sales_max_amount":0,"refunds_total_amount":0,"previous_chargeback":false,"currency":"AUD"},"billing_address":{"line1":"10 spring st","city":"sydney","state":"NSW","postal_code":"2000","country":"AU","first_name":"zip","last_name":"test"}},"order":{"reference":"AU141020000000088","amount":5,"currency":"AUD","shipping":{"pickup":false,"address":{"line1":"10 spring st","city":"sydney","state":"NSW","postal_code":"2000","country":"AU","first_name":"zip","last_name":"test"}},"items":[{"name":"Argus All-Weather Tank","amount":5,"reference":"507","quantity":1,"type":"sku","image_uri":"http:\/\/127.0.0.1\/magento240\/pub\/static\/version1623885585\/frontend\/Magento\/luma\/en_AU\/Magento_Catalog\/images\/product\/placeholder\/.jpg","item_uri":"http:\/\/127.0.0.1\/magento240\/default\/argus-all-weather-tank.html","product_code":"MT07-M-Gray"},{"name":"Discount","amount":-5,"reference":"Discount","quantity":1,"type":"discount"},{"name":"Shipping","amount":5,"reference":"Shipping","quantity":1,"type":"shipping"}],"cart_reference":"183"},"config":{"redirect_uri":"http:\/\/127.0.0.1\/magento240\/default\/zippayment\/complete\/"},"created":"2021-06-24T23:19:38+00:00","state":"created","metadata":{}} [] []
[2021-06-24 23:19:38] zipMoneyLog.INFO: Successful to get redirect url [ https://sandbox.zip.co/customer/account-selector?co=co_E7Q0mwyWFo5A0JPcG6lF24&m=52ca96a6-3286-4e2e-a085-06918554fc4f ]  [] []
[2021-06-24 23:19:48] zipMoneyLog.DEBUG: On Complete Controller [] []
[2021-06-24 23:19:48] zipMoneyLog.DEBUG: /magento240/default/zippayment/complete/?result=cancelled&checkoutId=au-co_E7Q0mwyWFo5A0JPcG6lF24 [] []
[2021-06-24 23:19:48] zipMoneyLog.DEBUG: Result:- %s [] []
[2021-06-24 23:19:48] zipMoneyLog.DEBUG: Current Customer Id:- %s Quote Customer Id:- %s Quote checkout method:- %s [] []
[2021-06-24 23:19:48] zipMoneyLog.DEBUG: Calling cancelledAction [] []
[2021-06-24 23:20:00] zipMoneyLog.DEBUG: On Complete Controller [] []
[2021-06-24 23:20:00] zipMoneyLog.DEBUG: /magento240/default/zippayment/complete/?result=approved&checkoutId=au-co_E7Q0mwyWFo5A0JPcG6lF24 [] []
[2021-06-24 23:20:00] zipMoneyLog.DEBUG: Result:- %s [] []
[2021-06-24 23:20:00] zipMoneyLog.DEBUG: Current Customer Id:- %s Quote Customer Id:- %s Quote checkout method:- %s [] []
[2021-06-24 23:20:01] zipMoneyLog.DEBUG: Quote Grand Total:- 5.0000 Quote Customer Id:-  Checkout Method:- guest [] []
[2021-06-24 23:20:06] zipMoneyLog.INFO: Successfull to place the order [] []
[2021-06-24 23:20:06] zipMoneyLog.DEBUG: Shipping Required:- Yes [] []
[2021-06-24 23:20:06] zipMoneyLog.DEBUG: Gift Card Amount:- 0 [] []
[2021-06-24 23:20:06] zipMoneyLog.DEBUG: 5--5-5-5 [] []
[2021-06-24 23:20:06] zipMoneyLog.DEBUG: Charge Payload:- {"authority":{"type":"checkout_id","value":"au-co_E7Q0mwyWFo5A0JPcG6lF24"},"reference":"AU141020000000088","amount":5,"currency":"AUD","capture":true,"order":{"reference":"AU141020000000088","shipping":{"pickup":false,"address":{"line1":"10 spring st","city":"sydney","state":"NSW","postal_code":"2000","country":"AU","first_name":"zip","last_name":"test"}},"items":[{"name":"Argus All-Weather Tank","amount":5,"reference":"379","quantity":1,"type":"sku","image_uri":"http:\/\/127.0.0.1\/magento240\/pub\/static\/version1623885585\/frontend\/Magento\/luma\/en_AU\/Magento_Catalog\/images\/product\/placeholder\/.jpg","item_uri":"http:\/\/127.0.0.1\/magento240\/default\/argus-all-weather-tank.html","product_code":"MT07-M-Gray"},{"name":"Discount","amount":-5,"reference":"Discount","quantity":1,"type":"discount"},{"name":"Shipping","amount":5,"reference":"Shipping","quantity":1,"type":"shipping"}]},"metadata":{}} [] []
[2021-06-24 23:20:08] zipMoneyLog.DEBUG: Charge Response:- {"id":"au-ch_zfYW3cheLgVIVyyORD4322","reference":"AU141020000000088","amount":5,"currency":"AUD","state":"captured","captured_amount":5,"refunded_amount":0,"created_date":"2021-06-24T23:20:07+00:00","order":{"reference":"AU141020000000088","shipping":{"pickup":false,"address":{"line1":"10 spring st","city":"sydney","state":"NSW","postal_code":"2000","country":"AU","first_name":"zip","last_name":"test"}},"items":[{"name":"Argus All-Weather Tank","amount":5,"reference":"379","quantity":1,"type":"sku","image_uri":"http:\/\/127.0.0.1\/magento240\/pub\/static\/version1623885585\/frontend\/Magento\/luma\/en_AU\/Magento_Catalog\/images\/product\/placeholder\/.jpg","item_uri":"http:\/\/127.0.0.1\/magento240\/default\/argus-all-weather-tank.html","product_code":"MT07-M-Gray"},{"name":"Discount","amount":-5,"reference":"Discount","quantity":1,"type":"discount"},{"name":"Shipping","amount":5,"reference":"Shipping","quantity":1,"type":"shipping"}],"cart_reference":"183"},"metadata":[],"receipt_number":"1882879"} [] []
[2021-06-24 23:20:08] zipMoneyLog.DEBUG: Charge State:- captured [] []
[2021-06-24 23:20:08] zipMoneyLog.INFO: Payment Captured [] []
[2021-06-24 23:20:08] zipMoneyLog.DEBUG: Order captured setting order state: processing status: processing [] []
simonworkhouse commented 3 years ago

@mahbub-zip It seems that you processed a payment for the same checkout ID that you cancelled. You need to cancel the one checkout and process the other.

Your logs show these two requests with the same checkout ID

/magento240/default/zippayment/complete/?result=cancelled&checkoutId=au-co_E7Q0mwyWFo5A0JPcG6lF24
/magento240/default/zippayment/complete/?result=approved&checkoutId=au-co_E7Q0mwyWFo5A0JPcG6lF24 [] []

Whereas my logs showed the two different checkout IDs

/zippayment/complete/?result=cancelled&checkoutId=au-co_qQSg86sBKq291yxxxxxxxx [] []
/zippayment/complete/?result=approved&checkoutId=au-co_FZCvATHzEw9VPTxxxxxxxx [] []
mahbub-zip commented 3 years ago

@simonworkhouse yes i can see the same checkout id for cancelled and approved. But whatever steps you mentioned i have followed those steps. please have a look on the below video link

https://user-images.githubusercontent.com/62676065/123365590-e3a77280-d5b9-11eb-99f3-cacfadac3e76.mp4

simonworkhouse commented 3 years ago

@mahbub-zip That's an incomplete video of the process, and your logs indicate that it's fetching the same checkout ID from the database as what's in the request parameters. In our logs we received Checkout Id does not match with the session quote..

Which branch are you running these tests on?

mahbub-zip commented 3 years ago

Using master branch. I followed same steps whatever you mentioned. I attached another video.

https://user-images.githubusercontent.com/62676065/123373307-86ff8400-d5c8-11eb-8ff1-7b54b91f3a3d.mp4

simonworkhouse commented 3 years ago

@mahbub-zip It would be helpful to have the logs tailed at the same time as that order was being placed, but probably not necessary as I think that I may be able to guess what the issue is based on the previous logs that you supplied.

As I highlighted previously, your logs indicate that the cancelled order checkout ID is what's provided in the redirect query parameters:

/magento240/default/zippayment/complete/?result=cancelled&checkoutId=au-co_E7Q0mwyWFo5A0JPcG6lF24
/magento240/default/zippayment/complete/?result=approved&checkoutId=au-co_E7Q0mwyWFo5A0JPcG6lF24 [] []

This leads to the question as to why you are being redirected back to Magento with a different checkout ID (co_E7Q0mwyWFo5A0JPcG6lF24) than the one that was used in the hosted payment page URL (https://sandbox.zip.co/customer/account-selector?co=co_W84Xx2fj04zAwqB1VyeCj6&m=52ca96a6-3286-4e2e-a085-06918554fc4f).

My guess is that it's due to the fact that you are already logged in to your Zip account, so retry all tests in an incognito/private session and only log in once you are about to process the payment.

This is just a guess, but if it's incorrect, then we would need to determine why the redirect back to Magento uses the incorrect checkout ID.

mahbub-zip commented 3 years ago

@simonworkhouse I have checked this in an incognito. I cannot replicate the issue. Before redirect to merchant from zip, zip can able to map with latest checkout id. When it is redirect to merchant that time URL has the latest checkout id. In this video i am not showing login process for security reason. I believe this video make you more clear.

https://user-images.githubusercontent.com/62676065/123391362-495a2580-d5df-11eb-83eb-5e92be658bc4.mp4

simonworkhouse commented 3 years ago

@mahbub-zip What mechanism is Zip supposedly using to map the user to the latest checkout ID? Session based? Mapped by order reference? Linked to a Zip account? Or something else? You can clearly see from the logs that I have provided that we are not being redirected to the latest checkout ID. Is there a setting on a merchant account that prevents cancelled orders from being approved?

Regardless of this mechanism, the module requires a fix to address situations where multiple payments have been created for an order.

mahbub-zip commented 3 years ago

@simonworkhouse could you please apply this https://github.com/zipMoney/zip.magento2/pull/45/files change on top our latest plugin and let me know is this resolve the issue?

simonworkhouse commented 3 years ago

I am attempting to perform some tests, but it appears that your sandbox is experiencing intermittent outages. image

I'll keep trying over the course of the day, but you'll have to forgive me if it takes me some time to complete testing.

simonworkhouse commented 3 years ago

@mahbub-zip Yes, that fix does appear to resolve the issue. However; it still doesn't necessarily handle multiple checkout IDs/payments in the ideal way.

Swiftless commented 2 years ago

@simonworkhouse and @mahbub-zip I am having an identical issue but something I noticed isn't being discussed is the failed requests to the Zip API right before the order is cancelled (your logs are the same as mine in this regard).

All our cases are identical with the logs looking like:

  1. Charge Payload
  2. ApiError
  3. Cancelling the order
  4. Could not process the pyament
  5. In errorAction
  6. An error occured
[2021-10-11 09:07:00] zipMoneyLog.DEBUG: ApiError:- [400] Error connecting to the API  (https://global-api.prod.au.edge.zip.co/merchant/charges) ...
[2021-10-11 09:07:00] zipMoneyLog.DEBUG: Cancelling the order [] []
[2021-10-11 09:07:03] zipMoneyLog.DEBUG: Could not process the payment [] []
[2021-10-11 09:07:04] zipMoneyLog.INFO: In errorAction [] []
[2021-10-11 09:07:04] zipMoneyLog.INFO: An error occurred. [] []

[2021-10-12 05:33:41] zipMoneyLog.DEBUG: ApiError:- [400] Error connecting to the API  (https://global-api.prod.au.edge.zip.co/merchant/charges) ...
[2021-10-12 05:33:41] zipMoneyLog.DEBUG: Cancelling the order [] []
[2021-10-12 05:33:42] zipMoneyLog.DEBUG: Could not process the payment [] []
[2021-10-12 05:33:44] zipMoneyLog.INFO: In errorAction [] []
[2021-10-12 05:33:44] zipMoneyLog.INFO: An error occurred. [] []

[2021-10-14 02:15:51] zipMoneyLog.DEBUG: ApiError:- [400] Error connecting to the API  (https://global-api.prod.au.edge.zip.co/merchant/charges) ...
...

[2021-10-14 12:26:41] zipMoneyLog.DEBUG: Error:- [500] Error connecting to the API  (https://global-api.prod.au.edge.zip.co/merchant/charges) ...
...

Does the extension need a way to handle these errors, possibly with some retry logic instead of simply canceling the order?

Swiftless commented 2 years ago

@mahbub-zip as per my comment above - this issue happened again today even after applying the suggested code change above. It happens rarely but it still happens.

Any idea? You never replied to my comment above.

mahbub-zip commented 2 years ago

Hey @Swiftless , Do you have staging site where same issue is happening? is it possible to send me the staging website url then i can have a look? Thanks