UNPKG

pcp-server-nodejs-sdk

Version:

[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=PAYONE-GmbH_PCP-server-nodeJS-SDK&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=PAYONE-GmbH_PCP-server-nodeJS-SDK) [![Coverage](https://sonarcloud.io/api/pr

195 lines 8.37 kB
import { Headers } from 'node-fetch'; import { CommunicatorConfiguration } from '../CommunicatorConfiguration.js'; import { BaseApiClient, CHECKOUT_ID_REQUIRED_ERROR, COMMERCE_CASE_ID_REQUIRED_ERROR, MERCHANT_ID_REQUIRED_ERROR, } from './BaseApiClient.js'; const PAYMENT_EXECUTION_ID_REQUIRED_ERROR = 'Payment Execution ID is required'; const EVENT_ID_REQUIRED_ERROR = 'Event ID is required'; export class PaymentExecutionApiClient extends BaseApiClient { constructor(config) { super(config); } async createPayment(merchantId, commerceCaseId, checkoutId, payload) { if (!merchantId) { throw new TypeError(MERCHANT_ID_REQUIRED_ERROR); } if (!commerceCaseId) { throw new TypeError(COMMERCE_CASE_ID_REQUIRED_ERROR); } if (!checkoutId) { throw new TypeError(CHECKOUT_ID_REQUIRED_ERROR); } const url = new URL(`/v1/${merchantId}/commerce-cases/${commerceCaseId}/checkouts/${checkoutId}/payment-executions`, this.getConfig().getHost()); const requestInit = { method: 'POST', headers: new Headers({ 'Content-Type': 'application/json', }), body: JSON.stringify(payload), }; return this.makeApiCall(url.toString(), requestInit); } async capturePayment(merchantId, commerceCaseId, checkoutId, paymentExecutionId, payload) { if (!merchantId) { throw new TypeError(MERCHANT_ID_REQUIRED_ERROR); } if (!commerceCaseId) { throw new TypeError(COMMERCE_CASE_ID_REQUIRED_ERROR); } if (!checkoutId) { throw new TypeError(CHECKOUT_ID_REQUIRED_ERROR); } if (!paymentExecutionId) { throw new TypeError(PAYMENT_EXECUTION_ID_REQUIRED_ERROR); } const url = new URL(`/v1/${merchantId}/commerce-cases/${commerceCaseId}/checkouts/${checkoutId}/payment-executions/${paymentExecutionId}/capture`, this.getConfig().getHost()); const requestInit = { method: 'POST', headers: new Headers({ 'Content-Type': 'application/json', }), body: JSON.stringify(payload), }; return this.makeApiCall(url.toString(), requestInit); } async cancelPayment(merchantId, commerceCaseId, checkoutId, paymentExecutionId, payload) { if (!merchantId) { throw new TypeError(MERCHANT_ID_REQUIRED_ERROR); } if (!commerceCaseId) { throw new TypeError(COMMERCE_CASE_ID_REQUIRED_ERROR); } if (!checkoutId) { throw new TypeError(CHECKOUT_ID_REQUIRED_ERROR); } if (!paymentExecutionId) { throw new TypeError(PAYMENT_EXECUTION_ID_REQUIRED_ERROR); } const url = new URL(`/v1/${merchantId}/commerce-cases/${commerceCaseId}/checkouts/${checkoutId}/payment-executions/${paymentExecutionId}/cancel`, this.getConfig().getHost()); const requestInit = { method: 'POST', headers: new Headers({ 'Content-Type': 'application/json', }), body: JSON.stringify(payload), }; return this.makeApiCall(url.toString(), requestInit); } async refundPayment(merchantId, commerceCaseId, checkoutId, paymentExecutionId, payload) { if (!merchantId) { throw new TypeError(MERCHANT_ID_REQUIRED_ERROR); } if (!commerceCaseId) { throw new TypeError(COMMERCE_CASE_ID_REQUIRED_ERROR); } if (!checkoutId) { throw new TypeError(CHECKOUT_ID_REQUIRED_ERROR); } if (!paymentExecutionId) { throw new TypeError(PAYMENT_EXECUTION_ID_REQUIRED_ERROR); } const url = new URL(`/v1/${merchantId}/commerce-cases/${commerceCaseId}/checkouts/${checkoutId}/payment-executions/${paymentExecutionId}/refund`, this.getConfig().getHost()); const requestInit = { method: 'POST', headers: new Headers({ 'Content-Type': 'application/json', }), body: JSON.stringify(payload), }; return this.makeApiCall(url.toString(), requestInit); } async completePayment(merchantId, commerceCaseId, checkoutId, paymentExecutionId, payload) { if (!merchantId) { throw new TypeError(MERCHANT_ID_REQUIRED_ERROR); } if (!commerceCaseId) { throw new TypeError(COMMERCE_CASE_ID_REQUIRED_ERROR); } if (!checkoutId) { throw new TypeError(CHECKOUT_ID_REQUIRED_ERROR); } if (!paymentExecutionId) { throw new TypeError(PAYMENT_EXECUTION_ID_REQUIRED_ERROR); } const url = new URL(`/v1/${merchantId}/commerce-cases/${commerceCaseId}/checkouts/${checkoutId}/payment-executions/${paymentExecutionId}/complete`, this.getConfig().getHost()); const requestInit = { method: 'POST', headers: new Headers({ 'Content-Type': 'application/json', }), body: JSON.stringify(payload), }; return this.makeApiCall(url.toString(), requestInit); } async pausePayment(merchantId, commerceCaseId, checkoutId, paymentExecutionId, payload) { if (!merchantId) { throw new TypeError(MERCHANT_ID_REQUIRED_ERROR); } if (!commerceCaseId) { throw new TypeError(COMMERCE_CASE_ID_REQUIRED_ERROR); } if (!checkoutId) { throw new TypeError(CHECKOUT_ID_REQUIRED_ERROR); } if (!paymentExecutionId) { throw new TypeError(PAYMENT_EXECUTION_ID_REQUIRED_ERROR); } const url = new URL(`/v1/${merchantId}/commerce-cases/${commerceCaseId}/checkouts/${checkoutId}/payment-executions/${paymentExecutionId}/pause`, this.getConfig().getHost()); const requestInit = { method: 'POST', headers: new Headers({ 'Content-Type': 'application/json', }), body: JSON.stringify(payload), }; return this.makeApiCall(url.toString(), requestInit); } async refreshPayment(merchantId, commerceCaseId, checkoutId, paymentExecutionId, payload) { if (!merchantId) { throw new TypeError(MERCHANT_ID_REQUIRED_ERROR); } if (!commerceCaseId) { throw new TypeError(COMMERCE_CASE_ID_REQUIRED_ERROR); } if (!checkoutId) { throw new TypeError(CHECKOUT_ID_REQUIRED_ERROR); } if (!paymentExecutionId) { throw new TypeError(PAYMENT_EXECUTION_ID_REQUIRED_ERROR); } const url = new URL(`/v1/${merchantId}/commerce-cases/${commerceCaseId}/checkouts/${checkoutId}/payment-executions/${paymentExecutionId}/refresh`, this.getConfig().getHost()); const requestInit = { method: 'POST', headers: new Headers({ 'Content-Type': 'application/json', }), body: JSON.stringify(payload), }; return this.makeApiCall(url.toString(), requestInit); } async createFundSplit(merchantId, commerceCaseId, checkoutId, paymentExecutionId, eventId, payload) { if (!merchantId) { throw new TypeError(MERCHANT_ID_REQUIRED_ERROR); } if (!commerceCaseId) { throw new TypeError(COMMERCE_CASE_ID_REQUIRED_ERROR); } if (!checkoutId) { throw new TypeError(CHECKOUT_ID_REQUIRED_ERROR); } if (!paymentExecutionId) { throw new TypeError(PAYMENT_EXECUTION_ID_REQUIRED_ERROR); } if (!eventId) { throw new TypeError(EVENT_ID_REQUIRED_ERROR); } const url = new URL(`/v1/${merchantId}/commerce-cases/${commerceCaseId}/checkouts/${checkoutId}/payment-executions/${paymentExecutionId}/events/${eventId}/fund-splits`, this.getConfig().getHost()); const requestInit = { method: 'POST', headers: new Headers({ 'Content-Type': 'application/json', }), body: JSON.stringify(payload), }; return this.makeApiCall(url.toString(), requestInit); } } //# sourceMappingURL=PaymentExecutionApiClient.js.map