├── .babelrc ├── .eslintrc ├── .gitignore ├── .npmignore ├── LICENSE ├── README.md ├── bower.json ├── package.json ├── pom.xml ├── src ├── adapters.js ├── gateways.js ├── gateways │ ├── au.com.fatzebra.js │ ├── com.2checkout.js │ ├── com.braintreegateway.js │ ├── com.dengionline.js │ ├── com.ewaypayments.js │ ├── com.mercadopago.js │ ├── com.mercurypay.js │ ├── com.paguelofacil.js │ ├── com.paybox.js │ ├── com.paymentexpress.js │ ├── com.pelecard.js │ ├── com.stripe.js │ ├── com.tranzila.js │ ├── com.worldpay.enterprise.js │ ├── il.co.creditguard.js │ ├── il.co.leumi-card.js │ └── net.authorize.js ├── index.js ├── methods.js └── methods │ ├── cash.js │ ├── com.cellarix.js │ ├── credit.js │ └── il.co.mysodexo.js └── test ├── adapters.test.js ├── gateways.test.js └── methods.test.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets":["es2015", "stage-2"], 3 | "plugins":["transform-runtime", "transform-strict-mode"] 4 | } 5 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "parser": "babel-eslint", 3 | "parserOptions": { 4 | "ecmaFeatures": { 5 | "modules": true, 6 | "jsx": true 7 | } 8 | }, 9 | "env": { 10 | "browser": true, 11 | "node": true, 12 | "es6": true 13 | }, 14 | "extends": ["eslint:recommended"], 15 | "globals": { 16 | "mapboxgl": true, 17 | "Q": true, 18 | "_": true, 19 | "google": true, 20 | "FB": true, 21 | "goog": true, 22 | "$": true, 23 | "moment": true, 24 | "dispatch": true, 25 | "connect": true, 26 | "React": true, 27 | "ReactDOM": true, 28 | "spiceProduction": true, 29 | "ReactBootstrap": true, 30 | "Wix": true, 31 | "If": true, 32 | "For": true, 33 | "Else": true, 34 | "define": true, 35 | "olark": true, 36 | "Reflux": true, 37 | "uniqueId": true, 38 | "describe": false, 39 | "it":false, 40 | "beforeEach":false, 41 | "before":false, 42 | "after":false, 43 | "spiceVer": false, 44 | "prodLocaleFile": true, 45 | "prodAppFile": true, 46 | }, 47 | "rules": { 48 | "strict": 0, 49 | "no-console": 0, 50 | "no-underscore-dangle": 0, 51 | "no-trailing-spaces": 2, 52 | "no-unused-vars": 2, 53 | "no-undef": 2, 54 | "semi": 2, 55 | "indent": ["error", 4] 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | dist 2 | node_modules 3 | resources 4 | .npmrc 5 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .babelrc 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This software is licensed under the Apache 2 license, quoted below. 2 | 3 | Copyright 2015 Wix.com Ltd. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); you may not 6 | use this file except in compliance with the License. You may obtain a copy of 7 | the License at: 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | License for the specific language governing permissions and limitations under 15 | the License. 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # payments 2 | Wix Restaurants payment configuration. 3 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "payments", 3 | "description": "Lists various payment methods. Used by Wix Restaurants for payment configuration.", 4 | "main": "dist/payments.js", 5 | "authors": [ 6 | "Wix Restaurants" 7 | ], 8 | "license": "Apache-2.0", 9 | "keywords": [ 10 | "apache", 11 | "payments", 12 | "gateways", 13 | "javascript" 14 | ], 15 | "homepage": "https://github.com/wix/payments", 16 | "ignore": [ 17 | "**/.*", 18 | "node_modules", 19 | "bower_components", 20 | "test", 21 | "tests" 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "payments", 3 | "version": "2.0.0", 4 | "description": "Lists various payment methods. Used by Wix Restaurants for payment configuration.", 5 | "main": "dist/index.js", 6 | "scripts": { 7 | "test": "mocha --compilers js:babel-register", 8 | "lint": "eslint ./src ./test", 9 | "posttest": "npm run lint", 10 | "compile": "babel -d dist/ src/", 11 | "compile-library": "webpack --output-library PaymentsMethods --output-library-target var dist bin/payments.src.js", 12 | "prepublish": "npm test && npm run compile && npm run compile-library", 13 | "build": "babel bin/payments.src.js | uglifyjs > bin/payments.js", 14 | "release": "npm install wnpm-ci --no-save && wnpm-release -- --no-shrinkwrap && npm install bower-auto-release && bower-auto-release --dist bin" 15 | }, 16 | "repository": { 17 | "type": "git", 18 | "url": "https://github.com/wix/payments" 19 | }, 20 | "keywords": [ 21 | "wix", 22 | "restaurants", 23 | "payment", 24 | "gateway" 25 | ], 26 | "author": "Wix Restaurants", 27 | "license": "Apache-2.0", 28 | "bugs": { 29 | "url": "https://github.com/wix/payments/issues" 30 | }, 31 | "homepage": "https://github.com/wix/payments", 32 | "dependencies": { 33 | "lodash": "^4.13.0" 34 | }, 35 | "devDependencies": { 36 | "babel": "^6.5.2", 37 | "babel-cli": "^6.8.0", 38 | "babel-plugin-transform-runtime": "^6.8.0", 39 | "babel-plugin-transform-strict-mode": "^6.8.0", 40 | "babel-preset-es2015": "^6.6.0", 41 | "babel-preset-stage-2": "^6.5.0", 42 | "babel-register": "^6.8.0", 43 | "babel-runtime": "^6.6.1", 44 | "chai": "^3.5.0", 45 | "eslint": "^3.9.0", 46 | "babel-eslint": "^7.1.1", 47 | "fs-extra": "^0.18.3", 48 | "mocha": "^2.4.5", 49 | "q": "^1.4.1", 50 | "webpack": "^1.13.0" 51 | }, 52 | "optionalDependencies": { 53 | "uglify-js": "^3.0.10" 54 | }, 55 | "publishConfig": { 56 | "registry": "https://registry.npmjs.org/" 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | com.wixpress.restaurants 7 | payments 8 | Wix Restaurants credit cards tokenizer 9 | Lists various payment methods. 10 | 11 | 12 | com.wixpress.common 13 | wix-master-parent 14 | 100.0.0-SNAPSHOT 15 | 16 | 17 | 18 | 4.0.0 19 | 1.0.0-SNAPSHOT 20 | pom 21 | 22 | 23 | 24 | Danny Leshem 25 | dannyl@wix.com 26 | 27 | owner 28 | 29 | 30 | 31 | Yoav Amit 32 | yoava@wix.com 33 | 34 | owner 35 | 36 | 37 | 38 | 39 | Restaurants 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /src/adapters.js: -------------------------------------------------------------------------------- 1 | import _ from 'lodash'; 2 | 3 | // Convert form values received from the UI to a merchant object 4 | export const simpleFormValuesToMerchant = formValues => _.reduce(formValues, (merchant, value, name) => { 5 | merchant[name] = value; 6 | return merchant; 7 | }, {}); 8 | 9 | // Convert a merchant object to a form that that UI can display 10 | export const simpleMerchantToFormValues = merchant => _.reduce(merchant, (formValues, value, name) => { 11 | formValues[name] = value; 12 | return formValues; 13 | }, {}); 14 | 15 | 16 | /****** Special Braintree handling **********/ 17 | export const braintreeFormValuesToMerchant = formValues => { 18 | const merchant = simpleFormValuesToMerchant(formValues); 19 | merchant.merchantAccountIds = {}; 20 | merchant.merchantAccountIds[merchant.currency] = merchant.merchantAccountId; 21 | delete merchant.currency; 22 | delete merchant.merchantAccountId; 23 | return merchant; 24 | }; 25 | 26 | export const braintreeMerchantToFormValues = merchant => { 27 | const formValues = simpleMerchantToFormValues(_.omit(merchant, 'merchantAccountIds')); 28 | const firstMerchantAccountId = _.chain(merchant.merchantAccountIds).toPairs().first().value() || ['', '']; 29 | formValues['currency'] = firstMerchantAccountId[0]; 30 | formValues['merchantAccountId'] = firstMerchantAccountId[1]; 31 | return formValues; 32 | }; 33 | /*******************************************/ 34 | -------------------------------------------------------------------------------- /src/gateways.js: -------------------------------------------------------------------------------- 1 | import _ from 'lodash'; 2 | 3 | import authorizeNet from './gateways/net.authorize'; 4 | import braintree from './gateways/com.braintreegateway'; 5 | import creditguard from './gateways/il.co.creditguard'; 6 | import eway from './gateways/com.ewaypayments'; 7 | import fatzebra from './gateways/au.com.fatzebra'; 8 | // // import mercadopago from './gateways/com.mercadopago'; 9 | import mercurypay from './gateways/com.mercurypay'; 10 | import paguelofacil from './gateways/com.paguelofacil'; 11 | import paybox from './gateways/com.paybox'; 12 | import paymentexpress from './gateways/com.paymentexpress'; 13 | import pelecard from './gateways/com.pelecard'; 14 | import stripe from './gateways/com.stripe'; 15 | import tranzila from './gateways/com.tranzila'; 16 | import worldpayEnterprise from './gateways/com.worldpay.enterprise'; 17 | 18 | 19 | // Gateways 20 | const gatewaysList = [ 21 | authorizeNet, 22 | braintree, 23 | creditguard, 24 | eway, 25 | fatzebra, 26 | // mercadopago, 27 | mercurypay, 28 | paguelofacil, 29 | paybox, 30 | paymentexpress, 31 | pelecard, 32 | stripe, 33 | tranzila, 34 | worldpayEnterprise 35 | ]; 36 | 37 | 38 | export const gateways = _.reduce(gatewaysList, (gateways, gateway) => {gateways[gateway.id] = gateway; return gateways;}, {}); 39 | 40 | export const getGatewaysForCountry = countryCode => { 41 | return _(gateways) 42 | .filter(gateway => _.includes(gateway.countries, countryCode)) 43 | .orderBy('ranking', 'desc') 44 | .map(gateway => _.omit(gateway, 'countries', 'ranking')) 45 | .value(); 46 | }; 47 | 48 | export const getGatewayById = gatewayId => _.find(gateways, {'id': gatewayId}); 49 | 50 | export const getGatewayDisplayName = (i18nGet, gatewayId) => i18nGet(`gateway_${gatewayId}_title`); 51 | export const getGatewayFieldDisplayName = (i18nGet, gatewayId, field) => i18nGet(`gateway_${gatewayId}_field_${field}`); 52 | -------------------------------------------------------------------------------- /src/gateways/au.com.fatzebra.js: -------------------------------------------------------------------------------- 1 | import { simpleFormValuesToMerchant, simpleMerchantToFormValues } from '../adapters'; 2 | 3 | export default { 4 | id : 'au.com.fatzebra', 5 | 6 | form : [ 7 | {type : 'string', name : 'username'}, 8 | {type : 'string', name : 'password'}, 9 | ], 10 | 11 | countries : [ 12 | 'AU', 13 | ], 14 | 15 | fields: ['holderName'], 16 | 17 | formValuesToMerchant : simpleFormValuesToMerchant, 18 | merchantToFormValues : simpleMerchantToFormValues, 19 | keyToMerchant : JSON.parse, 20 | merchantToKey : JSON.stringify, 21 | 22 | ranking: 4 23 | }; 24 | -------------------------------------------------------------------------------- /src/gateways/com.2checkout.js: -------------------------------------------------------------------------------- 1 | import { simpleFormValuesToMerchant, simpleMerchantToFormValues } from '../adapters'; 2 | 3 | export default { 4 | id : 'com.2checkout', 5 | 6 | form : [ 7 | {type : 'string', name : 'sellerId'}, 8 | {type : 'string', name : 'publishableKey'}, 9 | {type : 'string', name : 'privateKey'} 10 | ], 11 | 12 | // @see https://www.2checkout.com/global-payments 13 | countries : [ 14 | "AX", "AL", "DZ", "AD", "AO", "AI", "AQ", "AG", "AR", "AM", 15 | "AW", "AU", "AT", "AZ", "BS", "BH", "BD", "BB", "BY", "BE", 16 | "BZ", "BJ", "BM", "BT", "BO", "BQ", "BA", "BV", "BR", "IO", 17 | "BN", "BG", "BF", "BI", "CA", "CV", "KY", "CF", "TD", "CL", 18 | "CN", "CX", "CC", "CO", "KM", "CG", "CD", "CK", "CR", "HR", 19 | "CW", "CY", "CZ", "DK", "DJ", "DM", "DO", "EC", "EG", "SV", 20 | "GQ", "ER", "EE", "ET", "FK", "FJ", "FI", "FR", "PF", "TF", 21 | "GM", "GE", "DE", "GH", "GI", "GR", "GD", "GU", "GT", "GG", 22 | "GY", "HT", "HM", "HN", "HK", "HU", "IS", "IN", "ID", "IE", 23 | "IM", "IL", "IT", "JP", "JE", "JO", "KZ", "KE", "KI", "KR", 24 | "KS", "KW", "KG", "LA", "LV", "LB", "LS", "LR", "LY", "LI", 25 | "LT", "LU", "MO", "MK", "MG", "MW", "MY", "MT", "MH", "MQ", 26 | "MR", "MU", "YT", "MX", "FM", "MD", "MC", "MN", "ME", "MS", 27 | "MA", "NR", "NP", "NL", "AN", "NZ", "NI", "NE", "NG", "NU", 28 | "NF", "NO", "OM", "PK", "PW", "PS", "PA", "PG", "PY", "PE", 29 | "PH", "PN", "PL", "PT", "PR", "QA", "RO", "RU", "SH", "KN", 30 | "LC", "PM", "VC", "WS", "SM", "ST", "SA", "RS", "SC", "SL", 31 | "SG", "SX", "SK", "SI", "SB", "SO", "ZA", "GS", "ES", "LK", 32 | "SR", "SJ", "SE", "CH", "TW", "TZ", "TH", "TG", "TK", "TO", 33 | "TT", "TN", "TM", "TC", "TV", "UA", "AE", "GB", "US", "UY", 34 | "UZ", "VU", "VA", "VE", "VN", "VG", "VI", "WF", "EH", "YE", 35 | "ZM", "ZW" 36 | ], 37 | 38 | fields: [], 39 | 40 | formValuesToMerchant : simpleFormValuesToMerchant, 41 | merchantToFormValues : simpleMerchantToFormValues, 42 | keyToMerchant : JSON.parse, 43 | merchantToKey : JSON.stringify, 44 | 45 | ranking: 4 46 | }; 47 | -------------------------------------------------------------------------------- /src/gateways/com.braintreegateway.js: -------------------------------------------------------------------------------- 1 | import { braintreeFormValuesToMerchant, braintreeMerchantToFormValues } from '../adapters'; 2 | 3 | export default { 4 | id : 'com.braintreegateway', 5 | 6 | form : [ 7 | {type : 'string', name : 'merchantId'}, 8 | {type : 'string', name : 'publicKey'}, 9 | {type : 'string', name : 'privateKey'}, 10 | {type : 'currency', name : 'currency'}, 11 | {type : 'string', name : 'merchantAccountId'}, 12 | ], 13 | 14 | // @see https://www.braintreepayments.com/country-selection 15 | countries : [ 16 | 'AD', 'AT', 'AU', 'BE', 'BG', 'CA', 'CH', 'CY', 'CZ', 'DE', 17 | 'DK', 'EE', 'ES', 'FI', 'FR', 'GB', 'GG', 'GI', 'GR', 'HK', 18 | 'HR', 'HU', 'IE', 'IM', 'IS', 'IT', 'JE', 'LI', 'LT', 'LU', 19 | 'LV', 'MC', 'MT', 'MY', 'NL', 'NO', 'NZ', 'PL', 'PT', 'RO', 20 | 'SE', 'SG', 'SI', 'SK', 'SM', 'TR', 'US' 21 | ], 22 | 23 | fields: [], 24 | 25 | formValuesToMerchant : braintreeFormValuesToMerchant, 26 | merchantToFormValues : braintreeMerchantToFormValues, 27 | keyToMerchant : JSON.parse, 28 | merchantToKey : JSON.stringify, 29 | 30 | ranking: 4 31 | }; 32 | -------------------------------------------------------------------------------- /src/gateways/com.dengionline.js: -------------------------------------------------------------------------------- 1 | import { simpleFormValuesToMerchant, simpleMerchantToFormValues } from '../adapters'; 2 | 3 | export default { 4 | id : 'com.dengionline', 5 | 6 | form : [ 7 | {type : 'string', name : 'siteId'}, 8 | {type : 'string', name : 'salt'}, 9 | ], 10 | 11 | countries : [ 12 | 'RU' 13 | ], 14 | 15 | fields: ['holderName', 'csc'], 16 | 17 | formValuesToMerchant : simpleFormValuesToMerchant, 18 | merchantToFormValues : simpleMerchantToFormValues, 19 | keyToMerchant : JSON.parse, 20 | merchantToKey : JSON.stringify, 21 | 22 | ranking: 2 23 | }; 24 | -------------------------------------------------------------------------------- /src/gateways/com.ewaypayments.js: -------------------------------------------------------------------------------- 1 | import { simpleFormValuesToMerchant, simpleMerchantToFormValues } from '../adapters'; 2 | 3 | export default { 4 | id : 'com.ewaypayments', 5 | 6 | form : [ 7 | {type : 'string', name : 'customerId'}, 8 | ], 9 | 10 | // @see List of countries in https://eway.io/ (though some countries are not supported by the API version we use) 11 | countries : [ 12 | // 'AU', 'HK', 'MY', 'NZ', 'SG' 13 | 'AU' 14 | ], 15 | 16 | fields: [], 17 | 18 | formValuesToMerchant : simpleFormValuesToMerchant, 19 | merchantToFormValues : simpleMerchantToFormValues, 20 | keyToMerchant : JSON.parse, 21 | merchantToKey : JSON.stringify, 22 | 23 | ranking: 3 24 | }; 25 | -------------------------------------------------------------------------------- /src/gateways/com.mercadopago.js: -------------------------------------------------------------------------------- 1 | import { simpleFormValuesToMerchant, simpleMerchantToFormValues } from '../adapters'; 2 | 3 | export default { 4 | id : 'com.mercadopago', 5 | 6 | form : [ 7 | {type : 'string', name : 'clientId'}, 8 | {type : 'string', name : 'clientSecret'}, 9 | {type : 'country', name : 'countryCode'} 10 | ], 11 | 12 | // @see https://www.about-payments.com/knowledge-base/method/mercadopago#countries 13 | countries : [ 14 | 'AR', 'BR', 'CL', 'CO', 'MX', 'VE' 15 | ], 16 | 17 | fields: ['holderName', 'holderId', 'csc'], 18 | 19 | formValuesToMerchant : simpleFormValuesToMerchant, 20 | merchantToFormValues : simpleMerchantToFormValues, 21 | keyToMerchant : JSON.parse, 22 | merchantToKey : JSON.stringify, 23 | 24 | ranking: 4 25 | }; 26 | -------------------------------------------------------------------------------- /src/gateways/com.mercurypay.js: -------------------------------------------------------------------------------- 1 | import { simpleFormValuesToMerchant, simpleMerchantToFormValues } from '../adapters'; 2 | 3 | export default { 4 | id : 'com.mercurypay', 5 | 6 | form : [ 7 | {type : 'string', name : 'merchantId'}, 8 | {type : 'string', name : 'password'}, 9 | ], 10 | 11 | countries : [ 12 | 'US', 13 | ], 14 | 15 | fields: [], 16 | 17 | formValuesToMerchant : simpleFormValuesToMerchant, 18 | merchantToFormValues : simpleMerchantToFormValues, 19 | keyToMerchant : JSON.parse, 20 | merchantToKey : JSON.stringify, 21 | 22 | ranking: 3 23 | }; 24 | -------------------------------------------------------------------------------- /src/gateways/com.paguelofacil.js: -------------------------------------------------------------------------------- 1 | import { simpleFormValuesToMerchant, simpleMerchantToFormValues } from '../adapters'; 2 | 3 | export default { 4 | id : 'com.paguelofacil', 5 | 6 | form : [ 7 | {type : 'string', name : 'cclw'}, 8 | ], 9 | 10 | countries : [ 11 | 'PA' 12 | ], 13 | 14 | fields: ['holderName', 'csc'], 15 | 16 | formValuesToMerchant : simpleFormValuesToMerchant, 17 | merchantToFormValues : simpleMerchantToFormValues, 18 | keyToMerchant : JSON.parse, 19 | merchantToKey : JSON.stringify, 20 | 21 | ranking: 3 22 | }; 23 | -------------------------------------------------------------------------------- /src/gateways/com.paybox.js: -------------------------------------------------------------------------------- 1 | import { simpleFormValuesToMerchant, simpleMerchantToFormValues } from '../adapters'; 2 | 3 | export default { 4 | id : 'com.paybox', 5 | 6 | form : [ 7 | {type : 'string', name : 'site'}, 8 | {type : 'string', name : 'rang'}, 9 | {type : 'string', name : 'cle'}, 10 | ], 11 | 12 | countries : [ 13 | 'BE', 'FR', 'NL' 14 | ], 15 | 16 | fields: ['csc'], 17 | 18 | formValuesToMerchant : simpleFormValuesToMerchant, 19 | merchantToFormValues : simpleMerchantToFormValues, 20 | keyToMerchant : JSON.parse, 21 | merchantToKey : JSON.stringify, 22 | 23 | ranking: 4 24 | }; 25 | -------------------------------------------------------------------------------- /src/gateways/com.paymentexpress.js: -------------------------------------------------------------------------------- 1 | import { simpleFormValuesToMerchant, simpleMerchantToFormValues } from '../adapters'; 2 | 3 | export default { 4 | id : 'com.paymentexpress', 5 | 6 | form : [ 7 | {type : 'string', name : 'username'}, 8 | {type : 'string', name : 'password'}, 9 | ], 10 | 11 | // @see https://www.paymentexpress.com/Knowledge_Base/Connectivity.aspx 12 | // @see https://www.paymentexpress.com/Knowledge_Base/Bank_Guides 13 | countries : [ 14 | 'AU', 'BD', 'BN', 'CA', 'GB', 'HK', 'IE', 'MO', 'MY', 'NZ', 15 | 'SG', 'US', 'ZA' 16 | ], 17 | 18 | fields: [], 19 | 20 | formValuesToMerchant : simpleFormValuesToMerchant, 21 | merchantToFormValues : simpleMerchantToFormValues, 22 | keyToMerchant : JSON.parse, 23 | merchantToKey : JSON.stringify, 24 | 25 | ranking: 2 26 | }; 27 | -------------------------------------------------------------------------------- /src/gateways/com.pelecard.js: -------------------------------------------------------------------------------- 1 | import { simpleFormValuesToMerchant, simpleMerchantToFormValues } from '../adapters'; 2 | 3 | export default { 4 | id : 'com.pelecard', 5 | 6 | form : [ 7 | {type : 'string', name : 'terminalNumber'}, 8 | {type : 'string', name : 'user'}, 9 | {type : 'string', name : 'password'}, 10 | {type : 'string', name : 'shopNumber'}, 11 | ], 12 | 13 | countries : [ 14 | 'IL', 15 | ], 16 | 17 | fields: [], 18 | 19 | formValuesToMerchant : simpleFormValuesToMerchant, 20 | merchantToFormValues : simpleMerchantToFormValues, 21 | keyToMerchant : JSON.parse, 22 | merchantToKey : JSON.stringify, 23 | 24 | ranking: 4 25 | }; 26 | -------------------------------------------------------------------------------- /src/gateways/com.stripe.js: -------------------------------------------------------------------------------- 1 | import { simpleFormValuesToMerchant, simpleMerchantToFormValues } from '../adapters'; 2 | 3 | export default { 4 | id : 'com.stripe', 5 | 6 | form : [ 7 | {type : 'string', name : 'apiKey'}, 8 | ], 9 | 10 | // @see https://stripe.com/global 11 | countries : [ 12 | 'AT', 'AU', 'BE', 'BR', 'CA', 'CH', 'DE', 'DK', 'ES', 'FI', 13 | 'FR', 'GB', 'HK', 'IE', 'IT', 'JP', 'LU', 'MX', 'NL', 'NO', 14 | 'NZ', 'PT', 'SE', 'SG', 'US', 'PR' 15 | ], 16 | 17 | fields: [], 18 | 19 | formValuesToMerchant : simpleFormValuesToMerchant, 20 | merchantToFormValues : simpleMerchantToFormValues, 21 | keyToMerchant : JSON.parse, 22 | merchantToKey : JSON.stringify, 23 | 24 | ranking: 5 25 | }; 26 | -------------------------------------------------------------------------------- /src/gateways/com.tranzila.js: -------------------------------------------------------------------------------- 1 | import { simpleFormValuesToMerchant, simpleMerchantToFormValues } from '../adapters'; 2 | 3 | export default { 4 | id : 'com.tranzila', 5 | 6 | form : [ 7 | {type : 'string', name : 'username'}, 8 | ], 9 | 10 | countries : [ 11 | 'IL', 12 | ], 13 | 14 | fields: [], 15 | 16 | formValuesToMerchant : simpleFormValuesToMerchant, 17 | merchantToFormValues : simpleMerchantToFormValues, 18 | keyToMerchant : JSON.parse, 19 | merchantToKey : JSON.stringify, 20 | 21 | ranking: 3 22 | }; 23 | -------------------------------------------------------------------------------- /src/gateways/com.worldpay.enterprise.js: -------------------------------------------------------------------------------- 1 | import { simpleFormValuesToMerchant, simpleMerchantToFormValues } from '../adapters'; 2 | 3 | export default { 4 | id : 'com.worldpay.enterprise', 5 | 6 | form : [ 7 | {type : 'string', name : 'merchantCode'}, 8 | {type : 'string', name : 'merchantPassword'}, 9 | ], 10 | 11 | countries : [ 12 | 'BE', 'CH', 'DE', 'DK', 'ES', 'FI', 'FR', 'GB', 'HK', 'IE', 13 | 'IT', 'LU', 'NL', 'NO', 'SE', 'SG', 'US' 14 | ], 15 | 16 | fields: [], 17 | 18 | formValuesToMerchant : simpleFormValuesToMerchant, 19 | merchantToFormValues : simpleMerchantToFormValues, 20 | keyToMerchant : JSON.parse, 21 | merchantToKey : JSON.stringify, 22 | 23 | ranking: 2 24 | }; 25 | -------------------------------------------------------------------------------- /src/gateways/il.co.creditguard.js: -------------------------------------------------------------------------------- 1 | import { simpleFormValuesToMerchant, simpleMerchantToFormValues } from '../adapters'; 2 | 3 | export default { 4 | id : 'il.co.creditguard', 5 | 6 | form : [ 7 | {type : 'string', name : 'user'}, 8 | {type : 'string', name : 'password'}, 9 | {type : 'string', name : 'terminalNumber'}, 10 | {type : 'string', name : 'supplierNumber'}, 11 | {type : 'string', name : 'idPrefix'} 12 | ], 13 | 14 | countries : [ 15 | 'IL', 16 | ], 17 | 18 | fields: [], 19 | 20 | formValuesToMerchant : simpleFormValuesToMerchant, 21 | merchantToFormValues : simpleMerchantToFormValues, 22 | keyToMerchant : JSON.parse, 23 | merchantToKey : JSON.stringify, 24 | 25 | ranking: 2 26 | }; 27 | -------------------------------------------------------------------------------- /src/gateways/il.co.leumi-card.js: -------------------------------------------------------------------------------- 1 | import { simpleFormValuesToMerchant, simpleMerchantToFormValues } from '../adapters'; 2 | 3 | export default { 4 | id : 'il.co.leumi-card', 5 | 6 | form : [ 7 | {type : 'string', name : 'masof'} 8 | ], 9 | 10 | countries : [ 11 | 'IL', 12 | ], 13 | 14 | fields: ['holderName', 'holderId', 'csc'], 15 | 16 | formValuesToMerchant : simpleFormValuesToMerchant, 17 | merchantToFormValues : simpleMerchantToFormValues, 18 | keyToMerchant : JSON.parse, 19 | merchantToKey : JSON.stringify, 20 | 21 | ranking: 1 22 | }; 23 | -------------------------------------------------------------------------------- /src/gateways/net.authorize.js: -------------------------------------------------------------------------------- 1 | import { simpleFormValuesToMerchant, simpleMerchantToFormValues } from '../adapters'; 2 | 3 | export default { 4 | id : 'net.authorize', 5 | 6 | form : [ 7 | {type : 'string', name : 'login'}, 8 | {type : 'string', name : 'transactionKey'}, 9 | ], 10 | 11 | // @see http://www.authorize.net/international/ 12 | countries : [ 13 | 'AD', 'AT', 'AU', 'BE', 'BG', 'CA', 'CH', 'CY', 'CZ', 'DE', 14 | 'DK', 'ES', 'FI', 'FR', 'GB', 'GI', 'GR', 'GU', 'HU', 'IE', 15 | 'IT', 'LI', 'LU', 'MC', 'MT', 'NL', 'NO', 'NZ', 'PL', 'PT', 16 | 'RO', 'SE', 'SI', 'SK', 'SM', 'US', 'VA' 17 | ], 18 | 19 | fields: [], 20 | 21 | formValuesToMerchant : simpleFormValuesToMerchant, 22 | merchantToFormValues : simpleMerchantToFormValues, 23 | keyToMerchant : JSON.parse, 24 | merchantToKey : JSON.stringify, 25 | 26 | ranking: 4 27 | }; 28 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import * as Methods from './methods'; 2 | import * as Gateways from './gateways'; 3 | 4 | export { 5 | Methods, 6 | Gateways 7 | }; 8 | -------------------------------------------------------------------------------- /src/methods.js: -------------------------------------------------------------------------------- 1 | import _ from 'lodash'; 2 | 3 | import cash from './methods/cash'; 4 | import credit from './methods/credit'; 5 | import cellarix from './methods/com.cellarix'; 6 | import mysodexo from './methods/il.co.mysodexo'; 7 | 8 | // Methods 9 | const methodsList = [ 10 | cash, 11 | credit, 12 | cellarix, 13 | mysodexo 14 | ]; 15 | const methods = _.reduce(methodsList, (methods, method) => {methods[method.id] = method; return methods;}, {}); 16 | 17 | export const getMethodsForCountry = countryCode => { 18 | return _(methods) 19 | .filter(method => (_.isUndefined(method.countries) || _.includes(method.countries, countryCode))) 20 | .map(method => _.omit(method, 'countries')) 21 | .value(); 22 | }; 23 | 24 | export const getMethodDisplayName = (i18nGet, methodId) => i18nGet(`method_${methodId}_title`); 25 | -------------------------------------------------------------------------------- /src/methods/cash.js: -------------------------------------------------------------------------------- 1 | export default { 2 | id: 'cash' 3 | }; -------------------------------------------------------------------------------- /src/methods/com.cellarix.js: -------------------------------------------------------------------------------- 1 | export default { 2 | id: 'com.cellarix', 3 | countries: [ 4 | 'IL' 5 | ] 6 | }; 7 | -------------------------------------------------------------------------------- /src/methods/credit.js: -------------------------------------------------------------------------------- 1 | export default { 2 | id: 'credit' 3 | }; -------------------------------------------------------------------------------- /src/methods/il.co.mysodexo.js: -------------------------------------------------------------------------------- 1 | export default { 2 | id: 'il.co.mysodexo', 3 | countries: [ 4 | 'IL' 5 | ] 6 | }; 7 | -------------------------------------------------------------------------------- /test/adapters.test.js: -------------------------------------------------------------------------------- 1 | import { expect } from 'chai'; 2 | import * as adapters from '../src/adapters'; 3 | 4 | /***** Mock objects for testing the adapter *****/ 5 | // Generic object with arbitrary fields 6 | const formValues = { 7 | 'terminalNumber' : 'termnum', 8 | 'user' : 'username', 9 | 'password' : 'pwd' 10 | }; 11 | 12 | const merchant = { 13 | terminalNumber : 'termnum', 14 | user : 'username', 15 | password : 'pwd' 16 | }; 17 | 18 | // Braintree special object 19 | const btFormValues = { 20 | 'merchantId' : 'merchant identification number', 21 | 'publicKey' : 'a public key', 22 | 'privateKey' : 'a private key', 23 | 'currency' : 'USD', 24 | 'merchantAccountId' : 'some merchant account ID' 25 | }; 26 | 27 | const btMerchant = { 28 | merchantId : 'merchant identification number', 29 | publicKey : 'a public key', 30 | privateKey : 'a private key', 31 | merchantAccountIds : { 32 | 'USD' : 'some merchant account ID' 33 | } 34 | }; 35 | /*********************************************/ 36 | 37 | 38 | /*********** Tests ******************/ 39 | describe('Adapters', () => { 40 | it ('returns merchant from form', () => { 41 | expect(adapters.simpleFormValuesToMerchant(formValues)).to.deep.equal(merchant); 42 | }); 43 | it ('returns form from merchant', () => { 44 | expect(adapters.simpleMerchantToFormValues(merchant)).to.deep.equal(formValues); 45 | }); 46 | }); 47 | 48 | describe('Braintree Adapters', () => { 49 | it ('returns merchant from form', () => { 50 | expect(adapters.braintreeFormValuesToMerchant(btFormValues)).to.deep.equal(btMerchant); 51 | }); 52 | it ('returns form from merchant', () => { 53 | expect(adapters.braintreeMerchantToFormValues(btMerchant)).to.deep.equal(btFormValues); 54 | }); 55 | }); 56 | -------------------------------------------------------------------------------- /test/gateways.test.js: -------------------------------------------------------------------------------- 1 | import {expect} from 'chai'; 2 | import _ from 'lodash'; 3 | import * as gateways from '../src/gateways'; 4 | 5 | 6 | describe('gateways', () => { 7 | const i18nGet = (token) => token; 8 | 9 | describe('getGatewaysForCountry', () => { 10 | it ('returns just the gateways that support the given country', () => { 11 | const israeliGateways = gateways.getGatewaysForCountry('IL'); 12 | expect(israeliGateways).to.have.length.of(3); 13 | }); 14 | 15 | it ('returns gateways sorted by ranking, in descending order', () => { 16 | const israeliGateways = gateways.getGatewaysForCountry('IL'); 17 | expect(_.head(israeliGateways).id).to.equal('com.pelecard'); 18 | expect(_.last(israeliGateways).id).to.equal('il.co.creditguard'); 19 | }); 20 | 21 | it ('omits countries and ranking fields', () => { 22 | const israeliGateways = gateways.getGatewaysForCountry('IL'); 23 | const gateway = _.head(israeliGateways); 24 | expect(gateway.countries).to.be.undefined; 25 | expect(gateway.ranking).to.be.undefined; 26 | }); 27 | }); 28 | 29 | describe('getGatewayById', () => { 30 | it ('returns the expected object when fetching eway', () => { 31 | const gateway = gateways.getGatewayById('com.ewaypayments'); 32 | expect(gateway.id).to.equal('com.ewaypayments'); 33 | }); 34 | }); 35 | 36 | describe('getGatewayDisplayName', () => { 37 | it ('returns "gateway_com.braintreegateway_title" for "com.braintreegateway" (gateway name)', () => { 38 | expect(gateways.getGatewayDisplayName(i18nGet, 'com.braintreegateway')).to.equal('gateway_com.braintreegateway_title'); 39 | }); 40 | }); 41 | 42 | describe('getGatewayFieldDisplayName', () => { 43 | it ('returns "gateway_com.braintreegateway_field_merchantId" for Braintree "merchantId" (gateway field)', () => { 44 | expect(gateways.getGatewayFieldDisplayName(i18nGet, 'com.braintreegateway', 'merchantId')).to.equal('gateway_com.braintreegateway_field_merchantId'); 45 | }); 46 | }); 47 | }); -------------------------------------------------------------------------------- /test/methods.test.js: -------------------------------------------------------------------------------- 1 | import { expect } from 'chai'; 2 | import * as methods from '../src/methods'; 3 | 4 | 5 | describe('Getting method by country tests', () => { 6 | it ('returns the expected object when fetching Israel', () => { 7 | const israeliMethods = methods.getMethodsForCountry('IL'); 8 | expect(israeliMethods).to.have.length.of(4); 9 | }); 10 | }); 11 | 12 | 13 | describe('Locale tests)', () => { 14 | const i18nGet = (token) => token; 15 | it ('returns "method_cash_title" for "cash" (method name)', () => { 16 | expect(methods.getMethodDisplayName(i18nGet, 'cash')).to.equal('method_cash_title'); 17 | }); 18 | }); 19 | --------------------------------------------------------------------------------