Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V3 api #3

Merged
merged 131 commits into from
Aug 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
131 commits
Select commit Hold shift + click to select a range
c13f949
feat(configs.ts): point to v3 standard init endpoint
thecodecafe Jul 15, 2020
3e3ca84
feat(configs.ts): update payment options with v3 payment options
thecodecafe Jul 15, 2020
0ed9157
feat(flutterwaveinit): model options after v3 api standard initializa…
thecodecafe Jul 15, 2020
9b9eafd
feat(flutterwaveinit): add public_key as Authorization header and rem…
thecodecafe Jul 15, 2020
30e4f7e
feat(flutterwaveiniterror): add Flutterwave init error class
thecodecafe Jul 15, 2020
1a50243
test(flutterwaveiniterror): write tests for flutterwave init error class
thecodecafe Jul 15, 2020
b673c0b
feat(responseparser): add init request response parser
thecodecafe Jul 15, 2020
ecb8485
fix(flutterwaveinit): remove public key prop and replace with authori…
thecodecafe Jul 15, 2020
33fe5bf
fix(responseparser): default to "STANDARD_INIT_ERROR" if code is not …
thecodecafe Jul 15, 2020
85e22bf
test(responseparser): write tests for standard init response parser
thecodecafe Jul 15, 2020
19d4085
fix(flutterwavinit): restructure flutterwave init result
thecodecafe Jul 15, 2020
175aa95
feat(flutterwaveinit): make second argument abort controller
thecodecafe Jul 15, 2020
319f249
feat(flutterwaveinit): resolve only to string and reject if there is …
thecodecafe Jul 15, 2020
185ea28
feat(responseparser): promisify; resolve to link else reject to Flutt…
thecodecafe Jul 15, 2020
a851b86
test(responseparser): rewrite test to use as a promise
thecodecafe Jul 15, 2020
c8eec39
fix(flutterwaveinit): use promisified response parser
thecodecafe Jul 15, 2020
d8dfedb
test(flutterwaveinit): refactor test suite and handle resolve and rej…
thecodecafe Jul 15, 2020
c33843c
fix(flutterwaveinit): specify required options on interface
thecodecafe Jul 16, 2020
2b09542
feat(config): specify redirect url
thecodecafe Jul 16, 2020
d3e12ca
feat(flutterwavebutton): implement v3 api flutterwave init
thecodecafe Jul 16, 2020
7dcfa10
test(flutterwavebutton): refactor test with v3 implementation
thecodecafe Jul 16, 2020
bd16231
test(flutterwavebutton): updates webview error snapshot
thecodecafe Jul 16, 2020
72a2b78
chore(dist): build v3 library
thecodecafe Jul 16, 2020
18559be
fix(flutterwavebutton): reset link and tx_ref on standard init failure
thecodecafe Jul 16, 2020
c1fef5f
test(flutterwavebutton): add snapshot for webview render error view w…
thecodecafe Jul 16, 2020
8f505d3
Merge branch 'master' into v3-api
thecodecafe Jul 20, 2020
e4a1d56
fix(flutterwavebutton): define tx_ref in redirect params as always av…
thecodecafe Jul 20, 2020
be9c850
docs(readme): reference version 2 api library version
thecodecafe Jul 20, 2020
db9536c
docs(readme): redefine init meta interface
thecodecafe Jul 20, 2020
7355b6c
docs(readme): update on complete data
thecodecafe Jul 20, 2020
eae57ef
docs(readme): add InitCustomer interface to interfaces
thecodecafe Jul 20, 2020
4d76709
docs(readme): add InitCusomizations interface to interfaces
thecodecafe Jul 20, 2020
0721924
docs(readme): update FlutterwaveInitOptions interface
thecodecafe Jul 20, 2020
c00c5f7
fix(flutterwaveinit): add subaccount interface
thecodecafe Jul 20, 2020
5fef115
docs(readme): update FlutterwaveInitOptions table
thecodecafe Jul 20, 2020
5be41b1
docs(readme): update FlutterwaveButton table
thecodecafe Jul 20, 2020
a7f3f47
docs(readme): update FlutterwaveInit example
thecodecafe Jul 20, 2020
e4214c0
docs(readme): update FlutterwaveButton example
thecodecafe Jul 20, 2020
b2f51d6
docs(readme): rename InitCustomer interface
thecodecafe Jul 20, 2020
182e832
docs(readme): rename init customizations
thecodecafe Jul 20, 2020
a182075
docs(readme): fix xub account interface name and add sub account to TOC
thecodecafe Jul 20, 2020
b20bce0
fix(flutterwaveinit): fix customer and customizations interface name
thecodecafe Jul 20, 2020
0f6d46a
feat: build with identified fixes
thecodecafe Jul 20, 2020
b4dd6cb
docs(readme): fix incorrect link for v2 api reference in TOC
thecodecafe Jul 20, 2020
1e0cdb9
docs(abortingpaymentinitialization): update example to use v3 api flu…
thecodecafe Jul 20, 2020
9e6b0fc
docs(abortingpaymentinitialization): correct example code
thecodecafe Jul 20, 2020
1f4c0a9
docs(readme): fix broken links
thecodecafe Jul 20, 2020
4ca0c80
docs(readme): typo correction
thecodecafe Jul 21, 2020
00ce4a1
fix(flutterwavebutton): properly define options subaccount property type
thecodecafe Jul 21, 2020
5ea95ae
refactor: reorganize v2 specific code
thecodecafe Jul 21, 2020
854f85c
Merge branch 'v2-folders' into v3-api
thecodecafe Jul 21, 2020
fe73ed2
feat(assets): put images in assets folder
thecodecafe Jul 21, 2020
d8bbb74
feat(configs): add v2 api configs
thecodecafe Jul 21, 2020
e4c327f
test(customproptypesrules): remove config dependency for payment opti…
thecodecafe Jul 21, 2020
886872c
fix(defaultbutton): fix style and children prop definition and compil…
thecodecafe Jul 21, 2020
7084141
test(defaultbutton): update snapshot
thecodecafe Jul 21, 2020
18cf3e8
refactor(v3): move v3 specific modules to v3 folder and user v3 as de…
thecodecafe Jul 21, 2020
ae58d8c
test(v3): move v3 tests and snapshot to v3 tests subfolder
thecodecafe Jul 21, 2020
2d1f62a
feat(v2/flutterwavebutton): allow users specify button content
thecodecafe Jul 21, 2020
dbf7aa4
refactor(v2/flutterwavebutton): reference base types from base flutte…
thecodecafe Jul 21, 2020
beda6f1
fix(v2/flutterwavebutton): fix require path for button content and lo…
thecodecafe Jul 21, 2020
05187bd
refactor(v2/flutterwavbutton): use base options proptype and add cust…
thecodecafe Jul 21, 2020
9248b3f
fix(v2/flutterwavebutton): add missing dependencies
thecodecafe Jul 21, 2020
6bd1f53
refactor(v2/flutterwavebutton): user FlutterwaveInitError as object f…
thecodecafe Jul 21, 2020
a21a332
refactor(v2/flutterwavebutton): correctly name abortController property
thecodecafe Jul 21, 2020
bab4845
refactor(v2/flutterwavebutton): set v2 redirect params argument as ty…
thecodecafe Jul 21, 2020
6685df2
feat(v2/flutterwaveinit): implement new specs and use base flutterwav…
thecodecafe Jul 21, 2020
42ca045
feat(v2/flutterwavebutton): implement new v2 flutterwave init api
thecodecafe Jul 21, 2020
b285ec9
feat(v2/index): add default button to exports
thecodecafe Jul 21, 2020
cbd731e
refactor(v2): code cleaning
thecodecafe Jul 21, 2020
495ac21
feat(index): add v2 to base index modules export
thecodecafe Jul 21, 2020
7ed703f
refactor: remove redundant test file from v2 tests
thecodecafe Jul 21, 2020
fbd51f9
test(v2): use v2 configs
thecodecafe Jul 21, 2020
ca4d9d2
test(v2/flutterwavebutton): update snapshot
thecodecafe Jul 21, 2020
c4cdc2d
fix(v2/flutterwavebutton): use correct regex pattern for redirect url…
thecodecafe Jul 21, 2020
d6a29c3
fix(v2/flutterwaveinit): use proper error codes for malformed or miss…
thecodecafe Jul 21, 2020
52f8646
test(v2/flutterwaveinit): write tests for new v2 flutterwave init imp…
thecodecafe Jul 21, 2020
7f1319c
test(v2/flutterwavebutton): rewriter v2 flutterwave button tests
thecodecafe Jul 21, 2020
51efe29
test(v2/flutterwavebutton): update v2 flutterwave button snapshot
thecodecafe Jul 21, 2020
02595b7
fix(package.json): update assets locations in copy-files script
thecodecafe Jul 21, 2020
3d5d3cc
fix(v2/flutterwavebutton): fix incorrect spelling of cancelled prop o…
thecodecafe Jul 21, 2020
d026c3e
feat(flutterwavebutton): add GBP to base options currency option
thecodecafe Jul 21, 2020
4c20a28
feat(dist): create build with v2 and v3 options
thecodecafe Jul 21, 2020
496aae3
fix(flutterwavebutton): define prop(txref) in v2 redirect params as a…
thecodecafe Jul 21, 2020
d7dd4d5
docs(readme): properly reference version 2 documentaion
thecodecafe Jul 21, 2020
a15826c
docs(readme.v2): reference v3 documentation
thecodecafe Jul 21, 2020
ccd74bf
docs(readme.v2): replace onCompleteData with RedirectParamsV2
thecodecafe Jul 21, 2020
295a47d
docs(readme.v2): update examples with V2 modules
thecodecafe Jul 21, 2020
f7a1c9a
docs(readme.v2): remove redundant code and update footnote
thecodecafe Jul 21, 2020
29fb73a
docs(contributing.md): add footnote
thecodecafe Jul 21, 2020
9ea86ff
docs(v2/abortingpaymentinitialization): use new v2 flutterwave init a…
thecodecafe Jul 21, 2020
76e73a4
docs: add space between wave emoji and "Hi"
thecodecafe Jul 21, 2020
9fdc0c4
docs(readme): remove FlutterwaveSubAccount type repetetion
thecodecafe Jul 21, 2020
1fc9f75
docs(readme.v2): add API version to readme welcome message
thecodecafe Jul 21, 2020
f618b23
docs(readme): add API version to header welcome message
thecodecafe Jul 21, 2020
1de66bc
docs: add api version badge
thecodecafe Jul 21, 2020
de2d3f9
refactor(timetravel): move animation timetravel helper into a seperat…
thecodecafe Aug 3, 2020
c44f12c
feat(flwbutton): add component for displaying a pay with flutterwave …
thecodecafe Aug 3, 2020
97b29b9
test(flwbutton): tests and snapshot of flwbutton component
thecodecafe Aug 3, 2020
b88ee69
feat(flwcheckout): add flutterwave checkout modal component
thecodecafe Aug 3, 2020
26148b6
test(flwcheckout): test and generate snapshot of flwcheckout component
thecodecafe Aug 3, 2020
a6185c5
feat: add flwbutton and flwcheckout library entrypoint exports
thecodecafe Aug 3, 2020
a8a8fa5
feat(flutterwaveinit): rewrite base flutterwave init as v3
thecodecafe Aug 3, 2020
65f1ae7
fix(responseparser): fix import to point to correct flutterwave init
thecodecafe Aug 3, 2020
b3ffae7
test(flutterwaveinit): move flutterwaveinit test to base of tests folder
thecodecafe Aug 3, 2020
c2d29e3
fix(flutterwaveinitv2): move to base of library folder, fix import er…
thecodecafe Aug 3, 2020
1e402d5
fix: correctly import FlutterwaveInitv2
thecodecafe Aug 3, 2020
c84dc58
fix(flutterwaveinitv2): move to base of tests folder
thecodecafe Aug 3, 2020
55dccca
feat(paywithflutterwavebase): add component
thecodecafe Aug 3, 2020
c04f0cb
test(paywithflutterwavebutton): test and generate snaptshots for pay …
thecodecafe Aug 3, 2020
c86789c
feat(paywithflutterwave): add v3 pay with flutterwave
thecodecafe Aug 3, 2020
284daa4
test(paywithflutterwave): pay with flutterwave v3 tests and snapshot
thecodecafe Aug 3, 2020
e1a0825
feat(index.ts): add PayWithFlutterwave component and make the default…
thecodecafe Aug 3, 2020
a228e9a
feat(paywithflutterwavev2): create component
thecodecafe Aug 3, 2020
f988d5c
feat(index.ts): add PayWithFlutterwaveV2 to exports
thecodecafe Aug 3, 2020
b73f5bd
test(paywithflutterwavev2): write tests and generate snapshots
thecodecafe Aug 3, 2020
4cf13f9
refactor: remove old immplementations code
thecodecafe Aug 3, 2020
d346ad6
refactor(customproptypesrules): code cleaning
thecodecafe Aug 3, 2020
bddbb90
refactor(dist): remove old implementation builds
thecodecafe Aug 3, 2020
e47e33e
feat(dist): generate builds for new implementation
thecodecafe Aug 3, 2020
63ee87d
feat(dist): generate build for updates
thecodecafe Aug 3, 2020
cc58284
docs(readme): add exmples and types of new implementation
thecodecafe Aug 3, 2020
685648a
docs(readme.v2): add exmaples and types of new v2 implementation
thecodecafe Aug 3, 2020
a1946f9
docs(readme): correct meta description on init options table
thecodecafe Aug 3, 2020
7db830a
feat(flwbutton): rename to FlutterwaveButton
thecodecafe Aug 5, 2020
1be3398
feat(flwcheckout): change name to FlutterwaveCheckout
thecodecafe Aug 5, 2020
56971c1
refactor(readme.v2): remove old v3 readme
thecodecafe Aug 5, 2020
067b7ea
refactor(readme.v2.old): remove old v2 readme
thecodecafe Aug 5, 2020
5004435
fix(package.json): change library name
thecodecafe Aug 18, 2020
dc7add0
fix: user new library name in documentation
thecodecafe Aug 18, 2020
a87f5a3
refactor(setexample): remove lib name from comment
thecodecafe Aug 18, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ If you want to open a PR that fixes a bug or adds a feature, then we can't thank

## Submitting pull requests

### Modifying react-native-flutterwave
### Modifying flutterwave-react-native
1. Fork this repository
2. Clone your fork
3. Make a branch for your feature or bug fix (i.e. `git checkout -b what-im-adding`)
Expand All @@ -20,12 +20,12 @@ If you want to open a PR that fixes a bug or adds a feature, then we can't thank
Depending on the changes you make you might want to test to see if the feature/fix works correctly.
Use the following steps to test your newly added feature/fix.
1. Set up your react-native example project or use one you already have.
2. Create a `.env` file in the root of the library (react-native-flutterwave).
2. Create a `.env` file in the root of the library (flutterwave-react-native).
3. Add **RN_FLW_EXAMPLE_PROJECT** to the `.env` file it's value should be an absolute path to the install destination in your example project.
**E.g.** `RN_FLW_EXAMPLE_PROJECT="/Users/your-name/projects/example-project/src"`.
4. Run the following command `npm run set-example`.

Following these steps will result in you building and copy the built version of the library in the following directory `/Users/your-name/projects/example-project/src/react-native-flutterwave`, you can then go ahead an import the library from within your example project from the location the library has been copied to.
Following these steps will result in you building and copy the built version of the library in the following directory `/Users/your-name/projects/example-project/src/flutterwave-react-native`, you can then go ahead an import the library from within your example project from the location the library has been copied to.

### Writting Tests
We currently don't have strict rules for writting tests but when writting one be sure to make your tests and their captions clear and coincise, test only what you added, and then follow up with the dependencies if need be.
Expand All @@ -43,3 +43,5 @@ To start a commit simply run the following cli command from within the project `
4. Have your branch get merged in! :white_check_mark:

If you experience a problem at any point, please don't hesitate to file an issue to get some assistance!

With love from Flutterwave. :yellow_heart:
272 changes: 135 additions & 137 deletions README.md

Large diffs are not rendered by default.

317 changes: 317 additions & 0 deletions README.v2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,317 @@
# React Native Flutterwave
Easily implement Flutterwave for payments in your React Native appliction. This library supports both Android and iOS, and use the Flutterwave's V2 API.

[![V2 API](https://img.shields.io/badge/API-V2-brightgreen)](https://developer.flutterwave.com/v2.0/docs/getting-started) [![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)

<p align="center">
<img src=".github/images/github-preview-ios.gif" alt="ios-preview"/>
<img src=".github/images/github-preview-android.gif" alt="android-preview"/>
</p>

## Table Of Content
- Getting Started
- [V3 API](#warning-if-using-version-3-api-warning)
- [Installation](#installation)
- [Dependencies](#dependencies)
- [Activity Indicator (Android)](#activity-indicator-only-needed-for-android)
- [Important Information](#fire-important-information-fire)
- Usage
- [PayWithFlutterwaveV2 ](#paywithflutterwavev2)
- [PayWithFlutterwaveV2 (with custom render)](#paywithflutterwavev2-with-custom-render)
- [FlutterwaveButton (Flutterwave styled button)](#flutterwavebutton-flutterwave-styled-button)
- [FlutterwaveInitV2](#flutterwaveinitv2)
- [Aborting Payment Initialization](#aborting-payment-initialization)
- Props
- [FlutterwaveInitV2Options](#flutterwaveinitv2options)
- [PayWithFlutterwaveV2Props](#paywithflutterwavev2props)
- [FlutterwaveButton Props](#flutterwavebutton-props)
- Types
- [PayWithFlutterwaveV2Props](#paywithflutterwavev2props-interface)
- [FlutterwaveButtonProps](#flutterwavebuttonprops-interface)
- [FlutterwaveInitV2Options](#flutterwaveinitv2options-interface)
- [FlutterwaveInitError](#flutterwaveiniterror)
- [FlutterwavePaymentMetaV2](#flutterwavepaymentmetav2)
- [RedirectParamsV2](#redirectparamsv2)
- [CustomButtonProps](#custombuttonprops)
- [Contributing](./CONTRIBUTING.md)

## What's Inside?
- Pay with Flutterwave button and checkout dialog.
- Standard payment initialization function.
- Flutterwave designed button.

## :warning: If Using Version 3 API :warning:
This version of the library's docs focuses on use cases with the Version 2 of Flutterwaves API, if you are using the Version 3 API please use [this documentation](./README.md) instead.

## Installation
This library is available on npm, you can install it by running `npm install --save flutterwave-react-native` or `yarn add flutterwave-react-native`

### Dependencies
In order to render the Flutterwave checkout screen this library depends on [react-native-webview](https://github.com/react-native-community/react-native-webview) ensure you properly install this library before continuing.

### Activity Indicator (only needed for android)
To display the Flutterwave styled activity indicator when the checkout screen is being loaded on Android you will need to add some modules in `android/app/build.gradle`.
***Skip this if you already have setup your app to support gif images.***
````javascript
dependencies {
// If your app supports Android versions before Ice Cream Sandwich (API level 14)
implementation 'com.facebook.fresco:animated-base-support:1.3.0'

// For animated GIF support
implementation 'com.facebook.fresco:animated-gif:2.0.0'
}
````

### :fire: IMPORTANT INFORMATION :fire:
If the `options` property on the [PayWithFlutterwaveV2](flutterwavebuttonprops-interface) changes, when next the user taps on the button a new payment will be initialized whether the last one was successful or not.

Remember you cannot use the same transaction reference for two different payments, remember to recreate the transaction reference before allowing the user initiate a new payment.


## Usage
Below are a few examples showcasing how you can use the library to implement payment in your React Native app.

### PayWithFlutterwaveV2
<img src=".github/images/pay-with-flutterwave.png" alt="preview" width="350"/>

[View All Props](#flutterwavebuttonprops)

Import `PayWithFlutterwaveV2` from `flutterwave-react-native` and use it like so.
````jsx
import {PayWithFlutterwaveV2} from 'flutterwave-react-native';
// or import PayWithFlutterwaveV2 from 'flutterwave-react-native/PayWithFlutterwaveV2';

<PayWithFlutterwaveV2
...
onComplete={handleOnComplete}
options={{
txref: txref,
PBFPubKey: '[Your Flutterwave Public Key]',
customer_email: 'customer-email@example.com',
amount: 2000,
currency: 'NGN',
}}
/>
````

### PayWithFlutterwaveV2 (with custom render)
<img src=".github/images/pay-with-flutterwave-custom.png" alt="preview" width="350"/>

[View All Props](#flutterwavebuttonprops)

Import `PayWithFlutterwaveV2` from `flutterwave-react-native` and use it like so.
````jsx
import {PayWithFlutterwaveV2} from 'flutterwave-react-native';
// or import PayWithFlutterwaveV2 from 'flutterwave-react-native/PayWithFlutterwaveV2';

<PayWithFlutterwaveV2
...
onComplete={handleOnComplete}
options={{...}}
customButton={(props) => (
<TouchableOpacity
style={styles.paymentButton}
onPress={props.onPress}
isBusy={props.isInitializing}
disabled={props.disabled}>
<Text style={styles.paymentButtonText}>Pay $500</Text>
</TouchableOpacity>
)}
/>
````

### FlutterwaveButton (Flutterwave styled button)
<img src=".github/images/flutterwave-styled-button.png" alt="preview" width="350"/>

[View All Props](#flutterwavebuttonprops)

Import `FlutterwaveButton` from `flutterwave-react-native` and use it like so.
````jsx
import {FlutterwaveButton} from 'flutterwave-react-native';

<FlutterwaveButton
style={styles.paymentButton}
onPress={onPress}
disabled={disabled}>
<Text style={styles.paymentButtonText}>Pay $500</Text>
</FlutterwaveButton>
````

### FlutterwaveInitV2
When called, this function returns a Promise which resolves to a string on success and rejects if an error occurs. [See all config options](#flutterwaveinitv2options)

Import `FlutterwaveInitV2` from `flutterwave-react-native` and use it like so.
````javascript
import {FlutterwaveInitV2} from 'flutterwave-react-native';;
// or import FlutterwaveInitV2 from 'flutterwave-react-native/FlutterwaveInitV2';

// initialize a new payment
const payment = await FlutterwaveInitV2({
txref: generateTransactionRef(),
PBFPubKey: '[Your Flutterwave Public Key]',
amount: 100,
currency: 'USD',
});

// link is available if payment initialized successfully
if (payment.link) {
// use payment link
return usePaymentLink(payment.link);
}

// handle payment error
handlePaymentError(
payment.error
? paymet.error.message
: 'Kai, an unknown error occurred!'
);
````
### Aborting Payment Initialization
Hi :wave:, so there are cases where you have already initialized a payment with `FlutterwaveInitV2` but might also want to be able to cancel the payment initialization should in case your component is being unmounted or you want to allow users cancel the action before the payment is initialized, we have provided a way for you to do this... [continue reading](./docs/v2/AbortingPaymentInitialization.md)

## Props

### FlutterwaveInitV2Options
[See Interface](#flutterwaveinitv2options-interface)
| Name | Required | Type | Default | Description |
| --------- | --------- | ---- | ------- | ----------- |
| PBFPubKey | Yes | string | **REQUIRED** | Your merchant public key, see how to get your [API Keys](https://developer.flutterwave.com/v2.0/docs/api-keys)|
| txref | Yes | string | **REQUIRED** | Your Unique transaction reference.|
| customer_email | Yes | string | **REQUIRED** | The customer's email address. |
| customer_phone | No | string | undefined | The customer's phone number. |
| customer_firstname | No | string | undefined | The customer's first name. |
| customer_lastname | No | string | undefined | The customer's last name. |
| amount | Yes | number | undefined | Amount to charge the customer.|
| currency | No | string | NGN | Currency to charge in. Defaults to NGN. Check our [International Payments](https://developer.flutterwave.com/v2.0/docs/multicurrency-payments) section for more on international currencies.|
| redirect_url | No | string | undefined | URL to redirect to when a transaction is completed. This is useful for 3DSecure payments so we can redirect your customer back to a custom page you want to show them. |
| payment_options | No | string | undefined | This allows you to select the payment option you want for your users, see [Choose Payment Methods](https://developer.flutterwave.com/v2.0/docs/splitting-payment-methods) for more info. |
| payment_plan | No | number | undefined | This is the payment plan ID used for [Recurring billing](https://developer.flutterwave.com/v2.0/docs/recurring-billing). |
| subaccounts | No | array of [FlutterwaveInitSubAccount](#flutterwaveinitsubaccount) | undefined | This is an array of objects containing the subaccount IDs to [split the payment](https://developer.flutterwave.com/v2.0/docs/split-payment) into. |
| country | No | string | NG | Route country. Defaults to NG |
| pay_button_text | No | string | undefined | Text to be displayed on the Rave Checkout Button. |
| custom_title | No | string | undefined | Text to be displayed as the title of the payment modal. |
| custom_description | No | string | undefined | Text to be displayed as a short modal description. |
| custom_logo | No | string | undefined | Link to the Logo image. |
| meta | No | array of [FlutterwavePaymentMetaV2](#flutterwavepaymentmetav2) | undefined | Any other custom data you wish to pass. |

### PayWithFlutterwaveV2Props
[See Interface](#paywithflutterwavev2props-interface)
| Name | Required | Type | Default | Description |
| --------- | --------- | ---- | ------- | ----------- |
| style | No | object | undefined | Used to apply styling to the button.|
| onComplete | Yes | function | **REQUIRED** | Called when a payment is completed successfully or is canceled. The function will receive [on complete data](#oncompletedata)|
| onWillInitialize | No | function | undefined | This will be called before a payment link is generated.|
| onDidInitialize | No | function | undefined | This is called when a new payment link has been successfully initialized.|
| onInitializeError | No | function | undefined | This is called if an error occurred while initializing a new pyment link. The function will receive [FlutterwaveInitError](#flutterwaveiniterror) |
| onAbort | No | function | undefined | This is called if a user aborts a transaction, a user can abort a transaction when they click on the dialog's backdrop and choose cancel when prompted to cancel transaction. |
| options | Yes | **[FlutterwaveInitOptions](#flutterwaveinitv2options)** | **REQUIRED** | The option passed here is used to initialize a payment. |
| customButton | No | function | undefined | This is used to render a custom button. The function a prop argument structured like [CustomButtonProps](#custombuttonprops), this function should return a valid React node. |
| alignLeft | No | boolean | undefined | This aligns the content of the button to the left. |

### FlutterwaveButton Props
[See Interface](#flutterwavebuttonprops-interface)
| Name | Required | Type | Default | Description |
| --------- | --------- | ---- | ------- | ----------- |
| style | No | ViewStyle | undefined | This component uses the same style properties that are applicable to react-native's View component style.|
| onPress | Yes | function | undefined | This property receive a function that is called on button press. |
| disabled | No | boolean | undefined | This disables button, and causes onPress not to be fired.|
| alignLeft | No | boolean | undefined | This aligns the content of the button to the left. |

## Types
#### CustomButtonProps
````typescript
interface CustomButtonProps {
disabled: boolean;
isInitializing: boolean;
onPress: () => void;
}
````

#### RedirectParamsV2
````typescript
interface RedirectParamsV2 {
canceled?: 'true' | 'false';
flwref?: string;
txref: string;
}
````

#### FlutterwaveInitError
````typescript
interface FlutterwaveInitError {
code: string;
message: string;
}
````

### FlutterwaveInitSubAccount
```typescript
interface FlutterwaveInitSubAccount {
id: string;
transaction_split_ratio?: number;
transaction_charge_type?: string;
transaction_charge?: number;
}
```

#### FlutterwavePaymentMetaV2
````typescript
interface FlutterwavePaymentMetaV2 {
metaname: string;
metavalue: string;
}
````

#### FlutterwaveInitV2Options Interface
````typescript
export interface FlutterwaveInitV2Options {
txref: string;
PBFPubKey: string;
customer_firstname?: string;
customer_lastname?: string;
customer_phone?: string;
customer_email: string;
amount: number;
currency?: string;
redirect_url?: string;
payment_options?: string;
payment_plan?: number;
subaccounts?: Array<FlutterwaveInitSubAccount>;
country?: string;
pay_button_text?: string;
custom_title?: string;
custom_description?: string;
custom_logo?: string;
meta?: Array<FlutterwavePaymentMetaV2>;
}
````

#### PayWithFlutterwaveV2Props Interface
````typescript
interface PayWithFlutterwaveV2Props {
style?: ViewStyle;
onComplete: (data: RedirectParamsV2) => void;
onWillInitialize?: () => void;
onDidInitialize?: () => void;
onInitializeError?: (error: FlutterwaveInitError) => void;
onAbort?: () => void;
options: Omit<FlutterwaveInitOptions, 'redirect_url'>;
customButton?: (props: CustomButtonProps) => React.ReactNode;
alignLeft?: 'alignLeft' | boolean;
}
````

#### FlutterwaveButtonProps Interface
````typescript
interface FlutterwaveButton {
style?: ViewStyle;
onPress?: () => void;
disabled?: boolean;
alignLeft?: 'alignLeft' | boolean,
}
````

## Contributing
For information on how you can contribute to this repo, simply [go here](./CONTRIBUTING.md), all contributions are greatly appreciated.

With love from Flutterwave. :yellow_heart:
9 changes: 5 additions & 4 deletions __tests__/CustomPropTypesRules.spec.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
import 'react-native';
import {PaymentOptionsPropRule} from '../src/utils/CustomPropTypesRules';
const PropName = 'payment_options';
const PAYMENT_OPTIONS = ['barter', 'card', 'banktransfer']

describe('CustomPropTypes.PaymentOptionsPropRule', () => {
it ('returns null if prop is not defined in props', () => {
const result = PaymentOptionsPropRule({}, PropName);
const result = PaymentOptionsPropRule(PAYMENT_OPTIONS)({}, PropName);
expect(result).toBe(null);
});

it ('returns error if prop is not a string', () => {
const result = PaymentOptionsPropRule({[PropName]: []}, PropName);
const result = PaymentOptionsPropRule(PAYMENT_OPTIONS)({[PropName]: []}, PropName);
expect(result !== null).toBe(true);
expect(result.message).toContain('should be a string.');
});

it ('returns error if prop includes invalid payment option', () => {
const result = PaymentOptionsPropRule({[PropName]: 'barter, foo'}, PropName);
const result = PaymentOptionsPropRule(PAYMENT_OPTIONS)({[PropName]: 'barter, foo'}, PropName);
expect(result !== null).toBe(true);
expect(result.message).toContain('must be any of the following values.');
});

it ('returns null if payment options are valid', () => {
const result = PaymentOptionsPropRule({[PropName]: 'barter'}, PropName);
const result = PaymentOptionsPropRule(PAYMENT_OPTIONS)({[PropName]: 'barter'}, PropName);
expect(result).toBe(null);
});
})
Loading