- forget old ajax wp, now use fetch wp
- trying js files without imports
This commit is contained in:
@@ -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 createOrder() {
|
||||
//export async function createOrder() {
|
||||
async function createOrder() {
|
||||
try {
|
||||
const fetch_create_url = PLGNTLS_data.fetch_url + "/fipf_plugin/api/v1/orders";
|
||||
console.log("fetch_create_url:", fetch_create_url);
|
||||
const response = await fetch(fetch_create_url, {
|
||||
//const fetch_create_url = PLGNTLS_data.fetch_url + "/fipf_plugin/api/v1/orders";
|
||||
//console.log("fetch_create_url:", fetch_create_url);
|
||||
//const response = await fetch(fetch_create_url, {
|
||||
const response = await PLGNTLS_fetch('/fipf_plugin/api/v1/orders', {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"X-WP-Nonce": PLGNTLS_data.rest_nonce,
|
||||
//"X-WP-Nonce": PLGNTLS_data.rest_nonce,
|
||||
},
|
||||
// use the "body" param to optionally pass additional order information
|
||||
// like product ids and quantities
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { createOrder } from './create_order.js';
|
||||
import { onApprove } from './on_approve.js';
|
||||
//import { createOrder } from './create_order.js';
|
||||
//import { onApprove } from './on_approve.js';
|
||||
|
||||
|
||||
window.paypal.Buttons({
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
|
||||
// Example function to show a result to the user. Your site's UI library can be used instead.
|
||||
export function resultMessage(message) {
|
||||
//export function resultMessage(message) {
|
||||
function resultMessage(message) {
|
||||
const container = document.querySelector("#result-message");
|
||||
container.innerHTML = message;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user