From 3401eeef4d8f67d5aa3fece27f90802e536c1300 Mon Sep 17 00:00:00 2001 From: Rinor12010 <105772190+Rinor12010@users.noreply.github.com> Date: Mon, 27 Nov 2023 16:56:38 +0100 Subject: [PATCH] BP-3180-Add-External-Payments --- src/PaymentMethods/ExternalPayment/index.ts | 21 +++++++++++++++ src/PaymentMethods/index.ts | 3 ++- tests/PaymentMethods/ExternalPayment.test.ts | 28 ++++++++++++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 src/PaymentMethods/ExternalPayment/index.ts create mode 100644 tests/PaymentMethods/ExternalPayment.test.ts diff --git a/src/PaymentMethods/ExternalPayment/index.ts b/src/PaymentMethods/ExternalPayment/index.ts new file mode 100644 index 00000000..71fb12f4 --- /dev/null +++ b/src/PaymentMethods/ExternalPayment/index.ts @@ -0,0 +1,21 @@ +import { PayablePaymentMethod } from '../../Services'; +import { ServiceCode } from '../../Utils'; +import { IRequest } from "../../Models"; + +export default class ExternalPayment extends PayablePaymentMethod { + + private channel: 'BACKOFFICE' | 'POINT-OF-SALE' = 'BACKOFFICE'; + public defaultServiceCode(): ServiceCode { + return 'externalpayment'; + } + protected transactionRequest(payload?: IRequest) { + return super.transactionRequest(payload).setHeaders({Channel: this.channel}); + } + protected dataRequest(payload?: IRequest) { + return super.dataRequest(payload).setHeaders({Channel: this.channel}) + } + setChannel(channel: 'BACKOFFICE' | 'POINT-OF-SALE') { + this.channel = channel; + return this; + } +} diff --git a/src/PaymentMethods/index.ts b/src/PaymentMethods/index.ts index 8e85fdd2..f5fa73ff 100644 --- a/src/PaymentMethods/index.ts +++ b/src/PaymentMethods/index.ts @@ -83,4 +83,5 @@ export { default as alipay } from './Alipay'; export { default as trustly } from './Trustly'; export { default as wechatpay } from './WeChatPay'; export { default as In3 } from './In3'; -export { default as noservice } from './NoService'; \ No newline at end of file +export { default as noservice } from './NoService'; +export { default as externalpayment } from './ExternalPayment'; \ No newline at end of file diff --git a/tests/PaymentMethods/ExternalPayment.test.ts b/tests/PaymentMethods/ExternalPayment.test.ts new file mode 100644 index 00000000..813bdd9b --- /dev/null +++ b/tests/PaymentMethods/ExternalPayment.test.ts @@ -0,0 +1,28 @@ +import buckarooClientTest from '../BuckarooClient.test'; +import { uniqid } from '../../src'; + +const method = buckarooClientTest.method('externalpayment'); +describe('Testing ExternalPayment methods', () => { + test('Pay', async () => { + await method + .pay({ + amountDebit: 100, + }) + .request() + .then((response) => { + expect(response.isSuccess()).toBeTruthy(); + }); + }); + test('Refund', async () => { + method + .refund({ + invoice: uniqid(), + amountCredit: 0.01, + originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', + }) + .request() + .then((response) => { + expect(response.isFailed()).toBeTruthy(); + }); + }); +});