Code: Select all
.
Test
paypal.Buttons({
style: {
layout: 'vertical',
color: 'blue',
shape: 'rect',
label: 'paypal'
}
}).render('#paypal-button-container');
paypal.Buttons({
async createOrder() {
const response = await fetch("/my-server/create-paypal-order", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
cart: [
{
sku: "YOUR_PRODUCT_STOCK_KEEPING_UNIT",
quantity: "YOUR_PRODUCT_QUANTITY",
},
],
}),
});
const data = await response.json();
return data.id;
},
async onApprove(data) {
// Capture the funds from the transaction.
const response = await fetch("/my-server/capture-paypal-order", {
method: "POST",
body: JSON.stringify({
orderID: data.orderID
})
})
const details = await response.json();
// Show success message to buyer
alert(`Transaction completed by ${details.payer.name.given_name}`);
}
}).render('#paypal-button-container');
Ich habe es auch versucht :
Code: Select all
.
Test
paypal.Buttons({
style: {
layout: 'vertical',
color: 'blue',
shape: 'rect',
label: 'paypal'
},
async createOrder() {
const response = await fetch("/my-server/create-paypal-order", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
cart: [
{
sku: "YOUR_PRODUCT_STOCK_KEEPING_UNIT",
quantity: "YOUR_PRODUCT_QUANTITY",
},
],
}),
});
const data = await response.json();
return data.id;
},
async onApprove(data) {
// Capture the funds from the transaction.
const response = await fetch("/my-server/capture-paypal-order", {
method: "POST",
body: JSON.stringify({
orderID: data.orderID
})
})
const details = await response.json();
// Show success message to buyer
alert(`Transaction completed by ${details.payer.name.given_name}`);
}
}).render('#paypal-button-container');
Ich habe die richtige Client-ID verwendet, aber für den Code hier habe ich zur besseren Lesbarkeit myid eingegeben.
Was mache ich falsch?