From bb19e894259affdac55c2ea7b194c00725fbae80 Mon Sep 17 00:00:00 2001 From: Greg Jopa <534034+gregjopa@users.noreply.github.com> Date: Tue, 31 Jan 2023 16:44:32 -0600 Subject: [PATCH] chore: update createOrder callback comment and example payload --- advanced-integration/public/app.js | 26 +++++++++++++++++++++----- standard-integration/public/index.html | 14 +++++++++++--- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/advanced-integration/public/app.js b/advanced-integration/public/app.js index 056efc84..0eaef6db 100644 --- a/advanced-integration/public/app.js +++ b/advanced-integration/public/app.js @@ -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: "", + 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", }) @@ -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: "", + quantity: "", + }, + ], + }), }) .then((res) => res.json()) .then((orderData) => { diff --git a/standard-integration/public/index.html b/standard-integration/public/index.html index f0f8b659..28dba802 100644 --- a/standard-integration/public/index.html +++ b/standard-integration/public/index.html @@ -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: "", + 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", })