2024-05-20 18:46:44 +02:00
|
|
|
export async function createOrder() {
|
2024-06-22 12:32:36 +02:00
|
|
|
const config = wc.wcSettings.getSetting('ppcp-credit-card-gateway_data');
|
|
|
|
|
2024-05-20 18:46:44 +02:00
|
|
|
return fetch(config.scriptData.ajax.create_order.endpoint, {
|
|
|
|
method: "POST",
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
},
|
|
|
|
body: JSON.stringify({
|
|
|
|
nonce: config.scriptData.ajax.create_order.nonce,
|
|
|
|
context: config.scriptData.context,
|
|
|
|
payment_method: 'ppcp-credit-card-gateway',
|
2024-05-22 15:52:45 +02:00
|
|
|
save_payment_method: localStorage.getItem('ppcp-save-card-payment') === 'true',
|
2024-05-20 18:46:44 +02:00
|
|
|
}),
|
|
|
|
})
|
|
|
|
.then((response) => response.json())
|
|
|
|
.then((order) => {
|
|
|
|
return order.data.id;
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
console.error(err);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-06-03 11:29:04 +02:00
|
|
|
export async function onApprove(data) {
|
2024-06-22 12:32:36 +02:00
|
|
|
const config = wc.wcSettings.getSetting('ppcp-credit-card-gateway_data');
|
|
|
|
|
2024-06-03 11:29:04 +02:00
|
|
|
return fetch(config.scriptData.ajax.approve_order.endpoint, {
|
2024-05-20 18:46:44 +02:00
|
|
|
method: "POST",
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
},
|
|
|
|
body: JSON.stringify({
|
|
|
|
order_id: data.orderID,
|
|
|
|
nonce: config.scriptData.ajax.approve_order.nonce,
|
|
|
|
}),
|
|
|
|
})
|
|
|
|
.then((response) => response.json())
|
|
|
|
.then((data) => {
|
2024-05-22 15:52:45 +02:00
|
|
|
localStorage.removeItem('ppcp-save-card-payment');
|
2024-05-20 18:46:44 +02:00
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
console.error(err);
|
|
|
|
});
|
|
|
|
}
|