latitude-checkout / checkout-plugins-magento2

Latitude Checkout Plugins for Magento 2
Apache License 2.0
0 stars 5 forks source link

Order fails to be created after successful payment #3

Open simonworkhouse opened 2 years ago

simonworkhouse commented 2 years ago

In summary, when a customer was redirected back to the website from Latitude, the controller Latitude\Checkout\Controller\Payment\Complete attempted to verify and create an order. This controller action then called Latitude\Checkout\Model\Adapter\PurchaseVerify::verifyAndCreateOrder which attempted to validate the order using the in-built Magento\Quote\Model\SubmitQuoteValidator and this in turn used Magento\Sales\Model\Order\Address\Validator::validate to process validation for the address. At this point validation failed and an Exception was thrown due to the shipping address being considered invalid as it contained null in the email field. Additionally, after checking the database we were able to see that the quote record also contained null in the customer_email field.

This left the customer with a successful payment in Latitude and without a corresponding order created in Magento.

A null email for a shipping address is a common occurrence in Magento 2 and there are a number of way that can happen, so it's the responsibility of the payment method to handle this and account for it correctly. A point of note is that all other payment modules tested successfully completed transactions that also had shipping addresses with null in the email field, although after the order was created the shipping address did end up having the email field populated. I am not sure if the Magento would consider this to be a responsibility of the payment module or a core Magento bug, but that investigation is beyond the scope of this bug report.

See https://github.com/zipMoney/zip.magento2/blob/32ea759d90d8f29b1100cfe4df5d386b756f2171/Model/Charge.php#L404 for an example of one place where Zip have accounted for this in their Magento 2 module.

An example of one way that this occurs is when a customer has filled in all of their details in the checkout but has not yet paid for the order. The customer then leaves their computer until their cart has expired (e.g: after 24+ hours) and when they come back they are assigned a new quote ID for their cart. If the customer adds products to their cart and then proceeds to the checkout they will find that their email and other address details are already filled in. This is because Magento stores this information in the browser's local storage under (in this case) the mage-cache-storage key. It appears that since the user hasn't had to interact with the email address element, Magento doesn't actually save this data against the quote nor the shipping address. The customer can then proceed through the checkout as normal and when they return from Latitude they are shown an error and no order is created even though a successful payment has been placed in Latitude.

Below is an example of the log output in this scenario:

...
[2022-02-06 07:04:32] Latitude.DEBUG: Latitude\Checkout\Controller\Payment\Complete::execute Begin [] {"magentoVersion":"2.4.3-p1"}
[2022-02-06 07:04:32] Latitude.DEBUG: Latitude\Checkout\Model\Adapter\PurchaseVerify::verifyAndCreateOrder Begin [] {"magentoVersion":"2.4.3-p1"}
[2022-02-06 07:04:32] Latitude.DEBUG: Latitude\Checkout\Model\Adapter\CheckoutService::post Begin [] {"magentoVersion":"2.4.3-p1"}
[2022-02-06 07:04:34] Latitude.INFO: Latitude\Checkout\Model\Adapter\CheckoutService::_handleSuccess {"merchantId":"00041xxxx","isTest":false,"amount":3324,"currency":"AUD","result":"completed","transactionType":"sale","message":"","gatewayReference":"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx","promotionReference":"2006","merchantReference":"15xxxxx","transactionReference":"6cxxxxxxxxxx","storeMid":"00026xxxx"} [] {"magentoVersion":"2.4.3-p1"}
[2022-02-06 07:04:35] Latitude.ERROR: Latitude\Checkout\Model\Adapter\PurchaseVerify::_handleError Failed address validation:
%1 [] {"magentoVersion":"2.4.3-p1"}
[2022-02-06 07:04:35] Latitude.ERROR: Latitude\Checkout\Controller\Payment\Complete::_processError Failed address validation:
%1 [] {"magentoVersion":"2.4.3-p1"}
...
devendra-nationalwala commented 2 years ago

We have been facing the same issue since yesterday. We have received complaint of two customers due to this error.

[2022-02-02 10:53:21] Latitude.DEBUG: Latitude\Checkout\Controller\Payment\Process::_processCapture Processing capture [] {"magentoVersion":"2.4.2"} [2022-02-02 10:53:22] Latitude.DEBUG: Latitude\Checkout\Controller\Payment\Process::_processCapture Guest checkout [] {"magentoVersion":"2.4.2"} [2022-02-02 10:53:22] Latitude.DEBUG: Latitude\Checkout\Controller\Payment\Process::_processCapture cartId:xxxxxxxxxxx quoteId:xxxxxxxxxxx [] {"magentoVersion":"2.4.2"} [2022-02-02 10:53:22] Latitude.INFO: Latitude\Checkout\Controller\Payment\Process::_processCapture Quote saved. Quote id: xxxxxxxxxxx [] {"magentoVersion":"2.4.2"} [2022-02-02 10:57:53] Latitude.DEBUG: Latitude\Checkout\Controller\Payment\Process::_processCapture Processing capture [] {"magentoVersion":"2.4.2"} [2022-02-02 10:57:53] Latitude.DEBUG: Latitude\Checkout\Controller\Payment\Process::_processCapture Guest checkout [] {"magentoVersion":"2.4.2"} [2022-02-02 10:57:53] Latitude.DEBUG: Latitude\Checkout\Controller\Payment\Process::_processCapture cartId:xxxxxxxxxxx quoteId:xxxxxxxxxxx [] {"magentoVersion":"2.4.2"} [2022-02-02 10:57:54] Latitude.INFO: Latitude\Checkout\Controller\Payment\Process::_processCapture Quote saved. Quote id: xxxxxxxxxxx [] {"magentoVersion":"2.4.2"} [2022-02-02 10:59:21] Latitude.DEBUG: Latitude\Checkout\Api\Callback::handle Begin callback with request: {"merchant_id":"xxxxxx","amount":"699.00","currency":"AUD","merchant_reference":"xxxxxxxxxxx","transaction_reference":"xxxxxx","gateway_reference":"xxxxxxxxxxx","promotion_reference":"2012","result":"completed","transaction_type":"sale","test":"false","message":"","timestamp":"14176462010"} [] {"magentoVersion":"2.4.2"} [2022-02-02 10:59:21] Latitude.INFO: Latitude\Checkout\Api\Callback::handle Quote updated with result: completed [] {"magentoVersion":"2.4.2"} [2022-02-02 10:59:22] Latitude.DEBUG: Latitude\Checkout\Controller\Payment\Complete::execute Begin [] {"magentoVersion":"2.4.2"} [2022-02-02 10:59:22] Latitude.ERROR: Latitude\Checkout\Controller\Payment\Complete::_processError Failed address validation: %1 [] {"magentoVersion":"2.4.2"}

lizette-rabuya commented 2 years ago

Hi @devendrant , we have released a new plugin version 1.0.4 to address this issue. Please update to the latest plugin version.

Thanks, Lizette Rabuya Latitude/Gem Finance Technical Support Team