aboutsummaryrefslogtreecommitdiff
path: root/server/config
diff options
context:
space:
mode:
Diffstat (limited to 'server/config')
-rw-r--r--server/config/env.js5
-rw-r--r--server/config/paypal.js15
2 files changed, 19 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;