0.1.1 • Published 2 years ago

rn-payments v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

rn-payments

React native payments

Installation

npm install rn-payments

Usage

import {
  AllowedCardNetworkType,
  AllowedCardAuthMethodsType,
  RequestDataType,
  setEnvironment,
  isReadyToPay,
  requestPayment,
} from 'rn-payments';

Put this in your App.tsx to set environment for fgoogle pay

if (Platform.OS === 'android') {
  setEnvironment(0); // 0 - Test; 1 - Production
}

Set google pay payment data

const allowedCardNetworks: AllowedCardNetworkType[] = ['VISA', 'MASTERCARD'];
const allowedCardAuthMethods: AllowedCardAuthMethodsType[] = [
  'PAN_ONLY',
  'CRYPTOGRAM_3DS',
];

const gatewayRequestData: RequestDataType = {
  cardPaymentMethod: {
    tokenizationSpecification: {
      type: 'PAYMENT_GATEWAY',
      gateway: 'example',
      gatewayMerchantId: 'exampleGatewayMerchantId',
    },
    allowedCardNetworks,
    allowedCardAuthMethods,
  },
  transaction: {
    totalPrice: '123',
    totalPriceStatus: 'FINAL',
    currencyCode: 'RUB',
  },
  merchantName: 'Example Merchant',
};

const payWithGooglePay = (requestData: RequestDataType) => {
  // Check if Google Pay is available
  isReadyToPay(allowedCardNetworks, allowedCardAuthMethods).then((ready) => {
    if (ready) {
      // Request payment token
      requestPayment(requestData).then(handleSuccess).catch(handleError);
    } else {
      Alert.alert('GPay not ready!');
    }
  });
};

const handleSuccess = (token: string) => {
  // Send a token to your payment gateway
  Alert.alert('Success', `token: ${token}`);
};

const handleError = (error: any) =>
  Alert.alert('Error', `${error.code}\n${error.message}`);

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT


Made with create-react-native-library

0.1.1

2 years ago

0.1.0

2 years ago

0.7.2

6 years ago