- forget old ajax wp, now use fetch wp

- trying js files without imports
This commit is contained in:
asus
2024-02-26 13:18:19 +01:00
parent 5794e4cafe
commit 0177531924
11 changed files with 65 additions and 42 deletions

View File

@@ -1,18 +1,20 @@
import { resultMessage } from './result_message.js';
//import { resultMessage } from './result_message.js';
/**
* @see https://developer.paypal.com/docs/checkout/standard/integrate/#link-integratebackend
*/
export async function onApprove(data, actions) {
//export async function onApprove(data, actions) {
async function onApprove(data, actions) {
try {
const fetch_approve_url = PLGNTLS_data.fetch_url + "/fipf_plugin/api/v1/orders/" + data.orderID + "/capture";
console.log("fetch_approve_url:", fetch_approve_url);
const response = await fetch(fetch_approve_url, {
//const response = await fetch(fetch_approve_url, {
const response = await PLGNTLS_fetch('/fipf_plugin/api/v1/orders/' + data.orderID + '/capture', {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-WP-Nonce": PLGNTLS_data.rest_nonce,
//"X-WP-Nonce": PLGNTLS_data.rest_nonce,
},
});
@@ -39,14 +41,14 @@ export async function onApprove(data, actions) {
const transaction =
orderData?.purchase_units?.[0]?.payments?.captures?.[0] ||
orderData?.purchase_units?.[0]?.payments?.authorizations?.[0];
resultMessage(
`Transaction ${transaction.status}: ${transaction.id}<br><br>See console for all available details`,
);
// to show a message on page
//resultMessage(`Transaction ${transaction.status}: ${transaction.id}<br><br>See console for all available details`,);
console.log(
"Capture result",
orderData,
JSON.stringify(orderData, null, 2),
);
actions.redirect('https://local_fipfcard_plugin.com/');
}
} catch (error) {
console.error(error);