UNPKG

medusa-plugin-culqi-card

Version:

Medusa plugin for processing credit card payments with Culqi

1,158 lines (1,155 loc) 46.2 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator")); var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray")); var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties")); var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof")); var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); var _axios = _interopRequireDefault(require("axios")); var _lodash = require("lodash"); var _culqiLog = require("../models/culqi-log"); var _excluded = ["operation"]; function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } var CulqiClient = /*#__PURE__*/function () { function CulqiClient(culqiLogService) { (0, _classCallCheck2["default"])(this, CulqiClient); this.culqiLogService_ = culqiLogService; var secretKey = process.env.CULQI_SECRET_KEY; this.isTestEnv_ = secretKey.startsWith('sk_test_'); this.appEnv_ = process.env.CULQI_APP_ENV; this.devEmail_ = process.env.CULQI_DEV_EMAIL; this.log_culqi_requests_ = process.env.CULQI_LOG_CULQI_REQUESTS === 'true'; // API HTTP client this.httpInstance = _axios["default"].create({ baseURL: 'https://api.culqi.com/v2' }); this.httpInstance.defaults.headers.common['Authorization'] = "Bearer ".concat(secretKey); } (0, _createClass2["default"])(CulqiClient, [{ key: "objectToUrlSearchParams", value: function objectToUrlSearchParams(obj) { var rootName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; var ignoreList = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; var urlSearchParams = new URLSearchParams(); function appendUrlSearchParams(data, root) { if (!ignore(root)) { root = root || ''; if (Array.isArray(data)) { for (var i = 0; i < data.length; i++) { appendUrlSearchParams(data[i], root + '[' + i + ']'); } } else if ((0, _typeof2["default"])(data) === 'object' && data) { for (var key in data) { if (data.hasOwnProperty(key)) { if (root === '') { appendUrlSearchParams(data[key], key); } else { appendUrlSearchParams(data[key], root + '.' + key); } } } } else if (data !== null && typeof data !== 'undefined') { urlSearchParams.append(root, data); } } } function ignore(root) { return Array.isArray(ignoreList) && ignoreList.some(function (x) { return x === root; }); } appendUrlSearchParams(obj, rootName); return urlSearchParams; } /** * http * @param {CulqiAxiosRequestConfig} axiosConfig - axios config * @returns {Promise} - HTTP response */ }, { key: "http", value: function () { var _http = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(axiosConfig) { var operation, config, requestData, log, response, error, _response$headers, _response$headers2, isSuccessStatusCode, data; return _regenerator["default"].wrap(function _callee$(_context) { while (1) switch (_context.prev = _context.next) { case 0: operation = axiosConfig.operation, config = (0, _objectWithoutProperties2["default"])(axiosConfig, _excluded); requestData = config.data || config.params; log = { tracking_id: '', culqi_version: '', operation: operation, url: config.url.startsWith('/') ? config.url.substring(1) : config.url, request: requestData, response: {} }; _context.prev = 3; if (config.params) { config.params = this.objectToUrlSearchParams(config.params); } log.start_date_utc = new Date(); _context.next = 8; return this.httpInstance(_objectSpread(_objectSpread({}, config), {}, { headers: { 'Accept-Encoding': 'identity' } })); case 8: response = _context.sent; _context.next = 15; break; case 11: _context.prev = 11; _context.t0 = _context["catch"](3); error = { object: null, type: null, charge_id: null, code: null, decline_code: null, merchant_message: _context.t0.message, user_message: null, param: null }; if ((0, _lodash.isObject)(_context.t0.response)) { response = _context.t0.response; } case 15: _context.prev = 15; log.end_date_utc = new Date(); if (response) { log.http_code = response.status; if (typeof response.data === 'string') { response.data = { object: null, type: null, charge_id: null, code: null, decline_code: null, merchant_message: response.data, user_message: 'Culqi Server Error', param: null }; } log.response = response.data || {}; if ((_response$headers = response.headers) !== null && _response$headers !== void 0 && _response$headers['x-culqi-tracking-id']) { log.tracking_id = response.headers['x-culqi-tracking-id']; } if ((_response$headers2 = response.headers) !== null && _response$headers2 !== void 0 && _response$headers2['x-culqi-version']) { log.culqi_version = response.headers['x-culqi-version']; } } if (!this.log_culqi_requests_) { _context.next = 27; break; } _context.prev = 19; _context.next = 22; return this.culqiLogService_.create(log); case 22: _context.next = 27; break; case 24: _context.prev = 24; _context.t1 = _context["catch"](19); // eslint-disable-next-line no-console console.error('medusa-plugin-culqi-card -- CulqiLogService.create -- error', _context.t1); case 27: return _context.finish(15); case 28: if (!response) { _context.next = 34; break; } isSuccessStatusCode = response.status >= 200 && response.status <= 299; data = response.data; if (!isSuccessStatusCode) { _context.next = 33; break; } return _context.abrupt("return", [data, null]); case 33: return _context.abrupt("return", [null, data]); case 34: return _context.abrupt("return", [null, error]); case 35: case "end": return _context.stop(); } }, _callee, this, [[3, 11, 15, 28], [19, 24]]); })); function http(_x) { return _http.apply(this, arguments); } return http; }() // region Customers /** * get customer (async) * @param {string} customerId - customer id * @returns {object} - Response */ }, { key: "getCustomerAsync", value: function () { var _getCustomerAsync = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(customerId) { return _regenerator["default"].wrap(function _callee2$(_context2) { while (1) switch (_context2.prev = _context2.next) { case 0: _context2.next = 2; return this.http({ operation: _culqiLog.OperationType.GET_CUSTOMER, method: 'get', url: "/customers/".concat(customerId) }); case 2: return _context2.abrupt("return", _context2.sent); case 3: case "end": return _context2.stop(); } }, _callee2, this); })); function getCustomerAsync(_x2) { return _getCustomerAsync.apply(this, arguments); } return getCustomerAsync; }() /** * get customers (async) * @param {?CustomersListRequest} [listCustomersRequest=null] - list customers request * @returns {object} - Response */ }, { key: "getCustomersAsync", value: function () { var _getCustomersAsync = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3() { var listCustomersRequest, _args3 = arguments; return _regenerator["default"].wrap(function _callee3$(_context3) { while (1) switch (_context3.prev = _context3.next) { case 0: listCustomersRequest = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : null; _context3.next = 3; return this.http({ operation: _culqiLog.OperationType.LIST_CUSTOMERS, method: 'get', url: '/customers', params: listCustomersRequest }); case 3: return _context3.abrupt("return", _context3.sent); case 4: case "end": return _context3.stop(); } }, _callee3, this); })); function getCustomersAsync() { return _getCustomersAsync.apply(this, arguments); } return getCustomersAsync; }() /** * create customer (async) * @param {CustomerCreatePayload} customerRequest - customer request * @returns {object} - Response */ }, { key: "createCustomerAsync", value: function () { var _createCustomerAsync = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4(customerRequest) { var _customerRequest$addr, _customerRequest$addr2; var _yield$this$http, _yield$this$http2, customer, error, listRequest, _yield$this$getCustom, _yield$this$getCustom2, culqiCustomers, listError; return _regenerator["default"].wrap(function _callee4$(_context4) { while (1) switch (_context4.prev = _context4.next) { case 0: if (customerRequest.first_name.length > 50) { customerRequest.first_name = customerRequest.first_name.substring(0, 50); } if (customerRequest.last_name.length > 50) { customerRequest.last_name = customerRequest.last_name.substring(0, 50); } if (customerRequest.phone_number) { customerRequest.phone_number = customerRequest.phone_number.replace(/\D/g, ''); if (customerRequest.phone_number.length > 15) { customerRequest.phone_number = customerRequest.phone_number.substring(0, 15); } } if (((_customerRequest$addr = customerRequest.address) === null || _customerRequest$addr === void 0 ? void 0 : _customerRequest$addr.length) > 100) { customerRequest.address = customerRequest.address.substring(0, 100); } if (((_customerRequest$addr2 = customerRequest.address_city) === null || _customerRequest$addr2 === void 0 ? void 0 : _customerRequest$addr2.length) > 30) { customerRequest.address_city = customerRequest.address_city.substring(0, 30); } if (this.isTestEnv_ && this.appEnv_) { customerRequest.email = customerRequest.email.replace('@', "_".concat(this.appEnv_, "@")); } _context4.next = 8; return this.http({ operation: _culqiLog.OperationType.CREATE_CUSTOMER, method: 'post', url: '/customers', data: customerRequest }); case 8: _yield$this$http = _context4.sent; _yield$this$http2 = (0, _slicedToArray2["default"])(_yield$this$http, 2); customer = _yield$this$http2[0]; error = _yield$this$http2[1]; if (!error) { _context4.next = 25; break; } if (!(error.merchant_message === 'Un cliente esta registrado actualmente con este email.')) { _context4.next = 24; break; } listRequest = { email: customerRequest.email }; _context4.next = 17; return this.getCustomersAsync(listRequest); case 17: _yield$this$getCustom = _context4.sent; _yield$this$getCustom2 = (0, _slicedToArray2["default"])(_yield$this$getCustom, 2); culqiCustomers = _yield$this$getCustom2[0]; listError = _yield$this$getCustom2[1]; if (!listError) { _context4.next = 23; break; } return _context4.abrupt("return", [null, null, listError]); case 23: return _context4.abrupt("return", [culqiCustomers.data[0], true, null]); case 24: return _context4.abrupt("return", [null, null, error]); case 25: return _context4.abrupt("return", [customer, false, null]); case 26: case "end": return _context4.stop(); } }, _callee4, this); })); function createCustomerAsync(_x3) { return _createCustomerAsync.apply(this, arguments); } return createCustomerAsync; }() /** * update customer (async) * @param {string} customerId - customer id * @param {CustomerUpdatePayload} update - customer request * @returns {object} - Response */ }, { key: "updateCustomerAsync", value: function () { var _updateCustomerAsync = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5(customerId, update) { return _regenerator["default"].wrap(function _callee5$(_context5) { while (1) switch (_context5.prev = _context5.next) { case 0: _context5.next = 2; return this.http({ operation: _culqiLog.OperationType.UPDATE_CUSTOMER, method: 'patch', url: "/customers/".concat(customerId), data: update }); case 2: return _context5.abrupt("return", _context5.sent); case 3: case "end": return _context5.stop(); } }, _callee5, this); })); function updateCustomerAsync(_x4, _x5) { return _updateCustomerAsync.apply(this, arguments); } return updateCustomerAsync; }() /** * delete customer (async) * @param {string} customerId - customer id * @returns {boolean} - Response */ }, { key: "deleteCustomerAsync", value: function () { var _deleteCustomerAsync = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee6(customerId) { var _yield$this$http3, _yield$this$http4, _, error; return _regenerator["default"].wrap(function _callee6$(_context6) { while (1) switch (_context6.prev = _context6.next) { case 0: _context6.next = 2; return this.http({ operation: _culqiLog.OperationType.DELETE_CUSTOMER, method: 'get', url: "/customers/".concat(customerId) }); case 2: _yield$this$http3 = _context6.sent; _yield$this$http4 = (0, _slicedToArray2["default"])(_yield$this$http3, 2); _ = _yield$this$http4[0]; error = _yield$this$http4[1]; if (!error) { _context6.next = 8; break; } return _context6.abrupt("return", [false, error]); case 8: return _context6.abrupt("return", [true, null]); case 9: case "end": return _context6.stop(); } }, _callee6, this); })); function deleteCustomerAsync(_x6) { return _deleteCustomerAsync.apply(this, arguments); } return deleteCustomerAsync; }() // endregion //region Tokens /** * get token (async) * @param {string} tokenId - token id * @returns {object} - Response */ }, { key: "getTokenAsync", value: function () { var _getTokenAsync = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee7(tokenId) { return _regenerator["default"].wrap(function _callee7$(_context7) { while (1) switch (_context7.prev = _context7.next) { case 0: _context7.next = 2; return this.http({ operation: _culqiLog.OperationType.GET_TOKEN, method: 'get', url: "/tokens/".concat(tokenId) }); case 2: return _context7.abrupt("return", _context7.sent); case 3: case "end": return _context7.stop(); } }, _callee7, this); })); function getTokenAsync(_x7) { return _getTokenAsync.apply(this, arguments); } return getTokenAsync; }() //endregion // region Cards /** * get cards (async) * @param {?CardsListRequest} [listCardsRequest=null] - list cards request * @returns {object} - Response */ }, { key: "getCardsAsync", value: function () { var _getCardsAsync = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee8() { var listCardsRequest, _args8 = arguments; return _regenerator["default"].wrap(function _callee8$(_context8) { while (1) switch (_context8.prev = _context8.next) { case 0: listCardsRequest = _args8.length > 0 && _args8[0] !== undefined ? _args8[0] : null; _context8.next = 3; return this.http({ operation: _culqiLog.OperationType.LIST_CARDS, method: 'get', url: '/cards', params: listCardsRequest }); case 3: return _context8.abrupt("return", _context8.sent); case 4: case "end": return _context8.stop(); } }, _callee8, this); })); function getCardsAsync() { return _getCardsAsync.apply(this, arguments); } return getCardsAsync; }() /** * gets a cards by customer identifier (async) * @param {string} customerId - customer identifier * @returns {object} - Response */ }, { key: "getCardsByCustomerAsync", value: function () { var _getCardsByCustomerAsync = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee9(customerId) { var _customer$cards; var _yield$this$getCustom3, _yield$this$getCustom4, customer, error; return _regenerator["default"].wrap(function _callee9$(_context9) { while (1) switch (_context9.prev = _context9.next) { case 0: _context9.next = 2; return this.getCustomerAsync(customerId); case 2: _yield$this$getCustom3 = _context9.sent; _yield$this$getCustom4 = (0, _slicedToArray2["default"])(_yield$this$getCustom3, 2); customer = _yield$this$getCustom4[0]; error = _yield$this$getCustom4[1]; if (!error) { _context9.next = 8; break; } return _context9.abrupt("return", [null, error]); case 8: return _context9.abrupt("return", [(_customer$cards = customer === null || customer === void 0 ? void 0 : customer.cards) !== null && _customer$cards !== void 0 ? _customer$cards : [], null]); case 9: case "end": return _context9.stop(); } }, _callee9, this); })); function getCardsByCustomerAsync(_x8) { return _getCardsByCustomerAsync.apply(this, arguments); } return getCardsByCustomerAsync; }() /** * get card (async) * @param {string} cardId - card identifier * @returns {object} - Response */ }, { key: "getCardAsync", value: function () { var _getCardAsync = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee10(cardId) { return _regenerator["default"].wrap(function _callee10$(_context10) { while (1) switch (_context10.prev = _context10.next) { case 0: _context10.next = 2; return this.http({ operation: _culqiLog.OperationType.GET_CARD, method: 'get', url: "/cards/".concat(cardId) }); case 2: return _context10.abrupt("return", _context10.sent); case 3: case "end": return _context10.stop(); } }, _callee10, this); })); function getCardAsync(_x9) { return _getCardAsync.apply(this, arguments); } return getCardAsync; }() /** * create card (async) * @param {CardCreatePayload} card - card request * @returns {object} - Response */ }, { key: "createCardAsync", value: function () { var _createCardAsync = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee11(card) { return _regenerator["default"].wrap(function _callee11$(_context11) { while (1) switch (_context11.prev = _context11.next) { case 0: return _context11.abrupt("return", this.http({ operation: _culqiLog.OperationType.CREATE_CARD, method: 'post', url: '/cards', data: card })); case 1: case "end": return _context11.stop(); } }, _callee11, this); })); function createCardAsync(_x10) { return _createCardAsync.apply(this, arguments); } return createCardAsync; }() /** * update card (async) * @param {string} cardId - card id * @param {CardUpdatePayload} update - card request * @returns {object} - Response */ }, { key: "updateCardAsync", value: function () { var _updateCardAsync = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee12(cardId, update) { return _regenerator["default"].wrap(function _callee12$(_context12) { while (1) switch (_context12.prev = _context12.next) { case 0: _context12.next = 2; return this.http({ operation: _culqiLog.OperationType.UPDATE_CARD, method: 'patch', url: "/cards/".concat(cardId), data: update }); case 2: return _context12.abrupt("return", _context12.sent); case 3: case "end": return _context12.stop(); } }, _callee12, this); })); function updateCardAsync(_x11, _x12) { return _updateCardAsync.apply(this, arguments); } return updateCardAsync; }() // endregion // region Charges /** * get charges (async) * @param {?ChargesListRequest} [listChargesRequest=null] - list charges request * @returns {object} - Response */ }, { key: "getChargesAsync", value: function () { var _getChargesAsync = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee13() { var listChargesRequest, _args13 = arguments; return _regenerator["default"].wrap(function _callee13$(_context13) { while (1) switch (_context13.prev = _context13.next) { case 0: listChargesRequest = _args13.length > 0 && _args13[0] !== undefined ? _args13[0] : null; _context13.next = 3; return this.http({ operation: _culqiLog.OperationType.LIST_CHARGES, method: 'get', url: '/charges', params: listChargesRequest }); case 3: return _context13.abrupt("return", _context13.sent); case 4: case "end": return _context13.stop(); } }, _callee13, this); })); function getChargesAsync() { return _getChargesAsync.apply(this, arguments); } return getChargesAsync; }() /** * get charge (async) * @param {string} chargeId - charge identifier * @returns {object} - Response */ }, { key: "getChargeAsync", value: function () { var _getChargeAsync = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee14(chargeId) { return _regenerator["default"].wrap(function _callee14$(_context14) { while (1) switch (_context14.prev = _context14.next) { case 0: _context14.next = 2; return this.http({ operation: _culqiLog.OperationType.GET_CHARGES, method: 'get', url: "/charges/".concat(chargeId) }); case 2: return _context14.abrupt("return", _context14.sent); case 3: case "end": return _context14.stop(); } }, _callee14, this); })); function getChargeAsync(_x13) { return _getChargeAsync.apply(this, arguments); } return getChargeAsync; }() /** * create charge (async) * @param {ChargeCreatePayload} charge - charge request * @returns {object} - Response */ }, { key: "createChargeAsync", value: function () { var _createChargeAsync = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee15(charge) { var _charge$antifraud_det, _charge$antifraud_det2, _charge$antifraud_det3, _charge$antifraud_det4, _charge$antifraud_det5, _charge$antifraud_det6, _charge$antifraud_det7; var originalEmail; return _regenerator["default"].wrap(function _callee15$(_context15) { while (1) switch (_context15.prev = _context15.next) { case 0: if (((_charge$antifraud_det = charge.antifraud_details) === null || _charge$antifraud_det === void 0 ? void 0 : _charge$antifraud_det.first_name.length) > 50) { charge.antifraud_details.first_name = charge.antifraud_details.first_name.substring(0, 50); } if (((_charge$antifraud_det2 = charge.antifraud_details) === null || _charge$antifraud_det2 === void 0 ? void 0 : _charge$antifraud_det2.last_name.length) > 50) { charge.antifraud_details.last_name = charge.antifraud_details.last_name.substring(0, 50); } if ((_charge$antifraud_det3 = charge.antifraud_details) !== null && _charge$antifraud_det3 !== void 0 && _charge$antifraud_det3.phone_number) { charge.antifraud_details.phone_number = charge.antifraud_details.phone_number.replace(/\D/g, ''); if (charge.antifraud_details.phone_number.length > 15) { charge.antifraud_details.phone_number = charge.antifraud_details.phone_number.substring(0, 15); } } if (((_charge$antifraud_det4 = charge.antifraud_details) === null || _charge$antifraud_det4 === void 0 ? void 0 : (_charge$antifraud_det5 = _charge$antifraud_det4.address) === null || _charge$antifraud_det5 === void 0 ? void 0 : _charge$antifraud_det5.length) > 100) { charge.antifraud_details.address = charge.antifraud_details.address.substring(0, 100); } if (((_charge$antifraud_det6 = charge.antifraud_details) === null || _charge$antifraud_det6 === void 0 ? void 0 : (_charge$antifraud_det7 = _charge$antifraud_det6.address_city) === null || _charge$antifraud_det7 === void 0 ? void 0 : _charge$antifraud_det7.length) > 30) { charge.antifraud_details.address_city = charge.antifraud_details.address_city.substring(0, 30); } if (this.isTestEnv_ && this.devEmail_) { originalEmail = charge.email; charge.email = this.devEmail_; if (!charge.metadata) { charge.metadata = {}; } charge.metadata.originalEmail = originalEmail; if (this.appEnv_) { charge.metadata.env = this.appEnv_; } } return _context15.abrupt("return", this.http({ operation: _culqiLog.OperationType.CREATE_CHARGE, method: 'post', url: '/charges', data: charge })); case 7: case "end": return _context15.stop(); } }, _callee15, this); })); function createChargeAsync(_x14) { return _createChargeAsync.apply(this, arguments); } return createChargeAsync; }() /** * capture charge (async) * @param {string} chargeId - charge id * @returns {object} - Response */ }, { key: "captureChargeAsync", value: function () { var _captureChargeAsync = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee16(chargeId) { return _regenerator["default"].wrap(function _callee16$(_context16) { while (1) switch (_context16.prev = _context16.next) { case 0: return _context16.abrupt("return", this.http({ operation: _culqiLog.OperationType.CAPTURE_CHARGE, method: 'post', url: "/charges/".concat(chargeId, "/capture") })); case 1: case "end": return _context16.stop(); } }, _callee16, this); })); function captureChargeAsync(_x15) { return _captureChargeAsync.apply(this, arguments); } return captureChargeAsync; }() /** * update charge (async) * @param {string} chargeId - charge id * @param {ChargeUpdatePayload} update - charge request * @returns {object} - Response */ }, { key: "updateChargeAsync", value: function () { var _updateChargeAsync = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee17(chargeId, update) { return _regenerator["default"].wrap(function _callee17$(_context17) { while (1) switch (_context17.prev = _context17.next) { case 0: _context17.next = 2; return this.http({ operation: _culqiLog.OperationType.UPDATE_CHARGE, method: 'patch', url: "/charges/".concat(chargeId), data: update }); case 2: return _context17.abrupt("return", _context17.sent); case 3: case "end": return _context17.stop(); } }, _callee17, this); })); function updateChargeAsync(_x16, _x17) { return _updateChargeAsync.apply(this, arguments); } return updateChargeAsync; }() // endregion // region Refunds /** * get refunds (async) * @param {?RefundsListRequest} [listRefundsRequest=null] - list refunds request * @returns {object} - Response */ }, { key: "getRefundsAsync", value: function () { var _getRefundsAsync = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee18() { var listRefundsRequest, _args18 = arguments; return _regenerator["default"].wrap(function _callee18$(_context18) { while (1) switch (_context18.prev = _context18.next) { case 0: listRefundsRequest = _args18.length > 0 && _args18[0] !== undefined ? _args18[0] : null; _context18.next = 3; return this.http({ operation: _culqiLog.OperationType.LIST_REFUNDS, method: 'get', url: '/refunds', params: listRefundsRequest }); case 3: return _context18.abrupt("return", _context18.sent); case 4: case "end": return _context18.stop(); } }, _callee18, this); })); function getRefundsAsync() { return _getRefundsAsync.apply(this, arguments); } return getRefundsAsync; }() /** * get refund (async) * @param {string} refundId - refund identifier * @returns {object} - Response */ }, { key: "getRefundAsync", value: function () { var _getRefundAsync = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee19(refundId) { return _regenerator["default"].wrap(function _callee19$(_context19) { while (1) switch (_context19.prev = _context19.next) { case 0: _context19.next = 2; return this.http({ operation: _culqiLog.OperationType.GET_REFUND, method: 'get', url: "/refunds/".concat(refundId) }); case 2: return _context19.abrupt("return", _context19.sent); case 3: case "end": return _context19.stop(); } }, _callee19, this); })); function getRefundAsync(_x18) { return _getRefundAsync.apply(this, arguments); } return getRefundAsync; }() /** * create refund (async) * @param {RefundCreatePayload} refund - refund request * @returns {object} - Response */ }, { key: "createRefundAsync", value: function () { var _createRefundAsync = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee20(refund) { return _regenerator["default"].wrap(function _callee20$(_context20) { while (1) switch (_context20.prev = _context20.next) { case 0: return _context20.abrupt("return", this.http({ operation: _culqiLog.OperationType.CREATE_REFUND, method: 'post', url: '/refunds', data: refund })); case 1: case "end": return _context20.stop(); } }, _callee20, this); })); function createRefundAsync(_x19) { return _createRefundAsync.apply(this, arguments); } return createRefundAsync; }() /** * update refund (async) * @param {string} refundId - refund id * @param {RefundUpdatePayload} update - refund request * @returns {object} - Response */ }, { key: "updateRefundAsync", value: function () { var _updateRefundAsync = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee21(refundId, update) { return _regenerator["default"].wrap(function _callee21$(_context21) { while (1) switch (_context21.prev = _context21.next) { case 0: _context21.next = 2; return this.http({ operation: _culqiLog.OperationType.UPDATE_REFUND, method: 'patch', url: "/refunds/".concat(refundId), data: update }); case 2: return _context21.abrupt("return", _context21.sent); case 3: case "end": return _context21.stop(); } }, _callee21, this); })); function updateRefundAsync(_x20, _x21) { return _updateRefundAsync.apply(this, arguments); } return updateRefundAsync; }() // endregion // region Orders /** * get orders (async) * @param {?OrdersListRequest} [listOrdersRequest=null] - list orders request * @returns {object} - Response */ }, { key: "getOrdersAsync", value: function () { var _getOrdersAsync = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee22() { var listOrdersRequest, _args22 = arguments; return _regenerator["default"].wrap(function _callee22$(_context22) { while (1) switch (_context22.prev = _context22.next) { case 0: listOrdersRequest = _args22.length > 0 && _args22[0] !== undefined ? _args22[0] : null; _context22.next = 3; return this.http({ operation: _culqiLog.OperationType.LIST_ORDERS, method: 'get', url: '/orders', params: listOrdersRequest }); case 3: return _context22.abrupt("return", _context22.sent); case 4: case "end": return _context22.stop(); } }, _callee22, this); })); function getOrdersAsync() { return _getOrdersAsync.apply(this, arguments); } return getOrdersAsync; }() /** * get order (async) * @param {string} orderId - order identifier * @returns {object} - Response */ }, { key: "getOrderAsync", value: function () { var _getOrderAsync = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee23(orderId) { return _regenerator["default"].wrap(function _callee23$(_context23) { while (1) switch (_context23.prev = _context23.next) { case 0: _context23.next = 2; return this.http({ operation: _culqiLog.OperationType.GET_ORDER, method: 'get', url: "/orders/".concat(orderId) }); case 2: return _context23.abrupt("return", _context23.sent); case 3: case "end": return _context23.stop(); } }, _callee23, this); })); function getOrderAsync(_x22) { return _getOrderAsync.apply(this, arguments); } return getOrderAsync; }() /** * create order (async) * @param {OrderCreatePayload} order - order request * @returns {object} - Response */ }, { key: "createOrderAsync", value: function () { var _createOrderAsync = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee24(order) { var originalEmail; return _regenerator["default"].wrap(function _callee24$(_context24) { while (1) switch (_context24.prev = _context24.next) { case 0: if (this.isTestEnv_ && this.devEmail_) { originalEmail = order.client_details.email; order.client_details.email = this.devEmail_; if (!order.metadata) { order.metadata = {}; } order.metadata.originalEmail = originalEmail; if (this.appEnv_) { order.metadata.env = this.appEnv_; } } return _context24.abrupt("return", this.http({ operation: _culqiLog.OperationType.CREATE_ORDER, method: 'post', url: '/orders', data: order })); case 2: case "end": return _context24.stop(); } }, _callee24, this); })); function createOrderAsync(_x23) { return _createOrderAsync.apply(this, arguments); } return createOrderAsync; }() /** * confirm order (async) * @param {string} orderId - order id * @returns {object} - Response */ }, { key: "confirmOrderAsync", value: function () { var _confirmOrderAsync = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee25(orderId) { return _regenerator["default"].wrap(function _callee25$(_context25) { while (1) switch (_context25.prev = _context25.next) { case 0: return _context25.abrupt("return", this.http({ operation: _culqiLog.OperationType.CONFIRM_ORDER, method: 'post', url: "/orders/".concat(orderId, "/confirm") })); case 1: case "end": return _context25.stop(); } }, _callee25, this); })); function confirmOrderAsync(_x24) { return _confirmOrderAsync.apply(this, arguments); } return confirmOrderAsync; }() /** * update order (async) * @param {string} orderId - order id * @param {OrderUpdatePayload} update - order request * @returns {object} - Response */ }, { key: "updateOrderAsync", value: function () { var _updateOrderAsync = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee26(orderId, update) { return _regenerator["default"].wrap(function _callee26$(_context26) { while (1) switch (_context26.prev = _context26.next) { case 0: _context26.next = 2; return this.http({ operation: _culqiLog.OperationType.UPDATE_ORDER, method: 'patch', url: "/orders/".concat(orderId), data: update }); case 2: return _context26.abrupt("return", _context26.sent); case 3: case "end": return _context26.stop(); } }, _callee26, this); })); function updateOrderAsync(_x25, _x26) { return _updateOrderAsync.apply(this, arguments); } return updateOrderAsync; }() /** * delete order (async) * @param {string} orderId - order id * @returns {object} - Response */ }, { key: "deleteOrderAsync", value: function () { var _deleteOrderAsync = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee27(orderId) { var _yield$this$http5, _yield$this$http6, _, error; return _regenerator["default"].wrap(function _callee27$(_context27) { while (1) switch (_context27.prev = _context27.next) { case 0: _context27.next = 2; return this.http({ operation: _culqiLog.OperationType.DELETE_ORDER, method: 'delete', url: "/orders/".concat(orderId) }); case 2: _yield$this$http5 = _context27.sent; _yield$this$http6 = (0, _slicedToArray2["default"])(_yield$this$http5, 2); _ = _yield$this$http6[0]; error = _yield$this$http6[1]; if (!error) { _context27.next = 8; break; } return _context27.abrupt("return", [false, error]); case 8: return _context27.abrupt("return", [true, null]); case 9: case "end": return _context27.stop(); } }, _callee27, this); })); function deleteOrderAsync(_x27) { return _deleteOrderAsync.apply(this, arguments); } return deleteOrderAsync; }() // endregion }]); return CulqiClient; }(); var _default = CulqiClient; exports["default"] = _default;