Skip to content

Commit

Permalink
Refactor the backend for the advanced integration guide (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
gregjopa authored Aug 16, 2023
1 parent ed5eb63 commit 9363b5c
Show file tree
Hide file tree
Showing 9 changed files with 187 additions and 141 deletions.
4 changes: 2 additions & 2 deletions .devcontainer/advanced-integration/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
},

"secrets": {
"CLIENT_ID": {
"PAYPAL_CLIENT_ID": {
"description": "Sandbox client ID of the application.",
"documentationUrl": "https://developer.paypal.com/dashboard/applications/sandbox"
},
"APP_SECRET": {
"PAYPAL_CLIENT_SECRET": {
"description": "Sandbox secret of the application.",
"documentationUrl": "https://developer.paypal.com/dashboard/applications/sandbox"
}
Expand Down
4 changes: 2 additions & 2 deletions advanced-integration/.env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Create an application to obtain credentials at
# https://developer.paypal.com/dashboard/applications/sandbox

CLIENT_ID="YOUR_CLIENT_ID_GOES_HERE"
APP_SECRET="YOUR_SECRET_GOES_HERE"
PAYPAL_CLIENT_ID="YOUR_CLIENT_ID_GOES_HERE"
PAYPAL_CLIENT_SECRET="YOUR_SECRET_GOES_HERE"
2 changes: 1 addition & 1 deletion advanced-integration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Instructions

1. Rename `.env.example` to `.env` and update `CLIENT_ID` and `APP_SECRET`.
1. Rename `.env.example` to `.env` and update `PAYPAL_CLIENT_ID` and `PAYPAL_CLIENT_SECRET`.
2. Run `npm install`
3. Run `npm start`
4. Open http://localhost:8888
Expand Down
10 changes: 5 additions & 5 deletions advanced-integration/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@paypalcorp/advanced-integration",
"name": "paypal-advanced-integration",
"version": "1.0.0",
"description": "",
"main": "server.js",
Expand All @@ -11,9 +11,9 @@
"author": "",
"license": "Apache-2.0",
"dependencies": {
"dotenv": "^16.0.0",
"ejs": "^3.1.6",
"express": "^4.17.3",
"node-fetch": "^3.2.1"
"dotenv": "^16.3.1",
"ejs": "^3.1.9",
"express": "^4.18.2",
"node-fetch": "^3.3.2"
}
}
98 changes: 0 additions & 98 deletions advanced-integration/paypal-api.js

This file was deleted.

20 changes: 16 additions & 4 deletions advanced-integration/public/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ paypal
// Sets up the transaction when a payment button is clicked
createOrder: function () {
return fetch("/api/orders", {
method: "post",
method: "POST",
headers: {
'Content-Type': 'application/json',
},
// use the "body" param to optionally pass additional order information
// like product skus and quantities
body: JSON.stringify({
Expand All @@ -21,7 +24,10 @@ paypal
// Finalize the transaction after payer approval
onApprove: function (data) {
return fetch(`/api/orders/${data.orderID}/capture`, {
method: "post",
method: "POST",
headers: {
'Content-Type': 'application/json',
},
})
.then((response) => response.json())
.then((orderData) => {
Expand Down Expand Up @@ -54,7 +60,10 @@ if (paypal.HostedFields.isEligible()) {
// Call your server to set up the transaction
createOrder: () => {
return fetch("/api/orders", {
method: "post",
method: "POST",
headers: {
'Content-Type': 'application/json',
},
// use the "body" param to optionally pass additional order information
// like product skus and quantities
body: JSON.stringify({
Expand Down Expand Up @@ -127,7 +136,10 @@ if (paypal.HostedFields.isEligible()) {
})
.then(() => {
fetch(`/api/orders/${orderId}/capture`, {
method: "post",
method: "POST",
headers: {
'Content-Type': 'application/json',
},
})
.then((res) => res.json())
.then((orderData) => {
Expand Down
Loading

0 comments on commit 9363b5c

Please sign in to comment.