diff --git a/woocommerce/payment-gateway/class-sv-wc-payment-gateway.php b/woocommerce/payment-gateway/class-sv-wc-payment-gateway.php index 75e14a5c3..c862d0b71 100755 --- a/woocommerce/payment-gateway/class-sv-wc-payment-gateway.php +++ b/woocommerce/payment-gateway/class-sv-wc-payment-gateway.php @@ -1699,6 +1699,7 @@ public function get_payment_method_image_url( $type ) { * $order->payment->type - one of 'credit_card' or 'check' * $order->description - an order description based on the order * $order->unique_transaction_ref - a combination of order number + retry count, should provide a unique value for each transaction attempt + * $order->idempotency_key - a combination of order number, should provide a unique value for each transaction * * Note that not all gateways will necessarily pass or require all of the * above. These represent the most common attributes used among a variety @@ -1738,6 +1739,8 @@ public function get_order( $order ) { $order = $this->get_order_with_unique_transaction_ref( $order ); + $order = $this->get_order_idempotency_key( $order ); + /** * Filters the base order for a payment transaction. * @@ -2386,6 +2389,21 @@ protected function get_order_with_unique_transaction_ref( $order ) { return $order; } + /** + * Returns the $order object with a unique transaction ref member added. + * + * @since 2.2.0 + * + * @param \WC_Order $order the order object + * @return \WC_Order order object with member named idempotency_key + */ + protected function get_order_idempotency_key( $order ) { + + // generate a unique transaction ref based on the WordPress Sites URL and order order number, for gateways to process the requested operation only once successfully. + $order->idempotency_key = crc32( get_site_url() ) . $order->get_order_number(); + + return $order; + } /** * Called after an unsuccessful transaction attempt.