mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Add free trial block checkout card support for guest users
This commit is contained in:
parent
19fd6c806d
commit
f3b4a317c8
1 changed files with 25 additions and 15 deletions
|
@ -71,21 +71,31 @@ export async function createVaultSetupToken() {
|
||||||
export async function onApproveSavePayment( { vaultSetupToken } ) {
|
export async function onApproveSavePayment( { vaultSetupToken } ) {
|
||||||
const config = wc.wcSettings.getSetting( 'ppcp-credit-card-gateway_data' );
|
const config = wc.wcSettings.getSetting( 'ppcp-credit-card-gateway_data' );
|
||||||
|
|
||||||
const response = await fetch(
|
let endpoint =
|
||||||
config.scriptData.ajax.create_payment_token.endpoint,
|
config.scriptData.ajax.create_payment_token_for_guest.endpoint;
|
||||||
{
|
let bodyContent = {
|
||||||
method: 'POST',
|
nonce: config.scriptData.ajax.create_payment_token_for_guest.nonce,
|
||||||
credentials: 'same-origin',
|
vault_setup_token: vaultSetupToken,
|
||||||
headers: {
|
};
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
if ( config.scriptData.user.is_logged_in ) {
|
||||||
body: JSON.stringify( {
|
endpoint = config.scriptData.ajax.create_payment_token.endpoint;
|
||||||
nonce: config.scriptData.ajax.create_payment_token.nonce,
|
|
||||||
vault_setup_token: vaultSetupToken,
|
bodyContent = {
|
||||||
is_free_trial_cart: config.scriptData.is_free_trial_cart,
|
nonce: config.scriptData.ajax.create_payment_token.nonce,
|
||||||
} ),
|
vault_setup_token: vaultSetupToken,
|
||||||
}
|
is_free_trial_cart: config.scriptData.is_free_trial_cart,
|
||||||
);
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await fetch( endpoint, {
|
||||||
|
method: 'POST',
|
||||||
|
credentials: 'same-origin',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify( bodyContent ),
|
||||||
|
} );
|
||||||
|
|
||||||
const result = await response.json();
|
const result = await response.json();
|
||||||
if ( result.success !== true ) {
|
if ( result.success !== true ) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue