Skip to content

Commit

Permalink
Improve the displayLoginConfirmation
Browse files Browse the repository at this point in the history
- Updated references from PRB to ECE.
- Updated to handle ECE payment methods.
  • Loading branch information
asumaran committed Jul 4, 2024
1 parent 3298527 commit 1596331
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
37 changes: 26 additions & 11 deletions client/express-checkout/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,27 +119,42 @@ export const getErrorMessageFromNotice = ( notice: string ) => {
return div.firstChild ? div.firstChild.textContent : '';
};

type ExpressPaymentType =
| 'apple_pay'
| 'google_pay'
| 'amazon_pay'
| 'paypal'
| 'link';

/**
* Displays a `confirm` dialog which leads to a redirect.
*
* @param paymentRequestType Can be either apple_pay, google_pay or payment_request_api.
* @param expressPaymentType Can be either 'apple_pay', 'google_pay', 'amazon_pay', 'paypal' or 'link'.
*/
export const displayLoginConfirmation = ( paymentRequestType: string ) => {
export const displayLoginConfirmation = (
expressPaymentType: ExpressPaymentType
) => {
const loginConfirmation = getExpressCheckoutData( 'login_confirmation' );

if ( ! loginConfirmation ) {
return;
}

let message = loginConfirmation.message;

// Replace dialog text with specific payment request type "Apple Pay" or "Google Pay".
if ( paymentRequestType !== 'payment_request_api' ) {
message = message.replace(
/\*\*.*?\*\*/,
paymentRequestType === 'apple_pay' ? 'Apple Pay' : 'Google Pay'
);
}
const paymentTypesMap = {
apple_pay: 'Apple Pay',
google_pay: 'Google Pay',
amazon_pay: 'Amazon Pay',
paypal: 'PayPal',
link: 'Link',
};
let message =
'To complete your transaction with **the selected payment method**, you must log in or create an account with our site.';

// Replace dialog text with specific express checkout type.
message = message.replace(
/\*\*.*?\*\*/,
paymentTypesMap[ expressPaymentType ]
);

// Remove asterisks from string.
message = message.replace( /\*\*/g, '' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ public function ajax_empty_cart() {
* @return void
*/
public function set_session() {
// Don't set session cookies on product pages to allow for caching when payment request
// Don't set session cookies on product pages to allow for caching when express checkout
// buttons are disabled. But keep cookies if there is already an active WC session in place.
if (
! ( $this->express_checkout_button_helper->is_product() && $this->express_checkout_button_helper->should_show_express_checkout_button() )
Expand Down

0 comments on commit 1596331

Please sign in to comment.