Skip to content

Commit 1f26169

Browse files
authored
Merge pull request #85 from christianjombo/master
2 parents 7688c11 + 8e984a3 commit 1f26169

File tree

11 files changed

+357
-2
lines changed

11 files changed

+357
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
- [Tolulope Adekunte](https://github.com/adtrex)
2929
- [Ogaba Emmanuel](https://github.com/ElmageAce)
3030
- [Sofolahan Eniola (Nattive)](https://github.com/nattive)
31+
- [Christian Jombo](https://github.com/christianjombo)
3132

3233
## Contributing
3334
Please feel free to fork this package and contribute by submitting a pull request to enhance the functionalities. I will appreciate that a lot. Also please add your name to the credits.

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+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Create a subaccount
2+
3+
> Create a collection subaccount
4+
5+
```php
6+
<?php
7+
$data = [
8+
'account_number' => '0690000034',
9+
'account_bank' => '044',
10+
'business_name' => 'Christian Jombo and Sons',
11+
'business_mobile' => '08000000000',
12+
'split_type' => 'flat',
13+
'split_value' => 1000
14+
];
15+
16+
$subaccount = Flutterwave::subaccounts()->create($data);
17+
18+
dd($subaccount);
19+
```
20+
21+
## Parameters
22+
23+
| Parameter | Required | Description |
24+
| --------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
25+
| account_number | True | The subaccount's bank account number. When testing on staging, you can find a list of all the available test bank accounts [here](https://developer.flutterwave.com/docs/test-bank-accounts). |
26+
| account_bank | True | This is the subaccount’s bank code, you can use the [List of Banks](/banks/list-banks) to retrieve a bank code. |
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Delete a subaccount
2+
3+
> Delete a collection subaccount.
4+
5+
```php
6+
<?php
7+
8+
$subaccountId = 12596;
9+
10+
$subaccount = Flutterwave::subaccounts()->destroy($subaccountId);
11+
12+
dd($subaccount);
13+
```
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Fetch a subaccount
2+
3+
> Get a single collection subaccount details.
4+
5+
```php
6+
<?php
7+
8+
$subaccountId = 12596;
9+
10+
$subaccount = Flutterwave::subaccounts()->fetch($subaccountId);
11+
12+
dd($subaccount);
13+
```
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# List all subaccounts
2+
3+
> Fetch all subaccounts on your account.
4+
5+
```php
6+
<?php
7+
8+
$data = [
9+
'page' => 1
10+
];
11+
12+
// $data is optional
13+
$subaccounts = Flutterwave::subaccounts()->fetchAll($data);
14+
15+
dd($subaccounts);
16+
```
17+
18+
19+
## Parameters
20+
21+
| Parameter | Required | Description |
22+
| --------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
23+
| page | False | This allows you fetch from a specific page e.g. setting page to 1 fetches the first page. |
24+
| account_bank | False | This is the sub-accounts bank ISO code |
25+
| account_number | False | This is the account number associated with the subaccount you want to fetch |
26+
| bank_name | False | This is the name of the bank associated with the ISO code provided in account_bankfield |

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/Helper.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace KingFlamez\Rave\Helpers;
4+
5+
/**
6+
* Flutterwave's Rave payment laravel package
7+
* @author Oluwole Adebiyi - Flamez <[email protected]>
8+
* @version 3
9+
**/
10+
class Helper
11+
{
12+
13+
// public static function encryption($key, $data)
14+
// {
15+
// //encode the data and the
16+
// return self::encrypt3Des($data, $key);
17+
// }
18+
19+
public static function encrypt3Des(array $data, $key)
20+
{
21+
$encData = openssl_encrypt(json_encode($data), 'DES-EDE3', $key, OPENSSL_RAW_DATA);
22+
return base64_encode($encData);
23+
}
24+
25+
}

src/Helpers/Payments.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ class Payments
2020
/**
2121
* Construct
2222
*/
23-
function __construct(String $publicKey, String $secretKey, String $baseUrl)
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->encryptionKey = $encryptionKey;
2930
}
3031

3132

@@ -218,4 +219,32 @@ public function momoFranc(array $data)
218219

219220
return $payment;
220221
}
222+
223+
/**
224+
* Charge via Card
225+
* @param $data
226+
* @return object
227+
*/
228+
public function card(array $data)
229+
{
230+
$encryptedData = [];
231+
$encryptedData['client'] = Helper::encrypt3Des($data, $this->encryptionKey);
232+
233+
$payment = Http::withToken($this->secretKey)->post(
234+
$this->baseUrl . '/charges?type=card',
235+
$encryptedData
236+
)->json();
237+
238+
if ($payment['status'] === 'success') {
239+
$result = [
240+
'status' => $payment['status'],
241+
'message' => $payment['message'],
242+
'data' => $payment['meta']['authorization'],
243+
];
244+
$result['data']['flw_ref'] = $payment['data']['flw_ref'];
245+
return $result;
246+
}
247+
248+
return $payment;
249+
}
221250
}

src/Helpers/Subaccount.php

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
<?php
2+
3+
namespace KingFlamez\Rave\Helpers;
4+
5+
use Illuminate\Support\Facades\Log;
6+
use Illuminate\Support\Facades\Http;
7+
8+
/**
9+
* Flutterwave's Rave payment laravel package
10+
* @author Oluwole Adebiyi - Flamez <[email protected]>
11+
* @version 3
12+
**/
13+
class Subaccount
14+
{
15+
16+
protected $publicKey;
17+
protected $secretKey;
18+
protected $baseUrl;
19+
20+
/**
21+
* Construct
22+
*/
23+
function __construct(String $publicKey, String $secretKey, String $baseUrl)
24+
{
25+
26+
$this->publicKey = $publicKey;
27+
$this->secretKey = $secretKey;
28+
$this->baseUrl = $baseUrl;
29+
}
30+
31+
32+
/**
33+
* Create a subaccount
34+
* @param $data
35+
* @return object
36+
*/
37+
public function create(array $data)
38+
{
39+
$subaccount = Http::withToken($this->secretKey)->post(
40+
$this->baseUrl . '/subaccounts',
41+
$data
42+
)->json();
43+
44+
return $subaccount;
45+
}
46+
47+
48+
/**
49+
* Update a subaccount
50+
* @param $id, $data
51+
* @return object
52+
*/
53+
public function update($id, array $data)
54+
{
55+
$subaccount = Http::withToken($this->secretKey)->put(
56+
$this->baseUrl . '/subaccounts/'.$id,
57+
$data
58+
)->json();
59+
60+
return $subaccount;
61+
}
62+
63+
64+
65+
66+
/**
67+
* Get All Subaccounts
68+
* @param $data
69+
* @return object
70+
*/
71+
public function fetchAll(array $data = [])
72+
{
73+
$subaccounts = Http::withToken($this->secretKey)->get(
74+
$this->baseUrl . '/subaccounts',
75+
$data
76+
)->json();
77+
78+
return $subaccounts;
79+
}
80+
81+
82+
83+
84+
/**
85+
* Get A subaccount
86+
* @param $id
87+
* @return object
88+
*/
89+
public function fetch($id)
90+
{
91+
$subaccount = Http::withToken($this->secretKey)->get(
92+
$this->baseUrl . '/subaccounts/' . $id
93+
)->json();
94+
95+
return $subaccount;
96+
}
97+
98+
99+
100+
101+
/**
102+
* Delete A subaccount
103+
* @param $id
104+
* @return object
105+
*/
106+
public function destroy($id)
107+
{
108+
$subaccount = Http::withToken($this->secretKey)->delete(
109+
$this->baseUrl . '/subaccounts/' . $id
110+
)->json();
111+
112+
return $subaccount;
113+
}
114+
}

0 commit comments

Comments
 (0)