|
| 1 | +<p align="center"> |
| 2 | + <img title="Flutterwave" height="200" src="https://flutterwave.com/images/logo-colored.svg" width="50%"/> |
| 3 | +</p> |
| 4 | + |
| 5 | +# Flutterwave Flutter Standard SDK |
| 6 | + |
| 7 | +## Table of Contents |
| 8 | + |
| 9 | +- [About](#about) |
| 10 | +- [Getting Started](#getting-started) |
| 11 | +- [Usage](#usage) |
| 12 | +- [Deployment](#deployment) |
| 13 | +- [Built Using](#build-tools) |
| 14 | +- [References](#references) |
| 15 | +- [Support](#support) |
| 16 | + |
| 17 | +<a id="about"></a> |
| 18 | +## About |
| 19 | +Flutterwave's Flutter SDK is Flutterwave's offical flutter sdk to integrate Flutterwave's [Standard](https://developer.flutterwave.com/docs/flutterwave-standard) payment into your flutter app. It comes with a ready made Drop In UI. |
| 20 | + |
| 21 | + |
| 22 | + |
| 23 | +<a id="getting-started"></a> |
| 24 | + |
| 25 | +## Getting Started |
| 26 | + |
| 27 | +These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See [deployment](#deployment) for notes on how to deploy the project on a live system. |
| 28 | +See [references](#references) for links to dashboard and API documentation. |
| 29 | + |
| 30 | +### Prerequisite |
| 31 | + |
| 32 | +- Ensure you have your test (and live) [API keys](https://developer.flutterwave.com/docs/api-keys). |
| 33 | +``` |
| 34 | +Flutter version >= 1.17.0 |
| 35 | +Flutterwave version 3 API keys |
| 36 | +``` |
| 37 | + |
| 38 | + ### Installing |
| 39 | + |
| 40 | +**Step 1.** Add the dependency |
| 41 | + |
| 42 | +In your `pubspec.yaml` file add: |
| 43 | + |
| 44 | +1. `flutterwave_standard: 1.0.0` |
| 45 | +2. run `flutter pub get` |
| 46 | + |
| 47 | +<a id="usage"></a> |
| 48 | +## Usage |
| 49 | + |
| 50 | +### 1. Create a `Flutterwave` instance |
| 51 | + |
| 52 | +Create a `Flutterwave` instance by calling the constructor `Flutterwave` The constructor accepts a mandatory instance of the following: |
| 53 | + the calling `Context` , `publicKey`, `Customer`, `amount`, `currency`, `email`, `fullName`, `txRef`, `isDebug`, `paymentOptions`, and `Customization` . It returns an instance of `Flutterwave` which we then call the `async` method `.charge()` on. |
| 54 | + |
| 55 | + _handlePaymentInitialization() async { |
| 56 | + final style = FlutterwaveStyle( |
| 57 | + appBarText: "My Standard Blue", |
| 58 | + buttonColor: Color(0xffd0ebff), |
| 59 | + appBarIcon: Icon(Icons.message, color: Color(0xffd0ebff)), |
| 60 | + buttonTextStyle: TextStyle( |
| 61 | + color: Colors.black, |
| 62 | + fontWeight: FontWeight.bold, |
| 63 | + fontSize: 18, |
| 64 | + ), |
| 65 | + appBarColor: Color(0xffd0ebff), |
| 66 | + dialogCancelTextStyle: TextStyle( |
| 67 | + color: Colors.redAccent, |
| 68 | + fontSize: 18, |
| 69 | + ), |
| 70 | + dialogContinueTextStyle: TextStyle( |
| 71 | + color: Colors.blue, |
| 72 | + fontSize: 18, |
| 73 | + ) |
| 74 | + ); |
| 75 | + final Customer customer = Customer( |
| 76 | + name: "FLW Developer", |
| 77 | + phoneNumber: "1234566677777", |
| 78 | + email: "customer@customer.com"); |
| 79 | + |
| 80 | + final Flutterwave flutterwave = Flutterwave( |
| 81 | + context: context, |
| 82 | + style: style, |
| 83 | + publicKey: "Public Key, |
| 84 | + currency: "RWF", |
| 85 | + txRef: "unique_transaction_reference", |
| 86 | + amount: "3000", |
| 87 | + customer: customer, |
| 88 | + paymentOptions: "ussd, card, barter, payattitude", |
| 89 | + customization: Customization(title: "Test Payment"), |
| 90 | + isDebug: true); |
| 91 | + } |
| 92 | + |
| 93 | + |
| 94 | +### 2. Handle the response |
| 95 | + |
| 96 | + Calling the `.charge()` method returns a `Future` |
| 97 | + of `ChargeResponse` which we await for the actual response as seen above. |
| 98 | + |
| 99 | + ``` |
| 100 | + final ChargeResponse response = await flutterwave.charge(); |
| 101 | + if (response != null) { |
| 102 | + print(response.toJson()); |
| 103 | + if(response.success) { |
| 104 | + Call the verify transaction endpoint with the transactionID returned in `response.transactionId` to verify transaction before offering value to customer |
| 105 | + } else { |
| 106 | + // Transaction not successful |
| 107 | + } |
| 108 | + } else { |
| 109 | + // User cancelled |
| 110 | + } |
| 111 | +``` |
| 112 | + |
| 113 | + |
| 114 | + |
| 115 | +#### Please note that: |
| 116 | + - `ChargeResponse` can be null, depending on if the user cancels |
| 117 | + the transaction by pressing back. |
| 118 | + - You need to check the status of the transaction from the instance of `ChargeResponse` returned from calling `.charge()`, the `status`, `success` and `txRef` are successful and correct before providing value to the customer |
| 119 | + |
| 120 | +> **PLEASE NOTE** |
| 121 | +
|
| 122 | +> We advise you to do a further verification of transaction's details on your server to be sure everything checks out before providing service. |
| 123 | +<a id="deployment"></a> |
| 124 | +## Deployment |
| 125 | + |
| 126 | +- Switch to Live Mode on the Dashboard settings page |
| 127 | +- Use the Live Public API key from the API tab, see [here](https://developer.flutterwave.com/docs/api-keys) for more details. |
| 128 | + |
| 129 | +<a id="build-tools"></a> |
| 130 | +## Built Using |
| 131 | +- [flutter](https://flutter.dev/) |
| 132 | +- [http](https://pub.dev/packages/http) |
| 133 | +- [webview_flutter](https://pub.dev/packages/webview_flutter) |
| 134 | +- [fluttertoast](https://pub.dev/packages/fluttertoast) |
| 135 | + |
| 136 | +<a id="references"></a> |
| 137 | +## Flutterwave API References |
| 138 | + |
| 139 | +- [Flutterwave API Doc](https://developer.flutterwave.com/docs) |
| 140 | +- [Flutterwave Inline Payment Doc](https://developer.flutterwave.com/docs/flutterwave-inline) |
| 141 | +- [Flutterwave Dashboard](https://dashboard.flutterwave.com/login) |
| 142 | + |
| 143 | +<a id="support"></a> |
| 144 | +## Support |
| 145 | +* Have issues integrating? Reach out via [our Developer forum](https://developer.flutterwave.com/discuss) for support |
| 146 | + |
0 commit comments