Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Klarna Payment Context Support #383

Merged
merged 1 commit into from
Apr 23, 2024
Merged
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
141 changes: 101 additions & 40 deletions test/payment-contexts/payment-contexts-it.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from "chai";
import nock from "nock";
import Checkout from '../../src/Checkout.js'
import { NotFoundError } from "../../src/services/errors.js";
import { NotFoundError, ValidationError } from "../../src/services/errors.js";

afterEach(() => {
nock.cleanAll();
Expand All @@ -12,51 +12,112 @@ const cko = new Checkout(process.env.CHECKOUT_DEFAULT_SECRET_KEY);
const processingChannelId = process.env.CHECKOUT_PROCESSING_CHANNEL_ID;

describe('Integration::Payment-Contexts', () => {
describe('Paypal request', () => {
const request = {
source: {
type: "paypal"
},
amount: 2000,
currency: "EUR",
paymentType: "Regular",
capture: true,
processing_channel_id: processingChannelId,
success_url: "https://example.com/payments/success",
failure_url: "https://example.com/payments/fail",
items: [
{
name: "mask",
quantity: 1,
unit_price: 2000,
}
]
}

const request = {
source: {
type: "paypal"
},
amount: 2000,
currency: "EUR",
paymentType: "Regular",
capture: true,
processing_channel_id: processingChannelId,
success_url: "https://example.com/payments/success",
failure_url: "https://example.com/payments/fail",
items: [
{
name: "mask",
quantity: 1,
unit_price: 2000,
}
]
}
it('should request a payment context', async () => {
const response = await cko.paymentContexts.request(request);

it('should request a payment context', async () => {
const response = await cko.paymentContexts.request(request);
expect(response.id).not.to.be.null;
expect(response.partner_metadata.order_id).not.to.be.null;
});

expect(response.id).not.to.be.null;
expect(response.partner_metadata.order_id).not.to.be.null;
});
it('should get a payment context', async () => {
const responseRquest = await cko.paymentContexts.request(request);
const response = await cko.paymentContexts.get(responseRquest.id);

it('should get a payment context', async () => {
const responseRquest = await cko.paymentContexts.request(request);
const response = await cko.paymentContexts.get(responseRquest.id);

expect(response.payment_request.source.type).to.equal('paypal');
expect(response.payment_request.amount).to.equal(2000);
expect(response.payment_request.currency).to.equal("EUR");
expect(response.payment_request.currency.items).to.not.be.null
expect(response.payment_request.success_url).to.equal('https://example.com/payments/success');
expect(response.payment_request.failure_url).to.equal('https://example.com/payments/fail');
});
expect(response.payment_request.source.type).to.equal('paypal');
expect(response.payment_request.amount).to.equal(2000);
expect(response.payment_request.currency).to.equal("EUR");
expect(response.payment_request.currency.items).to.not.be.null;
expect(response.payment_request.success_url).to.equal('https://example.com/payments/success');
expect(response.payment_request.failure_url).to.equal('https://example.com/payments/fail');
});

it('should throw NotFoundError when getting an unexistant payment context', async () => {
try {
it('should throw NotFoundError when getting an unexistant payment context', async () => {
try {
await cko.paymentContexts.get('not_found');
} catch (err) {
} catch (err) {
expect(err).to.be.instanceOf(NotFoundError);
}
});
});

describe('Klarna request', () => {
const request = {
source: {
type: "klarna",
account_holder: {
billing_address: {
country: 'DE',
},
},
},
amount: 1000,
currency: "EUR",
paymentType: "Regular",
processing_channel_id: processingChannelId,
items: [
{
name: "mask",
quantity: 1,
unit_price: 1000,
total_amount: 1000,
reference: "BA67A"
}
],
processing: {
locale: "en-GB"
}
}
});

it('should request a payment context and get apm service unavailable', async () => {
try {
await cko.paymentContexts.request(request);
} catch (error) {
expect(error).to.be.instanceOf(ValidationError);
expect(error.http_code).to.equal(422);
expect(error.body.error_codes).to.contain("apm_service_unavailable");
}

});

it.skip('should request a payment context', async () => {
const response = await cko.paymentContexts.request(request);

expect(response.id).not.to.be.null;
expect(response.partner_metadata.order_id).not.to.be.null;
});

it.skip('should get a payment context', async () => {
const responseRquest = await cko.paymentContexts.request(request);
const response = await cko.paymentContexts.get(responseRquest.id);

expect(response.payment_request.source.type).to.equal('klarna');
expect(response.payment_request.source.account_holder).to.not.be.null;
expect(response.payment_request.amount).to.equal(2000);
expect(response.payment_request.currency).to.equal("EUR");
expect(response.payment_request.currency.items).to.not.be.null;
expect(response.payment_request.success_url).to.equal('https://example.com/payments/success');
expect(response.payment_request.failure_url).to.equal('https://example.com/payments/fail');
});
});
});
Loading