Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions test/hosted-payments/hosted-payments.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,48 @@ describe('Hosted Payments', () => {
);
});

it('should create a hosted payment with authorization_type and payment_plan', async () => {
let capturedBody;
nock('https://123456789.api.sandbox.checkout.com')
.post('/hosted-payments', (body) => {
capturedBody = body;
return true;
})
.reply(201, {
id: 'hpp_kQhs_fI9b8oQ',
reference: 'ORD-5023-4E89',
_links: {
redirect: {
href: 'https://pay.checkout.com/page/hpp_kQhs_fI9b8oQ',
},
},
});

const cko = new Checkout(SK, { subdomain: '123456789' });

await cko.hostedPayments.create({
amount: 1000,
currency: 'USD',
authorization_type: 'Estimated',
payment_plan: {
amount_variability: 'Variable',
days_between_payments: 28,
total_number_of_payments: 5,
current_payment_number: 3,
expiry: '20251031',
name: 'Subscription 1234',
},
success_url: 'https://example.com/success',
cancel_url: 'https://example.com/cancel',
failure_url: 'https://example.com/failure',
});

expect(capturedBody.authorization_type).to.equal('Estimated');
expect(capturedBody.payment_plan.amount_variability).to.equal('Variable');
expect(capturedBody.payment_plan.days_between_payments).to.equal(28);
expect(capturedBody.payment_plan.total_number_of_payments).to.equal(5);
});

it('should throw Authentication Error', async () => {
nock('https://123456789.api.sandbox.checkout.com').post('/hosted-payments').reply(401);

Expand Down
30 changes: 30 additions & 0 deletions test/payment-sessions/payment-sessions-unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,34 @@ describe('Unit::Payment-Sessions', () => {
}
});

it('should request a payment session with authorization_type and payment_plan', async () => {
let capturedBody;
nock('https://123456789.api.sandbox.checkout.com')
.post('/payment-sessions', (body) => {
capturedBody = body;
return true;
})
.reply(201, commonResponse);

const cko = new Checkout(SK, { subdomain: '123456789' });

await cko.paymentSessions.request({
...commonRequest,
authorization_type: 'Estimated',
payment_plan: {
amount_variability: 'Variable',
days_between_payments: 28,
total_number_of_payments: 5,
current_payment_number: 3,
expiry: '20251031',
name: 'Subscription 1234',
},
});

expect(capturedBody.authorization_type).to.equal('Estimated');
expect(capturedBody.payment_plan.amount_variability).to.equal('Variable');
expect(capturedBody.payment_plan.days_between_payments).to.equal(28);
expect(capturedBody.payment_plan.total_number_of_payments).to.equal(5);
});

});
44 changes: 44 additions & 0 deletions test/payments-links/payments-links.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,50 @@ describe('Payment Links', () => {
);
});

it('should create a payment link with authorization_type and payment_plan', async () => {
let capturedBody;
nock('https://123456789.api.sandbox.checkout.com')
.post('/payment-links', (body) => {
capturedBody = body;
return true;
})
.reply(201, {
id: 'pl_irx_SMlY5RCA',
expires_on: '2021-02-19T16:54:41.501Z',
_links: {
redirect: { href: 'https://pay.sandbox.checkout.com/link/IT1-wLhj_wM8' },
},
});

const cko = new Checkout(SK, { subdomain: '123456789' });

await cko.paymentLinks.create({
amount: 10359,
currency: 'EUR',
authorization_type: 'Estimated',
payment_plan: {
amount_variability: 'Fixed',
days_between_payments: 30,
total_number_of_payments: 12,
current_payment_number: 1,
expiry: '20251031',
name: 'Subscription 1234',
amount: 1234,
},
billing: {
address: {
country: 'DE',
},
},
return_url: 'https://pay.sandbox.checkout.com/link/examples/docs',
});

expect(capturedBody.authorization_type).to.equal('Estimated');
expect(capturedBody.payment_plan.amount_variability).to.equal('Fixed');
expect(capturedBody.payment_plan.total_number_of_payments).to.equal(12);
expect(capturedBody.payment_plan.amount).to.equal(1234);
});

it('should throw Authentication Error', async () => {
nock('https://123456789.api.sandbox.checkout.com').post('/payment-links').reply(401);

Expand Down
Loading