@mafpay/weblib-angular
v1.3.8
Published
This package is built using Angular 11 and is not compatible with Angular 9 due to TypeScript version differences. Please use [@mafpay/weblog-angular9](https://www.npmjs.com/package/@mafpay/weblib-angular9) to use it with Angular 9.
Downloads
21
Readme
Note
This package is built using Angular 11 and is not compatible with Angular 9 due to TypeScript version differences. Please use @mafpay/weblog-angular9 to use it with Angular 9.
Mafpay web library Angular version
Using MAF Pay library will provide the comfort during implementing the payment page, by providing the pre-defined web components that validate and process the user inputs by its own.
MAF Pay payment services allows merchants to accept payments by integrating with the payment APIs in the Javascript Framework of their choice. It offers:
- Customizable UI components.
- Validations to limit the chances of incorrect data entry.
- An easier API integration process.
- Tokenization service to securely store customer's data.
How to setup it
In your vue project, install the dependencies for payments component:
npm install @mafpay/weblib @mafpay/weblib-angular --save
Or if you use yarn
yarn add @mafpay/weblib @mafpay/weblib-angular
To configure the minimum styles add the following styles into angular.json
"styles": [
"./node_modules/@mafpay/weblib/dist/mafpay/mafpay.css"
],
Include MAF Pay components by calling defineCustomElements()
in your main JS file:
import { defineCustomElements } from "@mafpay/weblib";
defineCustomElements();
Next step is to import MAF Pay in an Angular module, as shown in the code snippet below:
import { MafpayWeblibModule } from '@mafpay/weblib-angular';
@NgModule({
imports: [
MafpayWeblibModule
],
})
export class YourModule { }
Create Card Payment Form
This payment form consists of six customizable UI components:
<mafpay-card-number></mafpay-card-number>
<mafpay-card-holder-name></mafpay-card-holder-name>
<mafpay-card-expiry></mafpay-card-expiry>
<mafpay-card-cvc></mafpay-card-cvc>
<mafpay-remember-card></mafpay-remember-card>
<mafpay-card-submit></mafpay-card-submit>
that can be used as shown in the following snippet of code
import { Component } from '@angular/core';
@Component({
selector: 'app-your-component',
template: `
<form method="POST" action="https://payment.sandbox.mafpayments.com/tokenize" noValidate>
<div className="payment-form">
<input type="hidden" name="merchantId" value="Your Marchent ID"/>
<input type="hidden" name="apiKey" value="Your API Key"/>
<input type="hidden" name="command" value="tokenize"/>
<mafpay-card-holder-name></mafpay-card-holder-name>
<mafpay-card-number></mafpay-card-number>
<mafpay-card-expiry></mafpay-card-expiry>
<mafpay-card-cvc masked="false"></mafpay-card-cvc>
<mafpay-card-submit></mafpay-card-submit>
</div>
</form>
`,
})
export class YourComponent {
}
To create the card payment form and apply the required UI customization you need to follow the steps in our integration guide: "https://apidocs.mafpayments.com/online/#web-library-create-card-payment-form"
And here is an example below, to give you an idea of how to use events with Angular:
import { Component, HostListener } from '@angular/core';
@Component({
selector: 'app-your-component',
template: `
<mafpay-card-number></mafpay-card-number>
`,
})
export class YourComponent {
@HostListener('cardNumberStatus', ['$event'])
cardNumberStatusEventHandler(event: any) {
console.log(event.detail);
}
}
And here is an example below, to give you an idea of how to use methods with Angular:
import {Component, ElementRef, ViewChild} from '@angular/core';
@Component({
selector: 'app-your-component',
template: `
<mafpay-card-number #mafpayCardNumberRef></mafpay-card-number>
<button (click)="resetHandler()">Reset</button>
`,
})
export class YourComponent {
@ViewChild('mafpayCardNumberRef', { read: ElementRef }) mafpayCardNumberRef: ElementRef;
resetHandler() {
this.mafpayCardNumberRef.nativeElement.resetField();
}
}
Create Card Form Using Wrapper Component(single component):
You can use mafpay-card-form
to create the card form that comes with our default UI design,
this component will build the entire credit/debit card form for you, for more details please follow the steps in our
integration guide:
You can listen to all events related to the card form component using on()
method, the method takes two parameters:
event name and callback function(the function will be called once the event has been emitted).
To reset all fields inside card form, you can use resetFields()
method.
The example below demonstrates how to use mafpay-card-form
component with Angular:
@Component({
selector: 'app-root',
template: `
<mafpay-card-form #mafpayCardForm [config]="config"></mafpay-card-form>
<button (click)="resetFieldsHandler()">Reset</button>
`,
})
export class AppComponent {
@ViewChild('mafpayCardForm', {static: true }) private mafpayCardForm
title = 'weblib-angular-sample';
config = {
tokenizev2: true,
verifyCard: 'threeds',
merchantId: '<YOUR MERCHIENT ID>',
apiKey: '<YOUR API KEY>',
command: 'tokenize',
cardNumberPlaceHolder: 'Card Number',
cardCvcPlaceHolder: 'CVC',
cardCvcMasked: true,
cardCvcTooltip: true,
cardExpiryPlaceHolder: 'MM/YY',
cardHolderNamePlaceHolder: 'Holder Name',
cardDefaultPlaceHolder: 'Default Card',
rememberCardPlaceHolder: 'Remember me?',
isHolderNameRequired: true,
submitLabel: 'Submit'
}
ngOnInit() {
this.mafpayCardForm.on('tokenizationComplete', this.tokenizationComplete);
this.mafpayCardForm.on('cardHolderNameStatus', this.cardHolderNameStatus);
this.mafpayCardForm.on('cardExpiryStatus', this.cardExpiryStatus);
this.mafpayCardForm.on('cardCvcStatus', this.cardCvcStatus);
this.mafpayCardForm.on('cardNumberStatus', this.cardCvcStatus);
}
resetFieldsHandler() {
this.mafpayCardForm.resetFields()
}
tokenizationComplete(event) {
console.log('tokenizationComplete', event)
}
cardHolderNameStatus(event) {
console.log('cardHolderNameStatus', event)
}
cardExpiryStatus(event) {
console.log('cardExpiryStatus', event)
}
cardCvcStatus(event) {
console.log('cardCvcStatus', event)
}
cardNumberStatus(event) {
console.log('cardNumberStatus', event)
}
}
Checkout Component
To create the checkout session component and apply the required UI customization you need to follow the steps in our integration guide: "https://apidocs.mafpayments.com/online/#web-library-checkout-component"
To use the checkout token with our Angular library, please follow the example below:
import { Component, HostListener, OnInit } from '@angular/core';
@Component({
selector: 'app-your-component',
template: `
<mafpay-checkout [token]="token"></mafpay-checkout>
`,
})
export class YourComponent implements OnInit {
token: string | undefined;
ngOnInit() {
// createCheckoutSession() function implementation is defined by the merchant
this.createCheckoutSession().then(({ checkoutToken }) => {
this.token = checkoutToken;
});
}
}
3D Secure 2
To create the 3DS component and apply the required customization you need to follow the steps in our integration guide: "https://apidocs.mafpayments.com/online/#web-library-3d-secure-2"
The example below gives you an idea of how to use our 3DS component with Angular:
import {Component, HostListener, OnInit} from '@angular/core';
@Component({
selector: 'app-your-component',
template: `
<mafpay-threeds-component *ngIf="threeDSAuthID" [threedsauthid]="threeDSAuthID"></mafpay-threeds-component>
`,
})
export class YourComponent implements OnInit {
threeDSAuthID: string | undefined;
ngOnInit() {
// createThreeDSAuthID() function implementation is defined by the merchant
this.createThreeDSAuthID().then(({ checkoutToken }) => {
this.threeDSAuthID = checkoutToken;
});
}
@HostListener('processComplete', ['$event'])
processCompleteEventHandler(event: any) {
console.log(event.detail);
}
}
Google Pay
To create the Google Pay button component and apply the required UI customization you need to follow the steps in our integration guide: "https://apidocs.mafpayments.com/online/#web-library-google-pay"
To use the Google Pay button component with our Angular library, please follow the example below:
import {Component, HostListener} from '@angular/core';
@Component({
selector: 'app-your-component',
template: `
<mafpay-google-pay-button
token="Checkout Token"
merchantId="Your merchant Id from Google Pay business console"
buttonColor="white"
enableButtonLoading="true"
></mafpay-google-pay-button>
`,
})
export class YourComponent {
@HostListener('googlePayClose', ['$event'])
googlePayCloseHandler(event: any) {
console.log(event.detail);
}
@HostListener('loadingEvent', ['$event'])
loadingEventHandler(event: any) {
console.log(event.detail);
}
}
Apple Pay
To create the Apple Pay button component and apply the required UI customization you need to follow the steps in our integration guide: "https://apidocs.mafpayments.com/online/#web-library-apple-pay"
To use the Apple Pay button component with our Angular library, please follow the example below:
import {Component, HostListener} from '@angular/core';
@Component({
selector: 'app-your-component',
template: `
<mafpay-apple-pay-button
token="Checkout Token"
buttonStyle="black"
buttonType="buy"
totalAmountLabel="Total"
></mafpay-apple-pay-button>
`,
})
export class YourComponent {
@HostListener('applePayClosed', ['$event'])
applePayClosedHandler(event: any) {
console.log(event.detail);
}
@HostListener('applePayCompleted', ['$event'])
applePayCompletedHandler(event: any) {
console.log(event.detail);
}
@HostListener('applePayError', ['$event'])
applePayErrorHandler(event: any) {
console.log(event.detail);
}
@HostListener('loadingEvent', ['$event'])
loadingEventHandler(event: any) {
console.log(event.detail);
}
}
Bank Transfer
To create the bank transfer components and apply the required UI customization you need to follow the steps in our integration guide: "https://apidocs.mafpayments.com/online/#web-library-bank-transfer"
To use the Link Bank component with our Angular library, please follow the example below:
import {Component, HostListener} from '@angular/core';
@Component({
selector: 'app-your-component',
template: `
<mafpay-link-bank
merchantId="Your merchant ID"
apiKey="Your api key"
accountHolderId="Account holder ID"
enableLoading="true"
<!-- auth0Token="You can use the auth0Token instead of apiKey and accountHolderId" -->
>
</mafpay-link-bank>
`,
})
export class YourComponent {
@HostListener('linkBankCompleted', ['$event'])
onCompletedHandler(event: any) {
console.log(event.detail);
}
@HostListener('linkBankError', ['$event'])
onErrorHandler(event: any) {
console.log(event.detail);
}
@HostListener('linkBankClosed', ['$event'])
onClosedHandler(event: any) {
console.log(event.detail);
}
@HostListener('linkBankLoading', ['$event'])
onLoadingHandler(event: any) {
console.log(event.detail);
}
}
To use the Bank Transfer Payment component with our Angular library, please follow the example below:
import {Component, HostListener} from '@angular/core';
@Component({
selector: 'app-your-component',
template: `
<mafpay-bank-transfer
checkout-token="CH16556502340323875442"
bank-token="TB16546781191062919744"
enableLoading="true"
>
</mafpay-bank-transfer>
`,
})
export class YourComponent {
@HostListener('bankTransferCompleted', ['$event'])
onCompletedHandler(event: any) {
console.log(event.detail);
}
@HostListener('bankTransferError', ['$event'])
onErrorHandler(event: any) {
console.log(event.detail);
}
@HostListener('bankTransferClosed', ['$event'])
onClosedHandler(event: any) {
console.log(event.detail);
}
@HostListener('bankTransferLoading', ['$event'])
onLoadingHandler(event: any) {
console.log(event.detail);
}
}
Tamara
To create Tamara button component you need to follow the steps in our integration guide: "https://apidocs.mafpayments.com/online/#web-library-tamara"
To use the Tamara button component with our Angular library, please follow the example below:
import {Component, HostListener} from '@angular/core';
@Component({
selector: 'app-your-component',
template: `
<mafpay-tamara-button token="Checkout Token"></mafpay-tamara-button>
`,
})
export class YourComponent {
@HostListener('tamaraError', ['$event'])
tamaraErrorHandler(event: any) {
console.log(event.detail);
}
@HostListener('tamaraLoading', ['$event'])
tamaraLoadingHandler(event: any) {
console.log(event.detail);
}
@HostListener('tamaraRedirectUrl', ['$event'])
tamaraRedirectUrlHandler(event: any) {
console.log(event.detail);
}
}