Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added get_order_idempotency_key function #492

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions woocommerce/payment-gateway/class-sv-wc-payment-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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.
Expand Down