Skip to content

chore: update createOrder callback comment and example payload #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions advanced-integration/public/app.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
paypal
.Buttons({
// Sets up the transaction when a payment button is clicked
createOrder: function (data, actions) {
createOrder: function () {
return fetch("/api/orders", {
method: "post",
// use the "body" param to optionally pass additional order information
// like product ids or amount
// like product skus and quantities
body: JSON.stringify({
cart: [
{
sku: "<YOUR_PRODUCT_STOCK_KEEPING_UNIT>",
quantity: "<YOUR_PRODUCT_QUANTITY>",
},
],
}),
})
.then((response) => response.json())
.then((order) => order.id);
},
// Finalize the transaction after payer approval
onApprove: function (data, actions) {
onApprove: function (data) {
return fetch(`/api/orders/${data.orderID}/capture`, {
method: "post",
})
Expand Down Expand Up @@ -47,8 +55,16 @@ if (paypal.HostedFields.isEligible()) {
createOrder: () => {
return fetch("/api/orders", {
method: "post",
// use the "body" param to optionally pass additional order information like
// product ids or amount.
// use the "body" param to optionally pass additional order information
// like product skus and quantities
body: JSON.stringify({
cart: [
{
sku: "<YOUR_PRODUCT_STOCK_KEEPING_UNIT>",
quantity: "<YOUR_PRODUCT_QUANTITY>",
},
],
}),
})
.then((res) => res.json())
.then((orderData) => {
Expand Down
14 changes: 11 additions & 3 deletions standard-integration/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,25 @@
paypal
.Buttons({
// Sets up the transaction when a payment button is clicked
createOrder: function (data, actions) {
createOrder: function () {
return fetch("/api/orders", {
method: "post",
// use the "body" param to optionally pass additional order information
// like product ids or amount
// like product skus and quantities
body: JSON.stringify({
cart: [
{
sku: "<YOUR_PRODUCT_STOCK_KEEPING_UNIT>",
quantity: "<YOUR_PRODUCT_QUANTITY>",
},
],
}),
})
.then((response) => response.json())
.then((order) => order.id);
},
// Finalize the transaction after payer approval
onApprove: function (data, actions) {
onApprove: function (data) {
return fetch(`/api/orders/${data.orderID}/capture`, {
method: "post",
})
Expand Down