Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
react-native-paystack
Advanced tools
React Native Wrappers for Paystack Android & iOS Mobile SDKs
for Android & iOS by Arttitude 360
This React Native module provides a wrapper to add Paystack Payments to your React Native application using the Paystack Android Mobile SDK and the Paystack iOS Mobile SDK libraries.
You can pull in react-native-paystack via npm:
npm install react-native-paystack --save
OR
yarn add react-native-paystack
RN >=0.40
only;gem install cocoapods
to set it up the first time. (Hint: Go grab a cup of coffee!)cd ios && pod init
at the root directory of your project. This would create a Podfile
in your ios
directory.react-native link react-native-paystack
at the root directory of your project and ensure you edit your Podfile to look like the sample below (remove all the targets you are not building for, such as Tests and tvOS):# platform :ios, '9.0'
target '_YOUR_PROJECT_TARGET_' do
# Pods for _YOUR_PROJECT_TARGET_
pod 'React', :path => '../node_modules/react-native', :subspecs => [
'Core',
'CxxBridge',
'DevSupport',
'RCTText',
'RCTImage',
'RCTNetwork',
'RCTWebSocket',
'RCTSettings',
'RCTAnimation',
'RCTLinkingIOS',
# Add any other subspecs you want to use in your project
# Remove any subspecs you don't want to use in your project
]
pod "yoga", :path => "../node_modules/react-native/ReactCommon/yoga"
pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'
# This should already be auto-added for you, if not add the line below
pod 'react-native-paystack', :path => '../node_modules/react-native-paystack'
end
pod install
from your ios
directory..xcworkspace
file to open the project. Or just use the react-native run-ios
command as usual to run your app in the simulator.Since React Native 0.60 and higher, autolinking makes the installation process simpler.
cd ios
pod install
.xcworkspace
file to open the project. Or just use the react-native run-ios
command as usual to run your app in the simulator.react-native link react-native-paystack
already.Add Files to <...>
. Ensure Copy items if needed
and Create groups
are checkednode_modules
➜ react-native-paystack/ios
➜ add RNPaystack.xcodeproj
.Build Phases
and drag the static library, libRNPaystack.a
from the Products
folder inside RNPaystack.xcodeproj
to Link Binary With Libraries
. See the react-native docs for more details.react-native link react-native-paystack
at the root directory of your project.Since React Native 0.60 and higher, autolinking makes the installation process simpler. Nothing more to do here (Gradle has you all set to go) - just head over to usage!
react-native link react-native-paystack
already.android/settings.gradle
file:include ':react-native-paystack'
project(':react-native-paystack').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-paystack/android')
android/app/build.grade
file:dependencies {
...
compile project(':react-native-paystack')
}
...MainApplication.java
file:import com.arttitude360.reactnative.rnpaystack.RNPaystackPackage;
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
...
new RNPaystackPackage() //<-- Add line
);
}
~ android/build.gradle
to look similar to build.gradle~ android/gradle/wrapper/gradle-wrapper.properties
to look similar to gradle-wrapper.propertiesAapt2
for your project by adding android.enableAapt2=true
to your android/gradle.properties
file.node-modules/react-native/react.gradle
file with this version @ commit da6a5e0 to avoid further build issues when assembling a release version of your app.Somewhere high up in your project and way before calling any other method exposed by this library, your index
file or equivalent is a good spot, ensure you initialize the library with your public key
as follos:
import RNPaystack from 'react-native-paystack';
RNPaystack.init({ publicKey: 'YOUR_PUBLIC_KEY_HERE' });
It's a cinch to charge a card token using the react-native-paystack module. This is the recommended or the most-preferred workflow favored by the folks at Paystack. Initiate a new transaction on your server side using the appropriate Paystack endpoint - obtain an access_code
and complete the charge on your mobile application. Pls note, the SDK assumes you are responsible for building the card form/UI.
RNPaystack.chargeCardWithAccessCode(cardParams);
To be more elaborate, cardParams
is a Javascript Object
representing the card to be charged and RNPaystack.chargeCardWithAccessCode()
returns a Javascript Promise
like:
import RNPaystack from 'react-native-paystack';
chargeCard() {
RNPaystack.chargeCardWithAccessCode({
cardNumber: '4123450131001381',
expiryMonth: '10',
expiryYear: '17',
cvc: '883',
accessCode: '2p3j42th639duy4'
})
.then(response => {
console.log(response); // do stuff with the token
})
.catch(error => {
console.log(error); // error is a javascript Error object
console.log(error.message);
console.log(error.code);
})
}
Argument | Type | Description |
---|---|---|
cardNumber | string | the card number as a String without any seperator e.g 5555555555554444 |
expiryMonth | string | the card expiry month as a double-digit ranging from 1-12 e.g 10 (October) |
expiryYear | string | the card expiry year as a double-digit e.g 15 |
cvc | string | the card 3/4 digit security code as a String e.g 123 |
accessCode | string | the access_code obtained for the charge |
An object of the form is returned from a successful token request
{
reference: "trx_1k2o600w"
}
Using the react-native-paystack module, you can start and complete a transaction with the mobile Paystack Android and iOS SDKs. With this option, you pass both your charge and card properties to the SDK - with this worklow, you initiate and complete a transaction on your mobile app. Note that as with charging with an access_code, the SDK assumes you are responsible for building the card form/UI.
RNPaystack.chargeCard(chargeParams);
To be more elaborate, chargeParams
is a Javascript Object
representing the parameters of the charge to be initiated and RNPaystack.chargeCard()
returns a Javascript Promise
like:
import RNPaystack from 'react-native-paystack';
chargeCard() {
RNPaystack.chargeCard({
cardNumber: '4123450131001381',
expiryMonth: '10',
expiryYear: '17',
cvc: '883',
email: 'chargeIOS@master.dev',
amountInKobo: 150000,
subAccount: 'ACCT_pz61jjjsslnx1d9',
})
.then(response => {
console.log(response); // card charged successfully, get reference here
})
.catch(error => {
console.log(error); // error is a javascript Error object
console.log(error.message);
console.log(error.code);
})
}
Argument | Type | Description |
---|---|---|
cardNumber | string | the card number as a String without any seperator e.g 5555555555554444 |
expiryMonth | string | the card expiry month as a double-digit ranging from 1-12 e.g 10 (October) |
expiryYear | string | the card expiry year as a double-digit e.g 15 |
cvc | string | the card 3/4 digit security code as e.g 123 |
string | email of the user to be charged | |
amountInKobo | integer | the transaction amount in kobo |
currency (optional) | string | sets the currency for the transaction e.g. USD |
plan (optional) | string | sets the plan ID if the transaction is to create a subscription e.g. PLN_n0p196bg73y4jcx |
subAccount (optional) | string | sets the subaccount ID for split-payment transactions e.g. ACCT_pz61jjjsslnx1d9 |
transactionCharge (optional) | integer | the amount to be charged on a split-payment, use only when subAccount is set |
bearer (optional) | string | sets which party bears paystack fees on a split-payment e.g. 'subaccount', use only when subAccount is set |
reference (optional) | string | sets the transaction reference which must be unique per transaction |
An object of the form is returned from a successful charge
{
reference: "trx_1k2o600w"
}
Verify a charge by calling Paystack's REST API with the reference
obtained above. An authorization_code
will be returned once the card has been charged successfully. Learn more about that here.
Parameter:
Example
$ curl https://api.paystack.co/transaction/verify/trx_1k2o600w \
-H "Authorization: Bearer SECRET_KEY" \
-H "Content-Type: application/json" \
-X GET
Perhaps needless to say, this module leverages the Paystack Android SDK and the Paystack IOS SDK for all the heavy liftings.
chargeCard
on both platforms.subscriptions
and split-payments
.getToken
on both platforms.chargeCardWithAccessCode
on both platforms.This should be The MIT License (MIT). I would have to get back to you on that!
FAQs
React Native Wrappers for Paystack Android & iOS Mobile SDKs
We found that react-native-paystack demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.