Mafpay web library Vue.js 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-vue --save
Or if you use yarn
yarn add @mafpay/weblib @mafpay/weblib-vue
To configure the minimum styles add the following styles to your main JS file:
import "../node_modules/@mafpay/weblib/dist/mafpay/mafpay.css"
or import it inside your main CSS file:
@import url("../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();
Create Card Payment Form
This payment form consists of six customizable UI components:
<MafpayCardNumber></MafpayCardNumber>
<MafpayCardHolderName></MafpayCardNumber>
<MafpayCardExpiry></MafpayCardNumber>
<MafpayCardCvc></MafpayCardNumber>
<MafpayRememberCard></MafpayRememberCard>
<MafpayCardSubmit></MafpayCardNumber>
that can be imported as shown in the following snippet of code
<template>
<form method="POST" action="https://payment.sandbox.mafpayments.com/tokenize" noValidate>
<div class="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"/>
<MafpayCardHolderName></MafpayCardHolderName>
<MafpayCardNumber></MafpayCardNumber>
<MafpayCardExpiry></MafpayCardExpiry>
<MafpayCardCvc masked="false"></MafpayCardCvc>
<MafpayCardSubmit></MafpayCardSubmit>
</div>
</form>
</template>
<script>
import Vue from "vue";
import {
MafpayCardNumber,
MafpayCardExpiry,
MafpayCardHolderName,
MafpayCardCvc,
MafpayCardSubmit
} from "@mafpay/weblib-vue"
export default Vue.extend({
components: { MafpayCardNumber, MafpayCardExpiry, MafpayCardHolderName, MafpayCardCvc, MafpayCardSubmit }
});
</script>
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 Vue JS:
<template>
<MafpayCardNumber @cardNumberStatus="cardNumberStatusHandler"></MafpayCardNumber>
</template>
<script>
import Vue from "vue";
import {
MafpayCardNumber,
} from "@mafpay/weblib-vue"
export default Vue.extend({
components: { MafpayCardNumber },
methods: {
cardNumberStatusHandler: function(event) {
console.log(event);
}
}
});
</script>
And here is an example below, to give you an idea of how to use methods with Vue JS:
<template>
<div>
<MafpayCardNumber ref="mafpayCardNumberRef"></MafpayCardNumber>
<button @click="resetHandler">Reset</button>
</div>
</template>
<script>
import Vue from "vue";
import {
MafpayCardNumber,
} from "@mafpay/weblib-vue"
export default Vue.extend({
components: { MafpayCardNumber },
methods: {
resetHandler: function() {
this.$refs.mafpayCardNumberRef.resetField();
}
}
});
</script>
Create Card Form Using Wrapper Component(single component):
You can use MafpayCardForm
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 MafpayCardForm
component with vue:
<template>
<div>
<MafpayCardForm ref="mafpayCardForm" :config="config"></MafpayCardForm>
<button @click="resetFieldsHandler">Reset</button>
</div>
</template>
<script>
import Vue from "vue";
import {MafpayCardForm} from "@mafpay/weblib-vue";
export default Vue.extend({
components: {
MafpayCardForm
},
data: () => {
return {
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'
}
}
},
mounted() {
this.$refs.mafpayCardForm.on('tokenizationComplete', this.tokenizationComplete)
this.$refs.mafpayCardForm.on('cardHolderNameStatus', this.cardHolderNameStatus);
this.$refs.mafpayCardForm.on('cardExpiryStatus', this.cardExpiryStatus);
this.$refs.mafpayCardForm.on('cardCvcStatus', this.cardCvcStatus);
this.$refs.mafpayCardForm.on('cardNumberStatus', this.cardNumberStatus);
},
methods: {
resetFieldsHandler() {
this.$refs.mafpayCardForm.resetFields()
},
tokenizationComplete(event) {
console.log('event', 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)
}
}
});
</script>
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 Vue JS library, please follow the example below:
<template>
<MafpayCheckout :token.prop="token"></MafpayCheckout>
</template>
<script>
import Vue from "vue";
import { MafpayCheckout } from "@mafpay/weblib-vue";
export default Vue.extend({
components: { MafpayCheckout },
data: function () {
return {
token: "",
};
},
mounted: async function () {
const { checkoutToken } = await createCheckoutSession(); // createCheckoutSession() function implementation is defined by the merchant
this.token = checkoutToken;
},
});
</script>
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 Vue JS:
<template>
<div>
<MafpayThreedsComponent v-if="threeDSAuthID" :threedsauthid.prop="threeDSAuthID" @processComplete="processCompleteHandler"></MafpayThreedsComponent>
</div>
</template>
<script>
import Vue from "vue";
import {
MafpayThreedsComponent,
} from "@mafpay/weblib-vue";
export default Vue.extend({
components: { MafpayThreedsComponent },
data: function () {
return {
threeDSAuthID: "",
};
},
methods: {
processCompleteHandler: function(event) {
console.log(event);
}
},
mounted: async function () {
const { threeDSAuthID } = await createThreeDSAuthID(); // createThreeDSAuthID() function implementation is defined by the merchant
this.threeDSAuthID = threeDSAuthID;
},
});
</script>
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 Vue JS library, please follow the example below:
<template>
<MafpayGooglePayButton
token="Checkout Token"
merchantId="Your merchant Id from Google Pay business console"
buttonColor="white"
enableButtonLoading="true"
@googlePayClose="googlePayCloseHandler"
@loadingEvent="loadingEventHandler"
></MafpayGooglePayButton>
</template>
<script>
import Vue from "vue";
import { MafpayGooglePayButton } from "@mafpay/weblib-vue";
export default Vue.extend({
components: { MafpayGooglePayButton },
methods: {
googlePayCloseHandler: function(event) {
console.log(event);
},
loadingEventHandler: function(event) {
console.log(event);
},
},
});
</script>
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 Vue JS library, please follow the example below:
<template>
<MafpayApplePayButton
token="Checkout Token"
buttonStyle="white"
buttonType="pay"
totalAmountLabel="Total"
@applePayClosed=applePayClosedHandler
@loadingEvent=loadingEventHandler
@applePayCompleted=applePayCompletedHandler
@applePayError=applePayErrorHandler
></MafpayApplePayButton>
</template>
<script>
import Vue from "vue";
import { MafpayApplePayButton } from "@mafpay/weblib-vue";
export default Vue.extend({
components: { MafpayApplePayButton },
methods: {
applePayClosedHandler: function(event) {
console.log(event);
},
loadingEventHandler: function(event) {
console.log(event);
},
applePayCompletedHandler: function(event) {
console.log(event);
},
applePayErrorHandler: function(event) {
console.log(event);
},
},
});
</script>
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 Vue JS library, please follow the example below:
<template>
<MafpayLinkBank
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"-->
@linkBankCompleted="onCompletedHandler"
@linkBankError="onErrorHandler"
@linkBankClosed="onClosedHandler"
@linkBankLoading="onLoadingHandler"
></MafpayLinkBank>
</template>
<script>
import Vue from "vue";
import { MafpayLinkBank } from "@mafpay/weblib-vue";
export default Vue.extend({
components: { MafpayLinkBank },
methods: {
onCompletedHandler: function(event) {
console.log(event);
},
onErrorHandler: function(event) {
console.log(event);
},
onClosedHandler: function(event) {
console.log(event);
},
onLoadingHandler: function(event) {
console.log(event);
},
},
});
</script>
To use the Bank Transfer Payment component with our Vue JS library, please follow the example below:
<template>
<MafpayBankTransfer
checkoutToken="Checkout Token"
bankToken="Bank Token"
enableLoading="true"
@bankTransferCompleted="onCompletedHandler"
@bankTransferError="onErrorHandler"
@bankTransferClosed="onClosedHandler"
@bankTransferLoading="onLoadingHandler"
></MafpayBankTransfer>
</template>
<script>
import Vue from "vue";
import { MafpayBankTransfer } from "@mafpay/weblib-vue";
export default Vue.extend({
components: { MafpayBankTransfer },
methods: {
onCompletedHandler: function(event) {
console.log(event);
},
onErrorHandler: function(event) {
console.log(event);
},
onClosedHandler: function(event) {
console.log(event);
},
onLoadingHandler: function(event) {
console.log(event);
},
},
});
</script>
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 Vue JS library, please follow the example below:
<template>
<MafpayTamaraButton
token="Checkout Token"
@tamaraLoading=tamaraLoadingHandler
@tamaraRedirectUrl=tamaraRedirectUrlHandler
@tamaraError=tamaraErrorHandler
></MafpayTamaraButton>
</template>
<script>
import Vue from "vue";
import { MafpayTamaraButton } from "@mafpay/weblib-vue";
export default Vue.extend({
components: { MafpayApplePayButton },
methods: {
tamaraLoadingHandler: function(event) {
console.log(event);
},
tamaraRedirectUrlHandler: function(event) {
console.log(event);
},
tamaraErrorHandler: function(event) {
console.log(event);
}
},
});
</script>