Skip to content

Commit

Permalink
Use parent gateway to process payment request buttons from UPE (#2691)
Browse files Browse the repository at this point in the history
  • Loading branch information
bborman22 authored Aug 10, 2021
1 parent 020bbec commit 84fdaeb
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 12 deletions.
3 changes: 3 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
*** WooCommerce Payments Changelog ***

= 2.8.3 - 2021-xx-xx =
* Fix - Fix for payment request buttons when the new payment methods gateway is enabled.

= 2.8.2 - 2021-08-05 =
* Fix - If account is disconnected or not set up do not display onboarding task and UPE inbox note.
* Fix - Fix for the site acting as disconnected after the account cache expires.
Expand Down
8 changes: 4 additions & 4 deletions includes/payment-methods/class-upe-payment-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,13 +302,13 @@ public function create_setup_intent() {
}

/**
* Create and confirm payment intent. Saved payment methods do not follow UPE workflow.
* Create and confirm payment intent. Function used to route any payments that do not use the UPE flow through the parent process payment.
*
* @param int $order_id Order ID to process the payment for.
*
* @return array|null An array with result of payment and redirect URL, or nothing.
*/
public function process_payment_using_saved_method( $order_id ) {
public function parent_process_payment( $order_id ) {
return parent::process_payment( $order_id );
}

Expand Down Expand Up @@ -344,8 +344,8 @@ public function process_payment( $order_id ) {
$selected_upe_payment_type
);
}
} elseif ( $token ) {
return $this->process_payment_using_saved_method( $order_id );
} else {
return $this->parent_process_payment( $order_id );
}

return [
Expand Down
3 changes: 3 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ Please note that our support for the checkout block is still experimental and th

== Changelog ==

= 2.8.3 - 2021-xx-xx =
* Fix - Fix for payment request buttons when the new payment methods gateway is enabled.

= 2.8.2 - 2021-08-05 =
* Fix - If account is disconnected or not set up do not display onboarding task and UPE inbox note.
* Fix - Fix for the site acting as disconnected after the account cache expires.
Expand Down
40 changes: 32 additions & 8 deletions tests/unit/payment-methods/test-class-upe-payment-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public function setUp() {
[
'get_return_url',
'manage_customer_details_for_order',
'process_payment_using_saved_method',
'parent_process_payment',
]
)
->getMock();
Expand All @@ -208,7 +208,7 @@ public function setUp() {
);
$this->mock_upe_gateway
->expects( $this->any() )
->method( 'process_payment_using_saved_method' )
->method( 'parent_process_payment' )
->will(
$this->returnValue( $this->mock_payment_result )
);
Expand Down Expand Up @@ -429,13 +429,16 @@ public function test_create_setup_intent_no_customer() {
}

public function test_process_payment_returns_correct_redirect_url() {
$order = WC_Helper_Order::create_order();
$order_id = $order->get_id();
$order = WC_Helper_Order::create_order();
$order_id = $order->get_id();
$_POST['wc_payment_intent_id'] = 'pi_abc123';

$this->set_cart_contains_subscription_items( false );

$result = $this->mock_upe_gateway->process_payment( $order->get_id() );

unset( $_POST['wc_payment_intent_id'] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing

$this->assertEquals( 'success', $result['result'] );
$this->assertEquals( true, $result['payment_needed'] );
$this->assertRegExp( "/order_id=$order_id/", $result['redirect_url'] );
Expand All @@ -447,15 +450,17 @@ public function test_process_payment_passes_save_payment_method() {
$order = WC_Helper_Order::create_order();
$order_id = $order->get_id();

$gateway_id = UPE_Payment_Gateway::GATEWAY_ID;
$save_payment_param = "wc-$gateway_id-new-payment-method";
$_POST[ $save_payment_param ] = 'yes';
$gateway_id = UPE_Payment_Gateway::GATEWAY_ID;
$save_payment_param = "wc-$gateway_id-new-payment-method";
$_POST[ $save_payment_param ] = 'yes';
$_POST['wc_payment_intent_id'] = 'pi_abc123';

$this->set_cart_contains_subscription_items( false );

$result = $this->mock_upe_gateway->process_payment( $order->get_id() );

unset( $_POST[ $save_payment_param ] );// phpcs:ignore WordPress.Security.NonceVerification.Missing
unset( $_POST[ $save_payment_param ] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
unset( $_POST['wc_payment_intent_id'] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing

$this->assertEquals( 'success', $result['result'] );
$this->assertRegExp( "/order_id=$order_id/", $result['redirect_url'] );
Expand All @@ -470,6 +475,25 @@ public function test_process_payment_returns_correct_redirect_when_using_saved_p
$this->set_cart_contains_subscription_items( false );

$result = $this->mock_upe_gateway->process_payment( $order->get_id() );

$this->mock_upe_gateway
->expects( $this->never() )
->method( 'manage_customer_details_for_order' );
$this->assertEquals( 'success', $result['result'] );
$this->assertRegExp( '/key=mock_order_key/', $result['redirect'] );
}

public function test_process_payment_returns_correct_redirect_when_using_payment_request() {
$order = WC_Helper_Order::create_order();
$_POST['payment_request_type'] = 'google_pay';

$this->set_cart_contains_subscription_items( false );

$result = $this->mock_upe_gateway->process_payment( $order->get_id() );

$this->mock_upe_gateway
->expects( $this->never() )
->method( 'manage_customer_details_for_order' );
$this->assertEquals( 'success', $result['result'] );
$this->assertRegExp( '/key=mock_order_key/', $result['redirect'] );
}
Expand Down

0 comments on commit 84fdaeb

Please sign in to comment.