|
1 |
| -# Python Flutterwave |
2 |
| - |
3 |
| -### Description |
4 |
| -Python Wrapper for interacting with the Flutterwave API |
5 |
| - |
6 |
| - |
7 |
| -### Contribution |
8 |
| - - Before making any further steps (for interested contributors), please refer to the [CONTRIBUTING GUIDE](/CONTRIBUTING.md). |
9 |
| - |
10 |
| - |
11 |
| -## Installation |
12 |
| - |
13 |
| -- ``pip install python-flutterwave`` |
14 |
| - |
15 |
| -## Usage |
16 |
| - |
17 |
| -- Create an account in Flutterwave [here](https://dashboard.flutterwave.com/signup?referrals=RV1284343) and obtain your `Secret Key` only. |
18 |
| - |
19 |
| -``` |
20 |
| -from python_flutterwave import payment |
21 |
| -
|
22 |
| -payment.token = 'YOUR_SECRET_KEY' |
23 |
| -``` |
24 |
| - |
25 |
| -``` |
26 |
| -Here are all the possible values for payment options available on Flutterwave: |
27 |
| -0: "account" |
28 |
| -1: "card" |
29 |
| -2: "banktransfer" |
30 |
| -3: "mpesa" |
31 |
| -4: "mobilemoneyrwanda" |
32 |
| -5: "mobilemoneyzambia" |
33 |
| -6: "qr" |
34 |
| -7: "mobilemoneyuganda" |
35 |
| -8: "ussd" |
36 |
| -9: "credit" |
37 |
| -10: "barter" |
38 |
| -11: "mobilemoneyghana" |
39 |
| -12: "payattitude" |
40 |
| -13: "mobilemoneyfranco" |
41 |
| -14: "paga" |
42 |
| -15: "1voucher" |
43 |
| -16: "mobilemoneytanzania" |
44 |
| -``` |
45 |
| - |
46 |
| -- To trigger a standard payment that returns a redirect uri |
47 |
| - |
48 |
| -```python |
49 |
| -uri = payment.initiate_payment(tx_ref="qwerty", amount=100, redirect_url='your_callback_url', |
50 |
| - payment_options='mpesa', customer_email='example@email.com', |
51 |
| - customer_phone_number='0123456789', currency='KES', customer_name='John Doe', |
52 |
| - title='Demo Payment', description='Just pay me...') |
53 |
| -print(uri) |
54 |
| -``` |
55 |
| -- Redirect the user to that uri where he/she will make the payment. |
56 |
| -- After payment is made, the user will be redirected to the `redirect_url` you declared but Flutterwave will append some |
57 |
| -info regarding the payment i.e. `transaction_id` and `tx_ref`. If your url is `https://example.com/callback` |
58 |
| -then it may be `http://example.com/callback/?status=successful&tx_ref=qwerty&transaction_id=2784792` |
59 |
| -- You should save the transaction_id to your DB as it will be used to query the transaction details. |
60 |
| - |
61 |
| -> There is no need to save the transaction_id as it is also possible to use tx_ref to get the payment details! |
62 |
| -> Check here - https://developer.flutterwave.com/reference/endpoints/transactions/ |
63 |
| -
|
64 |
| - |
65 |
| -- To check the transaction details e.g. successful or not, grab the transaction_id from the previous step. |
66 |
| -```python |
67 |
| -details = payment.get_payment_details(transaction_id) |
68 |
| -# or |
69 |
| -deailts = payment.get_payment_details_via_tx_ref(tx_ref) |
70 |
| - |
71 |
| -print(details) |
72 |
| -``` |
73 |
| - |
74 |
| -- To trigger an automatic MPESA charge on your customer through STK push, first configure your Webhook url in the dashboard, it may be a |
75 |
| -simple server; Flutterwave will post some data regarding your transaction status in that url. This method call will |
76 |
| -return a Python dict object. You can decide what to do thereon. |
77 |
| -```python |
78 |
| -mpesa_trans_details = payment.trigger_mpesa_payment(tx_ref="qwertyuio", amount=100, currency='KES', |
79 |
| - email='johndoe@gmail.com', phone_number='1234567890', |
80 |
| - full_name='John Doe') |
81 |
| -print(mpesa_trans_details) |
82 |
| -``` |
83 |
| - |
84 |
| -- To initiate a USSD payment to your customer, configure your webhook url in the dashboard where Flutterwave will post data |
85 |
| -regarding the transaction. This method call will return a Python Dict object from which you can extract the USSD code to |
86 |
| -show your customer for payment completion. For other banks, you may also need to extract the `payment_code` from the result. |
87 |
| - |
88 |
| - - By default, `NGN` is the only supported currency for USSD payments so this method automatically uses `NGN` |
89 |
| - - Only a number of banks support `USSD` so you have to refer to the docs to check your bank and its corresponding `account_bank` code. |
90 |
| -``` |
91 |
| -At the moment, banks available for USSD payments (and their numeric codes) are: |
92 |
| -
|
93 |
| -Access Bank -- 044 |
94 |
| -Ecobank -- 050 |
95 |
| -Fidelity Bank -- 070 |
96 |
| -First Bank of Nigeria -- 011 |
97 |
| -First City Monument Bank (FCMB) -- 214 |
98 |
| -GTBank -- 058 |
99 |
| -Heritage Bank -- 030 |
100 |
| -Keystone Bank -- 082 |
101 |
| -Stanbic IBTC Bank -- 221 |
102 |
| -Sterling Bank -- 232 |
103 |
| -Union Bank -- 032 |
104 |
| -United Bank for Africa -- 033 |
105 |
| -Unity Bank -- 215 |
106 |
| -VFD Microfinance Bank -- 090110 |
107 |
| -Wema Bank -- 035 |
108 |
| -Zenith Bank -- 057 |
109 |
| -``` |
110 |
| - |
111 |
| - |
112 |
| -```python |
113 |
| -details = payment.initiate_ussd_payment(tx_ref="123erd", amount=100, email='johndoe@gmail.com', |
114 |
| - phone_number='789456123', full_name='John Doe', account_bank='057') |
115 |
| -print(details) |
116 |
| -``` |
117 |
| - |
118 |
| -- For bank transactions, it is important to first verify the details given to you by the customer before granting incentives |
119 |
| -according to the specifications of your application. |
120 |
| -- To verify bank details call the function below that returns a Python dictionary with the data... |
121 |
| -```python |
122 |
| -details = payment.verify_bank_account_details(account_number= "0690000032", account_bank= "044") |
123 |
| -print(details) |
124 |
| -``` |
125 |
| - |
126 |
| -- For card transactions, it is advisable to ascertain the customer's card details before granting incentives according |
127 |
| -to the specifications of your application. |
128 |
| -- This function call takes the `card_bin` (usually the first 4-6 digits in debit/credit cards) and returns info regarding |
129 |
| -the card. A Python dict object is returned, thence use it according to your needs. |
130 |
| -```python |
131 |
| -details = payment.verify_card_details(card_bin=553188) |
132 |
| -print(details) |
133 |
| -``` |
134 |
| - |
135 |
| -[](https://dashboard.flutterwave.com/donate/zvapzky1ozls) |
| 1 | +```New docs under development``` |
0 commit comments