Add payment token for guest free trial subscription (WIP)

This commit is contained in:
Emili Castells Guasch 2024-04-09 17:34:51 +02:00
parent 636541c6c1
commit 197e70607a
7 changed files with 161 additions and 7 deletions

View file

@ -167,22 +167,21 @@ class CheckoutActionHandler {
console.error(result)
},
onApprove: async ({vaultSetupToken}) => {
const response = await fetch(this.config.ajax.create_payment_token.endpoint, {
const response = await fetch(this.config.ajax.create_payment_token_for_guest.endpoint, {
method: "POST",
credentials: 'same-origin',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
nonce: this.config.ajax.create_payment_token.nonce,
nonce: this.config.ajax.create_payment_token_for_guest.nonce,
vault_setup_token: vaultSetupToken,
return_url: location.href,
})
})
const result = await response.json();
if (result.success === true) {
window.location.href = location.href;
document.querySelector('#place_order').click()
return;
}