UNPKG

@monei-js/node-sdk

Version:

Node.js SDK for MONEI Digital Payment Gateway

981 lines (970 loc) 209 kB
'use strict'; var globalAxios = require('axios'); var crypto = require('crypto'); function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } function _interopNamespace(e) { if (e && e.__esModule) return e; var n = Object.create(null); if (e) { Object.keys(e).forEach(function (k) { if (k !== 'default') { var d = Object.getOwnPropertyDescriptor(e, k); Object.defineProperty(n, k, d.get ? d : { enumerable: true, get: function () { return e[k]; } }); } }); } n["default"] = e; return n; } var globalAxios__default = /*#__PURE__*/_interopDefaultLegacy(globalAxios); var crypto__namespace = /*#__PURE__*/_interopNamespace(crypto); var name = "@monei-js/node-sdk"; var description = "Node.js SDK for MONEI Digital Payment Gateway"; var version = "1.7.10"; var homepage = "https://monei.com"; var author = "MONEI <support@monei.com> (https://monei.com)"; var type = "module"; var license = "MIT"; var contributors = [ "Dmitriy Nevzorov <dn@monei.com>" ]; var repository = { type: "git", url: "https://github.com/MONEI/monei-node-sdk" }; var keywords = [ "monei", "payment gateway", "payment processing", "credit cards", "api" ]; var files = [ "dist", "LICENSE", "README.md" ]; var source = "./index.ts"; var main = "./dist/index.cjs"; var module$1 = "./dist/index.module.js"; var types = "./dist/index.d.ts"; var exports$1 = { ".": { types: "./dist/index.d.ts", require: "./dist/index.cjs", "import": "./dist/index.module.js" } }; var publishConfig = { access: "public", registry: "https://registry.npmjs.org/" }; var scripts = { generate: "openapi-generator-cli generate --generator-key typescript-axios", "generate:local": "openapi-generator-cli generate --generator-key typescript-axios-local", compile: "microbundle -f modern,cjs --target node --strict --name index --tsconfig tsconfig.build.json", dev: "microbundle watch -f modern,cjs --target node --strict --name index --tsconfig tsconfig.build.json", build: "run-s generate replace format compile", "build:local": "run-s generate:local replace format compile", replace: "node scripts/replace.js", release: "release-it", prepack: "yarn build", test: "vitest run", "test:watch": "vitest", "test:coverage": "vitest run --coverage", commitlint: "commitlint --edit", typecheck: "tsc --noEmit", "lint-staged": "lint-staged", format: "prettier --write \"**/*.ts\"", lint: "eslint .", "lint:fix": "eslint . --fix", prepare: "husky" }; var devDependencies = { "@commitlint/cli": "^19.8.0", "@commitlint/config-conventional": "^19.8.0", "@eslint/js": "^9.22.0", "@openapitools/openapi-generator-cli": "^2.17.0", "@release-it/conventional-changelog": "^10.0.0", "@types/node": "^22.13.10", "@vitest/coverage-v8": "^3.0.8", "axios-mock-adapter": "^2.1.0", eslint: "^9.22.0", husky: "^9.1.7", "lint-staged": "^15.4.3", microbundle: "^0.15.1", "npm-run-all": "^4.1.5", prettier: "^3.5.3", "release-it": "^18.1.2", "replace-in-file": "^8.3.0", typescript: "^5.8.2", "typescript-eslint": "^8.26.1", vitest: "^3.0.8" }; var dependencies = { axios: "^1.8.2" }; var packageManager = "yarn@4.7.0"; var pkg = { name: name, description: description, version: version, homepage: homepage, author: author, type: type, license: license, contributors: contributors, repository: repository, keywords: keywords, files: files, source: source, main: main, module: module$1, types: types, exports: exports$1, publishConfig: publishConfig, scripts: scripts, "lint-staged": { "*.ts": [ "prettier --write", "eslint --quiet --fix" ] }, devDependencies: devDependencies, dependencies: dependencies, packageManager: packageManager }; /* tslint:disable */ const BASE_PATH = 'https://api.monei.com/v1'.replace(/\/+$/, ''); /** * * @export * @class BaseAPI */ class BaseAPI { constructor(configuration, basePath = BASE_PATH, axios = globalAxios__default["default"]) { this.basePath = void 0; this.axios = void 0; this.configuration = void 0; this.basePath = basePath; this.axios = axios; if (configuration) { var _configuration$basePa; this.configuration = configuration; this.basePath = (_configuration$basePa = configuration.basePath) != null ? _configuration$basePa : basePath; } } } /** * * @export * @class RequiredError * @extends {Error} */ class RequiredError extends Error { constructor(field, msg) { super(msg); this.field = void 0; this.field = field; this.name = 'RequiredError'; } } /** * * @export */ const operationServerMap = {}; /* tslint:disable */ /** * * @export */ const DUMMY_BASE_URL = 'https://example.com'; /** * * @throws {RequiredError} * @export */ const assertParamExists = function (functionName, paramName, paramValue) { if (paramValue === null || paramValue === undefined) { throw new RequiredError(paramName, `Required parameter ${paramName} was null or undefined when calling ${functionName}.`); } }; /** * * @export */ const setApiKeyToObject = async function (object, keyParamName, configuration) { if (configuration && configuration.apiKey) { const localVarApiKeyValue = typeof configuration.apiKey === 'function' ? await configuration.apiKey(keyParamName) : await configuration.apiKey; object[keyParamName] = localVarApiKeyValue; } }; function setFlattenedQueryParams(urlSearchParams, parameter, key = '') { if (parameter == null) return; if (typeof parameter === 'object') { if (Array.isArray(parameter)) { parameter.forEach(item => setFlattenedQueryParams(urlSearchParams, item, key)); } else { Object.keys(parameter).forEach(currentKey => setFlattenedQueryParams(urlSearchParams, parameter[currentKey], `${key}${key !== '' ? '.' : ''}${currentKey}`)); } } else { if (urlSearchParams.has(key)) { urlSearchParams.append(key, parameter); } else { urlSearchParams.set(key, parameter); } } } /** * * @export */ const setSearchParams = function (url, ...objects) { const searchParams = new URLSearchParams(url.search); setFlattenedQueryParams(searchParams, objects); url.search = searchParams.toString(); }; /** * * @export */ const serializeDataIfNeeded = function (value, requestOptions, configuration) { const nonString = typeof value !== 'string'; const needsSerialization = nonString && configuration && configuration.isJsonMime ? configuration.isJsonMime(requestOptions.headers['Content-Type']) : nonString; return needsSerialization ? JSON.stringify(value !== undefined ? value : {}) : value || ''; }; /** * * @export */ const toPathString = function (url) { return url.pathname + url.search + url.hash; }; /** * * @export */ const createRequestFunction = function (axiosArgs, globalAxios, BASE_PATH, configuration) { return (axios = globalAxios, basePath = BASE_PATH) => { var _configuration$basePa; const axiosRequestArgs = { ...axiosArgs.options, url: (axios.defaults.baseURL ? '' : (_configuration$basePa = configuration == null ? void 0 : configuration.basePath) != null ? _configuration$basePa : basePath) + axiosArgs.url }; return axios.request(axiosRequestArgs); }; }; /* tslint:disable */ /** * ApplePayDomainApi - axios parameter creator * @export */ const ApplePayDomainApiAxiosParamCreator = function (configuration) { return { /** * Registers a domain with Apple Pay. This endpoint allows you to register your website domain with Apple Pay, which is required before you can accept Apple Pay payments on your website. The domain must be accessible via HTTPS and have a valid SSL certificate. Before registering, you must download this [domain association file](https://assets.monei.com/apple-pay/apple-developer-merchantid-domain-association/) and host it at `/.well-known/apple-developer-merchantid-domain-association` on your site. For example, if you\'re registering `example.com`, make that file available at `https://example.com/.well-known/apple-developer-merchantid-domain-association`. After registration, Apple will verify your domain. Once verified, you can display Apple Pay buttons and process Apple Pay payments on your website. * @summary Register Domain * @param {RegisterApplePayDomainRequest} registerApplePayDomainRequest * @param {*} [options] Override http request option. * @throws {RequiredError} */ register: async (registerApplePayDomainRequest, options = {}) => { // verify required parameter 'registerApplePayDomainRequest' is not null or undefined assertParamExists('register', 'registerApplePayDomainRequest', registerApplePayDomainRequest); const localVarPath = `/apple-pay/domains`; // use dummy base URL string because the URL constructor only accepts absolute URLs. const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); let baseOptions; if (configuration) { baseOptions = configuration.baseOptions; } const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options }; const localVarHeaderParameter = {}; const localVarQueryParameter = {}; // authentication APIKey required await setApiKeyToObject(localVarHeaderParameter, 'Authorization', configuration); localVarHeaderParameter['Content-Type'] = 'application/json'; setSearchParams(localVarUrlObj, localVarQueryParameter); let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers }; localVarRequestOptions.data = serializeDataIfNeeded(registerApplePayDomainRequest, localVarRequestOptions, configuration); return { url: toPathString(localVarUrlObj), options: localVarRequestOptions }; } }; }; /** * ApplePayDomainApi - functional programming interface * @export */ const ApplePayDomainApiFp = function (configuration) { const localVarAxiosParamCreator = ApplePayDomainApiAxiosParamCreator(configuration); return { /** * Registers a domain with Apple Pay. This endpoint allows you to register your website domain with Apple Pay, which is required before you can accept Apple Pay payments on your website. The domain must be accessible via HTTPS and have a valid SSL certificate. Before registering, you must download this [domain association file](https://assets.monei.com/apple-pay/apple-developer-merchantid-domain-association/) and host it at `/.well-known/apple-developer-merchantid-domain-association` on your site. For example, if you\'re registering `example.com`, make that file available at `https://example.com/.well-known/apple-developer-merchantid-domain-association`. After registration, Apple will verify your domain. Once verified, you can display Apple Pay buttons and process Apple Pay payments on your website. * @summary Register Domain * @param {RegisterApplePayDomainRequest} registerApplePayDomainRequest * @param {*} [options] Override http request option. * @throws {RequiredError} */ async register(registerApplePayDomainRequest, options) { var _configuration$server, _operationServerMap$A; const localVarAxiosArgs = await localVarAxiosParamCreator.register(registerApplePayDomainRequest, options); const localVarOperationServerIndex = (_configuration$server = configuration == null ? void 0 : configuration.serverIndex) != null ? _configuration$server : 0; const localVarOperationServerBasePath = (_operationServerMap$A = operationServerMap['ApplePayDomainApi.register']) == null || (_operationServerMap$A = _operationServerMap$A[localVarOperationServerIndex]) == null ? void 0 : _operationServerMap$A.url; return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios__default["default"], BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath); } }; }; /** * ApplePayDomainApi - factory interface * @export */ const ApplePayDomainApiFactory = function (configuration, basePath, axios) { const localVarFp = ApplePayDomainApiFp(configuration); return { /** * Registers a domain with Apple Pay. This endpoint allows you to register your website domain with Apple Pay, which is required before you can accept Apple Pay payments on your website. The domain must be accessible via HTTPS and have a valid SSL certificate. Before registering, you must download this [domain association file](https://assets.monei.com/apple-pay/apple-developer-merchantid-domain-association/) and host it at `/.well-known/apple-developer-merchantid-domain-association` on your site. For example, if you\'re registering `example.com`, make that file available at `https://example.com/.well-known/apple-developer-merchantid-domain-association`. After registration, Apple will verify your domain. Once verified, you can display Apple Pay buttons and process Apple Pay payments on your website. * @summary Register Domain * @param {RegisterApplePayDomainRequest} registerApplePayDomainRequest * @param {*} [options] Override http request option. * @throws {RequiredError} */ register(registerApplePayDomainRequest, options) { return localVarFp.register(registerApplePayDomainRequest, options).then(request => request(axios, basePath)); } }; }; /** * ApplePayDomainApi - object-oriented interface * @export * @class ApplePayDomainApi * @extends {BaseAPI} */ class ApplePayDomainApi extends BaseAPI { /** * Registers a domain with Apple Pay. This endpoint allows you to register your website domain with Apple Pay, which is required before you can accept Apple Pay payments on your website. The domain must be accessible via HTTPS and have a valid SSL certificate. Before registering, you must download this [domain association file](https://assets.monei.com/apple-pay/apple-developer-merchantid-domain-association/) and host it at `/.well-known/apple-developer-merchantid-domain-association` on your site. For example, if you\'re registering `example.com`, make that file available at `https://example.com/.well-known/apple-developer-merchantid-domain-association`. After registration, Apple will verify your domain. Once verified, you can display Apple Pay buttons and process Apple Pay payments on your website. * @summary Register Domain * @param {RegisterApplePayDomainRequest} registerApplePayDomainRequest * @param {*} [options] Override http request option. * @throws {RequiredError} * @memberof ApplePayDomainApi */ register(registerApplePayDomainRequest, options) { return ApplePayDomainApiFp(this.configuration).register(registerApplePayDomainRequest, options).then(request => request(this.axios, this.basePath)); } } /* tslint:disable */ /** * BizumApi - axios parameter creator * @export */ const BizumApiAxiosParamCreator = function (configuration) { return { /** * Validates if a phone number is registered with Bizum. Use this endpoint to check if a customer\'s phone number can be used for Bizum payments before attempting to process a payment. This helps provide a better user experience by preventing failed payment attempts for non-registered numbers. The response will indicate whether the phone number is valid for Bizum payments. * @summary Validate Phone * @param {ValidateBizumPhoneRequest} validateBizumPhoneRequest * @param {*} [options] Override http request option. * @throws {RequiredError} */ validatePhone: async (validateBizumPhoneRequest, options = {}) => { // verify required parameter 'validateBizumPhoneRequest' is not null or undefined assertParamExists('validatePhone', 'validateBizumPhoneRequest', validateBizumPhoneRequest); const localVarPath = `/bizum/validate-phone`; // use dummy base URL string because the URL constructor only accepts absolute URLs. const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); let baseOptions; if (configuration) { baseOptions = configuration.baseOptions; } const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options }; const localVarHeaderParameter = {}; const localVarQueryParameter = {}; // authentication APIKey required await setApiKeyToObject(localVarHeaderParameter, 'Authorization', configuration); localVarHeaderParameter['Content-Type'] = 'application/json'; setSearchParams(localVarUrlObj, localVarQueryParameter); let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers }; localVarRequestOptions.data = serializeDataIfNeeded(validateBizumPhoneRequest, localVarRequestOptions, configuration); return { url: toPathString(localVarUrlObj), options: localVarRequestOptions }; } }; }; /** * BizumApi - functional programming interface * @export */ const BizumApiFp = function (configuration) { const localVarAxiosParamCreator = BizumApiAxiosParamCreator(configuration); return { /** * Validates if a phone number is registered with Bizum. Use this endpoint to check if a customer\'s phone number can be used for Bizum payments before attempting to process a payment. This helps provide a better user experience by preventing failed payment attempts for non-registered numbers. The response will indicate whether the phone number is valid for Bizum payments. * @summary Validate Phone * @param {ValidateBizumPhoneRequest} validateBizumPhoneRequest * @param {*} [options] Override http request option. * @throws {RequiredError} */ async validatePhone(validateBizumPhoneRequest, options) { var _configuration$server, _operationServerMap$B; const localVarAxiosArgs = await localVarAxiosParamCreator.validatePhone(validateBizumPhoneRequest, options); const localVarOperationServerIndex = (_configuration$server = configuration == null ? void 0 : configuration.serverIndex) != null ? _configuration$server : 0; const localVarOperationServerBasePath = (_operationServerMap$B = operationServerMap['BizumApi.validatePhone']) == null || (_operationServerMap$B = _operationServerMap$B[localVarOperationServerIndex]) == null ? void 0 : _operationServerMap$B.url; return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios__default["default"], BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath); } }; }; /** * BizumApi - factory interface * @export */ const BizumApiFactory = function (configuration, basePath, axios) { const localVarFp = BizumApiFp(configuration); return { /** * Validates if a phone number is registered with Bizum. Use this endpoint to check if a customer\'s phone number can be used for Bizum payments before attempting to process a payment. This helps provide a better user experience by preventing failed payment attempts for non-registered numbers. The response will indicate whether the phone number is valid for Bizum payments. * @summary Validate Phone * @param {ValidateBizumPhoneRequest} validateBizumPhoneRequest * @param {*} [options] Override http request option. * @throws {RequiredError} */ validatePhone(validateBizumPhoneRequest, options) { return localVarFp.validatePhone(validateBizumPhoneRequest, options).then(request => request(axios, basePath)); } }; }; /** * BizumApi - object-oriented interface * @export * @class BizumApi * @extends {BaseAPI} */ class BizumApi extends BaseAPI { /** * Validates if a phone number is registered with Bizum. Use this endpoint to check if a customer\'s phone number can be used for Bizum payments before attempting to process a payment. This helps provide a better user experience by preventing failed payment attempts for non-registered numbers. The response will indicate whether the phone number is valid for Bizum payments. * @summary Validate Phone * @param {ValidateBizumPhoneRequest} validateBizumPhoneRequest * @param {*} [options] Override http request option. * @throws {RequiredError} * @memberof BizumApi */ validatePhone(validateBizumPhoneRequest, options) { return BizumApiFp(this.configuration).validatePhone(validateBizumPhoneRequest, options).then(request => request(this.axios, this.basePath)); } } /* tslint:disable */ /** * PaymentMethodsApi - axios parameter creator * @export */ const PaymentMethodsApiAxiosParamCreator = function (configuration) { return { /** * Retrieve available payment methods for an account or a specific payment. You can provide either an `accountId` or a `paymentId` as a query parameter to get the available payment methods. When providing a `paymentId`, the response will include additional payment-specific information such as amount and currency. This is useful when you want to show payment options that are specifically available for a particular transaction. When providing an `accountId`, the response will include all payment methods available for that account based on the merchant\'s configuration and supported payment methods. * @summary Get Payment Methods * @param {string} [accountId] The ID of the account to get payment methods for * @param {string} [paymentId] The ID of the payment to get payment methods for * @param {*} [options] Override http request option. * @throws {RequiredError} */ get: async (accountId, paymentId, options = {}) => { const localVarPath = `/payment-methods`; // use dummy base URL string because the URL constructor only accepts absolute URLs. const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); let baseOptions; if (configuration) { baseOptions = configuration.baseOptions; } const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options }; const localVarHeaderParameter = {}; const localVarQueryParameter = {}; // authentication APIKey required await setApiKeyToObject(localVarHeaderParameter, 'Authorization', configuration); if (accountId !== undefined) { localVarQueryParameter['accountId'] = accountId; } if (paymentId !== undefined) { localVarQueryParameter['paymentId'] = paymentId; } setSearchParams(localVarUrlObj, localVarQueryParameter); let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers }; return { url: toPathString(localVarUrlObj), options: localVarRequestOptions }; } }; }; /** * PaymentMethodsApi - functional programming interface * @export */ const PaymentMethodsApiFp = function (configuration) { const localVarAxiosParamCreator = PaymentMethodsApiAxiosParamCreator(configuration); return { /** * Retrieve available payment methods for an account or a specific payment. You can provide either an `accountId` or a `paymentId` as a query parameter to get the available payment methods. When providing a `paymentId`, the response will include additional payment-specific information such as amount and currency. This is useful when you want to show payment options that are specifically available for a particular transaction. When providing an `accountId`, the response will include all payment methods available for that account based on the merchant\'s configuration and supported payment methods. * @summary Get Payment Methods * @param {string} [accountId] The ID of the account to get payment methods for * @param {string} [paymentId] The ID of the payment to get payment methods for * @param {*} [options] Override http request option. * @throws {RequiredError} */ async get(accountId, paymentId, options) { var _configuration$server, _operationServerMap$P; const localVarAxiosArgs = await localVarAxiosParamCreator.get(accountId, paymentId, options); const localVarOperationServerIndex = (_configuration$server = configuration == null ? void 0 : configuration.serverIndex) != null ? _configuration$server : 0; const localVarOperationServerBasePath = (_operationServerMap$P = operationServerMap['PaymentMethodsApi.get']) == null || (_operationServerMap$P = _operationServerMap$P[localVarOperationServerIndex]) == null ? void 0 : _operationServerMap$P.url; return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios__default["default"], BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath); } }; }; /** * PaymentMethodsApi - factory interface * @export */ const PaymentMethodsApiFactory = function (configuration, basePath, axios) { const localVarFp = PaymentMethodsApiFp(configuration); return { /** * Retrieve available payment methods for an account or a specific payment. You can provide either an `accountId` or a `paymentId` as a query parameter to get the available payment methods. When providing a `paymentId`, the response will include additional payment-specific information such as amount and currency. This is useful when you want to show payment options that are specifically available for a particular transaction. When providing an `accountId`, the response will include all payment methods available for that account based on the merchant\'s configuration and supported payment methods. * @summary Get Payment Methods * @param {string} [accountId] The ID of the account to get payment methods for * @param {string} [paymentId] The ID of the payment to get payment methods for * @param {*} [options] Override http request option. * @throws {RequiredError} */ get(accountId, paymentId, options) { return localVarFp.get(accountId, paymentId, options).then(request => request(axios, basePath)); } }; }; /** * PaymentMethodsApi - object-oriented interface * @export * @class PaymentMethodsApi * @extends {BaseAPI} */ class PaymentMethodsApi extends BaseAPI { /** * Retrieve available payment methods for an account or a specific payment. You can provide either an `accountId` or a `paymentId` as a query parameter to get the available payment methods. When providing a `paymentId`, the response will include additional payment-specific information such as amount and currency. This is useful when you want to show payment options that are specifically available for a particular transaction. When providing an `accountId`, the response will include all payment methods available for that account based on the merchant\'s configuration and supported payment methods. * @summary Get Payment Methods * @param {string} [accountId] The ID of the account to get payment methods for * @param {string} [paymentId] The ID of the payment to get payment methods for * @param {*} [options] Override http request option. * @throws {RequiredError} * @memberof PaymentMethodsApi */ get(accountId, paymentId, options) { return PaymentMethodsApiFp(this.configuration).get(accountId, paymentId, options).then(request => request(this.axios, this.basePath)); } } /* tslint:disable */ /** * PaymentsApi - axios parameter creator * @export */ const PaymentsApiAxiosParamCreator = function (configuration) { return { /** * Releases reserved funds from a previously authorized payment. This endpoint can only be used with payments in `AUTHORIZED` status. This operation is part of the two-step authorization flow: 1. **Authorize**: Create a payment with `transactionType: AUTH` to reserve funds 2. **Cancel**: Release the reserved funds if you decide not to capture the payment Cancellation makes the reserved funds available to the customer again and prevents you from being able to capture those funds in the future. Once cancelled, an authorization cannot be reactivated. * @summary Cancel Payment * @param {string} id The payment ID * @param {CancelPaymentRequest} [cancelPaymentRequest] * @param {*} [options] Override http request option. * @throws {RequiredError} */ cancel: async (id, cancelPaymentRequest, options = {}) => { // verify required parameter 'id' is not null or undefined assertParamExists('cancel', 'id', id); const localVarPath = `/payments/{id}/cancel`.replace(`{${'id'}}`, encodeURIComponent(String(id))); // use dummy base URL string because the URL constructor only accepts absolute URLs. const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); let baseOptions; if (configuration) { baseOptions = configuration.baseOptions; } const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options }; const localVarHeaderParameter = {}; const localVarQueryParameter = {}; // authentication APIKey required await setApiKeyToObject(localVarHeaderParameter, 'Authorization', configuration); localVarHeaderParameter['Content-Type'] = 'application/json'; setSearchParams(localVarUrlObj, localVarQueryParameter); let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers }; localVarRequestOptions.data = serializeDataIfNeeded(cancelPaymentRequest, localVarRequestOptions, configuration); return { url: toPathString(localVarUrlObj), options: localVarRequestOptions }; }, /** * Captures funds from a previously authorized payment. This endpoint can only be used with payments in `AUTHORIZED` status. This operation completes the two-step authorization flow: 1. **Authorize**: Create a payment with `transactionType: AUTH` to reserve funds 2. **Capture**: Transfer the reserved funds to your account when ready to fulfill the order **Important**: Authorized payments expire after exactly seven days. After expiration, they will be marked as `EXPIRED` and can no longer be captured. Be sure to capture funds within this timeframe or communicate with your customer about a new payment. * @summary Capture Payment * @param {string} id The payment ID * @param {CapturePaymentRequest} [capturePaymentRequest] * @param {*} [options] Override http request option. * @throws {RequiredError} */ capture: async (id, capturePaymentRequest, options = {}) => { // verify required parameter 'id' is not null or undefined assertParamExists('capture', 'id', id); const localVarPath = `/payments/{id}/capture`.replace(`{${'id'}}`, encodeURIComponent(String(id))); // use dummy base URL string because the URL constructor only accepts absolute URLs. const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); let baseOptions; if (configuration) { baseOptions = configuration.baseOptions; } const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options }; const localVarHeaderParameter = {}; const localVarQueryParameter = {}; // authentication APIKey required await setApiKeyToObject(localVarHeaderParameter, 'Authorization', configuration); localVarHeaderParameter['Content-Type'] = 'application/json'; setSearchParams(localVarUrlObj, localVarQueryParameter); let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers }; localVarRequestOptions.data = serializeDataIfNeeded(capturePaymentRequest, localVarRequestOptions, configuration); return { url: toPathString(localVarUrlObj), options: localVarRequestOptions }; }, /** * Confirms a payment that was created without payment details. This endpoint can only be used with payments in `PENDING` status. The two-step payment flow: 1. **Create**: First, create a payment without payment details (status: `PENDING`) 2. **Confirm**: Then provide payment details to complete the transaction When confirming a payment, you can use: - A newly generated `paymentToken` from [monei.js Components](https://docs.monei.com/monei-js/overview/) - A permanent `paymentToken` from a previous payment (generated with `generatePaymentToken: true`) Using permanent payment tokens enables one-click checkout experiences for returning customers without requiring them to re-enter their payment information. You can provide additional customer information during confirmation, which will override any corresponding information originally passed in the payment creation request. * @summary Confirm Payment * @param {string} id The payment ID * @param {ConfirmPaymentRequest} [confirmPaymentRequest] * @param {*} [options] Override http request option. * @throws {RequiredError} */ confirm: async (id, confirmPaymentRequest, options = {}) => { // verify required parameter 'id' is not null or undefined assertParamExists('confirm', 'id', id); const localVarPath = `/payments/{id}/confirm`.replace(`{${'id'}}`, encodeURIComponent(String(id))); // use dummy base URL string because the URL constructor only accepts absolute URLs. const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); let baseOptions; if (configuration) { baseOptions = configuration.baseOptions; } const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options }; const localVarHeaderParameter = {}; const localVarQueryParameter = {}; // authentication APIKey required await setApiKeyToObject(localVarHeaderParameter, 'Authorization', configuration); localVarHeaderParameter['Content-Type'] = 'application/json'; setSearchParams(localVarUrlObj, localVarQueryParameter); let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers }; localVarRequestOptions.data = serializeDataIfNeeded(confirmPaymentRequest, localVarRequestOptions, configuration); return { url: toPathString(localVarUrlObj), options: localVarRequestOptions }; }, /** * Creates a new payment with the specified parameters. You can create a payment in two ways: 1. **Immediate processing**: Provide a `paymentToken` or `paymentMethod` - The payment will be processed instantly 2. **Deferred processing**: Create without payment details - The payment remains in `PENDING` status until you confirm it later using the [confirm endpoint](https://docs.monei.com/apis/rest/payments-confirm/) When creating a payment without payment details, you can redirect customers to the hosted payment page where they can select their preferred payment method and complete the transaction. For immediate processing, use one of these token options: - A temporary `paymentToken` generated on the frontend using [monei.js Components](https://docs.monei.com/monei-js/overview/) - A permanent `paymentToken` from a previous successful payment (when `generatePaymentToken: true` was included) Permanent tokens enable one-click checkout experiences for returning customers by allowing you to securely store and reuse payment details without requiring customers to re-enter their information. * @summary Create Payment * @param {CreatePaymentRequest} createPaymentRequest * @param {*} [options] Override http request option. * @throws {RequiredError} */ create: async (createPaymentRequest, options = {}) => { // verify required parameter 'createPaymentRequest' is not null or undefined assertParamExists('create', 'createPaymentRequest', createPaymentRequest); const localVarPath = `/payments`; // use dummy base URL string because the URL constructor only accepts absolute URLs. const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); let baseOptions; if (configuration) { baseOptions = configuration.baseOptions; } const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options }; const localVarHeaderParameter = {}; const localVarQueryParameter = {}; // authentication APIKey required await setApiKeyToObject(localVarHeaderParameter, 'Authorization', configuration); localVarHeaderParameter['Content-Type'] = 'application/json'; setSearchParams(localVarUrlObj, localVarQueryParameter); let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers }; localVarRequestOptions.data = serializeDataIfNeeded(createPaymentRequest, localVarRequestOptions, configuration); return { url: toPathString(localVarUrlObj), options: localVarRequestOptions }; }, /** * Retrieves the complete details of an existing payment by its unique ID. This endpoint returns all available information about the payment, including its current status, amount, customer details, timestamps, and transaction history. Use this to check the status of a payment, verify payment details, or retrieve information for your records. Supply the unique payment ID that was returned from your previous request. * @summary Get Payment * @param {string} id The payment ID * @param {*} [options] Override http request option. * @throws {RequiredError} */ get: async (id, options = {}) => { // verify required parameter 'id' is not null or undefined assertParamExists('get', 'id', id); const localVarPath = `/payments/{id}`.replace(`{${'id'}}`, encodeURIComponent(String(id))); // use dummy base URL string because the URL constructor only accepts absolute URLs. const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); let baseOptions; if (configuration) { baseOptions = configuration.baseOptions; } const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options }; const localVarHeaderParameter = {}; const localVarQueryParameter = {}; // authentication APIKey required await setApiKeyToObject(localVarHeaderParameter, 'Authorization', configuration); setSearchParams(localVarUrlObj, localVarQueryParameter); let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers }; return { url: toPathString(localVarUrlObj), options: localVarRequestOptions }; }, /** * Creates a subsequent charge using the payment details from a previous transaction. This endpoint enables recurring billing and subscription payments by: - Using the same payment method as the original payment - Charging the customer without requiring them to re-enter payment details - Supporting variable or fixed amounts (defaults to the original payment amount if not specified) **Prerequisites:** 1. The initial payment must be created with the `sequence` parameter 2. The initial payment will return a `sequenceId` in the response 3. This `sequenceId` must be provided in the URL path when making subsequent recurring charges Ideal for subscription services, membership renewals, and installment payments. **Need more advanced subscription management?** For comprehensive subscription management with features like billing cycles, trial periods, and automatic recurring billing, consider using the [Subscriptions API](https://docs.monei.com/apis/rest/subscriptions/) instead. It provides a complete solution for creating and managing subscription-based services. * @summary Recurring Payment * @param {string} sequenceId The sequence ID * @param {RecurringPaymentRequest} [recurringPaymentRequest] * @param {*} [options] Override http request option. * @throws {RequiredError} */ recurring: async (sequenceId, recurringPaymentRequest, options = {}) => { // verify required parameter 'sequenceId' is not null or undefined assertParamExists('recurring', 'sequenceId', sequenceId); const localVarPath = `/payments/{sequenceId}/recurring`.replace(`{${'sequenceId'}}`, encodeURIComponent(String(sequenceId))); // use dummy base URL string because the URL constructor only accepts absolute URLs. const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); let baseOptions; if (configuration) { baseOptions = configuration.baseOptions; } const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options }; const localVarHeaderParameter = {}; const localVarQueryParameter = {}; // authentication APIKey required await setApiKeyToObject(localVarHeaderParameter, 'Authorization', configuration); localVarHeaderParameter['Content-Type'] = 'application/json'; setSearchParams(localVarUrlObj, localVarQueryParameter); let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers }; localVarRequestOptions.data = serializeDataIfNeeded(recurringPaymentRequest, localVarRequestOptions, configuration); return { url: toPathString(localVarUrlObj), options: localVarRequestOptions }; }, /** * Returns funds from a completed payment back to the customer\'s original payment method. **Refund options:** - **Full refund**: Return the entire payment amount - **Partial refund**: Specify an amount less than the original payment - **Multiple partial refunds**: Issue several partial refunds until the total payment amount is reached **Limitations:** - You can only refund payments that have been successfully processed - A payment can only be refunded up to its original amount - Once fully refunded, a payment cannot be refunded again - Attempting to refund more than the remaining available amount will result in an error * @summary Refund Payment * @param {string} id The payment ID * @param {RefundPaymentRequest} [refundPaymentRequest] * @param {*} [options] Override http request option. * @throws {RequiredError} */ refund: async (id, refundPaymentRequest, options = {}) => { // verify required parameter 'id' is not null or undefined assertParamExists('refund', 'id', id); const localVarPath = `/payments/{id}/refund`.replace(`{${'id'}}`, encodeURIComponent(String(id))); // use dummy base URL string because the URL constructor only accepts absolute URLs. const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); let baseOptions; if (configuration) { baseOptions = configuration.baseOptions; } const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options }; const localVarHeaderParameter = {}; const localVarQueryParameter = {}; // authentication APIKey required await setApiKeyToObject(localVarHeaderParameter, 'Authorization', configuration); localVarHeaderParameter['Content-Type'] = 'application/json'; setSearchParams(localVarUrlObj, localVarQueryParameter); let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers }; localVarRequestOptions.data = serializeDataIfNeeded(refundPaymentRequest, localVarRequestOptions, configuration); return { url: toPathString(localVarUrlObj), options: localVarRequestOptions }; }, /** * Sends a payment link to the customer through their preferred communication channel. **This API can only be used for payments with the following status:** - Pending **Delivery channels are automatically selected based on available customer information:** - If customer email is available: Link is sent via email - If customer phone is available: Link is sent via WhatsApp - If WhatsApp delivery fails: Link is sent via SMS as a fallback The payment link allows customers to complete the payment at their convenience using their preferred payment method on the secure MONEI payment page. If no customer contact information is provided, the system will use the details stored in the payment record. * @summary Send Payment Link * @param {string} id The payment ID * @param {SendPaymentLinkRequest} [sendPaymentLinkRequest] * @param {*} [options] Override http request option. * @throws {RequiredError} */ sendLink: async (id, sendPaymentLinkRequest, options = {}) => { // verify required parameter 'id' is not null or undefined assertParamExists('sendLink', 'id', id); const localVarPath = `/payments/{id}/link`.replace(`{${'id'}}`, encodeURIComponent(String(id))); // use dummy base URL string because the URL constructor only accepts absolute URLs. const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); let baseOptions; if (configuration) { baseOptions = configuration.baseOptions; } const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options }; const localVarHeaderParameter = {}; const localVarQueryParameter = {}; // authentication APIKey required await setApiKeyToObject(localVarHeaderParameter, 'Authorization', configuration); localVarHeaderParameter['Content-Type'] = 'application/json'; setSearchParams(localVarUrlObj, localVarQueryParameter); let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers }; localVarRequestOptions.data = serializeDataIfNeeded(sendPaymentLinkRequest, localVarRequestOptions, configuration); return { url: toPathString(localVarUrlObj), options: localVarRequestOptions }; }, /** * Sends a payment receipt to the customer through their preferred communication channel. **This API can only be used for payments with the following status:** - Succeeded **Delivery channels are automatically selected based on available customer information:** - If customer email is available: Receipt is sent via email - If customer phone is available: Receipt is sent via WhatsApp - If WhatsApp delivery fails: Receipt is sent via SMS as a fallback The receipt includes payment details such as amount, date, transaction ID, and merchant information, providing customers with a record of their successful transaction. If no customer contact information is provided, the system will use the details stored in the payment record. * @summary Send Payment Receipt * @param {string} id The payment ID * @param {SendPaymentReceiptRequest} [sendPaymentReceiptRequest] * @param {*} [options] Override http request option. * @throws {RequiredError} */ sendReceipt: async (id, sendPaymentReceiptRequest, options = {}) => { // verify required parameter 'id' is not null or undefined assertParamExists('sendReceipt', 'id', id); const localVarPath = `/payments/{id}/receipt`.replace(`{${'id'}}`, encodeURIComponent(String(id))); // use dummy base URL string because the URL constructor only accepts absolute URLs. const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); let baseOptions; if (configuration) { baseOptions = configuration.baseOptions; } const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options }; const localVarHeaderParameter = {}; const localVarQueryParameter = {}; // authentication APIKey required await setApiKeyToObject(localVarHeaderParameter, 'Authorization', configuration); localVarHeaderParameter['Content-Type'] = 'application/json'; setSearchParams(localVarUrlObj, localVarQueryParameter); let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers }; localVarRequestOptions.data = serializeDataIfNeeded(sendPaymentReceiptRequest, localVarRequestOptions, configuration); return { url: toPathString(localVarUrlObj), options: localVarRequestOptions }; }, /** * Sends a direct payment request to the customer\'s phone with sma