Add card payment token for free trial subscriptions (WIP)

This commit is contained in:
Emili Castells Guasch 2024-07-24 16:00:55 +02:00
parent 112b98875b
commit efbd36025d
5 changed files with 134 additions and 6 deletions

View file

@ -108,6 +108,8 @@ class Configuration {
);
},
onApprove: async ( { vaultSetupToken } ) => {
const isFreeTrialCart =
this.ppcp_add_payment_method?.is_free_trial_cart ?? false;
const response = await fetch(
this.ppcp_add_payment_method.ajax.create_payment_token
.endpoint,
@ -122,12 +124,19 @@ class Configuration {
.create_payment_token.nonce,
vault_setup_token: vaultSetupToken,
payment_method: PaymentMethods.CARDS,
is_free_trial_cart: isFreeTrialCart,
} ),
}
);
const result = await response.json();
if ( result.success === true ) {
const context = this.ppcp_add_payment_method?.context ?? '';
if ( context === 'checkout' ) {
document.querySelector( '#place_order' ).click();
return;
}
if (
this.ppcp_add_payment_method
.is_subscription_change_payment_page