npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

paystack-react-native

v0.2.1

Published

test

Downloads

102

Readme

paystack-react-native

A React Native wrapper for the Paystack iOS and Android SDK's

Installation

npm install paystack-react-native
yarn add paystack-react-native

IOS

  pod install

Usage

The paystack-react-native module exports two methods: initSdk and chargeCard.

initSdk(publicKey: string): void

This method initializes the Paystack SDK with your public key. You should call this method once in your app, preferably at the entry point.

Example

import Paystack from 'paystack-react-native';

const publicKey = 'YOUR_PAYSTACK_PUBLIC_KEY';

Paystack.initSdk(publicKey);

chargeCard(paymentParams: IPaymentParams): void

This method charges a card using the provided payment parameters.

Parameters

paymentParams (required): an object containing the payment parameters. The payment parameters should have the following type:

interface IPaymentParams {
  cardNumber: string;
  expiryMonth: string;
  expiryYear: string;
  cvc: string;
  email: string;
  amount: number;
  currency: string;
  subAccount: string;
  transactionCharge: number; // How much commission are you charging
  bearer: string; // who is paying for fees 'account' || 'subaccount'
  reference: string;
}

Example

import Paystack from 'paystack-react-native';

const paymentParams = {
  cardNumber: '4084084084084081',
  expiryMonth: '01',
  expiryYear: '23',
  cvc: '408',
  email: '[email protected]',
  amount: 100000,
  currency: 'ZAR',
  subAccount: 'test_subaccount',
  transactionCharge: 0,
  bearer: 'account',
  reference: 'test_reference',
};

Paystack.chargeCard(paymentParams);

Full Example

import React, { useState } from 'react';
import { View, Button, TextInput } from 'react-native';
import Paystack from 'paystack-react-native';

const PaymentScreen = () => {
  const publicKey = 'YOUR_PAYSTACK_PUBLIC_KEY';
  const [cardNumber, setCardNumber] = useState('');
  const [expiryMonth, setExpiryMonth] = useState('');
  const [expiryYear, setExpiryYear] = useState('');
  const [cvc, setCvc] = useState('');
  const [email, setEmail] = useState('');
  const [amount, setAmount] = useState('');
  const [currency, setCurrency] = useState('ZAR');
  const [subAccount, setSubAccount] = useState('');
  const [transactionCharge, setTransactionCharge] = useState(0);
  const [bearer, setBearer] = useState('');
  const [reference, setReference] = useState('');

  const handleInitSdk = () => {
    Paystack.initSdk(publicKey);
  };

  const handleChargeCard = () => {
    const paymentParams = {
      cardNumber: Number(cardNumber),
      expiryMonth,
      expiryYear,
      cvc,
      email,
      amount: Number(amount),
      currency,
      subAccount,
      transactionCharge,
      bearer,
      reference,
    };

    Paystack.chargeCard(paymentParams);
  };

  return (
    <View>
      <TextInput
        placeholder="Card Number"
        value={cardNumber}
        onChangeText={setCardNumber}
      />
      <TextInput
        placeholder="Expiry Month"
        value={expiryMonth}
        onChangeText={setExpiryMonth}
      />
      <TextInput
        placeholder="Expiry Year"
        value={expiryYear}
        onChangeText={setExpiryYear}
      />
      <TextInput placeholder="CVC" value={cvc} onChangeText={setCvc} />
      <TextInput placeholder="Email" value={email} onChangeText={setEmail} />
      <TextInput placeholder="Amount" value={amount} onChangeText={setAmount} />
      <TextInput
        placeholder="Currency"
        value={currency}
        onChangeText={setCurrency}
      />
      <TextInput
        placeholder="Sub Account"
        value={subAccount}
        onChangeText={setSubAccount}
      />
      <TextInput
        placeholder="Transaction Charge"
        value={transactionCharge.toString()}
        onChangeText={setTransactionCharge}
      />
      <TextInput placeholder="Bearer" value={bearer} onChangeText={setBearer} />
      <TextInput
        placeholder="Reference"
        value={reference}
        onChangeText={setReference}
      />
      <Button title="Initialize SDK" onPress={handleInitSdk} />
      <Button title="Charge Card" onPress={handleChargeCard} />
    </View>
  );
};

export default PaymentScreen;

Contributing

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

License

Paystack-React-Native is licensed under the MIT License. See the LICENSE