aboutsummaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorMateja <mail@matejamaric.com>2021-07-15 22:29:03 +0200
committerMateja <mail@matejamaric.com>2021-07-15 22:29:03 +0200
commit1b04c332c2562f52c11ca653c4cd55f4c24548e5 (patch)
tree064da23ba0da233473687065ae308051cf8b5530 /server
parent1979502c006cc86ad150312d092f8cd5a19ac256 (diff)
downloadmevn-ecommerce-1b04c332c2562f52c11ca653c4cd55f4c24548e5.tar.gz
mevn-ecommerce-1b04c332c2562f52c11ca653c4cd55f4c24548e5.zip
Added PayPal config file.
Diffstat (limited to 'server')
-rw-r--r--server/config/env.js5
-rw-r--r--server/config/paypal.js15
-rw-r--r--server/package-lock.json13
-rw-r--r--server/package.json1
4 files changed, 33 insertions, 1 deletions
diff --git a/server/config/env.js b/server/config/env.js
index befa8ba..441d6b6 100644
--- a/server/config/env.js
+++ b/server/config/env.js
@@ -2,5 +2,8 @@ require('dotenv').config();
module.exports = {
port: process.env.PORT || 3000,
mongoUrl: process.env.DB_CONN || "mongodb://localhost/mevn_ecommerce_db",
- masterKey: process.env.APP_SECRET || "you-should-use-something-different"
+ masterKey: process.env.APP_SECRET || "you-should-use-something-different",
+ paypalEnvironment: process.env.PAYPAL_ENVIRONMENT || "sandbox",
+ paypalClientId: process.env.PAYPAL_CLIENT_ID || 'PAYPAL-SANDBOX-CLIENT-ID',
+ paypalClientSecret: process.env.PAYPAL_CLIENT_SECRET || 'PAYPAL-SANDBOX-CLIENT-SECRET'
};
diff --git a/server/config/paypal.js b/server/config/paypal.js
new file mode 100644
index 0000000..da6c2c3
--- /dev/null
+++ b/server/config/paypal.js
@@ -0,0 +1,15 @@
+const paypal = require('@paypal/checkout-server-sdk');
+const {paypalEnvironment, paypalClientId, paypalClientSecret} = require('./env');
+
+function environment() {
+ if (paypalEnvironment === 'live')
+ return new paypal.core.LiveEnvironment(paypalClientId, paypalClientSecret);
+ else
+ return new paypal.core.SandboxEnvironment(paypalClientId, paypalClientSecret);
+}
+
+function client() {
+ return new paypal.core.PayPalHttpClient(environment());
+}
+
+module.exports = client;
diff --git a/server/package-lock.json b/server/package-lock.json
index e71a274..56ce2fb 100644
--- a/server/package-lock.json
+++ b/server/package-lock.json
@@ -4,6 +4,19 @@
"lockfileVersion": 1,
"requires": true,
"dependencies": {
+ "@paypal/checkout-server-sdk": {
+ "version": "1.0.2",
+ "resolved": "https://registry.npmjs.org/@paypal/checkout-server-sdk/-/checkout-server-sdk-1.0.2.tgz",
+ "integrity": "sha512-9wNxqgXrolEPfX62PEwyUB3SBGVF7v9N28rNJpXNp89qEpLoLStM+CT4wm/fcfYiVj9BHpimKcB4B7CBbLirxQ==",
+ "requires": {
+ "@paypal/paypalhttp": "^1.0.0"
+ }
+ },
+ "@paypal/paypalhttp": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/@paypal/paypalhttp/-/paypalhttp-1.0.0.tgz",
+ "integrity": "sha512-6gHT5HhPLObICXU8LFFiuoH0vCh3y1y0jl0OWDRuTZvptZ1WRS2eKcHigheytqxk+CWTH0qh0M3S5vEf1PJrSw=="
+ },
"@sindresorhus/is": {
"version": "0.14.0",
"resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-0.14.0.tgz",
diff --git a/server/package.json b/server/package.json
index 9209187..676d617 100644
--- a/server/package.json
+++ b/server/package.json
@@ -10,6 +10,7 @@
"author": "Mateja Maric",
"license": "GPL-3.0",
"dependencies": {
+ "@paypal/checkout-server-sdk": "^1.0.2",
"bcryptjs": "^2.4.3",
"cors": "^2.8.5",
"dotenv": "^10.0.0",