Skip to content

Commit

Permalink
feat(payments): add support for Swish
Browse files Browse the repository at this point in the history
  • Loading branch information
dasanorct committed Feb 4, 2025
1 parent 36961a4 commit 9c70c00
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 3 deletions.
1 change: 1 addition & 0 deletions enabler/dev-utils/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const getSessionId = async (cartId, isDropin = false) => {
"paypal",
"przelewy24",
"sepadirectdebit",
"swish",
"twint",
], // add here your allowed methods for development purposes
}),
Expand Down
2 changes: 1 addition & 1 deletion enabler/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ <h1 class="h3 mb-3 font-weight-normal">Dev Site</h1>
});

if (builder.componentHasSubmit) {
const methodsRequireMounting = ['bancontactcard', 'bancontactmobile', 'blik', 'card', 'eps', 'ideal', 'klarna_billie', 'klarna_pay_later', 'klarna_pay_now', 'klarna_pay_overtime', 'przelewy24','sepadirectdebit', 'twint'];
const methodsRequireMounting = ['bancontactcard', 'bancontactmobile', 'blik', 'card', 'eps', 'ideal', 'klarna_billie', 'klarna_pay_later', 'klarna_pay_now', 'klarna_pay_overtime', 'przelewy24','sepadirectdebit', 'swish', 'twint'];
const isAvailable = await component.isAvailable();
if (isAvailable && methodsRequireMounting.includes(selectedValue)) {
component.mount("#container--external");
Expand Down
53 changes: 53 additions & 0 deletions enabler/src/components/payment-methods/swish.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { ComponentOptions, PaymentComponent, PaymentMethod } from "../../payment-enabler/payment-enabler";
import { AdyenBaseComponentBuilder, DefaultAdyenComponent } from "../base";
import { BaseOptions } from "../../payment-enabler/adyen-payment-enabler";
import { Swish, ICore } from "@adyen/adyen-web";
/**
* Swish component
*
* Configuration options:
* https://docs.adyen.com/payment-methods/swish/web-component/
*/
export class SwishBuilder extends AdyenBaseComponentBuilder {
constructor(baseOptions: BaseOptions) {
super(PaymentMethod.swish, baseOptions);
}

build(config: ComponentOptions): PaymentComponent {
const swishComponent = new SwishComponent({
paymentMethod: this.paymentMethod,
adyenCheckout: this.adyenCheckout,
componentOptions: config,
sessionId: this.sessionId,
processorUrl: this.processorUrl,
});
swishComponent.init();
return swishComponent;
}
}

export class SwishComponent extends DefaultAdyenComponent {
constructor(opts: {
paymentMethod: PaymentMethod;
adyenCheckout: ICore;
componentOptions: ComponentOptions;
sessionId: string;
processorUrl: string;
}) {
super(opts);
}

init(): void {
this.component = new Swish(this.adyenCheckout, {
showPayButton: this.componentOptions.showPayButton,
});
}

showValidation() {
this.component.showValidation();
}

isValid() {
return this.component.isValid;
}
}
2 changes: 2 additions & 0 deletions enabler/src/dropin/dropin-embedded.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
EPS,
Blik,
OnlineBankingPL,
Swish,
} from "@adyen/adyen-web";

export class DropinEmbeddedBuilder implements PaymentDropinBuilder {
Expand Down Expand Up @@ -80,6 +81,7 @@ export class DropinComponents implements DropinComponent {
PayPal,
Redirect,
SepaDirectDebit,
Swish,
Twint,
],
paymentMethodsConfiguration: {
Expand Down
2 changes: 2 additions & 0 deletions enabler/src/payment-enabler/adyen-payment-enabler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { BancontactMobileBuilder } from "../components/payment-methods/bancontac
import { KlarnaBillieBuilder } from "../components/payment-methods/klarna-billie";
import { BlikBuilder } from "../components/payment-methods/blik";
import { Przelewy24PLBuilder } from "../components/payment-methods/przelewy24";
import { SwishBuilder } from "../components/payment-methods/swish";

class AdyenInitError extends Error {
sessionId: string;
Expand Down Expand Up @@ -234,6 +235,7 @@ export class AdyenPaymentEnabler implements PaymentEnabler {
przelewy24: Przelewy24PLBuilder,
paypal: PaypalBuilder,
sepadirectdebit: SepaBuilder,
swish: SwishBuilder,
twint: TwintBuilder,
};

Expand Down
1 change: 1 addition & 0 deletions enabler/src/payment-enabler/payment-enabler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export enum PaymentMethod {
paypal = "paypal",
przelewy24 = "przelewy24",
sepadirectdebit = "sepadirectdebit",
swish = "swish",
twint = "twint",
}

Expand Down
3 changes: 3 additions & 0 deletions processor/src/config/payment-method.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,7 @@ export const paymentMethodConfig: PaymentMethodConfig = {
onlineBanking_PL: {
supportSeparateCapture: false,
},
swish: {
supportSeparateCapture: false,
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ export class PaymentComponentsConverter {
{
type: 'sepadirectdebit',
},
{
type: 'swish',
},
{
type: 'twint',
},
Expand Down
5 changes: 3 additions & 2 deletions processor/test/services/adyen-payment.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ describe('adyen-payment.service', () => {

test('getSupportedPaymentComponents', async () => {
const result: SupportedPaymentComponentsSchemaDTO = await paymentService.getSupportedPaymentComponents();
expect(result?.components).toHaveLength(16);
expect(result?.components).toHaveLength(17);
expect(result?.components[0]?.type).toStrictEqual('applepay');
expect(result?.components[1]?.type).toStrictEqual('bancontactcard');
expect(result?.components[2]?.type).toStrictEqual('bancontactmobile');
Expand All @@ -114,7 +114,8 @@ describe('adyen-payment.service', () => {
expect(result?.components[12]?.type).toStrictEqual('paypal');
expect(result?.components[13]?.type).toStrictEqual('przelewy24');
expect(result?.components[14]?.type).toStrictEqual('sepadirectdebit');
expect(result?.components[15]?.type).toStrictEqual('twint');
expect(result?.components[15]?.type).toStrictEqual('swish');
expect(result?.components[16]?.type).toStrictEqual('twint');
});

test('getStatus', async () => {
Expand Down

0 comments on commit 9c70c00

Please sign in to comment.