Skip to content

Commit

Permalink
BP-3180-Add-External-Payments
Browse files Browse the repository at this point in the history
  • Loading branch information
Rinor12010 committed Nov 27, 2023
1 parent 9841693 commit 3401eee
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/PaymentMethods/ExternalPayment/index.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}
3 changes: 2 additions & 1 deletion src/PaymentMethods/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
export { default as noservice } from './NoService';
export { default as externalpayment } from './ExternalPayment';
28 changes: 28 additions & 0 deletions tests/PaymentMethods/ExternalPayment.test.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});
});

0 comments on commit 3401eee

Please sign in to comment.