Skip to content

Commit

Permalink
fix: resolve merge conflicts with #1234
Browse files Browse the repository at this point in the history
  • Loading branch information
dkoo committed Aug 12, 2022
1 parent fbc94d9 commit 15fe247
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
20 changes: 18 additions & 2 deletions src/blocks/donate/streamlined/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,19 @@ export const processStreamlinedElements = ( parentElement = document ) =>
const enableForm = () => el.classList.remove( 'stripe-payment--disabled' );
enableForm();

const getCaptchaToken = async reCaptchaKey => {
// Display CC UI.
const displayCardUI = () => {
if ( isCardUIVisible ) {
return;
}
const inputsHiddenEl = el.querySelector( '.stripe-payment__inputs.stripe-payment--hidden' );
if ( inputsHiddenEl ) {
inputsHiddenEl.classList.remove( 'stripe-payment--hidden' );
isCardUIVisible = true;
}
};

const getCaptchaToken = async ( reCaptchaKey: string ) => {
return new Promise( ( res, rej ) => {
const { grecaptcha } = window;

Expand Down Expand Up @@ -72,6 +84,10 @@ export const processStreamlinedElements = ( parentElement = document ) =>
*/
requestPayloadOverrides = {}
) => {
if ( ! stripe ) {
return;
}

// Add reCaptcha challenge to form submission, if available.
const reCaptchaKey = settings?.captchaSiteKey;
let reCaptchaToken;
Expand All @@ -87,7 +103,7 @@ export const processStreamlinedElements = ( parentElement = document ) =>
return { error: true };
}
}
const formValues = utils.getFormValues( formElement );
const formValues = utils.getDonationFormValues( formElement );
const apiRequestPayload = {
captchaToken: reCaptchaToken,
tokenData: token,
Expand Down
10 changes: 7 additions & 3 deletions src/blocks/donate/streamlined/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ export const renderMessages = (
} );

if ( 'success' === type ) {
el.parentElement.replaceWith( el );
if ( el.parentElement ) {
el.parentElement.replaceWith( el );
}
}
};

Expand Down Expand Up @@ -74,8 +76,9 @@ export const getSettings = ( formElement: HTMLFormElement ) => {
feeMultiplier,
feeStatic,
stripePublishableKey,
paymentRequestType,
captchaSiteKey,
] = JSON.parse( formElement.getAttribute( 'data-settings' ) );
] = JSON.parse( settings );
return {
currency: currency.toLowerCase(),
currencySymbol,
Expand All @@ -86,6 +89,7 @@ export const getSettings = ( formElement: HTMLFormElement ) => {
feeMultiplier: parseFloat( feeMultiplier ),
feeStatic: parseFloat( feeStatic ),
stripePublishableKey,
paymentRequestType,
captchaSiteKey,
};
};
Expand Down Expand Up @@ -188,7 +192,7 @@ export const sendAPIRequest = async ( endpoint: string, data: object, method = '
return { error: responseData };
} );

export const renderSuccessMessageWithEmail = ( emailAddress, messagesEl ) => {
export const renderSuccessMessageWithEmail = ( emailAddress: string, messagesEl: HTMLElement ) => {
const successMessage = sprintf(
/* Translators: %s is the email address of the current user. */
__(
Expand Down
5 changes: 3 additions & 2 deletions src/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ declare global {
assets_path: string;
is_rendering_streamlined_block?: boolean;
};
grecaptcha: any
}

type PostId = number;
Expand All @@ -28,7 +29,7 @@ declare global {
clientId: string;
attributes: {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[ key: string ]: any;
[key: string]: any;
};
innerBlocks: Block[];
};
Expand All @@ -38,4 +39,4 @@ declare global {
};
}

export {};
export { };

0 comments on commit 15fe247

Please sign in to comment.