Kepar
Kepar
Explore posts from servers
DDeno
Created by Kepar on 10/16/2023 in #help
Help Web.js
rq need help in web.js \
window.paypal
.Buttons({
style: {
shape: "rect",
layout: "vertical",
},
async createOrder() {
try {
const userid = document.querySelector('script[data-userid]').getAttribute('data-userid'); // Access the data attribute

const response = await fetch("/api/orders", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
cart: [
{
id: "1800 Koonies",
quantity: "1",
price: "10",
userid: userid, // Use the userid variable
},
],
}),
});

const orderData = await response.json();

if (orderData.id) {
return orderData.id;
} else {
const errorDetail = orderData?.details?.[0];
const errorMessage = errorDetail
? `${errorDetail.issue} ${errorDetail.description} (${orderData.debug_id})`
: JSON.stringify(orderData);

throw new Error(errorMessage);
}
} catch (error) {
console.error(error);
resultMessage(`Could not initiate PayPal Checkout...<br><br>${error}`);
}
},
async onApprove(data, actions) {
try {
const response = await fetch(`/api/orders/${data.orderID}/capture/${userid}`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
});
# rest of the code...
window.paypal
.Buttons({
style: {
shape: "rect",
layout: "vertical",
},
async createOrder() {
try {
const userid = document.querySelector('script[data-userid]').getAttribute('data-userid'); // Access the data attribute

const response = await fetch("/api/orders", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
cart: [
{
id: "1800 Koonies",
quantity: "1",
price: "10",
userid: userid, // Use the userid variable
},
],
}),
});

const orderData = await response.json();

if (orderData.id) {
return orderData.id;
} else {
const errorDetail = orderData?.details?.[0];
const errorMessage = errorDetail
? `${errorDetail.issue} ${errorDetail.description} (${orderData.debug_id})`
: JSON.stringify(orderData);

throw new Error(errorMessage);
}
} catch (error) {
console.error(error);
resultMessage(`Could not initiate PayPal Checkout...<br><br>${error}`);
}
},
async onApprove(data, actions) {
try {
const response = await fetch(`/api/orders/${data.orderID}/capture/${userid}`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
});
# rest of the code...
INFO: 162.158.126.151:55288 - "POST /api/orders/3PE25468C5919202R/capture HTTP/1.1" 404 Not Found the user id is never sent to the /api/order/code/capture like supposed
15 replies
CC#
Created by Kepar on 5/30/2023 in #help
❔ Re-compiling error
4 replies