Skip to content

Commit 55a452b

Browse files
authored
chore: update createOrder callback comment and example payload (#21)
1 parent 734e5db commit 55a452b

File tree

2 files changed

+32
-8
lines changed

2 files changed

+32
-8
lines changed

advanced-integration/public/app.js

+21-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
paypal
22
.Buttons({
33
// Sets up the transaction when a payment button is clicked
4-
createOrder: function (data, actions) {
4+
createOrder: function () {
55
return fetch("/api/orders", {
66
method: "post",
77
// use the "body" param to optionally pass additional order information
8-
// like product ids or amount
8+
// like product skus and quantities
9+
body: JSON.stringify({
10+
cart: [
11+
{
12+
sku: "<YOUR_PRODUCT_STOCK_KEEPING_UNIT>",
13+
quantity: "<YOUR_PRODUCT_QUANTITY>",
14+
},
15+
],
16+
}),
917
})
1018
.then((response) => response.json())
1119
.then((order) => order.id);
1220
},
1321
// Finalize the transaction after payer approval
14-
onApprove: function (data, actions) {
22+
onApprove: function (data) {
1523
return fetch(`/api/orders/${data.orderID}/capture`, {
1624
method: "post",
1725
})
@@ -47,8 +55,16 @@ if (paypal.HostedFields.isEligible()) {
4755
createOrder: () => {
4856
return fetch("/api/orders", {
4957
method: "post",
50-
// use the "body" param to optionally pass additional order information like
51-
// product ids or amount.
58+
// use the "body" param to optionally pass additional order information
59+
// like product skus and quantities
60+
body: JSON.stringify({
61+
cart: [
62+
{
63+
sku: "<YOUR_PRODUCT_STOCK_KEEPING_UNIT>",
64+
quantity: "<YOUR_PRODUCT_QUANTITY>",
65+
},
66+
],
67+
}),
5268
})
5369
.then((res) => res.json())
5470
.then((orderData) => {

standard-integration/public/index.html

+11-3
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,25 @@
1212
paypal
1313
.Buttons({
1414
// Sets up the transaction when a payment button is clicked
15-
createOrder: function (data, actions) {
15+
createOrder: function () {
1616
return fetch("/api/orders", {
1717
method: "post",
1818
// use the "body" param to optionally pass additional order information
19-
// like product ids or amount
19+
// like product skus and quantities
20+
body: JSON.stringify({
21+
cart: [
22+
{
23+
sku: "<YOUR_PRODUCT_STOCK_KEEPING_UNIT>",
24+
quantity: "<YOUR_PRODUCT_QUANTITY>",
25+
},
26+
],
27+
}),
2028
})
2129
.then((response) => response.json())
2230
.then((order) => order.id);
2331
},
2432
// Finalize the transaction after payer approval
25-
onApprove: function (data, actions) {
33+
onApprove: function (data) {
2634
return fetch(`/api/orders/${data.orderID}/capture`, {
2735
method: "post",
2836
})

0 commit comments

Comments
 (0)