rn-openpay
TypeScript icon, indicating that this package has built-in type declarations

0.1.5 • Public • Published

Openpay React Native CI status

openpay-react-native Generates the device_session_id and tokenize the credit cards with Openpay.

Openpay React Native

Features

Requirements

  • npm >= 6

Installation

Via npm

$ npm install @urielcuriel/react-native-open-pay --save

Via yarn

$ yarn add @urielcuriel/react-native-open-pay

Usage

import Openpay, {createDeviceSessionId} from ' @urielcuriel/react-native-open-pay  ';

<Openpay 
    isProductionMode={false} 
    merchantId="YOUR_MERCHANT_ID" 
    publicKey="YOUR_PUBLIC_KEY" 
    address={address} 
    successToken={this.successToken} 
    failToken={this.failToken} 
    loading={this.state.loading}
    buttonText="Some text"
/>

// Note: address prop is optional.

And then on your successToken or failToken handler:

state = {
    loading: false
}

successToken = (response) => {        
    const deviceSessionId = createDeviceSessionId();
    console.log('createDeviceSessionId', deviceSessionId);
    console.log('successToken', response);
    this.setState(() => ({loading: false}))
}

failToken = (response) => {
    console.log('failToken', response);
}

Props

Property Type Description Required
isProductionMode Boolean Defines the Openpay environment Yes
merchantId String Openpay Merchant ID Yes
publicKey String Openpay Public Key Yes
successToken Function It will receive the card token and here you will need to add your logic Yes
failToken Function It will receive the error if something wrong happen Yes
loading Boolean Adds a spinner to the button when the user clicks on it Yes
address Object You can add the address of your customer No
buttonText String Button's text No

Methods

createDeviceSessionId

This method creates the device session id.

const deviceSessionId = createDeviceSessionId();

Example

import React, {Component} from 'react';
import Openpay, {createDeviceSessionId} from 'openpay-react-native';

export default class OpenpayScreen extends Component {
    state = {
        loading: false
    }

    successToken = (response) => {        
        const deviceSessionId = createDeviceSessionId();
        const token = response.id;
        this.setState(() => ({loading: false}));

        // Make the call to your server with your charge request
    }

    failToken = (response) => {
        console.log('failToken', response);
    }

    render() {
        const address = {
            "city":"Querétaro",
            "country_code":"MX",
            "postal_code":"76900",
            "line1":"Av 5 de Febrero",
            "line2":"Roble 207",
            "line3":"Col Carrillo",
            "state":"Queretaro"
        };

        return (
            <Openpay 
                isProductionMode={false} 
                merchantId="YOUR_MERCHANT_ID" 
                publicKey="YOUR_PUBLIC_KEY" 
                address={address} 
                successToken={this.successToken} 
                failToken={this.failToken} 
                loading={this.state.loading}
            />
        );
    }
}

Future Improvements

  • Customize credit card image
  • Customize button style
  • Add unit tests

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT

Package Sidebar

Install

npm i rn-openpay

Weekly Downloads

0

Version

0.1.5

License

MIT

Unpacked Size

66.1 kB

Total Files

9

Last publish

Collaborators

  • urielcuriel