idempotency_key increment causing Double charging in case of false error respons
-
The issue:
We have a site using the WooCommerce Square plugin for a payment gateway that utilize the WooCommerce Plugin Framework. The issue appears to happen from 2 parts.1st Issue
When the WooCommerce Square plugin makes a charge request to the Square API it will sometimes return a 500 Internal Server Error as a response when in fact it has charged the card. This leads to the customer seeing and error and repeating the transaction. We have been working with the Square API support team to try and resolve the issue. They have said their partnerships engineer just let me know that WooCommerce contacted them, and stated they were able to troubleshoot the issue. We still do not know is causing the 500 code response, but causes the 2nd issue.2nd Issue
When the user repeats the charge a new “idempotency_key”: is created built from a md5 hash from the sites URL followed by the order ID from woocommerce. This key is regenerated with an incremented number appended to it, meaning that Square views it as a new requests and repeats the charge.Here is an exmaple:
“idempotency_key”: “d40b426b36bc2091a80197f2521b1776:242011” – Original
“idempotency_key”: “d40b426b36bc2091a80197f2521b1776:242011-1” – Repeat ChargeIt looks like in this file:
woocommerce-square/vendor/skyverge/wc-plugin-framework/woocommerce/payment-gateway/class-sv-wc-payment-gateway.phpIn the function
get_order_with_unique_transaction_refthey include the retry count at the end of the key to make it unique for each try.They increment it on every request no matter what. Nothing to check if the previous request was a server error.
This is used to create the “idempotency_key” when the order is created and charged
https://plugins.trac.wordpress.org/browser/woocommerce-square/tags/2.1.0/includes/Gateway/API/Requests/Transactions.php#L78This idempotency_key needs to always be the same to prevent just this from happening so it should be set using a different method.
Please let us know if you need anymore information.
We are also going to post an update request to the https://github.com/skyverge/wc-plugin-framework to potentially add a function to handle this.
The topic ‘idempotency_key increment causing Double charging in case of false error respons’ is closed to new replies.