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.
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.
In your vue project, install the dependencies for payments component:
``shell`
npm install @mafpay/weblib @mafpay/weblib-angular9 --save
Or if you use yarn
`shell`
yarn add @mafpay/weblib @mafpay/weblib-angular9
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:
`js
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-angular9';
@NgModule({
imports: [
MafpayWeblibModule
],
})
export class YourModule { }
`
This payment form consists of six customizable UI components:
- ```
- ``
- ``
- ``
- ``
- `
that can be used as shown in the following snippet of code
`
import { Component } from '@angular/core';
@Component({
selector: 'app-your-component',
template:
,
})
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:
,
})
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:
,
})
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
url">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 Angular9:`
@Component({
selector: 'app-root',
template: ,
})
export class AppComponent {
@ViewChild('mafpayCardForm', {static: true }) private mafpayCardForm
title = 'weblib-angular-sample';
config = {
tokenizev2: true,
verifyCard: 'threeds',
merchantId: '',
apiKey: '',
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:
,
})
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:
,
})
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:
,
})
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 9 library, please follow the example below:`
import {Component, HostListener} from '@angular/core';@Component({
selector: 'app-your-component',
template:
,
})
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 9 library, please follow the example below:`
import {Component, HostListener} from '@angular/core';@Component({
selector: 'app-your-component',
template:
,
})
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:
,
})
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 9 library, please follow the example below:`
import {Component, HostListener} from '@angular/core';@Component({
selector: 'app-your-component',
template:
,
})
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);
}
}
``