Skip to content

Commit

Permalink
Allowing for the use of multiple payment methods (mrvautin#169)
Browse files Browse the repository at this point in the history
* Catering for multiple payments

* Schema fixes

* Updated docs

* Fix config

* Payment fixes

* Small payment UI changes

* Stripe and instore fixes

* Fixed incorrect field

* Conditional GW config

* Updated readme

* Paypal fixes

* Fix payway key

* Bump version
  • Loading branch information
mrvautin authored Sep 21, 2020
1 parent 83d3be9 commit 08db4c6
Show file tree
Hide file tree
Showing 43 changed files with 261 additions and 159 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,9 @@ This email is used for any email receipts which are sent by your website.

##### Payment Gateway

This determines which payment gateway to use. You will also need to configure your payment gateway configuration file here: `/config/payment/config/<gateway_name>.json` or use the `env.yaml` file.
An array of payment gateways to use. You will also need to configure your payment gateway configuration file(s) here: `/config/payment/config/<gateway_name>.json` or use the `env.yaml` file.

> Multiple payment gateways can be provided to combine checkout. Eg: Card and Instore pickup

##### Currency symbol

Expand Down Expand Up @@ -257,6 +259,7 @@ The Paypal config file is located: `/config/payment/config/paypal.json`. A examp

```
{
"description": "Paypal payment",
"mode": "live", // sandbox or live
"client_id": "this_is_not_real",
"client_secret": "this_is_not_real",
Expand All @@ -272,6 +275,7 @@ The Stripe config file is located: `/config/payment/config/stripe.json`. A examp

```
{
"description": "Card payment",
"secretKey": "sk_test_this_is_not_real",
"publicKey": "pk_test_this_is_not_real",
"stripeCurrency": "usd", The Stripe currency to charge in
Expand All @@ -292,6 +296,7 @@ The Blockonomics config file is located: `/config/payment/config/blockonomics.js

```
{
"description": "Blockonomics payment",
"apiKey": "this_is_not_real",
"hostUrl": "https://www.blockonomics.co", // You usually don't need to change this
"newAddressApi": "/api/new_address", // You usually don't need to change this
Expand All @@ -306,6 +311,7 @@ The Authorize.net config file is located: `/config/payment/config/authorizenet.j

```
{
"description": "Card payment",
"loginId": "loginId",
"transactionKey": "transactionKey",
"clientKey": "clientKey",
Expand All @@ -321,9 +327,10 @@ The Adyen config file is located: `/config/payment/config/adyen.json`. A example

```
{
"description": "Card payment",
"environment": "TEST",
"apiKey": "this_is_not_real",
"publicKey": "this_is_not_real",
"originKey": "this_is_not_real",
"merchantAccount": "this_is_not_real",
"statementDescriptor": "a_statement_descriptor",
"currency": "AUD"
Expand All @@ -338,6 +345,7 @@ The PayWay config file is located: `/config/payment/config/payway.json`. A examp

```
{
"description": "Card payment",
"apiKey": "TXXXXX_SEC_btbqXxXxqgtzXk2p27hapvxXXXXxw28gh3febtuaf2etnkXxXxehdqu98u",
"publishableApiKey": "T11266_PUB_btbq8r6sqgtz5k2p27hapvx8nurxw28gh3fepbtua2f2etnkp4bmehdqu98u",
"merchantId": "TEST"
Expand All @@ -352,6 +360,7 @@ The Instore config file is located: `/config/payment/config/instore.json`. A exa

```
{
"description": "Instore payment",
"orderStatus": "Pending",
"buttonText": "Place order, pay instore",
"resultMessage": "The order is place. Please pay for your order instore on pickup."
Expand Down
31 changes: 19 additions & 12 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ if(baseConfig === false){
}

// Validate the payment gateway config
if(ajv.validate(
require(`./config/payment/schema/${config.paymentGateway}`),
require(`./config/payment/config/${config.paymentGateway}`)) === false
){
console.log(colors.red(`${config.paymentGateway} config is incorrect: ${ajv.errorsText()}`));
process.exit(2);
}
_.forEach(config.paymentGateway, (gateway) => {
if(ajv.validate(
require(`./config/payment/schema/${gateway}`),
require(`./config/payment/config/${gateway}`)) === false
){
console.log(colors.red(`${gateway} config is incorrect: ${ajv.errorsText()}`));
process.exit(2);
}
});

// require the routes
const index = require('./routes/index');
Expand All @@ -54,9 +56,6 @@ const customer = require('./routes/customer');
const order = require('./routes/order');
const user = require('./routes/user');

// Add the payment route
const paymentRoute = require(`./lib/payments/${config.paymentGateway}`);

const app = express();

// Language initialize
Expand Down Expand Up @@ -294,6 +293,12 @@ handlebars = handlebars.create({
}
return text;
},
contains: (values, value, options) => {
if(values.includes(value)){
return options.fn(this);
}
return options.inverse(this);
},
fixTags: (html) => {
html = html.replace(/&gt;/g, '>');
html = html.replace(/&lt;/g, '<');
Expand Down Expand Up @@ -390,8 +395,10 @@ app.use('/', order);
app.use('/', user);
app.use('/', admin);

// Payment route
app.use(`/${config.paymentGateway}`, paymentRoute);
// Payment route(s)
_.forEach(config.paymentGateway, (gateway) => {
app.use(`/${gateway}`, require(`./lib/payments/${gateway}`));
});

// catch 404 and forward to error handler
app.use((req, res, next) => {
Expand Down
3 changes: 2 additions & 1 deletion config/payment/config/adyen.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"description": "Card payment",
"environment": "TEST",
"apiKey": "this_is_not_real",
"publicKey": "this_is_not_real",
"originKey": "this_is_not_real",
"merchantAccount": "this_is_not_real",
"statementDescriptor": "a_statement_descriptor",
"currency": "AUD"
Expand Down
1 change: 1 addition & 0 deletions config/payment/config/authorizenet.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"description": "Card payment",
"loginId": "loginId",
"transactionKey": "transactionKey",
"clientKey": "clientKey",
Expand Down
1 change: 1 addition & 0 deletions config/payment/config/blockonomics.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"description": "Blockonomics payment",
"apiKey": "this_is_not_real",
"hostUrl": "https://www.blockonomics.co",
"newAddressApi": "/api/new_address",
Expand Down
1 change: 1 addition & 0 deletions config/payment/config/instore.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"description": "Instore pickup",
"orderStatus": "Pending",
"buttonText": "Place order, pay instore",
"resultMessage": "The order is place. Please pay for your order instore on pickup."
Expand Down
1 change: 1 addition & 0 deletions config/payment/config/paypal.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"description": "PayPal payment",
"mode": "sandbox",
"client_id": "this_is_not_real",
"client_secret": "this_is_not_real",
Expand Down
3 changes: 2 additions & 1 deletion config/payment/config/payway.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"description": "Card payment",
"apiKey": "TXXXXX_SEC_btbqXxXxqgtzXk2p27hapvxXXXXxw28gh3febtuaf2etnkXxXxehdqu98u",
"publishableApiKey": "T11266_PUB_btbq8r6sqgtz5k2p27hapvx8nurxw28gh3fepbtua2f2etnkp4bmehdqu98u",
"publishableApiKey": "TXXXXX_PUB_btbq8rXXXXtz5kXXXXhapvx8nurxw2XXXXfepbtXXXX2etnkp4bmehdqu98u",
"merchantId": "TEST"
}
1 change: 1 addition & 0 deletions config/payment/config/stripe.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"description": "Card payment",
"secretKey": "sk_test_this_is_not_real",
"publicKey": "pk_test_this_is_not_real",
"stripeCurrency": "usd",
Expand Down
8 changes: 6 additions & 2 deletions config/payment/schema/adyen.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
{
"properties": {
"description": {
"type": "string"
},
"environment": {
"type": "string",
"enum": ["TEST", "LIVE"]
},
"apiKey": {
"type": "string"
},
"publicKey": {
"originKey": {
"type": "string"
},
"merchantAccount": {
Expand All @@ -21,9 +24,10 @@
}
},
"required": [
"description",
"environment",
"apiKey",
"publicKey",
"originKey",
"merchantAccount",
"statementDescriptor",
"currency"
Expand Down
4 changes: 4 additions & 0 deletions config/payment/schema/authorizenet.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"properties": {
"description": {
"type": "string"
},
"loginId": {
"type": "string"
},
Expand All @@ -15,6 +18,7 @@
}
},
"required": [
"description",
"loginId",
"transactionKey",
"clientKey",
Expand Down
5 changes: 4 additions & 1 deletion config/payment/schema/blockonomics.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"properties": {
"description": {
"type": "string"
},
"apiKey": {
"type": "string"
},
Expand All @@ -14,7 +17,7 @@
}
},
"required": [
"api_key", "hostUrl", "newAddressApi", "priceApi"
"description", "apiKey", "hostUrl", "newAddressApi", "priceApi"
],
"additionalProperties": false
}
4 changes: 4 additions & 0 deletions config/payment/schema/instore.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"properties": {
"description": {
"type": "string"
},
"orderStatus": {
"type": "string",
"enum": ["Completed", "Paid", "Pending"]
Expand All @@ -12,6 +15,7 @@
}
},
"required": [
"description",
"orderStatus",
"buttonText",
"resultMessage"
Expand Down
4 changes: 4 additions & 0 deletions config/payment/schema/paypal.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"properties": {
"description": {
"type": "string"
},
"mode": {
"type": "string",
"enum": ["sandbox", "live"]
Expand All @@ -18,6 +21,7 @@
}
},
"required": [
"description",
"mode",
"client_id",
"client_secret",
Expand Down
4 changes: 4 additions & 0 deletions config/payment/schema/payway.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"properties": {
"description": {
"type": "string"
},
"apiKey": {
"type": "string"
},
Expand All @@ -11,6 +14,7 @@
}
},
"required": [
"description",
"apiKey",
"publishableApiKey",
"merchantId"
Expand Down
4 changes: 4 additions & 0 deletions config/payment/schema/stripe.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"properties": {
"description": {
"type": "string"
},
"secretKey": {
"type": "string",
"default": "sandbox"
Expand All @@ -22,6 +25,7 @@
}
},
"required": [
"description",
"secretKey",
"publicKey",
"stripeCurrency",
Expand Down
4 changes: 3 additions & 1 deletion config/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
"injectJs": "",
"customCss": "",
"currencySymbol": "£",
"paymentGateway": "stripe",
"paymentGateway": [
"stripe"
],
"databaseConnectionString": "mongodb://127.0.0.1:27017/expresscart",
"theme": "Cloth",
"trackStock": false,
Expand Down
35 changes: 33 additions & 2 deletions config/settingsSchema.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,39 @@
"default": "USD"
},
"paymentGateway": {
"type": "string",
"enum": ["paypal", "blockonomics", "stripe", "authorizenet", "adyen", "payway", "instore"]
"type": "array",
"items": {
"oneOf": [
{
"type": "string",
"enum": [ "paypal"]
},
{
"type": "string",
"enum": [ "blockonomics"]
},
{
"type": "string",
"enum": [ "stripe"]
},
{
"type": "string",
"enum": [ "authorizenet"]
},
{
"type": "string",
"enum": [ "adyen"]
},
{
"type": "string",
"enum": [ "payway"]
},
{
"type": "string",
"enum": [ "instore"]
}
]
}
},
"databaseConnectionString": {
"type": "string"
Expand Down
Loading

0 comments on commit 08db4c6

Please sign in to comment.