Martin Donnelly 57bd6c8e6a init
2018-06-24 21:15:03 +01:00

90 lines
3.0 KiB
JavaScript

/**
* Functions to interact with Worldpay
* This is based on the Worldpay JSON API Specification.
* @see {@url https://developer.worldpay.com/jsonapi/api}
*/
'use strict';
const Q = require('q');
const _ = require('lodash');
const debug = require('debug')('utils:acquirers:worldpay');
const errors = require(global.pathPrefix + '../utils/acquirers/acquirer_errors.js');
const encryption = require(global.pathPrefix + '../utils/encryption.js');
module.exports = {
invalidateMerchantAccount: invalidateMerchantAccount,
payTransaction: payTransaction,
validateMerchantAccount: validateMerchantAccount
};
/**
* Demo accounts don't have any stored tokens, so nothing to do here
*
* @param {string} token - The token to be invalidated
* @param {string} merchantID - The merchant ID of the account
* @param {string} cipher - The merchant cipher of the account
* @param {string} accountID - The accountID for creating a tracking id
*
* @returns {promise} - A promise that resolves on success, or rejects on fail
*/
function invalidateMerchantAccount(token, merchantID, cipher, accountID) {
return Q.resolve();
}
/**
* Makes a payment from customer to merchant using the appropriate acquirer
*
* @param {Object} client - the client making the payment
* @param {Object} device - the device the client is using
* @param {Object} data - various neccessary data
* @param {String} data.ClientKey - the client key required to decrypt the payment details
* @param {String} data.ipAddress - ipAddress of the client
* @param {Object} [data.cardDetails] - optional decrypted card details
* @param {Object} transaction - The transaction object with the payment info
* @param {Object} merchantInfo - Merchant account and address info
* @param {Object} customerInfo - Customer account and address info
*
* @returns {Promise} - Resolves to payment info, or rejects ERRORS value
*/
function payTransaction(
client,
device,
data,
transaction,
merchantInfo,
customerInfo
) {
/**
* Check that we have a payment method we can use
*/
if (
customerInfo.account.AcquirerName !== 'Demo' &&
customerInfo.account.AccountType !== 'Direct Credit/Debit Card Payment'
) {
return Q.reject({name: errors.INVALID_COMBINATION});
}
//
// Always return success
//
const info = {
SaleReference: 'DEMO SALE REF',
SaleAuthCode: 'DEMO SALE AUTH',
RiskScore: 0,
AVSResponse: '',
GatewayResponse: 'DEMO SALE G-RESPONSE',
};
return Q.resolve(info);
}
/**
* Validates that a merchant account is valid for Demo. This always returns
* success
*
* @param {Object} account - the account to validate
* @returns {Promise} - resolves on succes or rejects with ERRORS value
*/
function validateMerchantAccount(account) {
return Q.resolve(); // No other tests neccessary for a demo account
}