Skip to content

Commit 1fd463d

Browse files
authored
Provide return URL with platform init request (#5315)
1 parent 73def4c commit 1fd463d

File tree

4 files changed

+10
-1
lines changed

4 files changed

+10
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Significance: patch
2+
Type: add
3+
Comment: The change is for a feature that is not generally available at this moment
4+
5+

client/checkout/api/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,7 @@ export default class WCPayAPI {
662662
_wpnonce: nonce,
663663
email: userEmail,
664664
user_session: platformCheckoutUserSession,
665+
return_url: window?.location?.href ?? '',
665666
}
666667
);
667668
}

client/checkout/api/test/index.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ describe( 'WCPayAPI', () => {
2525
expect( request ).toHaveBeenLastCalledWith( 'https://example.org/', {
2626
_wpnonce: 'foo',
2727
28+
return_url: 'http://localhost/',
2829
user_session: 'qwerty123',
2930
} );
3031
} );

includes/class-wc-payments.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1088,8 +1088,9 @@ public static function ajax_init_platform_checkout() {
10881088

10891089
$session_cookie_name = apply_filters( 'woocommerce_cookie', 'wp_woocommerce_session_' . COOKIEHASH );
10901090

1091-
$email = ! empty( $_POST['email'] ) ? wc_clean( wp_unslash( $_POST['email'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification
1091+
$email = ! empty( $_POST['email'] ) ? wc_clean( wp_unslash( $_POST['email'] ) ) : '';
10921092
$user = wp_get_current_user();
1093+
$return_url = ! empty( $_POST['return_url'] ) ? wc_clean( wp_unslash( $_POST['return_url'] ) ) : '';
10931094
$customer_id = self::$customer_service->get_customer_id_by_user_id( $user->ID );
10941095
if ( null === $customer_id ) {
10951096
// create customer.
@@ -1127,6 +1128,7 @@ public static function ajax_init_platform_checkout() {
11271128
'is_subscriptions_plugin_active' => self::get_gateway()->is_subscriptions_plugin_active(),
11281129
'woocommerce_tax_display_cart' => get_option( 'woocommerce_tax_display_cart' ),
11291130
'ship_to_billing_address_only' => wc_ship_to_billing_address_only(),
1131+
'return_url' => $return_url,
11301132
],
11311133
'user_session' => isset( $_REQUEST['user_session'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['user_session'] ) ) : null,
11321134
];

0 commit comments

Comments
 (0)