diff --git a/README.md b/README.md index a39493f..c2471e9 100755 --- a/README.md +++ b/README.md @@ -25,10 +25,6 @@ - [Abhishek Prakash](https://github.com/abhishek6262) - [Wallace Myem Aboiyar](https://github.com/wallacemyem) - [Chigozie Ekwonu](https://github.com/chygoz2) -- [Tolulope Adekunte](https://github.com/adtrex) -- [Ogaba Emmanuel](https://github.com/ElmageAce) -- [Sofolahan Eniola (Nattive)](https://github.com/nattive) -- [Christian Jombo](https://github.com/christianjombo) ## Contributing 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. diff --git a/docs/getting-started/payment-implementation.md b/docs/getting-started/payment-implementation.md index 0c69a2e..abc6fd2 100644 --- a/docs/getting-started/payment-implementation.md +++ b/docs/getting-started/payment-implementation.md @@ -69,7 +69,7 @@ class FlutterwaveController extends Controller 'redirect_url' => route('callback'), 'customer' => [ 'email' => request()->email, - "phone_number" => request()->phone, + "phonenumber" => request()->phone, "name" => request()->name ], @@ -96,25 +96,14 @@ class FlutterwaveController extends Controller */ public function callback() { - - $status = request()->status; - //if payment is successful - if ($status == 'successful') { - $transactionID = Flutterwave::getTransactionIDFromCallback(); $data = Flutterwave::verifyTransaction($transactionID); dd($data); - } - elseif ($status == 'cancelled'){ - //Put desired action/code after transaction has been cancelled here - } - else{ - //Put desired action/code after transaction has failed here - } // Get the transaction from your DB using the transaction reference (txref) // Check if you have previously given value for the transaction. If you have, redirect to your successpage else, continue + // Confirm that the $data['data']['status'] is 'successful' // Confirm that the currency on your db transaction is equal to the returned currency // Confirm that the db transaction amount is equal to the returned amount // Update the db transaction record (including parameters that didn't exist before the transaction is completed. for audit purpose) diff --git a/docs/payments/card.md b/docs/payments/card.md deleted file mode 100644 index 5172bd0..0000000 --- a/docs/payments/card.md +++ /dev/null @@ -1,71 +0,0 @@ -# Charge via Card - -This document describes how to collect payments via Card. - -```php - 100, - 'email' => 'wole@email.co', - 'redirect_url' => route('callback') - 'tx_ref' => $tx_ref, - 'card_number' => '5399670123490229', - 'cvv' => 123, - 'expiry_month' => '05', - 'expiry_year' => '45', - 'subaccounts' => [ - ["id" => "RS_D87A9EE339AE28BFA2AE86041C6DE70E"], - ["id" => "RS_B45A9VV221HQ28UYA2AE97681C6DR44R"] - ] -]; - -$charge = Flutterwave::payments()->card($data); - -if ($charge['status'] === 'success') { - # code... - //Handle Authorization Mode - if($charge['data']['mode'] == 'redirect'){ - // Redirect to the charge url - return redirect($charge['data']['redirect']); - - }elseif($charge['data']['mode'] == 'otp'){ - // Validate with OTP and FLW_REF - - }elseif($charge['data']['mode'] == 'avs_noauth'){ - //Charge again with the following data city, address, state, country, and zipcode - - }elseif($charge['data']['mode'] == 'pin'){ - //Charge again with the card PIN - - } - -} -``` - -## Parameters - -| Parameter | Required | Description | -| ------------------ | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| amount | True | This is the amount to be charged. Expected value is ZMW | -| card_number | True | This is the number on the cardholders card. E.g. 5399 6701 2349 0229 | -| cvv | True | Card security code. This is 3/4 digit code at the back of the customers card, used for web payments. | -| 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. | -| expiry_year | True | Unique ref for the mobilemoney transaction to be provided by the merchant. | -| email | True | Two-digit number representing the card's expiration year. It is the last two digits of the expiry date on the card. | -| tx_ref | True | This is a unique reference peculiar to the transaction being carried out. | -| currency | False | This is the specified currency to charge in. | -| phone_number | False | This is the phone number linked to the customer's Bank account or mobile money account | -| fullname | False | This is the name of the customer making the payment. | -| preauthoize | False | This should be set to true for preauthoize card transactions. | -| redirect_url | False | URL to redirect to when a transaction is completed. | -| client_ip | False | IP - Internet Protocol. This represents the current IP address of the customer carrying out the transaction | -| 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. | -| meta | False | This is used to include additional payment information` | -| 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"]]` | -| 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'] | - - diff --git a/docs/subaccounts/create-subaccount.md b/docs/subaccounts/create-subaccount.md deleted file mode 100644 index 93d7eae..0000000 --- a/docs/subaccounts/create-subaccount.md +++ /dev/null @@ -1,26 +0,0 @@ -# Create a subaccount - -> Create a collection subaccount - -```php - '0690000034', - 'account_bank' => '044', - 'business_name' => 'Christian Jombo and Sons', - 'business_mobile' => '08000000000', - 'split_type' => 'flat', - 'split_value' => 1000 -]; - -$subaccount = Flutterwave::subaccounts()->create($data); - -dd($subaccount); -``` - -## Parameters - -| Parameter | Required | Description | -| --------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| 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). | -| 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. | diff --git a/docs/subaccounts/delete-subaccount.md b/docs/subaccounts/delete-subaccount.md deleted file mode 100644 index 592dfc3..0000000 --- a/docs/subaccounts/delete-subaccount.md +++ /dev/null @@ -1,13 +0,0 @@ -# Delete a subaccount - -> Delete a collection subaccount. - -```php -destroy($subaccountId); - - dd($subaccount); -``` diff --git a/docs/subaccounts/fetch-subaccount.md b/docs/subaccounts/fetch-subaccount.md deleted file mode 100644 index b74db6b..0000000 --- a/docs/subaccounts/fetch-subaccount.md +++ /dev/null @@ -1,13 +0,0 @@ -# Fetch a subaccount - -> Get a single collection subaccount details. - -```php -fetch($subaccountId); - - dd($subaccount); -``` diff --git a/docs/subaccounts/list-subaccounts.md b/docs/subaccounts/list-subaccounts.md deleted file mode 100644 index c5c3113..0000000 --- a/docs/subaccounts/list-subaccounts.md +++ /dev/null @@ -1,26 +0,0 @@ -# List all subaccounts - -> Fetch all subaccounts on your account. - -```php - 1 - ]; - - // $data is optional - $subaccounts = Flutterwave::subaccounts()->fetchAll($data); - - dd($subaccounts); -``` - - -## Parameters - -| Parameter | Required | Description | -| --------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| page | False | This allows you fetch from a specific page e.g. setting page to 1 fetches the first page. | -| account_bank | False | This is the sub-accounts bank ISO code | -| account_number | False | This is the account number associated with the subaccount you want to fetch | -| bank_name | False | This is the name of the bank associated with the ISO code provided in account_bankfield | diff --git a/resources/config/flutterwave.php b/resources/config/flutterwave.php index f5468a8..f3af081 100755 --- a/resources/config/flutterwave.php +++ b/resources/config/flutterwave.php @@ -28,12 +28,4 @@ * */ 'secretHash' => env('FLW_SECRET_HASH', ''), - - /** - * Encryption Key: Your Rave encryptionKey. Sign up on https://dashboard.flutterwave.com/ to get one from your settings page - * - */ - 'encryptionKey' => env('FLW_ENCRYPTION_KEY', ''), - - ]; diff --git a/src/Facades/Rave.php b/src/Facades/Rave.php index ffc3e12..dc11e6b 100755 --- a/src/Facades/Rave.php +++ b/src/Facades/Rave.php @@ -12,27 +12,7 @@ namespace KingFlamez\Rave\Facades; use Illuminate\Support\Facades\Facade; -use KingFlamez\Rave\Helpers\Banks; -use KingFlamez\Rave\Helpers\Beneficiary; -use KingFlamez\Rave\Helpers\Payments; -use KingFlamez\Rave\Helpers\Transfers; -/** - * Class Rave - * - * @method static string generateReference(String $transactionPrefix = null) - * @method static object initializePayment(array $data) - * @method static string getTransactionIDFromCallback() - * @method static object verifyTransaction(string $transactionId) - * @method static bool verifyWebhook() - * @method static Payments payments() - * @method static Banks banks() - * @method static Transfers transfers() - * @method static Beneficiary beneficiaries() - * - * @see \KingFlamez\Rave\Rave - * - */ class Rave extends Facade { /** diff --git a/src/Helpers/Bills.php b/src/Helpers/Bills.php new file mode 100644 index 0000000..6d16b66 --- /dev/null +++ b/src/Helpers/Bills.php @@ -0,0 +1,110 @@ + + * @version 3 + **/ +class Bills +{ + + protected $publicKey; + protected $secretKey; + protected $baseUrl; + + /** + * Construct + */ + function __construct(String $publicKey, String $secretKey, String $baseUrl) + { + $this->publicKey = $publicKey; + $this->secretKey = $secretKey; + $this->baseUrl = $baseUrl; + } + + + /** + * Initiate a Bill payment + * @param $data + * @return object + */ + public function initiate(array $data) + { + return $data; + $bill = Http::withToken($this->secretKey)->post( + $this->baseUrl . '/bills', + $data + )->json(); + + return $bill; + } + + + /** + * Initiate a bulk transfer + * @param $data + * @return object + */ + public function get_categories(array $data=[]) + { + $bills_categories = Http::withToken($this->secretKey)->get( + $this->baseUrl . '/bill-categories', + $data + )->json(); + + return $bills_categories; + } + + + /** + * Validate bill payment + * @param $item_code, array $data + * @return object + */ + public function validate(string $item_code, array $data) + { + $validate = Http::withToken($this->secretKey)->get( + $this->baseUrl . "/bill-items/$item_code/validate", + $data + )->json(); + + return $validate; + } + + + /** + * Get All bills payment history + * @param $data + * @return object + */ + public function fetchAll(array $data = []) + { + $bills = Http::withToken($this->secretKey)->get( + $this->baseUrl . '/bills', + $data + )->json(); + + return $bills; + } + + + /** + * Get A Bill payment status + * @param $reference + * @return object + */ + public function fetch_status($reference) + { + $status = Http::withToken($this->secretKey)->get( + $this->baseUrl . '/bills/'.$reference + )->json(); + + return $status; + } + +} diff --git a/src/Helpers/Helper.php b/src/Helpers/Helper.php deleted file mode 100644 index 484c437..0000000 --- a/src/Helpers/Helper.php +++ /dev/null @@ -1,25 +0,0 @@ - - * @version 3 - **/ -class Helper -{ - - // public static function encryption($key, $data) - // { - // //encode the data and the - // return self::encrypt3Des($data, $key); - // } - - public static function encrypt3Des(array $data, $key) - { - $encData = openssl_encrypt(json_encode($data), 'DES-EDE3', $key, OPENSSL_RAW_DATA); - return base64_encode($encData); - } - -} \ No newline at end of file diff --git a/src/Helpers/Payments.php b/src/Helpers/Payments.php index 5f5e9c5..c812c56 100644 --- a/src/Helpers/Payments.php +++ b/src/Helpers/Payments.php @@ -20,13 +20,12 @@ class Payments /** * Construct */ - function __construct(String $publicKey, String $secretKey, String $baseUrl, $encryptionKey = '') + function __construct(String $publicKey, String $secretKey, String $baseUrl) { $this->publicKey = $publicKey; $this->secretKey = $secretKey; $this->baseUrl = $baseUrl; - $this->encryptionKey = $encryptionKey; } @@ -219,32 +218,4 @@ public function momoFranc(array $data) return $payment; } - - /** - * Charge via Card - * @param $data - * @return object - */ - public function card(array $data) - { - $encryptedData = []; - $encryptedData['client'] = Helper::encrypt3Des($data, $this->encryptionKey); - - $payment = Http::withToken($this->secretKey)->post( - $this->baseUrl . '/charges?type=card', - $encryptedData - )->json(); - - if ($payment['status'] === 'success') { - $result = [ - 'status' => $payment['status'], - 'message' => $payment['message'], - 'data' => $payment['meta']['authorization'], - ]; - $result['data']['flw_ref'] = $payment['data']['flw_ref']; - return $result; - } - - return $payment; - } } diff --git a/src/Helpers/Subaccount.php b/src/Helpers/Subaccount.php deleted file mode 100644 index a015e07..0000000 --- a/src/Helpers/Subaccount.php +++ /dev/null @@ -1,114 +0,0 @@ - - * @version 3 - **/ -class Subaccount -{ - - protected $publicKey; - protected $secretKey; - protected $baseUrl; - - /** - * Construct - */ - function __construct(String $publicKey, String $secretKey, String $baseUrl) - { - - $this->publicKey = $publicKey; - $this->secretKey = $secretKey; - $this->baseUrl = $baseUrl; - } - - - /** - * Create a subaccount - * @param $data - * @return object - */ - public function create(array $data) - { - $subaccount = Http::withToken($this->secretKey)->post( - $this->baseUrl . '/subaccounts', - $data - )->json(); - - return $subaccount; - } - - - /** - * Update a subaccount - * @param $id, $data - * @return object - */ - public function update($id, array $data) - { - $subaccount = Http::withToken($this->secretKey)->put( - $this->baseUrl . '/subaccounts/'.$id, - $data - )->json(); - - return $subaccount; - } - - - - - /** - * Get All Subaccounts - * @param $data - * @return object - */ - public function fetchAll(array $data = []) - { - $subaccounts = Http::withToken($this->secretKey)->get( - $this->baseUrl . '/subaccounts', - $data - )->json(); - - return $subaccounts; - } - - - - - /** - * Get A subaccount - * @param $id - * @return object - */ - public function fetch($id) - { - $subaccount = Http::withToken($this->secretKey)->get( - $this->baseUrl . '/subaccounts/' . $id - )->json(); - - return $subaccount; - } - - - - - /** - * Delete A subaccount - * @param $id - * @return object - */ - public function destroy($id) - { - $subaccount = Http::withToken($this->secretKey)->delete( - $this->baseUrl . '/subaccounts/' . $id - )->json(); - - return $subaccount; - } -} diff --git a/src/Helpers/Verification.php b/src/Helpers/Verification.php deleted file mode 100644 index 49c845e..0000000 --- a/src/Helpers/Verification.php +++ /dev/null @@ -1,93 +0,0 @@ - - * @version 3 - **/ -class Verification -{ - - protected $publicKey; - protected $secretKey; - protected $baseUrl; - - /** - * Construct - */ - function __construct(String $publicKey, String $secretKey, String $baseUrl) - { - - $this->publicKey = $publicKey; - $this->secretKey = $secretKey; - $this->baseUrl = $baseUrl; - } - - - /** - * Confirm bank account - * @param $data - * @return object - */ - public function account(array $data) - { - - $account = Http::withToken($this->secretKey)->post( - $this->baseUrl . '/accounts/resolve', - $data - )->json(); - - return $account; - } - - - /** - * Verify BVN - * @param $bvn - * @return object - */ - public function bvn($bvn) - { - $bvn = Http::withToken($this->secretKey)->get( - $this->baseUrl . '/kyc/bvns/' . $bvn - )->json(); - - return $bvn; - } - - /** - * Verify reference - * @param $reference - * @return object - */ - public function transaction($reference) - { - $transaction = Http::withToken($this->secretKey)->get( - $this->baseUrl . '/transactions/' . $reference . 'verify' - )->json(); - - return $transaction; - } - - /** - * Verify Card bin - * @param $bin - * @return object - */ - public function CardBin($bin) - { - $card = Http::withToken($this->secretKey)->get( - $this->baseUrl . '/card-bins/' . $bin - )->json(); - - return $card; - } - - - -} diff --git a/src/Rave.php b/src/Rave.php index dc1f12c..d721397 100755 --- a/src/Rave.php +++ b/src/Rave.php @@ -6,10 +6,9 @@ use Illuminate\Support\Facades\Http; use KingFlamez\Rave\Helpers\Banks; use KingFlamez\Rave\Helpers\Beneficiary; +use KingFlamez\Rave\Helpers\Bills; use KingFlamez\Rave\Helpers\Payments; use KingFlamez\Rave\Helpers\Transfers; -use KingFlamez\Rave\Helpers\Verification; -use KingFlamez\Rave\Helpers\Subaccount; /** * Flutterwave's Rave payment laravel package @@ -32,7 +31,6 @@ function __construct() $this->publicKey = config('flutterwave.publicKey'); $this->secretKey = config('flutterwave.secretKey'); $this->secretHash = config('flutterwave.secretHash'); - $this->encryptionKey = config('flutterwave.encryptionKey'); $this->baseUrl = 'https://api.flutterwave.com/v3'; } @@ -83,22 +81,6 @@ public function getTransactionIDFromCallback() return $transactionID; } - /** - * Reaches out to Flutterwave to validate a charge - * @param $data - * @return object - */ - public function validateCharge(array $data) - { - - $payment = Http::withToken($this->secretKey)->post( - $this->baseUrl . '/validate-charge', - $data - )->json(); - - return $payment; - } - /** * Reaches out to Flutterwave to verify a transaction * @param $id @@ -136,7 +118,7 @@ public function verifyWebhook() */ public function payments() { - $payments = new Payments($this->publicKey, $this->secretKey, $this->baseUrl, $this->encryptionKey); + $payments = new Payments($this->publicKey, $this->secretKey, $this->baseUrl); return $payments; } @@ -170,24 +152,13 @@ public function beneficiaries() return $beneficiary; } - /** - * Verification - * @return Verification - */ - public function verification() - { - $verification = new Verification($this->publicKey, $this->secretKey, $this->baseUrl); - return $verification; - } - /** - * Subaccounts - * @return Subaccount + * Bill payments + * @return Bills */ - public function subaccounts() + public function bill() { - $subaccount = new Subaccount($this->publicKey, $this->secretKey, $this->baseUrl); - return $subaccount; + $bills = new Bills($this->publicKey, $this->secretKey, $this->baseUrl); + return $bills; } - } diff --git a/src/RaveServiceProvider.php b/src/RaveServiceProvider.php index 0c72cac..e3fa02c 100755 --- a/src/RaveServiceProvider.php +++ b/src/RaveServiceProvider.php @@ -31,9 +31,7 @@ public function register() { $this->app->singleton('laravelrave', function ($app) { - return new Rave($app->make("request")); - }); $this->app->alias('laravelrave', "KingFlamez\Rave\Rave");