Skip to content

Commit

Permalink
Add support for cross-platform chargeCard, split-payments and subscri…
Browse files Browse the repository at this point in the history
…ptions. Bump to 2.1.2
  • Loading branch information
tolu360 committed Dec 10, 2016
1 parent 462473b commit ae3ed0a
Show file tree
Hide file tree
Showing 19 changed files with 535 additions and 258 deletions.
65 changes: 52 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ npm install react-native-paystack --save
react-native link react-native-paystack
```
- (iOS only): The next steps are necessary for iOS at this time as publishing to NPM seems to break symlinks contained in the Paystack iOS framework shipped with this package, thus causing XCode build errors.
- Download a fresh copy of the `Paystack iOS framework` from [Dropbox](https://www.dropbox.com/s/ykt5h0xjjkfwmk6/Paystack.framework.zip?dl=0) or from their [releases page on Github](https://github.com/PaystackHQ/paystack-ios/releases/).
- Download a fresh copy of the `Paystack iOS framework` from [Dropbox](https://www.dropbox.com/s/rxds20w3ud4wqs2/PaystackiOS%20%283%29.zip?dl=0) or from their [releases page on Github](https://github.com/PaystackHQ/paystack-ios/releases/).
- Extract `Paystack.framework` from the downloaded zip.
- In XCode's "Project navigator", right click on project name folder ➜ `Add Files to <Your-Project-Name>`. Ensure `Copy items if needed` and `Create groups` are checked and select your copy of `Paystack.framework`.
- Your files tree in XCode should look similar to the screenshot below:
Expand Down Expand Up @@ -104,20 +104,25 @@ protected List<ReactPackage> getPackages() {
<meta-data android:name="co.paystack.android.PublishableKey" android:value="INSERT-PUBLIC-KEY-HERE"/>
```

### Getting a Token (iOS & Android)
### Getting a Token (iOS & Android - To be deprecated soon)
It's a cinch to obtain a single-use card token using the react-native-paystack module. Pls note, the SDK assumes you are responsible for building the card form/UI.

```javascript
RNPaystack.getToken(cardNumber, expiryMonth, expiryYear, cvc);
RNPaystack.getToken(cardParams);
```
To be more elaborate, `RNPaystack.getToken()` returns a Javascript `Promise` like:
To be more elaborate, `cardParams` is a Javascript `Object` representing the card to be tokenized and `RNPaystack.getToken()` returns a Javascript `Promise` like:

```js
import RNPaystack from 'react-native-paystack';

getToken() {

RNPaystack.getToken('4123450131001381', '01', '17', '883')
RNPaystack.getToken({
cardNumber: '4123450131001381',
expiryMonth: '10',
expiryYear: '17',
cvc: '883'
})
.then(response => {
console.log(response); // do stuff with the token
})
Expand Down Expand Up @@ -173,20 +178,28 @@ Send the token to your server and create a charge by calling the Paystack REST A

```

### Charging a Card (Android Only)
Using the react-native-paystack module, you can complete the transaction with the Paystack Android SDK. Note that as with getting a card token, the SDK assumes you are responsible for building the card form/UI.
### Charging a Card (iOS & Android)
Using the react-native-paystack module, you can complete the transaction with the Paystack Android and iOS SDKs. Note that as with getting a card token, the SDK assumes you are responsible for building the card form/UI.

```javascript
RNPaystack.chargeCard(cardNumber, expiryMonth, expiryYear, cvc, email, amountInKobo);
RNPaystack.chargeCard(chargeParams);
```
To be more elaborate, `RNPaystack.chargeCard()` returns a Javascript `Promise` like:
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:

```js
import RNPaystack from 'react-native-paystack';

chargeCard() {

RNPaystack.chargeCard('4123450131001381', '01', '17', '883', 'dev-master@rnpaystack.dev', '10000')
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
})
Expand All @@ -199,7 +212,7 @@ chargeCard() {
}
```

#### Request Signature
#### Request Signature (chargeParams)

| Argument | Type | Description |
| ------------- |:-------------:| :-----|
Expand All @@ -209,6 +222,12 @@ chargeCard() {
| cvc | string | the card 3/4 digit security code as e.g 123 |
| email | 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 |

#### Response Object

Expand All @@ -220,18 +239,38 @@ An object of the form is returned from a successful charge
}
```

### Verifying a Charge
Verify a charge by calling Paystack's [REST API](https://api.paystack.co/transaction/verify) with the `reference` obtained above. An `authorization_code` will be returned once the card has been charged successfully. Learn more about that [here](https://developers.paystack.co/docs/verify-transaction).

**Parameter:**

- reference - the transaction reference (required)

**Example**

```bash
$ curl https://api.paystack.co/transaction/verify/trx_1k2o600w \
-H "Authorization: Bearer SECRET_KEY" \
-H "Content-Type: application/json" \
-X GET
```

## 4. CREDITS

Perhaps needless to say, this module leverages the [Paystack Android SDK](https://github.com/PaystackHQ/paystack-android) and the [Paystack IOS SDK](https://github.com/PaystackHQ/paystack-ios) for all the heavy liftings.

## 5. CHANGELOG

+ 1.0.12: initial version supporting Android.
+ 1.1.1: android library upgrade and initial iOS support.
+ 1.0.12: Initial version supporting Android.
+ 1.1.1: Android library upgrade and initial iOS support.
+ 2.0.0: A couple of breaking changes have been introduced, see [Old Docs](./Old Docs.md) for previous documentations.
+ 2.0.0: Upgraded to v2.0 of the Paystack Android SDK.
+ 2.0.0: Unified APIs across both platforms (iOS & Android).
+ 2.0.0: Methods now return Javascript Promises on both platforms.
+ 2.1.1: Upgraded to v2.1+ of both the Paystack iOS and Android SDKs.
+ 2.1.1: Added support for `chargeCard` on both platforms.
+ 2.1.1: Added support for `subscriptions` and `split-payments`.
+ 2.1.1: For v2-specific documentations, see [v2 Docs](./v2-Docs.md)

## 6. License

Expand Down
13 changes: 8 additions & 5 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
compileSdkVersion 25
buildToolsVersion "25.0.1"

defaultConfig {
minSdkVersion 16
targetSdkVersion 23
targetSdkVersion 25
versionCode 1
versionName "1.0"
}
Expand All @@ -20,14 +20,17 @@ android {
}
}


repositories {
maven {
url 'https://dl.bintray.com/paystack/maven/'
}

jcenter()
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:25.0.1'
compile 'com.facebook.react:react-native:+'
compile 'co.paystack.android:paystack:2.0.1'
compile 'co.paystack.android:paystack:2.1.2'
}
Loading

0 comments on commit ae3ed0a

Please sign in to comment.