pcp-server-nodejs-sdk
Version:
[](https://sonarcloud.io/summary/new_code?id=PAYONE-GmbH_PCP-server-nodeJS-SDK) [ || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
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';
export class PaymentExecutionApiClient extends BaseApiClient {
constructor(config) {
super(config);
}
createPayment(merchantId, commerceCaseId, checkoutId, payload) {
return __awaiter(this, void 0, void 0, function* () {
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);
});
}
capturePayment(merchantId, commerceCaseId, checkoutId, paymentExecutionId, payload) {
return __awaiter(this, void 0, void 0, function* () {
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);
});
}
cancelPayment(merchantId, commerceCaseId, checkoutId, paymentExecutionId, payload) {
return __awaiter(this, void 0, void 0, function* () {
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);
});
}
refundPayment(merchantId, commerceCaseId, checkoutId, paymentExecutionId, payload) {
return __awaiter(this, void 0, void 0, function* () {
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);
});
}
completePayment(merchantId, commerceCaseId, checkoutId, paymentExecutionId, payload) {
return __awaiter(this, void 0, void 0, function* () {
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);
});
}
pausePayment(merchantId, commerceCaseId, checkoutId, paymentExecutionId, payload) {
return __awaiter(this, void 0, void 0, function* () {
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);
});
}
refreshPayment(merchantId, commerceCaseId, checkoutId, paymentExecutionId, payload) {
return __awaiter(this, void 0, void 0, function* () {
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);
});
}
}
//# sourceMappingURL=PaymentExecutionApiClient.js.map