|
1 | 1 | paypal
|
2 | 2 | .Buttons({
|
3 | 3 | // Sets up the transaction when a payment button is clicked
|
4 |
| - createOrder: function (data, actions) { |
| 4 | + createOrder: function () { |
5 | 5 | return fetch("/api/orders", {
|
6 | 6 | method: "post",
|
7 | 7 | // 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 | + }), |
9 | 17 | })
|
10 | 18 | .then((response) => response.json())
|
11 | 19 | .then((order) => order.id);
|
12 | 20 | },
|
13 | 21 | // Finalize the transaction after payer approval
|
14 |
| - onApprove: function (data, actions) { |
| 22 | + onApprove: function (data) { |
15 | 23 | return fetch(`/api/orders/${data.orderID}/capture`, {
|
16 | 24 | method: "post",
|
17 | 25 | })
|
@@ -47,8 +55,16 @@ if (paypal.HostedFields.isEligible()) {
|
47 | 55 | createOrder: () => {
|
48 | 56 | return fetch("/api/orders", {
|
49 | 57 | 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 | + }), |
52 | 68 | })
|
53 | 69 | .then((res) => res.json())
|
54 | 70 | .then((orderData) => {
|
|
0 commit comments