Skip to content

Commit 93743be

Browse files
committed
feat: add native Klarna support
1 parent 830b2fd commit 93743be

5 files changed

Lines changed: 110 additions & 31 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ Here is where customers select a payment method and place the order.
156156
| --------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------- |
157157
| [Adyen](https://docs.commercelayer.io/developers/v/how-tos/payments/adyen) | Credit card / [PayPal](https://docs.adyen.com/payment-methods/paypal/web-drop-in) / [Klarna](https://docs.adyen.com/payment-methods/klarna/web-drop-in) | ✓ |
158158
| [Braintree](https://docs.commercelayer.io/developers/v/how-tos/payments/braintree) | Credit card | ✓ |
159+
| [Klarna](https://docs.commercelayer.io/developers/v/how-tos/payments/klarna) | Klarna | ✗ |
159160
| [PayPal](https://docs.commercelayer.io/developers/v/how-tos/payments/paypal) | PayPal | ✗ |
160161
| [Stripe](https://docs.commercelayer.io/developers/v/how-tos/payments/stripe) | Credit card / Apple Pay / Google Pay / PayPal / Klarna | ✓ |
161162
| [Manual gateway](https://docs.commercelayer.io/developers/v/how-tos/payments/manual-payments) | Manual payment | ✗ |

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
"commercelayer"
7373
],
7474
"dependencies": {
75-
"@commercelayer/react-components": "^4.5.1",
75+
"@commercelayer/react-components": "^4.6.0-beta.0",
7676
"@commercelayer/sdk": "^5.13.2",
7777
"@faker-js/faker": "^8.0.2",
7878
"@headlessui/react": "^1.7.17",

pnpm-lock.yaml

Lines changed: 36 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

specs/e2e/payments-klarna.spec.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { faker } from "@faker-js/faker"
2+
import { euAddress } from "specs/utils/addresses"
3+
4+
import { test, expect } from "../fixtures/tokenizedPage"
5+
6+
const customerEmail = faker.internet.email().toLocaleLowerCase()
7+
8+
test.use({
9+
defaultParams: {
10+
order: "with-items",
11+
lineItemsAttributes: [
12+
{ sku_code: "BABYONBU000000E63E7412MX", quantity: 2 },
13+
],
14+
orderAttributes: {
15+
customer_email: customerEmail,
16+
},
17+
},
18+
})
19+
20+
test("should execute a checkout with klarna", async ({ checkoutPage }) => {
21+
await checkoutPage.checkOrderSummary("Order Summary")
22+
23+
await checkoutPage.setCustomerMail()
24+
await checkoutPage.setBillingAddress({ ...euAddress, phone: "+393293399456" })
25+
26+
await checkoutPage.checkStep("Customer", "open")
27+
28+
await checkoutPage.save("Customer")
29+
30+
await checkoutPage.checkStep("Shipping", "open")
31+
32+
await checkoutPage.checkShippingSummary("To be calculated")
33+
34+
await expect(
35+
checkoutPage.page.locator("text=Standard Shipping")
36+
).toBeVisible()
37+
await checkoutPage.selectShippingMethod({ text: "Standard Shipping" })
38+
39+
await checkoutPage.checkShippingSummary("FREE")
40+
await checkoutPage.save("Shipping")
41+
42+
await checkoutPage.checkStep("Payment", "open")
43+
44+
await checkoutPage.selectPayment("klarna")
45+
46+
await checkoutPage.save("Payment", undefined, true)
47+
48+
await checkoutPage.completePayment({ type: "klarna" })
49+
50+
await checkoutPage.checkPaymentRecap("Klarna")
51+
52+
await checkoutPage.page.reload()
53+
54+
await checkoutPage.checkPaymentRecap("Klarna")
55+
})

specs/fixtures/CheckoutPage.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,7 @@ export class CheckoutPage {
645645
| "adyen"
646646
| "checkout_com"
647647
| "adyen-dropin"
648+
| "klarna"
648649
) {
649650
let paymentMethod
650651
if (type === "wire") {
@@ -659,11 +660,11 @@ export class CheckoutPage {
659660

660661
async completePayment({
661662
type,
662-
gateway,
663+
gateway = "klarna_pay_now",
663664
language,
664665
}: {
665-
type: "adyen-dropin"
666-
gateway:
666+
type: "adyen-dropin" | "klarna"
667+
gateway?:
667668
| "paypal"
668669
| "card"
669670
| "card3DS"
@@ -673,6 +674,19 @@ export class CheckoutPage {
673674
language?: "fr" | "de"
674675
}) {
675676
switch (type) {
677+
case "klarna": {
678+
const [newPage] = await Promise.all([this.page.waitForEvent("popup")])
679+
await newPage.locator("#onContinue").click()
680+
await newPage.locator("#otp_field__container input").fill("123456")
681+
await newPage.getByTestId("select-payment-category").click()
682+
await newPage.getByTestId("pick-plan").click()
683+
await newPage.getByTestId("confirm-and-pay").click()
684+
await this.page
685+
686+
.locator("text=Thank you for your order!")
687+
.waitFor({ state: "visible", timeout: 60000 })
688+
break
689+
}
676690
case "adyen-dropin": {
677691
switch (gateway) {
678692
case "paypal": {

0 commit comments

Comments
 (0)