|
| 1 | +import { |
| 2 | + ComponentOptions, |
| 3 | + PaymentComponent, |
| 4 | + PaymentMethod, |
| 5 | +} from "../../payment-enabler/payment-enabler"; |
| 6 | +import { AdyenBaseComponentBuilder, DefaultAdyenComponent } from "../base"; |
| 7 | +import { BaseOptions } from "../../payment-enabler/adyen-payment-enabler"; |
| 8 | +import { MolPayEBankingMY, ICore } from "@adyen/adyen-web"; |
| 9 | + |
| 10 | +/** |
| 11 | + * fpx-online-banking-malaysia component |
| 12 | + * |
| 13 | + * Configuration options: |
| 14 | + * https://docs.adyen.com/payment-methods/fpx-online-banking-malaysia/web-component/ |
| 15 | + */ |
| 16 | +export class FPXBuilder extends AdyenBaseComponentBuilder { |
| 17 | + constructor(baseOptions: BaseOptions) { |
| 18 | + super(PaymentMethod.fpx, baseOptions); |
| 19 | + } |
| 20 | + |
| 21 | + build(config: ComponentOptions): PaymentComponent { |
| 22 | + const fpxComponent = new FPXComponent({ |
| 23 | + paymentMethod: this.paymentMethod, |
| 24 | + adyenCheckout: this.adyenCheckout, |
| 25 | + componentOptions: config, |
| 26 | + sessionId: this.sessionId, |
| 27 | + processorUrl: this.processorUrl, |
| 28 | + paymentComponentConfigOverride: |
| 29 | + this.resolvePaymentComponentConfigOverride(PaymentMethod.fpx), |
| 30 | + }); |
| 31 | + fpxComponent.init(); |
| 32 | + return fpxComponent; |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +export class FPXComponent extends DefaultAdyenComponent { |
| 37 | + constructor(opts: { |
| 38 | + paymentMethod: PaymentMethod; |
| 39 | + adyenCheckout: ICore; |
| 40 | + componentOptions: ComponentOptions; |
| 41 | + sessionId: string; |
| 42 | + processorUrl: string; |
| 43 | + paymentComponentConfigOverride: Record<string, any>; |
| 44 | + }) { |
| 45 | + super(opts); |
| 46 | + } |
| 47 | + |
| 48 | + init(): void { |
| 49 | + this.component = new MolPayEBankingMY(this.adyenCheckout, { |
| 50 | + // Override the default config with the one provided by the user |
| 51 | + ...this.paymentComponentConfigOverride, |
| 52 | + // Configuration that can not be overridden |
| 53 | + showPayButton: this.componentOptions.showPayButton, |
| 54 | + }); |
| 55 | + } |
| 56 | + |
| 57 | + async showValidation() { |
| 58 | + this.component.showValidation(); |
| 59 | + } |
| 60 | + |
| 61 | + async isValid() { |
| 62 | + return this.component.isValid; |
| 63 | + } |
| 64 | +} |
0 commit comments