Skip to content

Commit 9363b5c

Browse files
authored
Refactor the backend for the advanced integration guide (#64)
1 parent ed5eb63 commit 9363b5c

File tree

9 files changed

+187
-141
lines changed

9 files changed

+187
-141
lines changed

.devcontainer/advanced-integration/devcontainer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727
},
2828

2929
"secrets": {
30-
"CLIENT_ID": {
30+
"PAYPAL_CLIENT_ID": {
3131
"description": "Sandbox client ID of the application.",
3232
"documentationUrl": "https://developer.paypal.com/dashboard/applications/sandbox"
3333
},
34-
"APP_SECRET": {
34+
"PAYPAL_CLIENT_SECRET": {
3535
"description": "Sandbox secret of the application.",
3636
"documentationUrl": "https://developer.paypal.com/dashboard/applications/sandbox"
3737
}

advanced-integration/.env.example

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Create an application to obtain credentials at
22
# https://developer.paypal.com/dashboard/applications/sandbox
33

4-
CLIENT_ID="YOUR_CLIENT_ID_GOES_HERE"
5-
APP_SECRET="YOUR_SECRET_GOES_HERE"
4+
PAYPAL_CLIENT_ID="YOUR_CLIENT_ID_GOES_HERE"
5+
PAYPAL_CLIENT_SECRET="YOUR_SECRET_GOES_HERE"

advanced-integration/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Instructions
44

5-
1. Rename `.env.example` to `.env` and update `CLIENT_ID` and `APP_SECRET`.
5+
1. Rename `.env.example` to `.env` and update `PAYPAL_CLIENT_ID` and `PAYPAL_CLIENT_SECRET`.
66
2. Run `npm install`
77
3. Run `npm start`
88
4. Open http://localhost:8888

advanced-integration/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "@paypalcorp/advanced-integration",
2+
"name": "paypal-advanced-integration",
33
"version": "1.0.0",
44
"description": "",
55
"main": "server.js",
@@ -11,9 +11,9 @@
1111
"author": "",
1212
"license": "Apache-2.0",
1313
"dependencies": {
14-
"dotenv": "^16.0.0",
15-
"ejs": "^3.1.6",
16-
"express": "^4.17.3",
17-
"node-fetch": "^3.2.1"
14+
"dotenv": "^16.3.1",
15+
"ejs": "^3.1.9",
16+
"express": "^4.18.2",
17+
"node-fetch": "^3.3.2"
1818
}
1919
}

advanced-integration/paypal-api.js

Lines changed: 0 additions & 98 deletions
This file was deleted.

advanced-integration/public/app.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ paypal
33
// Sets up the transaction when a payment button is clicked
44
createOrder: function () {
55
return fetch("/api/orders", {
6-
method: "post",
6+
method: "POST",
7+
headers: {
8+
'Content-Type': 'application/json',
9+
},
710
// use the "body" param to optionally pass additional order information
811
// like product skus and quantities
912
body: JSON.stringify({
@@ -21,7 +24,10 @@ paypal
2124
// Finalize the transaction after payer approval
2225
onApprove: function (data) {
2326
return fetch(`/api/orders/${data.orderID}/capture`, {
24-
method: "post",
27+
method: "POST",
28+
headers: {
29+
'Content-Type': 'application/json',
30+
},
2531
})
2632
.then((response) => response.json())
2733
.then((orderData) => {
@@ -54,7 +60,10 @@ if (paypal.HostedFields.isEligible()) {
5460
// Call your server to set up the transaction
5561
createOrder: () => {
5662
return fetch("/api/orders", {
57-
method: "post",
63+
method: "POST",
64+
headers: {
65+
'Content-Type': 'application/json',
66+
},
5867
// use the "body" param to optionally pass additional order information
5968
// like product skus and quantities
6069
body: JSON.stringify({
@@ -127,7 +136,10 @@ if (paypal.HostedFields.isEligible()) {
127136
})
128137
.then(() => {
129138
fetch(`/api/orders/${orderId}/capture`, {
130-
method: "post",
139+
method: "POST",
140+
headers: {
141+
'Content-Type': 'application/json',
142+
},
131143
})
132144
.then((res) => res.json())
133145
.then((orderData) => {

0 commit comments

Comments
 (0)