Skip to content

Commit ab7f576

Browse files
authored
Merge pull request #38 from kpose/updateREADME
docs(readme.md): show examples of onRedirect and transactionRef required props
2 parents 815366d + 2f6041e commit ab7f576

File tree

1 file changed

+108
-40
lines changed

1 file changed

+108
-40
lines changed

README.md

Lines changed: 108 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
<img title="Flutterwave" height="200" src="https://flutterwave.com/images/logo-colored.svg" width="50%"/>
33
</p>
44

5-
65
# React Native Flutterwave
7-
Easily implement Flutterwave for payments in your React Native appliction. This library supports both Android and iOS, and use the Flutterwave's V3 API.
6+
7+
Easily implement Flutterwave for payments in your React Native appliction. This library supports both Android and iOS, and use the Flutterwave's V3 API.
88

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

@@ -14,6 +14,7 @@ Easily implement Flutterwave for payments in your React Native appliction. This
1414
</p>
1515

1616
## Table Of Content
17+
1718
- Getting Started
1819
- [V2 API](#warning-if-using-version-2-api-warning)
1920
- [Installation](#installation)
@@ -45,59 +46,92 @@ Easily implement Flutterwave for payments in your React Native appliction. This
4546
- [Contributing](./CONTRIBUTING.md)
4647

4748
## What's Inside?
49+
4850
- Pay with Flutterwave button and checkout dialog.
4951
- Standard payment initialization function.
5052
- Flutterwave designed button.
5153

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

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

5862
### Dependencies
63+
5964
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.
6065

6166
### Activity Indicator (only needed for android)
67+
6268
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`.
63-
***Skip this if you already have setup your app to support gif images.***
64-
````javascript
69+
**_Skip this if you already have setup your app to support gif images._**
70+
71+
```javascript
6572
dependencies {
6673
// If your app supports Android versions before Ice Cream Sandwich (API level 14)
6774
implementation 'com.facebook.fresco:animated-base-support:1.3.0'
6875

6976
// For animated GIF support
7077
implementation 'com.facebook.fresco:animated-gif:2.0.0'
7178
}
72-
````
79+
```
7380

7481
### :fire: MERCHANT PUBLIC KEY :fire:
82+
7583
In order to use this library you are required to use your merchant public key and not the secret key. See how to get your API Keys [here](https://developer.flutterwave.com/v3.0/docs/api-keys)
7684

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

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

82-
8391
## Usage
92+
8493
Below are a few examples showcasing how you can use the library to implement payment in your React Native app.
8594

86-
### PayWithFlutterwave
95+
### PayWithFlutterwave
96+
8797
<img src=".github/images/pay-with-flutterwave.png" alt="preview" width="350"/>
8898

8999
[View All Props](#flutterwavebuttonprops)
90100

91101
Import `PayWithFlutterwave` from `flutterwave-react-native` and use it like so.
92-
````jsx
102+
103+
```tsx
93104
import {PayWithFlutterwave} from 'flutterwave-react-native';
94105
// or import PayWithFlutterwave from 'flutterwave-react-native';
95106

107+
interface RedirectParams {
108+
status: 'successful' | 'cancelled';
109+
transaction_id?: string;
110+
tx_ref: string;
111+
}
112+
113+
/* An example function called when transaction is completed successfully or canceled */
114+
const handleOnRedirect = (data: RedirectParams) => {
115+
console.log(data);
116+
};
117+
118+
/* An example function to generate a random transaction reference */
119+
const generateTransactionRef = (length: number) => {
120+
var result = '';
121+
var characters =
122+
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
123+
var charactersLength = characters.length;
124+
for (var i = 0; i < length; i++) {
125+
result += characters.charAt(Math.floor(Math.random() * charactersLength));
126+
}
127+
return `flw_tx_ref_${result}`;
128+
};
129+
96130
<PayWithFlutterwave
97131
...
98132
onRedirect={handleOnRedirect}
99133
options={{
100-
tx_ref: transactionReference,
134+
tx_ref: generateTransactionRef(10)
101135
authorization: '[merchant public key]',
102136
customer: {
103137
email: 'customer-email@example.com'
@@ -107,18 +141,31 @@ import {PayWithFlutterwave} from 'flutterwave-react-native';
107141
payment_options: 'card'
108142
}}
109143
/>
110-
````
144+
```
111145

112146
### PayWithFlutterwave (with custom render)
147+
113148
<img src=".github/images/pay-with-flutterwave-custom.png" alt="preview" width="350"/>
114149

115150
[View All Props](#flutterwavebuttonprops)
116151

117152
Import `PayWithFlutterwave` from `flutterwave-react-native` and use it like so.
118-
````jsx
153+
154+
```tsx
119155
import {PayWithFlutterwave} from 'flutterwave-react-native';
120156
// or import PayWithFlutterwave from 'flutterwave-react-native';
121157

158+
interface RedirectParams {
159+
status: 'successful' | 'cancelled';
160+
transaction_id?: string;
161+
tx_ref: string;
162+
}
163+
164+
/* An example function called when transaction is completed successfully or canceled */
165+
const handleOnRedirect = (data: RedirectParams) => {
166+
console.log(data);
167+
};
168+
122169
<PayWithFlutterwave
123170
...
124171
onRedirect={handleOnRedirect}
@@ -133,30 +180,34 @@ import {PayWithFlutterwave} from 'flutterwave-react-native';
133180
</TouchableOpacity>
134181
)}
135182
/>
136-
````
183+
```
137184

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

141189
[View All Props](#flutterwavebuttonprops)
142190

143191
Import `FlutterwaveButton` from `flutterwave-react-native` and use it like so.
144-
````jsx
192+
193+
```jsx
145194
import {FlutterwaveButton} from 'flutterwave-react-native';
146195

147196
<FlutterwaveButton
148197
style={styles.paymentButton}
149198
onPress={onPress}
150199
disabled={disabled}>
151-
<Text style={styles.paymentButtonText}>Pay $500</Text>
152-
</FlutterwaveButton>
153-
````
200+
<Text style={styles.paymentButtonText}>Pay $500</Text>
201+
</FlutterwaveButton>;
202+
```
154203

155204
### FlutterwaveInit
205+
156206
When called, this function returns a Promise which resolves to a string on success and rejects if an error occurs. [See all config options](#flutterwaveinitoptions)
157207

158208
Import `FlutterwaveInit` from `flutterwave-react-native` and use it like so.
159-
````javascript
209+
210+
```javascript
160211
import {FlutterwaveInit} from 'flutterwave-react-native';
161212

162213
try {
@@ -167,25 +218,28 @@ try {
167218
amount: 100,
168219
currency: 'USD',
169220
customer: {
170-
email: 'customer-email@example.com'
221+
email: 'customer-email@example.com',
171222
},
172-
payment_options: 'card'
223+
payment_options: 'card',
173224
});
174225
// use payment link
175226
usePaymentLink(paymentLink);
176227
} catch (error) {
177228
// handle payment error
178229
displayError(error.message);
179230
}
180-
````
231+
```
232+
181233
### Aborting Payment Initialization
234+
182235
:wave: Hi, so there are cases where you have already initialized a payment with `FlutterwaveInit` 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/AbortingPaymentInitialization.md)
183236

184237
## Props
185238

186239
### FlutterwaveInitOptions
240+
187241
[See Interface](#flutterwaveinitoptions-interface)
188-
| Name | Required | Type | Default | Description |
242+
| Name | Required | Type | Default | Description |
189243
| --------- | --------- | ---- | ------- | ----------- |
190244
| authorization | Yes | string | **REQUIRED** | Your merchant public key, see how to get your [API Keys](https://developer.flutterwave.com/v3.0/docs/api-keys)|
191245
| tx_ref | Yes | string | **REQUIRED** | Your transaction reference. This MUST be unique for every transaction.|
@@ -195,14 +249,15 @@ try {
195249
| payment_options | Yes | string | **REQUIRED** | This specifies the payment options to be displayed e.g - card, mobilemoney, ussd and so on. |
196250
| payment_plan | No | number | undefined | This is the payment plan ID used for [Recurring billing](https://developer.flutterwave.com/v3.0/docs/recurring-billing). |
197251
| redirect_url | Yes | string | **REQUIRED** | 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. **IMPORTANT** This only required when you are directly using [FlutterwaveInit](#flutterwave-standard-init) |
198-
| customer | Yes | [FlutterwaveInitCustomer](#flutterwaveinitcustomer) | **REQUIRED** | This is an object that can contains your customer details. `E.g.'customer': { 'email': 'example@example.com', 'phonenumber': '08012345678', 'name': 'Takeshi Kovacs' }.` |
252+
| customer | Yes | [FlutterwaveInitCustomer](#flutterwaveinitcustomer) | **REQUIRED** | This is an object that contains your customer details. `E.g.'customer': { 'email': 'example@example.com', 'phonenumber': '08012345678', 'name': 'Takeshi Kovacs' }.` |
199253
| subaccounts | No | array of [FlutterwaveInitSubAccount](#flutterwaveinitsubaccount) | undefined | This is an array of objects containing the subaccount IDs to split the payment into. Check out the [Split Payment page](https://developer.flutterwave.com/docs/split-payment) for more info |
200254
| meta | No | [FlutterwavePaymentMeta](#flutterwavepaymentmeta) | undefined | This is an object that helps you include additional payment information to your request. `E.g. { 'consumer_id': 23, 'consumer_mac': '92a3-912ba-1192a' }` |
201255
| customizations | No | [FlutterwaveInitCustomizations](#flutterwaveinitcustomizations) | undefined | This is an object that contains title, logo, and description you want to display on the modal `E.g. {'title': 'Pied Piper Payments', 'description': 'Middleout isn't free. Pay the price', 'logo': 'https://assets.piedpiper.com/logo.png'}` |
202256

203257
### PayWithFlutterwaveProps
258+
204259
[See Interface](#paywithflutterwaveprops-interface)
205-
| Name | Required | Type | Default | Description |
260+
| Name | Required | Type | Default | Description |
206261
| --------- | --------- | ---- | ------- | ----------- |
207262
| style | No | object | undefined | Used to apply styling to the button.|
208263
| onRedirect | Yes | function | **REQUIRED** | Called when a payment is completed successfully or is canceled. The function will receive [redirect params](#redirectparams) as an argument.|
@@ -215,51 +270,58 @@ try {
215270
| alignLeft | No | boolean | undefined | This aligns the content of the button to the left. |
216271

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

226282
## Types
283+
227284
#### CustomButtonProps
228-
````typescript
285+
286+
```typescript
229287
interface CustomButtonProps {
230288
disabled: boolean;
231289
isInitializing: boolean;
232290
onPress: () => void;
233291
}
234-
````
292+
```
235293

236294
#### RedirectParams
237-
````typescript
295+
296+
```typescript
238297
interface RedirectParams {
239-
status: 'successful' | 'cancelled',
298+
status: 'successful' | 'cancelled';
240299
transaction_id?: string;
241300
tx_ref: string;
242301
}
243-
````
302+
```
244303

245304
#### FlutterwaveInitError
246-
````typescript
305+
306+
```typescript
247307
interface FlutterwaveInitError {
248308
code: string;
249309
message: string;
250310
errorId?: string;
251311
errors?: Array<string>;
252312
}
253-
````
313+
```
254314

255315
#### FlutterwavePaymentMeta
256-
````typescript
316+
317+
```typescript
257318
interface FlutterwavePaymentMeta {
258319
[k: string]: any;
259320
}
260-
````
321+
```
261322

262323
### FlutterwaveInitCustomer
324+
263325
```typescript
264326
interface FlutterwaveInitCustomer {
265327
email: string;
@@ -269,6 +331,7 @@ interface FlutterwaveInitCustomer {
269331
```
270332

271333
### FlutterwaveInitCustomizations
334+
272335
```typescript
273336
interface FlutterwaveInitCustomizations {
274337
title?: string;
@@ -278,6 +341,7 @@ interface FlutterwaveInitCustomizations {
278341
```
279342

280343
### FlutterwaveInitSubAccount
344+
281345
```typescript
282346
interface FlutterwaveInitSubAccount {
283347
id: string;
@@ -288,7 +352,8 @@ interface FlutterwaveInitSubAccount {
288352
```
289353

290354
#### FlutterwaveInitOptions Interface
291-
````typescript
355+
356+
```typescript
292357
export interface FlutterwaveInitOptions {
293358
authorization: string;
294359
tx_ref: string;
@@ -300,13 +365,14 @@ export interface FlutterwaveInitOptions {
300365
redirect_url: string;
301366
customer: FlutterwaveInitCustomer;
302367
subaccounts?: Array<FlutterwaveInitSubAccount>;
303-
meta?: Array<FlutterwavePaymentMeta>;
368+
meta?: FlutterwavePaymentMeta;
304369
customizations?: FlutterwaveInitCustomizations;
305370
}
306-
````
371+
```
307372

308373
#### PayWithFlutterwaveProps Interface
309-
````typescript
374+
375+
```typescript
310376
interface PayWithFlutterwaveProps {
311377
style?: ViewStyle;
312378
onRedirect: (data: RedirectParams) => void;
@@ -318,19 +384,21 @@ interface PayWithFlutterwaveProps {
318384
customButton?: (props: CustomButtonProps) => React.ReactNode;
319385
alignLeft?: 'alignLeft' | boolean;
320386
}
321-
````
387+
```
322388

323389
#### FlutterwaveButtonProps Interface
324-
````typescript
390+
391+
```typescript
325392
interface FlutterwaveButtonProps {
326393
style?: StyleProp<ViewStyle>;
327394
disabled?: boolean;
328395
alignLeft?: boolean;
329396
onPress?: () => void;
330397
}
331-
````
398+
```
332399

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

336404
With love from Flutterwave. :yellow_heart:

0 commit comments

Comments
 (0)