Skip to content

Commit 8e984a3

Browse files
finalize charge card and docs
1 parent 7fc9b57 commit 8e984a3

File tree

4 files changed

+87
-5
lines changed

4 files changed

+87
-5
lines changed

docs/payments/card.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Charge via Card
2+
3+
This document describes how to collect payments via Card.
4+
5+
```php
6+
<?php
7+
8+
$tx_ref = Flutterwave::generateReference();
9+
$order_id = Flutterwave::generateReference('card');
10+
11+
$data = [
12+
'amount' => 100,
13+
'email' => '[email protected]',
14+
'redirect_url' => route('callback')
15+
'tx_ref' => $tx_ref,
16+
'card_number' => '5399670123490229',
17+
'cvv' => 123,
18+
'expiry_month' => '05',
19+
'expiry_year' => '45',
20+
'subaccounts' => [
21+
["id" => "RS_D87A9EE339AE28BFA2AE86041C6DE70E"],
22+
["id" => "RS_B45A9VV221HQ28UYA2AE97681C6DR44R"]
23+
]
24+
];
25+
26+
$charge = Flutterwave::payments()->card($data);
27+
28+
if ($charge['status'] === 'success') {
29+
# code...
30+
//Handle Authorization Mode
31+
if($charge['data']['mode'] == 'redirect'){
32+
// Redirect to the charge url
33+
return redirect($charge['data']['redirect']);
34+
35+
}elseif($charge['data']['mode'] == 'otp'){
36+
// Validate with OTP and FLW_REF
37+
38+
}elseif($charge['data']['mode'] == 'avs_noauth'){
39+
//Charge again with the following data city, address, state, country, and zipcode
40+
41+
}elseif($charge['data']['mode'] == 'pin'){
42+
//Charge again with the card PIN
43+
44+
}
45+
46+
}
47+
```
48+
49+
## Parameters
50+
51+
| Parameter | Required | Description |
52+
| ------------------ | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
53+
| amount | True | This is the amount to be charged. Expected value is ZMW |
54+
| card_number | True | This is the number on the cardholders card. E.g. 5399 6701 2349 0229 |
55+
| cvv | True | Card security code. This is 3/4 digit code at the back of the customers card, used for web payments. |
56+
| expiry_month | True | Two-digit number representing the card's expiration month. It is usually the first two digits of the expiry date on the card. |
57+
| expiry_year | True | Unique ref for the mobilemoney transaction to be provided by the merchant. |
58+
| email | True | Two-digit number representing the card's expiration year. It is the last two digits of the expiry date on the card. |
59+
| tx_ref | True | This is a unique reference peculiar to the transaction being carried out. |
60+
| currency | False | This is the specified currency to charge in. |
61+
| phone_number | False | This is the phone number linked to the customer's Bank account or mobile money account |
62+
| fullname | False | This is the name of the customer making the payment. |
63+
| preauthoize | False | This should be set to true for preauthoize card transactions. |
64+
| redirect_url | False | URL to redirect to when a transaction is completed. |
65+
| client_ip | False | IP - Internet Protocol. This represents the current IP address of the customer carrying out the transaction |
66+
| device_fingerprint | False | This is the fingerprint for the device being used. It can be generated using a library on whatever platform is being used. |
67+
| meta | False | This is used to include additional payment information` |
68+
| subaccounts | False | This is an array of objects containing the subaccount IDs to split the payment into. Check our Split Payment page for more info. eg `[ ["id" => "RS_D87A9EE339AE28BFA2AE86041C6DE70E"]]` |
69+
| meta | False | This is an object that helps you include additional payment information to your request e.g ['consumer_id'=>23, 'consumer_mac'=>'92a3-912ba-1192a'] |
70+
71+

resources/config/flutterwave.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,12 @@
2828
*
2929
*/
3030
'secretHash' => env('FLW_SECRET_HASH', ''),
31+
32+
/**
33+
* Encryption Key: Your Rave encryptionKey. Sign up on https://dashboard.flutterwave.com/ to get one from your settings page
34+
*
35+
*/
36+
'encryptionKey' => env('FLW_ENCRYPTION_KEY', ''),
37+
38+
3139
];

src/Helpers/Payments.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ class Payments
2020
/**
2121
* Construct
2222
*/
23-
function __construct(String $publicKey, String $secretKey, String $baseUrl, $secretHash = '')
23+
function __construct(String $publicKey, String $secretKey, String $baseUrl, $encryptionKey = '')
2424
{
2525

2626
$this->publicKey = $publicKey;
2727
$this->secretKey = $secretKey;
2828
$this->baseUrl = $baseUrl;
29-
$this->secretHash = $secretHash;
29+
$this->encryptionKey = $encryptionKey;
3030
}
3131

3232

@@ -228,19 +228,21 @@ public function momoFranc(array $data)
228228
public function card(array $data)
229229
{
230230
$encryptedData = [];
231-
$encryptedData['client'] = Helper::encrypt3Des($data, $this->secretHash);
231+
$encryptedData['client'] = Helper::encrypt3Des($data, $this->encryptionKey);
232232

233233
$payment = Http::withToken($this->secretKey)->post(
234234
$this->baseUrl . '/charges?type=card',
235235
$encryptedData
236236
)->json();
237237

238238
if ($payment['status'] === 'success') {
239-
return [
239+
$result = [
240240
'status' => $payment['status'],
241241
'message' => $payment['message'],
242242
'data' => $payment['meta']['authorization'],
243243
];
244+
$result['data']['flw_ref'] = $payment['data']['flw_ref'];
245+
return $result;
244246
}
245247

246248
return $payment;

src/Rave.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ function __construct()
3232
$this->publicKey = config('flutterwave.publicKey');
3333
$this->secretKey = config('flutterwave.secretKey');
3434
$this->secretHash = config('flutterwave.secretHash');
35+
$this->encryptionKey = config('flutterwave.encryptionKey');
3536
$this->baseUrl = 'https://api.flutterwave.com/v3';
3637
}
3738

@@ -135,7 +136,7 @@ public function verifyWebhook()
135136
*/
136137
public function payments()
137138
{
138-
$payments = new Payments($this->publicKey, $this->secretKey, $this->baseUrl, $this->secretHash);
139+
$payments = new Payments($this->publicKey, $this->secretKey, $this->baseUrl, $this->encryptionKey);
139140
return $payments;
140141
}
141142

0 commit comments

Comments
 (0)