Nanoscale Parts Manufacturing

    @mafpay/weblib-react
    TypeScript icon, indicating that this package has built-in type declarations

    1.3.6 • Public • Published

    Mafpay web library React 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-react --save

    Or if you use yarn

    yarn add @mafpay/weblib @mafpay/weblib-react

    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 />
    • <MafpayCardHolderName />
    • <MafpayCardExpiry />
    • <MafpayCardCvc />
    • <MafpayRememberCard />
    • <MafpayCardSubmit />

    that can be imported as shown in the following snippet of code

    import React from "react";
    import { MafpayCardHolderName, MafpayCardNumber, MafpayCardExpiry, MafpayCardCvc, MafpayCardSubmit } from "@mafpay/weblib-react";
    
    const App = () => {
      return (
        <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"/> 
    
            <MafpayCardHolderName />
            <MafpayCardNumber />
            <MafpayCardExpiry />
            <MafpayCardCvc masked="false" />
            <MafpayCardSubmit />
    
          </div> 
    
        </form>
      );
    }
    
    export default App;
    

    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 React JS:

    import React from "react";
    import { MafpayCardNumber } from "@mafpay/weblib-react";
    
    const App = () => {
    
      const onCardNumberStatusHandler = (event) => {
        console.log(event.detail);
      }
    
      return (
        <MafpayCardNumber onCardNumberStatus={(event) => onCardNumberStatusHandler(event)} />
      );
    
    }
    
    export default App;
    

    And here is an example below, to give you an idea of how to use methods with React JS:

    import React from "react";
    import { MafpayCardNumber } from "@mafpay/weblib-react";
    
    const App = () => {
    
        const mafpayCardNumberRef = React.useRef(null);
    
        const resetHandler = () => {
            mafpayCardNumberRef.current.resetField();
        }
    
        return (
            <div>
                <MafpayCardNumber ref={mafpayCardNumberRef} />
                <button onClick={() => resetHandler()}>Reset</button>
            </div>
        );
    
    }
    
    export default App;
    

    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 react:

    import React from "react";
    import { MafpayCardForm } from "@mafpay/weblib-react";
    
    const App = () => {
        const mafpayCardForm = React.useRef(null);
        const [config, setConfig] = React.useState({
           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'
        });
        
        useEffect(() => {
          mafpayCardForm.current.on('tokenizationComplete', tokenizationComplete);
          mafpayCardForm.current.on('cardHolderNameStatus', cardHolderNameStatus);
          mafpayCardForm.current.on('cardExpiryStatus', cardExpiryStatus);
          mafpayCardForm.current.on('cardCvcStatus', cardCvcStatus);
          mafpayCardForm.current.on('cardNumberStatus', cardNumberStatus);
        }, []);
    
        function resetFieldsHandler() {
          mafpayCardForm.current.resetFields()
        }
    
        function tokenizationComplete(event) {
         console.log('tokenizationComplete', event)
        }
    
        function cardHolderNameStatus(event) {
         console.log('cardHolderNameStatus', event)
        }
    
        function cardExpiryStatus(event) {
          console.log('cardExpiryStatus', event)
        }
    
        function cardCvcStatus(event) {
         console.log('cardCvcStatus', event)
        }
    
        function cardNumberStatus(event) {
         console.log('cardNumberStatus', event)
        }
    
        return (
        <div>
          <MafpayCardForm ref={mafpayCardForm} config={config}/>
          <button onClick={resetFieldsHandler}>Reset</button>
        </div>
      )
    }
    
    export default App;
    
    

    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 React JS library, please follow the example below:

    import React from "react";
    import { MafpayCheckout } from "@mafpay/weblib-react";
    
    const App = () => {
    
      const [token, setToken] = React.useState("");
    
      // createCheckoutSession() function implementation is defined by the merchant
      createCheckoutSession().then(({ checkoutToken }) => {
        setToken(checkoutToken);
      }); 
      
      return (
        <div>
          <MafpayCheckout token={token} />
        </div>
      );
    
    }
    
    export default App;
    

    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 React JS:

    import React from "react";
    import { MafpayThreedsComponent } from "@mafpay/weblib-react";
    
    const App = () => {
    
        const [threeDSAuthID, setThreeDSAuthID] = React.useState("");
    
        // createThreeDSAuthID() function implementation is defined by the merchant
        createThreeDSAuthID().then(({ threeDSAuthID }) => {
            setThreeDSAuthID(threeDSAuthID);
        });
    
        const processCompleteHandler = (event) => {
            console.log(event.detail);
        }
    
        return (
            <div>
                {threeDSAuthID && <MafpayThreedsComponent threedsauthid={threeDSAuthID} onProcessComplete={(event) => processCompleteHandler(event)} />}
            </div>
        );
    
    }
    
    export default App;
    

    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 React JS library, please follow the example below:

    import React from "react";
    import { MafpayGooglePayButton } from "@mafpay/weblib-react";
    
    const App = () => {
    
        const onGooglePayCloseHandler = (event) => {
            console.log(event.detail);
        }
    
        const onLoadingEventHandler = (event) => {
            console.log(event.detail);
        }
    
        return (
            <MafpayGooglePayButton
                token="Checkout Token"
                merchantId="Your merchant Id from Google Pay business console"
                buttonColor="white"
                enableButtonLoading="true"
                onGooglePayClose={(event) => onGooglePayCloseHandler(event)}
                onLoadingEvent={(event) => onLoadingEventHandler(event)}
            />
        );
    
    }
    
    export default App;
    

    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 React JS library, please follow the example below:

    import React from "react";
    import { MafpayApplePayButton } from "@mafpay/weblib-react";
    
    const App = () => {
    
        const onApplePayClosedHandler = (event) => {
            console.log(event.detail);
        }
        
        const onApplePayErrorHandler = (event) => {
            console.log(event.detail);
        }
        
        const onApplePayCompletedHandler = (event) => {
            console.log(event.detail);
        }
    
        const onLoadingEventHandler = (event) => {
            console.log(event.detail);
        }
    
        return (
            <MafpayApplePayButton
                token="Checkout Token"
                buttonStyle="white"
                buttonType="pay"
                totalAmountLabel="Total"
                onApplePayClosed={(event) => onApplePayClosedHandler(event)}
                onLoadingEvent={(event) => onLoadingEventHandler(event)}
                onApplePayCompleted={(event) => onApplePayCompletedHandler(event)}
                onApplePayError={(event) => onApplePayErrorHandler(event)}
            />
        );
    
    }
    
    export default App;
    

    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 React JS library, please follow the example below:

    import React from "react";
    import { MafpayLinkBank } from "@mafpay/weblib-react";
    
    const App = () => {
    
        const onCompletedHandler = (event) => {
            console.log(event.detail);
        }
    
        const onErrorHandler = (event) => {
            console.log(event.detail);
        }
    
        const onClosedHandler = (event) => {
            console.log(event.detail);
        }
    
        const onLoadingHandler = (event) => {
            console.log(event.detail);
        }
    
        return (
            <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'}
                onLinkBankCompleted={onCompletedHandler}
                onLinkBankError={onErrorHandler}
                onLinkBankClosed={onClosedHandler}
                onLinkBankLoading={onLoadingHandler}
            />
        );
    
    }
    
    export default App;
    

    To use the Bank Transfer Payment component with our React JS library, please follow the example below:

    import React from "react";
    import { MafpayBankTransfer } from "@mafpay/weblib-react";
    
    const App = () => {
    
        const onCompletedHandler = (event) => {
            console.log(event.detail);
        }
    
        const onErrorHandler = (event) => {
            console.log(event.detail);
        }
    
        const onClosedHandler = (event) => {
            console.log(event.detail);
        }
    
        const onLoadingHandler = (event) => {
            console.log(event.detail);
        }
    
        return (
            <MafpayBankTransfer
                checkoutToken="Checkout Token"
                bankToken="Bank Token"
                enableLoading={true}
                onBankTransferCompleted={onCompletedHandler}
                onBankTransferError={onErrorHandler}
                onBankTransferClosed={onClosedHandler}
                onBankTransferLoading={onLoadingHandler}
            />
        );
    
    }
    
    export default App;
    

    Keywords

    none

    Install

    npm i @mafpay/weblib-react

    DownloadsWeekly Downloads

    81

    Version

    1.3.6

    License

    UNLICENSED

    Unpacked Size

    52.5 kB

    Total Files

    33

    Last publish

    Collaborators

    • mafpay