payments
Version:
Lists various payment methods. Used by Wix Restaurants for payment configuration.
47 lines (39 loc) • 2.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.braintreeMerchantToFormValues = exports.braintreeFormValuesToMerchant = exports.simpleMerchantToFormValues = exports.simpleFormValuesToMerchant = undefined;
var _lodash = require('lodash');
var _lodash2 = _interopRequireDefault(_lodash);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// Convert form values received from the UI to a merchant object
var simpleFormValuesToMerchant = exports.simpleFormValuesToMerchant = function simpleFormValuesToMerchant(formValues) {
return _lodash2.default.reduce(formValues, function (merchant, value, name) {
merchant[name] = value;
return merchant;
}, {});
};
// Convert a merchant object to a form that that UI can display
var simpleMerchantToFormValues = exports.simpleMerchantToFormValues = function simpleMerchantToFormValues(merchant) {
return _lodash2.default.reduce(merchant, function (formValues, value, name) {
formValues[name] = value;
return formValues;
}, {});
};
/****** Special Braintree handling **********/
var braintreeFormValuesToMerchant = exports.braintreeFormValuesToMerchant = function braintreeFormValuesToMerchant(formValues) {
var merchant = simpleFormValuesToMerchant(formValues);
merchant.merchantAccountIds = {};
merchant.merchantAccountIds[merchant.currency] = merchant.merchantAccountId;
delete merchant.currency;
delete merchant.merchantAccountId;
return merchant;
};
var braintreeMerchantToFormValues = exports.braintreeMerchantToFormValues = function braintreeMerchantToFormValues(merchant) {
var formValues = simpleMerchantToFormValues(_lodash2.default.omit(merchant, 'merchantAccountIds'));
var firstMerchantAccountId = _lodash2.default.chain(merchant.merchantAccountIds).toPairs().first().value() || ['', ''];
formValues['currency'] = firstMerchantAccountId[0];
formValues['merchantAccountId'] = firstMerchantAccountId[1];
return formValues;
};
/*******************************************/