Add save card payment for changing subscription payment method (WIP)

This commit is contained in:
Emili Castells Guasch 2024-01-08 17:47:52 +01:00
parent f081fc2392
commit 0262c28580
7 changed files with 149 additions and 19 deletions

View file

@ -128,6 +128,33 @@ document.addEventListener(
const result = await response.json();
if(result.success === true) {
if(ppcp_add_payment_method.is_subscription_change_payment_page) {
const subscriptionId = ppcp_add_payment_method.subscription_id_to_change_payment;
if(subscriptionId && result.data) {
const req = await fetch(ppcp_add_payment_method.ajax.subscription_change_payment_method.endpoint, {
method: "POST",
credentials: 'same-origin',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
nonce: ppcp_add_payment_method.ajax.subscription_change_payment_method.nonce,
subscription_id: subscriptionId,
payment_method: getCurrentPaymentMethod(),
wc_payment_token_id: result.data
})
});
const res = await req.json();
if (res.success === true) {
window.location.href = `${ppcp_add_payment_method.view_subscriptions_page}/${subscriptionId}`;
return;
}
}
return;
}
window.location.href = ppcp_add_payment_method.payment_methods_page;
return;
}