diff --git a/README.md b/README.md
index 7e574d4..ddd14d3 100644
--- a/README.md
+++ b/README.md
@@ -106,8 +106,7 @@ include('library/rave.php');
include('library/raveEventHandlerInterface.php');
-use Flutterwave\Rave;
-use Flutterwave\EventHandlerInterface;
+use Flutterwave\EventHandlers\EventHandlers\EventHandlers\EventHandlers\EventHandlers\Rave;
$URL = (isset($_SERVER['HTTPS']) ? 'https' : 'http') . '://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
@@ -306,7 +305,7 @@ The following implementation shows how to initiate a direct bank charge. Use the
```php
require("Flutterwave-Rave-PHP-SDK/library/AccountPayment.php");
-use Flutterwave\Account;
+use Flutterwave\EventHandlers\EventHandlers\EventHandlers\EventHandlers\EventHandlers\AccountPayment;
//The data variable holds the payload
$data = array(
@@ -325,7 +324,7 @@ $data = array(
]
);
-$payment = new Account();
+$payment = new AccountPayment();
$result = $payment->accountCharge($data);
if(isset($result['data'])){
@@ -342,7 +341,7 @@ The following implementation shows how to accept payments directly from customer
```php
require("Flutterwave-Rave-PHP-SDK/library/AchPayment.php");
-use Flutterwave\Ach;
+use Flutterwave\EventHandlers\EventHandlers\EventHandlers\EventHandlers\EventHandlers\AchPayment;
// The data variable holds the payload
$data = array(
@@ -357,7 +356,7 @@ $data = array(
"redirect_url" => "http://ekene.com/u/payment-completed",
);
-$payment = new Ach();
+$payment = new AchPayment();
$result = $payment->achCharge($data);
if(isset($result['data'])){
@@ -376,7 +375,7 @@ The following implementation shows how to initiate a card charge. Use the Playgr
```php
require("Flutterwave-Rave-PHP-SDK/library/CardPayment.php");
-use Flutterwave\Card;
+use Flutterwave\EventHandlers\EventHandlers\EventHandlers\EventHandlers\EventHandlers\CardPayment;
//The data variable holds the payload
$data = array(
@@ -395,7 +394,7 @@ $data = array(
);
-$payment = new Card();
+$payment = new CardPayment();
$res = $payment->cardCharge($data);//This call is to figure out the authmodel
$data['authorization']['mode'] = $res['meta']['authorization']['mode'];
@@ -432,9 +431,10 @@ if($result['data']['auth_mode'] == 'otp'){
### Mobile Money Payments
The following implementation shows how to initiate a mobile money payment. Use the Playground Directory to view Responses and samples of use.
+
```php
require("Flutterwave-Rave-PHP-SDK/library/MobileMoney.php");
-use Flutterwave\MobileMoney
+use Flutterwave\EventHandlers\EventHandlers\EventHandlers\EventHandlers\EventHandlers\MobileMoney;
// The data variable holds the payload
$data = array(
@@ -466,7 +466,7 @@ Collect payments via ussd
```php
require("Flutterwave-Rave-PHP-SDK/library/Ussd.php");
-use Flutterwave\Ussd;
+use Flutterwave\EventHandlers\EventHandlers\EventHandlers\EventHandlers\EventHandlers\Ussd;
//The data variable holds the payload
$data = array(
"tx_ref" => "MC-15852309v5050e8",
@@ -502,7 +502,7 @@ Collect payments from your customers via Mpesa.
```php
require("Flutterwave-Rave-PHP-SDK/library/Mpesa.php");
-use Flutterwave\Mpesa;
+use Flutterwave\EventHandlers\EventHandlers\EventHandlers\EventHandlers\EventHandlers\Mpesa;
$data = array(
"amount" => "1500",
@@ -535,7 +535,7 @@ How to make a transfer payment
```php
require("Flutterwave-Rave-PHP-SDK/library/Transfer.php");
-use Flutterwave\Transfer;
+use Flutterwave\EventHandlers\EventHandlers\EventHandlers\EventHandlers\EventHandlers\Transfer;
// sample payload for payBill()
$data = array(
@@ -606,7 +606,7 @@ The following implementation shows how to create virtual cards on rave. Use the
```php
require("Flutterwave-Rave-PHP-SDK/library/VirtualCards.php");
-use Flutterwave\VirtualCard;
+use Flutterwave\EventHandlers\EventHandlers\EventHandlers\EventHandlers\EventHandlers\VirtualCard;
$data = array(
"currency"=>"NGN",
@@ -645,7 +645,7 @@ The following implementation shows how to verify a Bank Verification Number.
```php
require("Flutterwave-Rave-PHP-SDK/library/Bvn.php");
-use Flutterwave\Bvn;
+use Flutterwave\EventHandlers\EventHandlers\EventHandlers\EventHandlers\EventHandlers\Bvn;
//The data variable holds the payload
$bvn_number = "123456789";
$bvn = new Bvn();
@@ -661,7 +661,7 @@ The following implementation shows how to create a payment plan on the rave dash
```php
require("Flutterwave-Rave-PHP-SDK/library/PaymentPlan.php");
-use Flutterwave\PaymentPlan;
+use Flutterwave\EventHandlers\EventHandlers\EventHandlers\EventHandlers\EventHandlers\PaymentPlan;
//sample payload for payBill()
$data = array(
@@ -687,9 +687,10 @@ print_r($result);
The following implementation shows how to create a subaccount on the rave dashboard
Use the Playground Directory to view Responses and samples of use.
+
```php
require("Flutterwave-Rave-PHP-SDK/library/Subaccount.php");
-use Flutterwave\Subaccount;
+use Flutterwave\EventHandlers\EventHandlers\EventHandlers\EventHandlers\EventHandlers\Subaccount;
$data = array(
"account_bank"=> "044",
@@ -730,7 +731,7 @@ The following implementation shows how to create a transfer recipient on the rav
```php
require("Flutterwave-Rave-PHP-SDK/library/Recipient.php");
-use Flutterwave\Recipient;
+use Flutterwave\EventHandlers\EventHandlers\EventHandlers\EventHandlers\EventHandlers\Recipient;
$data = array(
"account_bank"=> "044",
@@ -759,7 +760,7 @@ The following implementation shows how to activate a subscription, fetch a subsc
```php
require("Flutterwave-Rave-PHP-SDK/library/Subscription.php");
-use Flutterwave\Subscription;
+use Flutterwave\EventHandlers\EventHandlers\EventHandlers\EventHandlers\EventHandlers\Subscription;
$id = 1112 //Id of subscription plan
//$cid = 2222
@@ -780,7 +781,7 @@ visit: https://developer.flutterwave.com/v3.0/reference#buy-airtime-bill
```php
require("Flutterwave-Rave-PHP-SDK/library/Bill.php");
-use Flutterwave\Bill;
+use Flutterwave\EventHandlers\EventHandlers\EventHandlers\EventHandlers\EventHandlers\Bill;
$data = array(
"country"=> "NG",
@@ -836,7 +837,7 @@ The following implementation shows how to create a electronic receipt.
```php
require("Flutterwave-Rave-PHP-SDK/library/Ebill.php");
-use Flutterwave\Ebill;
+use Flutterwave\EventHandlers\EventHandlers\EventHandlers\EventHandlers\EventHandlers\Ebill;
$data = array(
"narration"=> "mndkn blls",
@@ -870,7 +871,7 @@ https://developer.flutterwave.com/reference#create-a-virtual-account-number
```php
require("Flutterwave-Rave-PHP-SDK/library/VirtualAccount.php");
-use Flutterwave\VirtualAccount;
+use Flutterwave\EventHandlers\EventHandlers\EventHandlers\EventHandlers\EventHandlers\VirtualAccount;
//sample payload for payBill()
$data = array(
@@ -910,7 +911,7 @@ Once the charge and validation process is complete for the first charge on the c
```php
require("Flutterwave-Rave-PHP-SDK/library/TokenizedCharge.php");
-use Flutterwave\TokenizedCharge;
+use Flutterwave\EventHandlers\EventHandlers\EventHandlers\EventHandlers\EventHandlers\TokenizedCharge;
$data = array(
"token"=> "flw-t1nf-1ff187b04cecb4acff4ac62c2b6f7784-m03k",
@@ -937,7 +938,7 @@ List all transactions on your account. You could do a specific query using ```cu
```php
require("Flutterwave-Rave-PHP-SDK/library/Transactions.php");
-use Flutterwave\Transactions;
+use Flutterwave\EventHandlers\EventHandlers\EventHandlers\EventHandlers\EventHandlers\Transactions;
$data = array(
'amount'=> 1000
@@ -965,7 +966,7 @@ Collect ZAR payments offline using Vouchers
```php
require("Flutterwave-Rave-PHP-SDK/library/VoucherPayment.php");
-use Flutterwave\VoucherPayment;
+use Flutterwave\EventHandlers\EventHandlers\EventHandlers\EventHandlers\EventHandlers\VoucherPayment;
//The data variable holds the payload
$data = array(
//"public_key": "FLWPUBK-6c4e3dcb21282d44f907c9c9ca7609cb-X"//you can ommit the public key as the key is take from your .env file
diff --git a/composer.json b/composer.json
index ab0761d..a8a6c6a 100644
--- a/composer.json
+++ b/composer.json
@@ -6,7 +6,7 @@
"homepage": "https://github.com/Flutterwave/Flutterwave-PHP-v3",
"autoload": {
"psr-4": {
- "Flutterwave\\": "library/Rave"
+ "Flutterwave\\": "library/"
}
},
"require": {
diff --git a/library/AccountPayment.php b/library/AccountPayment.php
index 1ff5cd3..e698c3a 100644
--- a/library/AccountPayment.php
+++ b/library/AccountPayment.php
@@ -4,90 +4,9 @@
//uncomment if you need this
//define("BASEPATH", 1);//Allow direct access to rave.php and raveEventHandler.php
-require_once('rave.php');
-require_once('raveEventHandlerInterface.php');
-require_once('EventTracker.php');
+use Flutterwave\EventHandlers\AccountEventHandler;
-class accountEventHandler implements EventHandlerInterface
-{
- use EventTracker;
- /**
- * This is called only when a transaction is successful
- * */
-
- function onSuccessful($transactionData)
- {
- // 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
- // Comfirm that the transaction is successful
- // Confirm that the chargecode is 00 or 0
- // 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 (includeing parameters that didn't exist before the transaction is completed. for audit purpose)
- // Give value for the transaction
- // Update the transaction to note that you have given value for the transaction
- // You can also redirect to your success page from here
- if ($transactionData["data"]["chargecode"] === '00' || $transactionData["data"]["chargecode"] === '0') {
- self::sendAnalytics("Initiate-Account-charge");
- echo "Transaction Completed";
- } else {
-
- $this->onFailure($transactionData);
- }
- }
-
- /**
- * This is called only when a transaction failed
- * */
- function onFailure($transactionData)
- {
- self::sendAnalytics("Initiate-Account-charge-error");
- // Get the transaction from your DB using the transaction reference (txref)
- // Update the db transaction record (includeing parameters that didn't exist before the transaction is completed. for audit purpose)
- // You can also redirect to your failure page from here
-
- }
-
- /**
- * This is called when a transaction is requeryed from the payment gateway
- * */
- function onRequery($transactionReference)
- {
- // Do something, anything!
- }
-
- /**
- * This is called a transaction requery returns with an error
- * */
- function onRequeryError($requeryResponse)
- {
- // Do something, anything!
- }
-
- /**
- * This is called when a transaction is canceled by the user
- * */
- function onCancel($transactionReference)
- {
- // Do something, anything!
- // Note: Somethings a payment can be successful, before a user clicks the cancel button so proceed with caution
-
- }
-
- /**
- * This is called when a transaction doesn't return with a success or a failure response. This can be a timedout transaction on the Rave server or an abandoned transaction by the customer.
- * */
- function onTimeout($transactionReference, $data)
- {
- // Get the transaction from your DB using the transaction reference (txref)
- // Queue it for requery. Preferably using a queue system. The requery should be about 15 minutes after.
- // Ask the customer to contact your support and you should escalate this issue to the flutterwave support team. Send this as an email and as a notification on the page. just incase the page timesout or disconnects
-
- }
-}
-
-
-class Account
+class AccountPayment
{
protected $payment;
@@ -103,7 +22,7 @@ function accountCharge($array)
//set the payment handler
//add tx_ref to the paylaod
- if (!isset($array['tx_ref']) || empty($array['tx_ref'])) {
+ if (empty($array['tx_ref'])) {
$array['tx_ref'] = $this->payment->txref;
} else {
$this->payment->txref = $array['tx_ref'];
@@ -117,7 +36,7 @@ function accountCharge($array)
}
- $this->payment->eventHandler(new accountEventHandler);
+ $this->payment->eventHandler(new AccountEventHandler);
//set the endpoint for the api call
if ($this->type === $this->type[0]) {
$this->payment->setEndPoint("v3/charges?type=debit_uk_account");
@@ -125,9 +44,9 @@ function accountCharge($array)
$this->payment->setEndPoint("v3/charges?type=debit_ng_account");
}
- accountEventHandler::startRecording();
+ AccountEventHandler::startRecording();
$response = $this->payment->chargePayment($array);
- accountEventHandler::sendAnalytics('Initiate-Account-Charge');
+ AccountEventHandler::sendAnalytics('Initiate-Account-Charge');
return $response;
}
@@ -135,7 +54,7 @@ function accountCharge($array)
function validateTransaction($otp, $ref)
{
//validate the charge
- $this->payment->eventHandler(new accountEventHandler);
+ $this->payment->eventHandler(new AccountEventHandler);
return $this->payment->validateTransaction($otp, $ref, $this->payment->type);//Uncomment this line if you need it
@@ -155,4 +74,4 @@ function verifyTransaction($id)
}
-?>
+
diff --git a/library/AchPayment.php b/library/AchPayment.php
index f80172e..49776ee 100644
--- a/library/AchPayment.php
+++ b/library/AchPayment.php
@@ -4,90 +4,10 @@
//uncomment if you need this
//define("BASEPATH", 1);//Allow direct access to rave.php and raveEventHandler.php
-require_once('rave.php');
-require_once('raveEventHandlerInterface.php');
-require_once('EventTracker.php');
+use Flutterwave\EventHandlers\AchEventHandler;
-class achEventHandler implements EventHandlerInterface
-{
- use EventTracker;
-
- /**
- * This is called only when a transaction is successful
- * @param array
- * */
- function onSuccessful($transactionData)
- {
- // 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
- // Comfirm that the transaction is successful
- // Confirm that the chargecode is 00 or 0
- // 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 (includeing parameters that didn't exist before the transaction is completed. for audit purpose)
- // Give value for the transaction
- // Update the transaction to note that you have given value for the transaction
- // You can also redirect to your success page from here
- if ($transactionData["data"]["chargecode"] === '00' || $transactionData["data"]["chargecode"] === '0') {
- self::sendAnalytics("Initiate-Ach-Payment");
- echo "Transaction Completed";
- } else {
- $this->onFailure($transactionData);
- }
- }
-
- /**
- * This is called only when a transaction failed
- * */
- function onFailure($transactionData)
- {
- self::sendAnalytics("Initiate-Ach-Payment-error");
- // Get the transaction from your DB using the transaction reference (txref)
- // Update the db transaction record (includeing parameters that didn't exist before the transaction is completed. for audit purpose)
- // You can also redirect to your failure page from here
-
- }
-
- /**
- * This is called when a transaction is requeryed from the payment gateway
- * */
- function onRequery($transactionReference)
- {
- // Do something, anything!
- }
-
- /**
- * This is called a transaction requery returns with an error
- * */
- function onRequeryError($requeryResponse)
- {
- // Do something, anything!
- }
-
- /**
- * This is called when a transaction is canceled by the user
- * */
- function onCancel($transactionReference)
- {
- // Do something, anything!
- // Note: Somethings a payment can be successful, before a user clicks the cancel button so proceed with caution
-
- }
-
- /**
- * This is called when a transaction doesn't return with a success or a failure response. This can be a timedout transaction on the Rave server or an abandoned transaction by the customer.
- * */
- function onTimeout($transactionReference, $data)
- {
- // Get the transaction from your DB using the transaction reference (txref)
- // Queue it for requery. Preferably using a queue system. The requery should be about 15 minutes after.
- // Ask the customer to contact your support and you should escalate this issue to the flutterwave support team. Send this as an email and as a notification on the page. just incase the page timesout or disconnects
-
- }
-}
-
-class Ach
+class AchPayment
{
protected $payment;
@@ -101,7 +21,7 @@ function __construct()
function achCharge($array)
{
- if (!isset($array['tx_ref']) || empty($array['tx_ref'])) {
+ if (empty($array['tx_ref'])) {
$array['tx_ref'] = $this->payment->txref;
} else {
$this->payment->txref = $array['tx_ref'];
@@ -109,15 +29,15 @@ function achCharge($array)
$this->payment->type = 'ach_payment';
//set the payment handler
- $this->payment->eventHandler(new achEventHandler)
+ $this->payment->eventHandler(new AchEventHandler)
//set the endpoint for the api call
->setEndPoint("v3/charges?type=" . $this->payment->type);
//returns the value from the results
//$result = $this->payment->chargePayment($array);
- achEventHandler::startRecording();
+ AchEventHandler::startRecording();
$result = $this->payment->chargePayment($array);
- achEventHandler::sendAnalytics('Initiate-Ach-Payment');
+ AchEventHandler::sendAnalytics('Initiate-Ach-Payment');
return $result;
//change this
@@ -133,5 +53,3 @@ function verifyTransaction($id)
}
-
-?>
diff --git a/library/Bill.php b/library/Bill.php
index f684ca1..1b07480 100644
--- a/library/Bill.php
+++ b/library/Bill.php
@@ -2,89 +2,8 @@
namespace Flutterwave;
-require_once('rave.php');
-require_once('raveEventHandlerInterface.php');
-require_once('EventTracker.php');
-class billEventHandler implements EventHandlerInterface
-{
-
- use EventTracker;
-
- /**
- * This is called only when a transaction is successful
- * */
- function onSuccessful($transactionData)
- {
- // 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
- // Comfirm that the transaction is successful
- // Confirm that the chargecode is 00 or 0
- // 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 (includeing parameters that didn't exist before the transaction is completed. for audit purpose)
- // Give value for the transaction
- // Update the transaction to note that you have given value for the transaction
- // You can also redirect to your success page from here
- if ($transactionData["data"]["chargecode"] === '00' || $transactionData["data"]["chargecode"] === '0') {
- self::sendAnalytics("Bills");
- echo "Transaction Completed";
- } else {
- $this->onFailure($transactionData);
- }
- }
-
- /**
- * This is called only when a transaction failed
- * */
- function onFailure($transactionData)
- {
- self::sendAnalytics("Bills-error");
- // Get the transaction from your DB using the transaction reference (txref)
- // Update the db transaction record (includeing parameters that didn't exist before the transaction is completed. for audit purpose)
- // You can also redirect to your failure page from here
-
- }
-
- /**
- * This is called when a transaction is requeryed from the payment gateway
- * */
- function onRequery($transactionReference)
- {
- // Do something, anything!
- }
-
- /**
- * This is called a transaction requery returns with an error
- * */
- function onRequeryError($requeryResponse)
- {
- // Do something, anything!
- }
-
- /**
- * This is called when a transaction is canceled by the user
- * */
- function onCancel($transactionReference)
- {
- // Do something, anything!
- // Note: Somethings a payment can be successful, before a user clicks the cancel button so proceed with caution
-
- }
-
- /**
- * This is called when a transaction doesn't return with a success or a failure response. This can be a timedout transaction on the Rave server or an abandoned transaction by the customer.
- * */
- function onTimeout($transactionReference, $data)
- {
- // Get the transaction from your DB using the transaction reference (txref)
- // Queue it for requery. Preferably using a queue system. The requery should be about 15 minutes after.
- // Ask the customer to contact your support and you should escalate this issue to the flutterwave support team. Send this as an email and as a notification on the page. just incase the page timesout or disconnects
-
- }
-
-
-}
+use Flutterwave\EventHandlers\BillEventHandler;
class Bill
{
@@ -167,13 +86,13 @@ function payBill($array)
break;
}
- $this->payment->eventHandler(new billEventHandler)
+ $this->payment->eventHandler(new BillEventHandler)
//set the endpoint for the api call
->setEndPoint("v3/bills");
- billEventHandler::startRecording();
+ BillEventHandler::startRecording();
$response = $this->payment->bill($array);
- billEventHandler::sendAnalytics("Pay-Bills");
+ BillEventHandler::sendAnalytics("Pay-Bills");
return $response;
}
@@ -186,12 +105,12 @@ function bulkBill($array)
';
}
- $this->payment->eventHandler(new billEventHandler)
+ $this->payment->eventHandler(new BillEventHandler)
->setEndPoint('v3/bulk-bills');
- billEventHandler::startRecording();
+ BillEventHandler::startRecording();
$response = $this->payment->bulkBills($array);
- billEventHandler::sendAnalytics("Pay-Bulk-Bills");
+ BillEventHandler::sendAnalytics("Pay-Bulk-Bills");
return $response;
}
@@ -199,7 +118,7 @@ function bulkBill($array)
function getBill($array)
{
- $this->payment->eventHandler(new billEventHandler);
+ $this->payment->eventHandler(new BillEventHandler);
if (array_key_exists('reference', $array) && !array_key_exists('from', $array)) {
echo "Im here";
@@ -216,9 +135,9 @@ function getBill($array)
}
}
- billEventHandler::startRecording();
+ BillEventHandler::startRecording();
$response = $this->payment->getBill($array);
- billEventHandler::sendAnalytics("Get-Bills");
+ BillEventHandler::sendAnalytics("Get-Bills");
return $response;
}
@@ -227,24 +146,24 @@ function getBillCategories()
{
- $this->payment->eventHandler(new billEventHandler)
+ $this->payment->eventHandler(new BillEventHandler)
->setEndPoint('v3');
- billEventHandler::startRecording();
+ BillEventHandler::startRecording();
$response = $this->payment->getBillCategories();
- billEventHandler::sendAnalytics("Get-Bill-Categories");
+ BillEventHandler::sendAnalytics("Get-Bill-Categories");
return $response;
}
function getAgencies()
{
- $this->payment->eventHandler(new billEventHandler)
+ $this->payment->eventHandler(new BillEventHandler)
->setEndPoint('v3');
- billEventHandler::startRecording();
+ BillEventHandler::startRecording();
$response = $this->payment->getBillers();
- billEventHandler::sendAnalytics("Get-Billing-Agencies");
+ BillEventHandler::sendAnalytics("Get-Billing-Agencies");
return $response;
}
diff --git a/library/Bvn.php b/library/Bvn.php
new file mode 100644
index 0000000..66a482b
--- /dev/null
+++ b/library/Bvn.php
@@ -0,0 +1,33 @@
+bvn = new Rave($_ENV['SECRET_KEY']);
+ }
+
+ function verifyBVN($bvn)
+ {
+ //set the payment handler
+ $this->bvn->eventHandler(new BvnEventHandler)
+ //set the endpoint for the api call
+ ->setEndPoint("v3/kyc/bvns");
+ //returns the value from the results
+
+ BvnEventHandler::startRecording();
+ $response= $this->bvn->bvn($bvn);
+ BvnEventHandler::sendAnalytics("Verify-BVN");
+
+ return $response;
+ }
+}
diff --git a/library/CardPayment.php b/library/CardPayment.php
index 83b49a7..957e8b0 100644
--- a/library/CardPayment.php
+++ b/library/CardPayment.php
@@ -1,110 +1,28 @@
onFailure($transactionData);
- }
- }
-
- /**
- * This is called only when a transaction failed
- * */
- function onFailure($transactionData)
- {
- self::sendAnalytics("Initiate-Card-Payments-error");
- // Get the transaction from your DB using the transaction reference (txref)
- // Update the db transaction record (includeing parameters that didn't exist before the transaction is completed. for audit purpose)
- // You can also redirect to your failure page from here
-
- }
-
- /**
- * This is called when a transaction is requeryed from the payment gateway
- * */
- function onRequery($transactionReference)
- {
- // Do something, anything!
- }
-
- /**
- * This is called a transaction requery returns with an error
- * */
- function onRequeryError($requeryResponse)
- {
- // Do something, anything!
- }
-
- /**
- * This is called when a transaction is canceled by the user
- * */
- function onCancel($transactionReference)
- {
- // Do something, anything!
- // Note: Somethings a payment can be successful, before a user clicks the cancel button so proceed with caution
-
- }
-
- /**
- * This is called when a transaction doesn't return with a success or a failure response. This can be a timedout transaction on the Rave server or an abandoned transaction by the customer.
- * */
- function onTimeout($transactionReference, $data)
- {
- // Get the transaction from your DB using the transaction reference (txref)
- // Queue it for requery. Preferably using a queue system. The requery should be about 15 minutes after.
- // Ask the customer to contact your support and you should escalate this issue to the flutterwave support team. Send this as an email and as a notification on the page. just incase the page timesout or disconnects
-
- }
-}
+use Flutterwave\EventHandlers\CardEventHandler;
-class Card
+class CardPayment
{
protected $payment;
- function __construct()
- {
+ function __construct() {
$this->payment = new Rave($_ENV['SECRET_KEY']);
$this->valType = "card";
}
- function cardCharge($array)
- {
+ function cardCharge($array) {
// echo "
";
// print_r($array);
// echo "
";
// exit;
- if (!isset($array['tx_ref']) || empty($array['tx_ref'])) {
+ if (empty($array['tx_ref'])) {
$array['tx_ref'] = $this->payment->txref;
} else {
$this->payment->txref = $array['tx_ref'];
@@ -112,15 +30,15 @@ function cardCharge($array)
$this->payment->type = 'card';
//set the payment handler
- $this->payment->eventHandler(new cardEventHandler)
+ $this->payment->eventHandler(new CardEventHandler)
//set the endpoint for the api call
->setEndPoint("v3/charges?type=" . $this->payment->type);
//returns the value from the results
//$result = $this->payment->chargePayment($array);
- cardEventHandler::startRecording();
+ CardEventHandler::startRecording();
$result = $this->payment->chargePayment($array);
- cardEventHandler::setResponseTime();
+ CardEventHandler::setResponseTime();
return $result;
@@ -133,8 +51,7 @@ function cardCharge($array)
* You can write out your function to execute when the verification is successful in the onSuccessful function
***/
- function validateTransaction($element, $ref)
- {
+ function validateTransaction($element, $ref) {
//validate the charge
return $this->payment->validateTransaction($element, $ref, $this->payment->type);//Uncomment this line if you need it
@@ -142,13 +59,11 @@ function validateTransaction($element, $ref)
}
- function return_txref()
- {
+ function return_txref() {
return $this->payment->txref;
}
- function verifyTransaction($id)
- {
+ function verifyTransaction($id) {
//verify the charge
return $this->payment->verifyTransaction($id);//Uncomment this line if you need it
@@ -157,4 +72,3 @@ function verifyTransaction($id)
}
-?>
diff --git a/library/Ebill.php b/library/Ebill.php
index 2f22ff3..6a8205e 100644
--- a/library/Ebill.php
+++ b/library/Ebill.php
@@ -2,119 +2,56 @@
namespace Flutterwave;
-require_once('rave.php');
-require_once('raveEventHandlerInterface.php');
-
-use Flutterwave\Rave;
-use Flutterwave\EventHandlerInterface;
-
-class ebillEventHandler implements EventHandlerInterface{
- /**
- * This is called only when a transaction is successful
- * */
- function onSuccessful($transactionData){
- // 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
- // Comfirm that the transaction is successful
- // Confirm that the chargecode is 00 or 0
- // 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 (includeing parameters that didn't exist before the transaction is completed. for audit purpose)
- // Give value for the transaction
- // Update the transaction to note that you have given value for the transaction
- // You can also redirect to your success page from here
- }
-
- /**
- * This is called only when a transaction failed
- * */
- function onFailure($transactionData){
- // Get the transaction from your DB using the transaction reference (txref)
- // Update the db transaction record (includeing parameters that didn't exist before the transaction is completed. for audit purpose)
- // You can also redirect to your failure page from here
-
- }
-
- /**
- * This is called when a transaction is requeryed from the payment gateway
- * */
- function onRequery($transactionReference){
- // Do something, anything!
- }
-
- /**
- * This is called a transaction requery returns with an error
- * */
- function onRequeryError($requeryResponse){
- // Do something, anything!
- }
+use Flutterwave\EventHandlers\EbillEventHandler;
- /**
- * This is called when a transaction is canceled by the user
- * */
- function onCancel($transactionReference){
- // Do something, anything!
- // Note: Somethings a payment can be successful, before a user clicks the cancel button so proceed with caution
-
- }
-
- /**
- * This is called when a transaction doesn't return with a success or a failure response. This can be a timedout transaction on the Rave server or an abandoned transaction by the customer.
- * */
- function onTimeout($transactionReference, $data){
- // Get the transaction from your DB using the transaction reference (txref)
- // Queue it for requery. Preferably using a queue system. The requery should be about 15 minutes after.
- // Ask the customer to contact your support and you should escalate this issue to the flutterwave support team. Send this as an email and as a notification on the page. just incase the page timesout or disconnects
-
- }
-}
-
-class Ebill {
- function __construct(){
+class Ebill
+{
+ function __construct() {
$this->eb = new Rave($_ENV['SECRET_KEY']);
- $this->keys = array('amount', 'phone_number','country', 'ip','email');
+ $this->keys = array('amount', 'phone_number', 'country', 'ip', 'email');
}
- function order($array){
- if(!isset($array['tx_ref']) || empty($array['tx_ref'])){
+ function order($array) {
+
+ if (empty($array['tx_ref'])) {
$array['tx_ref'] = $this->payment->txref;
}
- if(!isset($array['amount']) || !isset($array['phone_number']) ||
- !isset($array['email']) || !isset($array['country']) || !isset($array['ip'])){
+ if (!isset($array['amount']) || !isset($array['phone_number']) ||
+ !isset($array['email']) || !isset($array['country']) || !isset($array['ip'])) {
return ' Error:
- Missing values for one of the following body params: "'.$this->keys[0].' ,
- '.$this->keys[1].' , '.$this->keys[2].' , '.$this->keys[3].' and '.$this->keys[4].'"
+ Missing values for one of the following body params: "' . $this->keys[0] . ' ,
+ ' . $this->keys[1] . ' , ' . $this->keys[2] . ' , ' . $this->keys[3] . ' and ' . $this->keys[4] . '"
';
}
- $this->eb->eventHandler(new ebillEventHandler)
- //set the endpoint for the api call
- ->setEndPoint("v3/ebills");
+ $this->eb->eventHandler(new EbillEventHandler)
+ //set the endpoint for the api call
+ ->setEndPoint("v3/ebills");
//returns the value of the result.
- return $this->eb->createOrder($array);
+ return $this->eb->createOrder($array);
}
- function updateOrder($data){
+ function updateOrder($data) {
- if(!isset($data['amount'])){
+ if (!isset($data['amount'])) {
return ' Error:
- Missing values for one of the following body params: "'.$this->keys[0].' '.'and reference'.'"
+ Missing values for one of the following body params: "' . $this->keys[0] . ' ' . 'and reference' . '"
';
}
- if(gettype($data['amount']) !== 'integer'){
- $data['amount'] = (int) $data['amount'];
+ if (gettype($data['amount']) !== 'integer') {
+ $data['amount'] = (int)$data['amount'];
}
- $this->eb->eventHandler(new ebillEventHandler)
- //set the endpoint for the api call
- ->setEndPoint("v3/ebills/".$data['reference']);
+ $this->eb->eventHandler(new EbillEventHandler)
+ //set the endpoint for the api call
+ ->setEndPoint("v3/ebills/" . $data['reference']);
//returns the value of the result.
- return $this->eb->updateOrder($data);
+ return $this->eb->updateOrder($data);
}
}
diff --git a/library/EventHandlers/AccountEventHandler.php b/library/EventHandlers/AccountEventHandler.php
new file mode 100644
index 0000000..71dd89e
--- /dev/null
+++ b/library/EventHandlers/AccountEventHandler.php
@@ -0,0 +1,76 @@
+onFailure($transactionData);
+ }
+ }
+
+ /**
+ * This is called only when a transaction failed
+ * */
+ function onFailure($transactionData) {
+ self::sendAnalytics("Initiate-Account-charge-error");
+ // Get the transaction from your DB using the transaction reference (txref)
+ // Update the db transaction record (includeing parameters that didn't exist before the transaction is completed. for audit purpose)
+ // You can also redirect to your failure page from here
+
+ }
+
+ /**
+ * This is called when a transaction is requeryed from the payment gateway
+ * */
+ function onRequery($transactionReference) {
+ // Do something, anything!
+ }
+
+ /**
+ * This is called a transaction requery returns with an error
+ * */
+ function onRequeryError($requeryResponse) {
+ // Do something, anything!
+ }
+
+ /**
+ * This is called when a transaction is canceled by the user
+ * */
+ function onCancel($transactionReference) {
+ // Do something, anything!
+ // Note: Somethings a payment can be successful, before a user clicks the cancel button so proceed with caution
+
+ }
+
+ /**
+ * This is called when a transaction doesn't return with a success or a failure response. This can be a timedout transaction on the Rave server or an abandoned transaction by the customer.
+ * */
+ function onTimeout($transactionReference, $data) {
+ // Get the transaction from your DB using the transaction reference (txref)
+ // Queue it for requery. Preferably using a queue system. The requery should be about 15 minutes after.
+ // Ask the customer to contact your support and you should escalate this issue to the flutterwave support team. Send this as an email and as a notification on the page. just incase the page timesout or disconnects
+
+ }
+}
\ No newline at end of file
diff --git a/library/EventHandlers/AchEventHandler.php b/library/EventHandlers/AchEventHandler.php
new file mode 100644
index 0000000..823e568
--- /dev/null
+++ b/library/EventHandlers/AchEventHandler.php
@@ -0,0 +1,75 @@
+onFailure($transactionData);
+ }
+ }
+
+ /**
+ * This is called only when a transaction failed
+ * */
+ function onFailure($transactionData) {
+ self::sendAnalytics("Initiate-Ach-Payment-error");
+ // Get the transaction from your DB using the transaction reference (txref)
+ // Update the db transaction record (includeing parameters that didn't exist before the transaction is completed. for audit purpose)
+ // You can also redirect to your failure page from here
+
+ }
+
+ /**
+ * This is called when a transaction is requeryed from the payment gateway
+ * */
+ function onRequery($transactionReference) {
+ // Do something, anything!
+ }
+
+ /**
+ * This is called a transaction requery returns with an error
+ * */
+ function onRequeryError($requeryResponse) {
+ // Do something, anything!
+ }
+
+ /**
+ * This is called when a transaction is canceled by the user
+ * */
+ function onCancel($transactionReference) {
+ // Do something, anything!
+ // Note: Somethings a payment can be successful, before a user clicks the cancel button so proceed with caution
+
+ }
+
+ /**
+ * This is called when a transaction doesn't return with a success or a failure response. This can be a timedout transaction on the Rave server or an abandoned transaction by the customer.
+ * */
+ function onTimeout($transactionReference, $data) {
+ // Get the transaction from your DB using the transaction reference (txref)
+ // Queue it for requery. Preferably using a queue system. The requery should be about 15 minutes after.
+ // Ask the customer to contact your support and you should escalate this issue to the flutterwave support team. Send this as an email and as a notification on the page. just incase the page timesout or disconnects
+
+ }
+}
\ No newline at end of file
diff --git a/library/EventHandlers/BillEventHandler.php b/library/EventHandlers/BillEventHandler.php
new file mode 100644
index 0000000..c300890
--- /dev/null
+++ b/library/EventHandlers/BillEventHandler.php
@@ -0,0 +1,77 @@
+onFailure($transactionData);
+ }
+ }
+
+ /**
+ * This is called only when a transaction failed
+ * */
+ function onFailure($transactionData) {
+ self::sendAnalytics("Bills-error");
+ // Get the transaction from your DB using the transaction reference (txref)
+ // Update the db transaction record (includeing parameters that didn't exist before the transaction is completed. for audit purpose)
+ // You can also redirect to your failure page from here
+
+ }
+
+ /**
+ * This is called when a transaction is requeryed from the payment gateway
+ * */
+ function onRequery($transactionReference) {
+ // Do something, anything!
+ }
+
+ /**
+ * This is called a transaction requery returns with an error
+ * */
+ function onRequeryError($requeryResponse) {
+ // Do something, anything!
+ }
+
+ /**
+ * This is called when a transaction is canceled by the user
+ * */
+ function onCancel($transactionReference) {
+ // Do something, anything!
+ // Note: Somethings a payment can be successful, before a user clicks the cancel button so proceed with caution
+
+ }
+
+ /**
+ * This is called when a transaction doesn't return with a success or a failure response. This can be a timedout transaction on the Rave server or an abandoned transaction by the customer.
+ * */
+ function onTimeout($transactionReference, $data) {
+ // Get the transaction from your DB using the transaction reference (txref)
+ // Queue it for requery. Preferably using a queue system. The requery should be about 15 minutes after.
+ // Ask the customer to contact your support and you should escalate this issue to the flutterwave support team. Send this as an email and as a notification on the page. just incase the page timesout or disconnects
+
+ }
+
+
+}
\ No newline at end of file
diff --git a/library/bvn.php b/library/EventHandlers/BvnEventHandler.php
similarity index 68%
rename from library/bvn.php
rename to library/EventHandlers/BvnEventHandler.php
index d104499..4d22934 100644
--- a/library/bvn.php
+++ b/library/EventHandlers/BvnEventHandler.php
@@ -1,15 +1,8 @@
bvn = new Rave($_ENV['SECRET_KEY']);
- }
-
- function verifyBVN($bvn)
- {
- //set the payment handler
- $this->bvn->eventHandler(new bvnEventHandler)
- //set the endpoint for the api call
- ->setEndPoint("v3/kyc/bvns");
- //returns the value from the results
-
- bvnEventHandler::startRecording();
- $response= $this->bvn->bvn($bvn);
- bvnEventHandler::sendAnalytics("Verify-BVN");
-
- return $response;
- }
-}
-
-?>
+}
\ No newline at end of file
diff --git a/library/EventHandlers/CardEventHandler.php b/library/EventHandlers/CardEventHandler.php
new file mode 100644
index 0000000..28812ac
--- /dev/null
+++ b/library/EventHandlers/CardEventHandler.php
@@ -0,0 +1,75 @@
+onFailure($transactionData);
+ }
+ }
+
+ /**
+ * This is called only when a transaction failed
+ * */
+ function onFailure($transactionData) {
+ self::sendAnalytics("Initiate-Card-Payments-error");
+ // Get the transaction from your DB using the transaction reference (txref)
+ // Update the db transaction record (includeing parameters that didn't exist before the transaction is completed. for audit purpose)
+ // You can also redirect to your failure page from here
+
+ }
+
+ /**
+ * This is called when a transaction is requeryed from the payment gateway
+ * */
+ function onRequery($transactionReference) {
+ // Do something, anything!
+ }
+
+ /**
+ * This is called a transaction requery returns with an error
+ * */
+ function onRequeryError($requeryResponse) {
+ // Do something, anything!
+ }
+
+ /**
+ * This is called when a transaction is canceled by the user
+ * */
+ function onCancel($transactionReference) {
+ // Do something, anything!
+ // Note: Somethings a payment can be successful, before a user clicks the cancel button so proceed with caution
+
+ }
+
+ /**
+ * This is called when a transaction doesn't return with a success or a failure response. This can be a timedout transaction on the Rave server or an abandoned transaction by the customer.
+ * */
+ function onTimeout($transactionReference, $data) {
+ // Get the transaction from your DB using the transaction reference (txref)
+ // Queue it for requery. Preferably using a queue system. The requery should be about 15 minutes after.
+ // Ask the customer to contact your support and you should escalate this issue to the flutterwave support team. Send this as an email and as a notification on the page. just incase the page timesout or disconnects
+
+ }
+}
\ No newline at end of file
diff --git a/library/EventHandlers/EbillEventHandler.php b/library/EventHandlers/EbillEventHandler.php
new file mode 100644
index 0000000..158d7b8
--- /dev/null
+++ b/library/EventHandlers/EbillEventHandler.php
@@ -0,0 +1,65 @@
+
diff --git a/library/EventTracker.php b/library/EventHandlers/EventTracker.php
similarity index 94%
rename from library/EventTracker.php
rename to library/EventHandlers/EventTracker.php
index 733d0a4..cc04de7 100644
--- a/library/EventTracker.php
+++ b/library/EventHandlers/EventTracker.php
@@ -1,11 +1,11 @@
onFailure($transactionData);
+ }
+ }
+
+ /**
+ * This is called only when a transaction failed
+ * */
+ function onFailure($transactionData) {
+ self::sendAnalytics("Initiate-Mobile-Money-error");
+ // Get the transaction from your DB using the transaction reference (txref)
+ // Update the db transaction record (includeing parameters that didn't exist before the transaction is completed. for audit purpose)
+ // You can also redirect to your failure page from here
+
+ }
+
+ /**
+ * This is called when a transaction is requeryed from the payment gateway
+ * */
+ function onRequery($transactionReference) {
+ // Do something, anything!
+ }
+
+ /**
+ * This is called a transaction requery returns with an error
+ * */
+ function onRequeryError($requeryResponse) {
+ // Do something, anything!
+ }
+
+ /**
+ * This is called when a transaction is canceled by the user
+ * */
+ function onCancel($transactionReference) {
+ // Do something, anything!
+ // Note: Somethings a payment can be successful, before a user clicks the cancel button so proceed with caution
+
+ }
+
+ /**
+ * This is called when a transaction doesn't return with a success or a failure response. This can be a timedout transaction on the Rave server or an abandoned transaction by the customer.
+ * */
+ function onTimeout($transactionReference, $data) {
+ // Get the transaction from your DB using the transaction reference (txref)
+ // Queue it for requery. Preferably using a queue system. The requery should be about 15 minutes after.
+ // Ask the customer to contact your support and you should escalate this issue to the flutterwave support team. Send this as an email and as a notification on the page. just incase the page timesout or disconnects
+
+ }
+}
\ No newline at end of file
diff --git a/library/EventHandlers/MpesaEventHandler.php b/library/EventHandlers/MpesaEventHandler.php
new file mode 100644
index 0000000..efeef8b
--- /dev/null
+++ b/library/EventHandlers/MpesaEventHandler.php
@@ -0,0 +1,78 @@
+onFailure($transactionData);
+
+ }
+ }
+
+ /**
+ * This is called only when a transaction failed
+ * */
+ function onFailure($transactionData) {
+ self::sendAnalytics("Initiate-Mpesa-error");
+ // Get the transaction from your DB using the transaction reference (txref)
+ // Update the db transaction record (includeing parameters that didn't exist before the transaction is completed. for audit purpose)
+ // You can also redirect to your failure page from here
+
+ }
+
+ /**
+ * This is called when a transaction is requeryed from the payment gateway
+ * */
+ function onRequery($transactionReference) {
+ // Do something, anything!
+ }
+
+ /**
+ * This is called a transaction requery returns with an error
+ * */
+ function onRequeryError($requeryResponse) {
+ // Do something, anything!
+ }
+
+ /**
+ * This is called when a transaction is canceled by the user
+ * */
+ function onCancel($transactionReference) {
+ // Do something, anything!
+ // Note: Somethings a payment can be successful, before a user clicks the cancel button so proceed with caution
+
+ }
+
+ /**
+ * This is called when a transaction doesn't return with a success or a failure response. This can be a timedout transaction on the Rave server or an abandoned transaction by the customer.
+ * */
+ function onTimeout($transactionReference, $data) {
+ // Get the transaction from your DB using the transaction reference (txref)
+ // Queue it for requery. Preferably using a queue system. The requery should be about 15 minutes after.
+ // Ask the customer to contact your support and you should escalate this issue to the flutterwave support team. Send this as an email and as a notification on the page. just incase the page timesout or disconnects
+
+ }
+}
\ No newline at end of file
diff --git a/library/EventHandlers/PaymentPlanEventHandler.php b/library/EventHandlers/PaymentPlanEventHandler.php
new file mode 100644
index 0000000..d548764
--- /dev/null
+++ b/library/EventHandlers/PaymentPlanEventHandler.php
@@ -0,0 +1,69 @@
+onFailure($transactionData);
+ }
+ }
+
+ /**
+ * This is called only when a transaction failed
+ * */
+ function onFailure($transactionData) {
+ self::sendAnalytics("Initiate-Tokenized-charge-error");
+ // Get the transaction from your DB using the transaction reference (txref)
+ // Update the db transaction record (includeing parameters that didn't exist before the transaction is completed. for audit purpose)
+ // You can also redirect to your failure page from here
+
+ }
+
+ /**
+ * This is called when a transaction is requeryed from the payment gateway
+ * */
+ function onRequery($transactionReference) {
+ // Do something, anything!
+ }
+
+ /**
+ * This is called a transaction requery returns with an error
+ * */
+ function onRequeryError($requeryResponse) {
+ // Do something, anything!
+ }
+
+ /**
+ * This is called when a transaction is canceled by the user
+ * */
+ function onCancel($transactionReference) {
+ // Do something, anything!
+ // Note: Somethings a payment can be successful, before a user clicks the cancel button so proceed with caution
+
+ }
+
+ /**
+ * This is called when a transaction doesn't return with a success or a failure response. This can be a timedout transaction on the Rave server or an abandoned transaction by the customer.
+ * */
+ function onTimeout($transactionReference, $data) {
+ // Get the transaction from your DB using the transaction reference (txref)
+ // Queue it for requery. Preferably using a queue system. The requery should be about 15 minutes after.
+ // Ask the customer to contact your support and you should escalate this issue to the flutterwave support team. Send this as an email and as a notification on the page. just incase the page timesout or disconnects
+
+ }
+}
\ No newline at end of file
diff --git a/library/EventHandlers/TransactionVerificationEventHandler.php b/library/EventHandlers/TransactionVerificationEventHandler.php
new file mode 100644
index 0000000..cdb72a7
--- /dev/null
+++ b/library/EventHandlers/TransactionVerificationEventHandler.php
@@ -0,0 +1,70 @@
+onFailure($transactionData);
+ }
+ }
+
+ /**
+ * This is called only when a transaction failed
+ * */
+ function onFailure($transactionData) {
+ // Get the transaction from your DB using the transaction reference (txref)
+ // Update the db transaction record (includeing parameters that didn't exist before the transaction is completed. for audit purpose)
+ // You can also redirect to your failure page from here
+ self::sendAnalytics("Initiate-Voucher-Payment-error");
+
+ }
+
+ /**
+ * This is called when a transaction is requeryed from the payment gateway
+ * */
+ function onRequery($transactionReference) {
+ // Do something, anything!
+ }
+
+ /**
+ * This is called a transaction requery returns with an error
+ * */
+ function onRequeryError($requeryResponse) {
+ // Do something, anything!
+ }
+
+ /**
+ * This is called when a transaction is canceled by the user
+ * */
+ function onCancel($transactionReference) {
+ // Do something, anything!
+ // Note: Somethings a payment can be successful, before a user clicks the cancel button so proceed with caution
+
+ }
+
+ /**
+ * This is called when a transaction doesn't return with a success or a failure response. This can be a timedout transaction on the Rave server or an abandoned transaction by the customer.
+ * */
+ function onTimeout($transactionReference, $data) {
+ // Get the transaction from your DB using the transaction reference (txref)
+ // Queue it for requery. Preferably using a queue system. The requery should be about 15 minutes after.
+ // Ask the customer to contact your support and you should escalate this issue to the flutterwave support team. Send this as an email and as a notification on the page. just incase the page timesout or disconnects
+
+ }
+}
\ No newline at end of file
diff --git a/library/Misc.php b/library/Misc.php
index 3705d56..01ff8b5 100644
--- a/library/Misc.php
+++ b/library/Misc.php
@@ -1,5 +1,7 @@
onFailure($transactionData);
- }
- }
-
- /**
- * This is called only when a transaction failed
- * */
- function onFailure($transactionData)
- {
- self::sendAnalytics("Initiate-Mobile-Money-error");
- // Get the transaction from your DB using the transaction reference (txref)
- // Update the db transaction record (includeing parameters that didn't exist before the transaction is completed. for audit purpose)
- // You can also redirect to your failure page from here
-
- }
-
- /**
- * This is called when a transaction is requeryed from the payment gateway
- * */
- function onRequery($transactionReference)
- {
- // Do something, anything!
- }
-
- /**
- * This is called a transaction requery returns with an error
- * */
- function onRequeryError($requeryResponse)
- {
- // Do something, anything!
- }
-
- /**
- * This is called when a transaction is canceled by the user
- * */
- function onCancel($transactionReference)
- {
- // Do something, anything!
- // Note: Somethings a payment can be successful, before a user clicks the cancel button so proceed with caution
-
- }
-
- /**
- * This is called when a transaction doesn't return with a success or a failure response. This can be a timedout transaction on the Rave server or an abandoned transaction by the customer.
- * */
- function onTimeout($transactionReference, $data)
- {
- // Get the transaction from your DB using the transaction reference (txref)
- // Queue it for requery. Preferably using a queue system. The requery should be about 15 minutes after.
- // Ask the customer to contact your support and you should escalate this issue to the flutterwave support team. Send this as an email and as a notification on the page. just incase the page timesout or disconnects
-
- }
-}
+use Flutterwave\EventHandlers\MomoEventHandler;
class MobileMoney
{
@@ -101,7 +20,7 @@ function mobilemoney($array)
{
//add tx_ref to the paylaod
//add tx_ref to the paylaod
- if (!isset($array['tx_ref']) || empty($array['tx_ref'])) {
+ if (empty($array['tx_ref'])) {
$array['tx_ref'] = $this->payment->txref;
}
@@ -144,15 +63,15 @@ function mobilemoney($array)
}
//set the payment handler
- $this->payment->eventHandler(new momoEventHandler)
+ $this->payment->eventHandler(new MomoEventHandler)
//set the endpoint for the api call
->setEndPoint("v3/charges?type=" . $this->type);
//returns the value from the results
- momoEventHandler::startRecording();
+ MomoEventHandler::startRecording();
$response = $this->payment->chargePayment($array);
- momoEventHandler::setResponseTime();
+ MomoEventHandler::setResponseTime();
return $response;
//echo 'Type selected: '.$this->type;
@@ -173,5 +92,3 @@ function verifyTransaction($id)
}
-
-?>
diff --git a/library/Mpesa.php b/library/Mpesa.php
index d0d071f..7154bd6 100644
--- a/library/Mpesa.php
+++ b/library/Mpesa.php
@@ -1,85 +1,8 @@
onFailure($transactionData);
-
- }
- }
-
- /**
- * This is called only when a transaction failed
- * */
- function onFailure($transactionData){
- self::sendAnalytics("Initiate-Mpesa-error");
- // Get the transaction from your DB using the transaction reference (txref)
- // Update the db transaction record (includeing parameters that didn't exist before the transaction is completed. for audit purpose)
- // You can also redirect to your failure page from here
-
- }
-
- /**
- * This is called when a transaction is requeryed from the payment gateway
- * */
- function onRequery($transactionReference){
- // Do something, anything!
- }
-
- /**
- * This is called a transaction requery returns with an error
- * */
- function onRequeryError($requeryResponse){
- // Do something, anything!
- }
-
- /**
- * This is called when a transaction is canceled by the user
- * */
- function onCancel($transactionReference){
- // Do something, anything!
- // Note: Somethings a payment can be successful, before a user clicks the cancel button so proceed with caution
-
- }
- /**
- * This is called when a transaction doesn't return with a success or a failure response. This can be a timedout transaction on the Rave server or an abandoned transaction by the customer.
- * */
- function onTimeout($transactionReference, $data){
- // Get the transaction from your DB using the transaction reference (txref)
- // Queue it for requery. Preferably using a queue system. The requery should be about 15 minutes after.
- // Ask the customer to contact your support and you should escalate this issue to the flutterwave support team. Send this as an email and as a notification on the page. just incase the page timesout or disconnects
-
- }
-}
+use Flutterwave\EventHandlers\MpesaEventHandler;
class Mpesa {
function __construct(){
@@ -90,7 +13,7 @@ function __construct(){
function mpesa($array){
//add tx_ref to the paylaod
- if(!isset($array['tx_ref']) || empty($array['tx_ref'])){
+ if(empty($array['tx_ref'])){
$array['tx_ref'] = $this->payment->txref;
}
@@ -98,14 +21,14 @@ function mpesa($array){
$this->payment->type = 'mpesa';
//set the payment handler
- $this->payment->eventHandler(new mpesaEventHandler)
+ $this->payment->eventHandler(new MpesaEventHandler)
//set the endpoint for the api call
->setEndPoint("v3/charges?type=".$this->payment->type);
//returns the value from the results
- mpesaEventHandler::startRecording();
+ MpesaEventHandler::startRecording();
$response= $this->payment->chargePayment($array);
- mpesaEventHandler::sendAnalytics('Initiate-Mpesa');
+ MpesaEventHandler::sendAnalytics('Initiate-Mpesa');
return $response;
}
diff --git a/library/PaymentPlan.php b/library/PaymentPlan.php
index 06b2e69..aeb6d91 100644
--- a/library/PaymentPlan.php
+++ b/library/PaymentPlan.php
@@ -5,96 +5,20 @@
//uncomment if you need this
//define("BASEPATH", 1);//Allow direct access to rave.php and raveEventHandler.php
-require_once('rave.php');
-require_once('raveEventHandlerInterface.php');
-require_once('EventTracker.php');
-
-class paymentPlanEventHandler implements EventHandlerInterface
-{
- use EventTracker;
-
- /**
- * This is called only when a transaction is successful
- * */
- function onSuccessful($transactionData)
- {
- // 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
- // Comfirm that the transaction is successful
- // Confirm that the chargecode is 00 or 0
- // 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 (includeing parameters that didn't exist before the transaction is completed. for audit purpose)
- // Give value for the transaction
- // Update the transaction to note that you have given value for the transaction
- // You can also redirect to your success page from here
- self::sendAnalytics("Initiate-Payment-Plan");
- }
-
- /**
- * This is called only when a transaction failed
- * */
- function onFailure($transactionData)
- {
- self::sendAnalytics("Initiate-Payment-Plan-error");
- // Get the transaction from your DB using the transaction reference (txref)
- // Update the db transaction record (includeing parameters that didn't exist before the transaction is completed. for audit purpose)
- // You can also redirect to your failure page from here
-
- }
-
- /**
- * This is called when a transaction is requeryed from the payment gateway
- * */
- function onRequery($transactionReference)
- {
- // Do something, anything!
- }
-
- /**
- * This is called a transaction requery returns with an error
- * */
- function onRequeryError($requeryResponse)
- {
- // Do something, anything!
- }
-
- /**
- * This is called when a transaction is canceled by the user
- * */
- function onCancel($transactionReference)
- {
- // Do something, anything!
- // Note: Somethings a payment can be successful, before a user clicks the cancel button so proceed with caution
-
- }
-
- /**
- * This is called when a transaction doesn't return with a success or a failure response. This can be a timedout transaction on the Rave server or an abandoned transaction by the customer.
- * */
- function onTimeout($transactionReference, $data)
- {
- // Get the transaction from your DB using the transaction reference (txref)
- // Queue it for requery. Preferably using a queue system. The requery should be about 15 minutes after.
- // Ask the customer to contact your support and you should escalate this issue to the flutterwave support team. Send this as an email and as a notification on the page. just incase the page timesout or disconnects
-
- }
-}
+use Flutterwave\EventHandlers\PaymentPlanEventHandler;
class PaymentPlan
{
protected $plan;
- function __construct()
- {
+ function __construct() {
$this->plan = new Rave($_ENV['SECRET_KEY']);
}
- function createPlan($array)
- {
+ function createPlan($array) {
//set the payment handler
- $this->plan->eventHandler(new paymentPlanEventHandler)
+ $this->plan->eventHandler(new PaymentPlanEventHandler)
//set the endpoint for the api call
->setEndPoint("v3/payment-plans");
@@ -113,16 +37,15 @@ function createPlan($array)
// }
//returns the value from the results
- paymentPlanEventHandler::startRecording();
+ PaymentPlanEventHandler::startRecording();
$response = $this->plan->createPlan($array);
- paymentPlanEventHandler::sendAnalytics('Initiate-Create-Plan');
+ PaymentPlanEventHandler::sendAnalytics('Initiate-Create-Plan');
return $response;
}
- function updatePlan($array)
- {
+ function updatePlan($array) {
if (!isset($array['id']) || !isset($array['name']) || !isset($array['status'])) {
return ' Error:
@@ -131,20 +54,19 @@ function updatePlan($array)
}
//set the payment handler
- $this->plan->eventHandler(new paymentPlanEventHandler)
+ $this->plan->eventHandler(new PaymentPlanEventHandler)
//set the endpoint for the api call
->setEndPoint("v3/payment-plans/" . $array['id']);
- paymentPlanEventHandler::startRecording();
+ PaymentPlanEventHandler::startRecording();
$response = $this->plan->updatePlan($array);
- paymentPlanEventHandler::sendAnalytics('Initiate-Update-Plan');
+ PaymentPlanEventHandler::sendAnalytics('Initiate-Update-Plan');
return $response;
}
- function cancelPlan($array)
- {
+ function cancelPlan($array) {
if (!isset($array['id'])) {
return '
Error:
@@ -153,44 +75,41 @@ function cancelPlan($array)
}
//set the payment handler
- $this->plan->eventHandler(new paymentPlanEventHandler)
+ $this->plan->eventHandler(new PaymentPlanEventHandler)
//set the endpoint for the api call
->setEndPoint("v3/payment-plans/" . $array['id'] . "/cancel");
- paymentPlanEventHandler::startRecording();
+ PaymentPlanEventHandler::startRecording();
$response = $this->plan->cancelPlan($array);
- paymentPlanEventHandler::sendAnalytics('Initiate-Cancel-Plan');
+ PaymentPlanEventHandler::sendAnalytics('Initiate-Cancel-Plan');
return $response;
}
- function getPlans()
- {
+ function getPlans() {
//set the payment handler
- $this->plan->eventHandler(new paymentPlanEventHandler)
+ $this->plan->eventHandler(new PaymentPlanEventHandler)
//set the endpoint for the api call
->setEndPoint("v3/payment-plans");
- paymentPlanEventHandler::startRecording();
+ PaymentPlanEventHandler::startRecording();
$response = $this->plan->getPlans();
- paymentPlanEventHandler::sendAnalytics('Get-Plans');
+ PaymentPlanEventHandler::sendAnalytics('Get-Plans');
return $response;
}
- function get_a_Plan($array)
- {
+ function get_a_Plan($array) {
//set the payment handler
- $this->plan->eventHandler(new paymentPlanEventHandler)
+ $this->plan->eventHandler(new PaymentPlanEventHandler)
//set the endpoint for the api call
->setEndPoint("v3/payment-plans/" . $array['id']);
- paymentPlanEventHandler::startRecording();
+ PaymentPlanEventHandler::startRecording();
$response = $this->plan->get_a_Plan();
- paymentPlanEventHandler::sendAnalytics('Get-A-Plan');
+ PaymentPlanEventHandler::sendAnalytics('Get-A-Plan');
return $response;
}
}
-?>
diff --git a/library/Preauth.php b/library/Preauth.php
index 44cdec5..e3da9a0 100644
--- a/library/Preauth.php
+++ b/library/Preauth.php
@@ -2,45 +2,7 @@
namespace Flutterwave;
-require("rave.php");
-require("raveEventHandlerInterface.php");
-require_once('EventTracker.php');
-
-class preEventHandler implements EventHandlerInterface
-{
-
- use EventTracker;
-
- function onSuccessful($transactionData)
- {
- self::sendAnalytics("Initiate-Preauth");
- }
-
- function onFailure($transactionData)
- {
- self::sendAnalytics("Initiate-Preauth-Error");
- }
-
- function onRequery($transactionReference)
- {
- // TODO: Implement onRequery() method.
- }
-
- function onRequeryError($requeryResponse)
- {
- // TODO: Implement onRequeryError() method.
- }
-
- function onCancel($transactionReference)
- {
- // TODO: Implement onCancel() method.
- }
-
- function onTimeout($transactionReference, $data)
- {
- // TODO: Implement onTimeout() method.
- }
-}
+use Flutterwave\EventHandlers\PreEventHandler;
class Preauth
{
@@ -56,7 +18,7 @@ function cardCharge($array)
// echo "";
// exit;
$mode = "";
- if(!isset($array['preauthorize'])|| empty($array['preauthorize']))
+ if(empty($array['preauthorize']))
{
$array['preauthorize'] = true;
}
@@ -66,7 +28,7 @@ function cardCharge($array)
$mode = "VBVSECURECODE";
}
- if (!isset($array['tx_ref']) || empty($array['tx_ref'])) {
+ if (empty($array['tx_ref'])) {
$array['tx_ref'] = $this->preauthPayment->txref;
} else {
$this->preauthPayment->txref = $array['tx_ref'];
@@ -75,16 +37,16 @@ function cardCharge($array)
$this->preauthPayment->type = 'card';
//set the payment handler
- $this->preauthPayment->eventHandler(new preEventHandler)
+ $this->preauthPayment->eventHandler(new PreEventHandler)
//set the endpoint for the api call
->setEndPoint("v3/charges?type=" . $this->preauthPayment->type);
//returns the value from the results
//you can choose to store the returned value in a variable and validate within this function
$this->preauthPayment->setAuthModel("AUTH");
- preEventHandler::startRecording();
+ PreEventHandler::startRecording();
$response = $this->preauthPayment->chargePayment($array);
- preEventHandler::sendAnalytics('Initiate-Preauth');
+ PreEventHandler::sendAnalytics('Initiate-Preauth');
return $response;
/**you will need to validate and verify the charge
@@ -104,13 +66,13 @@ function captureFunds($array)
return '
' . $result['message'] . '
';;
}
//set the payment handler
- $this->preauthPayment->eventHandler(new preEventHandler)
+ $this->preauthPayment->eventHandler(new PreEventHandler)
//set the endpoint for the api call
->setEndPoint("v3/charges/$flw_ref/capture");
//returns the value from the results
- preEventHandler::startRecording();
+ PreEventHandler::startRecording();
$response = $this->preauthPayment->captureFunds($array);
- preEventHandler::sendAnalytics('Initiate-Capture-Funds');
+ PreEventHandler::sendAnalytics('Initiate-Capture-Funds');
return json_decode($response);
}
@@ -124,13 +86,13 @@ function voidFunds($array)
return '
' . $result['message'] . '
';;
}
//set the payment handler
- $this->preauthPayment->eventHandler(new preEventHandler)
+ $this->preauthPayment->eventHandler(new PreEventHandler)
//set the endpoint for the api call
->setEndPoint("v3/charges/$flw_ref/void");
//returns the value from the results
- preEventHandler::startRecording();
+ PreEventHandler::startRecording();
$response = $this->preauthPayment->void($array);
- preEventHandler::sendAnalytics('Initiate-Preauth-Void');
+ PreEventHandler::sendAnalytics('Initiate-Preauth-Void');
return json_decode($response);
@@ -145,13 +107,13 @@ function reFunds($array)
return '
' . $result['message'] . '
';;
}
//set the payment handler
- $this->preauthPayment->eventHandler(new preEventHandler)
+ $this->preauthPayment->eventHandler(new PreEventHandler)
//set the endpoint for the api call
->setEndPoint("v3/charges/$flw_ref/refund");
//returns the value from the results
- preEventHandler::startRecording();
+ PreEventHandler::startRecording();
$response = $this->preauthPayment->preRefund($array);
- preEventHandler::sendAnalytics('Initiate-Preauth-Refund');
+ PreEventHandler::sendAnalytics('Initiate-Preauth-Refund');
return json_decode($response);
diff --git a/library/rave.php b/library/Rave.php
similarity index 100%
rename from library/rave.php
rename to library/Rave.php
diff --git a/library/Recipient.php b/library/Recipient.php
index c9e93f7..98d29db 100644
--- a/library/Recipient.php
+++ b/library/Recipient.php
@@ -5,82 +5,8 @@
//uncomment if you need this
//define("BASEPATH", 1);//Allow direct access to rave.php and raveEventHandler.php
-require_once('rave.php');
-require_once('raveEventHandlerInterface.php');
-require_once('EventTracker.php');
-
-class recipientEventHandler implements EventHandlerInterface
-{
- use EventTracker;
-
- /**
- * This is called only when a transaction is successful
- * */
- function onSuccessful($transactionData)
- {
- // 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
- // Comfirm that the transaction is successful
- // Confirm that the chargecode is 00 or 0
- // 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 (includeing parameters that didn't exist before the transaction is completed. for audit purpose)
- // Give value for the transaction
- // Update the transaction to note that you have given value for the transaction
- // You can also redirect to your success page from here
- self::sendAnalytics("Recipient");
- }
-
- /**
- * This is called only when a transaction failed
- * */
- function onFailure($transactionData)
- {
- self::sendAnalytics("Recipient-Error");
- // Get the transaction from your DB using the transaction reference (txref)
- // Update the db transaction record (includeing parameters that didn't exist before the transaction is completed. for audit purpose)
- // You can also redirect to your failure page from here
-
- }
-
- /**
- * This is called when a transaction is requeryed from the payment gateway
- * */
- function onRequery($transactionReference)
- {
- // Do something, anything!
- }
-
- /**
- * This is called a transaction requery returns with an error
- * */
- function onRequeryError($requeryResponse)
- {
- // Do something, anything!
- }
-
- /**
- * This is called when a transaction is canceled by the user
- * */
- function onCancel($transactionReference)
- {
- // Do something, anything!
- // Note: Somethings a payment can be successful, before a user clicks the cancel button so proceed with caution
-
- }
-
- /**
- * This is called when a transaction doesn't return with a success or a failure response. This can be a timedout transaction on the Rave server or an abandoned transaction by the customer.
- * */
- function onTimeout($transactionReference, $data)
- {
- // Get the transaction from your DB using the transaction reference (txref)
- // Queue it for requery. Preferably using a queue system. The requery should be about 15 minutes after.
- // Ask the customer to contact your support and you should escalate this issue to the flutterwave support team. Send this as an email and as a notification on the page. just incase the page timesout or disconnects
-
- }
-}
+use Flutterwave\EventHandlers\RecipientEventHandler;
class Recipient
{
@@ -100,27 +26,27 @@ function createRecipient($array)
The following body params are required
account_number and account_bank
';
}
- $this->recipient->eventHandler(new recipientEventHandler)
+ $this->recipient->eventHandler(new RecipientEventHandler)
//set the endpoint for the api call
->setEndPoint("v3/beneficiaries");
//returns the value from the results
- recipientEventHandler::startRecording();
+ RecipientEventHandler::startRecording();
$response = $this->recipient->createBeneficiary($array);
- recipientEventHandler::sendAnalytics('Create-Recipient');
+ RecipientEventHandler::sendAnalytics('Create-Recipient');
return $response;
}
function listRecipients()
{
- $this->recipient->eventHandler(new recipientEventHandler)
+ $this->recipient->eventHandler(new RecipientEventHandler)
//set the endpoint for the api call
->setEndPoint("v3/beneficiaries");
//returns the value from the results
- recipientEventHandler::startRecording();
+ RecipientEventHandler::startRecording();
$response = $this->recipient->getBeneficiaries();
- recipientEventHandler::sendAnalytics('List-Recipients');
+ RecipientEventHandler::sendAnalytics('List-Recipients');
return $response;
}
@@ -137,13 +63,13 @@ function fetchBeneficiary($array)
$array['id'] = (string)$array['id'];
}
- $this->recipient->eventHandler(new recipientEventHandler)
+ $this->recipient->eventHandler(new RecipientEventHandler)
//set the endpoint for the api call
->setEndPoint("v3/beneficiaries/" . $array['id']);
//returns the value from the results
- recipientEventHandler::startRecording();
+ RecipientEventHandler::startRecording();
$response = $this->recipient->getBeneficiaries();
- recipientEventHandler::sendAnalytics('Fetch-Beneficiary');
+ RecipientEventHandler::sendAnalytics('Fetch-Beneficiary');
return $response;
}
@@ -161,14 +87,14 @@ function deleteBeneficiary($array)
$array['id'] = (string)$array['id'];
}
- $this->recipient->eventHandler(new recipientEventHandler)
+ $this->recipient->eventHandler(new RecipientEventHandler)
//set the endpoint for the api call
->setEndPoint("v3/beneficiaries/" . $array['id']);
//returns the value from the results
- recipientEventHandler::startRecording();
+ RecipientEventHandler::startRecording();
$response= $this->recipient->deleteBeneficiary();
- recipientEventHandler::sendAnalytics('Delete-Beneficiary');
+ RecipientEventHandler::sendAnalytics('Delete-Beneficiary');
return $response;
}
diff --git a/library/Settlement.php b/library/Settlement.php
index 3829acf..57b5bb0 100644
--- a/library/Settlement.php
+++ b/library/Settlement.php
@@ -2,116 +2,40 @@
namespace Flutterwave;
-require("lib/rave.php");
-require_once('raveEventHandlerInterface.php');
-require_once('EventTracker.php');
-class settlementEventHandler implements EventHandlerInterface
-{
- use EventTracker;
-
- /**
- * This is called only when a transaction is successful
- * */
- function onSuccessful($transactionData)
- {
- // 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
- // Comfirm that the transaction is successful
- // Confirm that the chargecode is 00 or 0
- // 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 (includeing parameters that didn't exist before the transaction is completed. for audit purpose)
- // Give value for the transaction
- // Update the transaction to note that you have given value for the transaction
- // You can also redirect to your success page from here
- self::sendAnalytics("Initiate-Settlement");
- }
-
- /**
- * This is called only when a transaction failed
- * */
- function onFailure($transactionData)
- {
- self::sendAnalytics("Initiate-Settlement-error");
- // Get the transaction from your DB using the transaction reference (txref)
- // Update the db transaction record (includeing parameters that didn't exist before the transaction is completed. for audit purpose)
- // You can also redirect to your failure page from here
-
- }
-
- /**
- * This is called when a transaction is requeryed from the payment gateway
- * */
- function onRequery($transactionReference)
- {
- // Do something, anything!
- }
-
- /**
- * This is called a transaction requery returns with an error
- * */
- function onRequeryError($requeryResponse)
- {
- // Do something, anything!
- }
-
- /**
- * This is called when a transaction is canceled by the user
- * */
- function onCancel($transactionReference)
- {
- // Do something, anything!
- // Note: Somethings a payment can be successful, before a user clicks the cancel button so proceed with caution
-
- }
-
- /**
- * This is called when a transaction doesn't return with a success or a failure response. This can be a timedout transaction on the Rave server or an abandoned transaction by the customer.
- * */
- function onTimeout($transactionReference, $data)
- {
- // Get the transaction from your DB using the transaction reference (txref)
- // Queue it for requery. Preferably using a queue system. The requery should be about 15 minutes after.
- // Ask the customer to contact your support and you should escalate this issue to the flutterwave support team. Send this as an email and as a notification on the page. just incase the page timesout or disconnects
-
- }
-}
+use Flutterwave\EventHandlers\SettlementEventHandler;
class Settlement
{
- function __construct()
- {
+ function __construct() {
$this->settle = new Rave($_ENV['PUBLIC_KEY'], $_ENV['SECRET_KEY'], $_ENV['ENV']);
}
- function fetchSettlement($array)
- {
+ function fetchSettlement($array) {
//set the payment handler
- $this->subscription->eventHandler(new settlementEventHandler)
+ $this->subscription->eventHandler(new SettlementEventHandler)
//set the endpoint for the api call
->setEndPoint("v3/settlements/" . $array['id']);
//returns the value from the results
- settlementEventHandler::startRecording();
+ SettlementEventHandler::startRecording();
$response = $this->settle->fetchASettlement();
- settlementEventHandler::sendAnalytics('Fetch-Settlement');
+ SettlementEventHandler::sendAnalytics('Fetch-Settlement');
return $response;
}
- function listAllSettlements()
- {
+ function listAllSettlements() {
//set the payment handler
- $this->settle->eventHandler(new settlementEventHandler)
+ $this->settle->eventHandler(new SettlementEventHandler)
//set the endpoint for the api call
->setEndPoint("v3/settlements");
//returns the value from the results
- settlementEventHandler::startRecording();
+ SettlementEventHandler::startRecording();
$response = $this->settle->getAllSettlements();
- settlementEventHandler::sendAnalytics('List-All-Settlements');
+ SettlementEventHandler::sendAnalytics('List-All-Settlements');
return $response;
diff --git a/library/Subaccount.php b/library/Subaccount.php
index ef7e6d1..135e2dd 100644
--- a/library/Subaccount.php
+++ b/library/Subaccount.php
@@ -4,81 +4,7 @@
//uncomment if you need this
//define("BASEPATH", 1);//Allow direct access to rave.php and raveEventHandler.php
-require_once('rave.php');
-require_once('raveEventHandlerInterface.php');
-require_once('EventTracker.php');
-
-class subaccountEventHandler implements EventHandlerInterface
-{
- use EventTracker;
-
- /**
- * This is called only when a transaction is successful
- * */
- function onSuccessful($transactionData)
- {
- // 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
- // Comfirm that the transaction is successful
- // Confirm that the chargecode is 00 or 0
- // 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 (includeing parameters that didn't exist before the transaction is completed. for audit purpose)
- // Give value for the transaction
- // Update the transaction to note that you have given value for the transaction
- // You can also redirect to your success page from here
- self::sendAnalytics("Initiate-Subaccount");
- }
-
- /**
- * This is called only when a transaction failed
- * */
- function onFailure($transactionData)
- {
- self::sendAnalytics("Initiate-Subaccount");
- // Get the transaction from your DB using the transaction reference (txref)
- // Update the db transaction record (includeing parameters that didn't exist before the transaction is completed. for audit purpose)
- // You can also redirect to your failure page from here
-
- }
-
- /**
- * This is called when a transaction is requeryed from the payment gateway
- * */
- function onRequery($transactionReference)
- {
- // Do something, anything!
- }
-
- /**
- * This is called a transaction requery returns with an error
- * */
- function onRequeryError($requeryResponse)
- {
- // Do something, anything!
- }
-
- /**
- * This is called when a transaction is canceled by the user
- * */
- function onCancel($transactionReference)
- {
- // Do something, anything!
- // Note: Somethings a payment can be successful, before a user clicks the cancel button so proceed with caution
-
- }
-
- /**
- * This is called when a transaction doesn't return with a success or a failure response. This can be a timedout transaction on the Rave server or an abandoned transaction by the customer.
- * */
- function onTimeout($transactionReference, $data)
- {
- // Get the transaction from your DB using the transaction reference (txref)
- // Queue it for requery. Preferably using a queue system. The requery should be about 15 minutes after.
- // Ask the customer to contact your support and you should escalate this issue to the flutterwave support team. Send this as an email and as a notification on the page. just incase the page timesout or disconnects
-
- }
-}
+use Flutterwave\EventHandlers\SubaccountEventHandler;
class Subaccount
{
@@ -92,13 +18,13 @@ function __construct()
function createSubaccount($array)
{
//set the payment handler
- $this->subaccount->eventHandler(new subaccountEventHandler)
+ $this->subaccount->eventHandler(new SubaccountEventHandler)
//set the endpoint for the api call
->setEndPoint("v3/subaccounts");
//returns the value from the results
- subaccountEventHandler::startRecording();
+ SubaccountEventHandler::startRecording();
$response = $this->subaccount->createSubaccount($array);
- subaccountEventHandler::sendAnalytics('Create-Subaccount');
+ SubaccountEventHandler::sendAnalytics('Create-Subaccount');
return $response;
}
@@ -106,13 +32,13 @@ function createSubaccount($array)
function getSubaccounts()
{
- $this->subaccount->eventHandler(new subaccountEventHandler)
+ $this->subaccount->eventHandler(new SubaccountEventHandler)
//set the endpoint for the api call
->setEndPoint("v3/subaccounts");
//returns the value from the results
- subaccountEventHandler::startRecording();
+ SubaccountEventHandler::startRecording();
$response = $this->subaccount->getSubaccounts();
- subaccountEventHandler::sendAnalytics('Get-Subaccounts');
+ SubaccountEventHandler::sendAnalytics('Get-Subaccounts');
return $response;
}
@@ -120,13 +46,13 @@ function getSubaccounts()
function fetchSubaccount($array)
{
- $this->subaccount->eventHandler(new subaccountEventHandler)
+ $this->subaccount->eventHandler(new SubaccountEventHandler)
//set the endpoint for the api call
->setEndPoint("v3/subaccounts/" . $array['id']);
//returns the value from the results
- subaccountEventHandler::startRecording();
+ SubaccountEventHandler::startRecording();
$response = $this->subaccount->fetchSubaccount();
- subaccountEventHandler::sendAnalytics('Fetch-Subaccount');
+ SubaccountEventHandler::sendAnalytics('Fetch-Subaccount');
return $response;
@@ -141,13 +67,13 @@ function updateSubaccount($array)
';
}
- $this->subaccount->eventHandler(new subaccountEventHandler)
+ $this->subaccount->eventHandler(new SubaccountEventHandler)
//set the endpoint for the api call
->setEndPoint("v3/subaccounts/" . $array['id']);
//returns the value from the results
- subaccountEventHandler::startRecording();
+ SubaccountEventHandler::startRecording();
$response = $this->subaccount->updateSubaccount($array);
- subaccountEventHandler::sendAnalytics('Update-Subaccount');
+ SubaccountEventHandler::sendAnalytics('Update-Subaccount');
return $response;
@@ -155,18 +81,15 @@ function updateSubaccount($array)
function deleteSubaccount($array)
{
- $this->subaccount->eventHandler(new subaccountEventHandler)
+ $this->subaccount->eventHandler(new SubaccountEventHandler)
//set the endpoint for the api call
->setEndPoint("v3/subaccounts/" . $array['id']);
//returns the value from the results
- subaccountEventHandler::startRecording();
+ SubaccountEventHandler::startRecording();
$response = $this->subaccount->deleteSubaccount();
- subaccountEventHandler::sendAnalytics('Delete-Subaccount');
+ SubaccountEventHandler::sendAnalytics('Delete-Subaccount');
return $response;
}
}
-
-
-?>
diff --git a/library/Subscription.php b/library/Subscription.php
index 41c6994..9d2a5fb 100644
--- a/library/Subscription.php
+++ b/library/Subscription.php
@@ -5,82 +5,8 @@
//uncomment if you need this
//define("BASEPATH", 1);//Allow direct access to rave.php and raveEventHandler.php
-require_once('rave.php');
-require_once('raveEventHandlerInterface.php');
-require_once('EventTracker.php');
-
-class subscriptionEventHandler implements EventHandlerInterface
-{
- use EventTracker;
-
- /**
- * This is called only when a transaction is successful
- * */
- function onSuccessful($transactionData)
- {
- // 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
- // Comfirm that the transaction is successful
- // Confirm that the chargecode is 00 or 0
- // 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 (includeing parameters that didn't exist before the transaction is completed. for audit purpose)
- // Give value for the transaction
- // Update the transaction to note that you have given value for the transaction
- // You can also redirect to your success page from here
- self::sendAnalytics("Initiate-Subscription");
- }
-
- /**
- * This is called only when a transaction failed
- * */
- function onFailure($transactionData)
- {
- // Get the transaction from your DB using the transaction reference (txref)
- // Update the db transaction record (includeing parameters that didn't exist before the transaction is completed. for audit purpose)
- // You can also redirect to your failure page from here
- self::sendAnalytics("Initiate-Subscription-error");
-
- }
-
- /**
- * This is called when a transaction is requeryed from the payment gateway
- * */
- function onRequery($transactionReference)
- {
- // Do something, anything!
- }
-
- /**
- * This is called a transaction requery returns with an error
- * */
- function onRequeryError($requeryResponse)
- {
- // Do something, anything!
- }
-
- /**
- * This is called when a transaction is canceled by the user
- * */
- function onCancel($transactionReference)
- {
- // Do something, anything!
- // Note: Somethings a payment can be successful, before a user clicks the cancel button so proceed with caution
-
- }
-
- /**
- * This is called when a transaction doesn't return with a success or a failure response. This can be a timedout transaction on the Rave server or an abandoned transaction by the customer.
- * */
- function onTimeout($transactionReference, $data)
- {
- // Get the transaction from your DB using the transaction reference (txref)
- // Queue it for requery. Preferably using a queue system. The requery should be about 15 minutes after.
- // Ask the customer to contact your support and you should escalate this issue to the flutterwave support team. Send this as an email and as a notification on the page. just incase the page timesout or disconnects
-
- }
-}
+use Flutterwave\EventHandlers\SubscriptionEventHandler;
class Subscription
{
@@ -95,13 +21,13 @@ function activateSubscription($id)
{
//set the payment handler
$endPoint = 'v3/subscriptions/' . $id . '/activate';
- $this->subscription->eventHandler(new subscriptionEventHandler)
+ $this->subscription->eventHandler(new SubscriptionEventHandler)
//set the endpoint for the api call
->setEndPoint($endPoint);
//returns the value from the results
- subscriptionEventHandler::startRecording();
+ SubscriptionEventHandler::startRecording();
$response = $this->subscription->activateSubscription();
- subscriptionEventHandler::sendAnalytics('Activate-Subscriptions');
+ SubscriptionEventHandler::sendAnalytics('Activate-Subscriptions');
return $response;
}
@@ -109,13 +35,13 @@ function activateSubscription($id)
function getAllSubscription()
{
//set the payment handler
- $this->subscription->eventHandler(new subscriptionEventHandler)
+ $this->subscription->eventHandler(new SubscriptionEventHandler)
//set the endpoint for the api call
->setEndPoint("v3/subscriptions");
//returns the value from the results
- subscriptionEventHandler::startRecording();
+ SubscriptionEventHandler::startRecording();
$response = $this->subscription->getAllSubscription();
- subscriptionEventHandler::sendAnalytics('Get-All-Subscriptions');
+ SubscriptionEventHandler::sendAnalytics('Get-All-Subscriptions');
return $response;
}
@@ -125,16 +51,15 @@ function cancelSubscription($id)
$endPoint = 'v3/subscriptions/' . $id . '/cancel';
//set the payment handler
- $this->subscription->eventHandler(new subscriptionEventHandler)
+ $this->subscription->eventHandler(new SubscriptionEventHandler)
//set the endpoint for the api call
->setEndPoint($endPoint);
//returns the value from the results
- subscriptionEventHandler::startRecording();
+ SubscriptionEventHandler::startRecording();
$response= $this->subscription->cancelSubscription();
- subscriptionEventHandler::sendAnalytics('Cancel-Subscription');
+ SubscriptionEventHandler::sendAnalytics('Cancel-Subscription');
return $response;
}
}
-?>
diff --git a/library/TokenizedCharge.php b/library/TokenizedCharge.php
new file mode 100644
index 0000000..1b4383b
--- /dev/null
+++ b/library/TokenizedCharge.php
@@ -0,0 +1,109 @@
+payment = new Rave($_ENV['SECRET_KEY']);
+ }
+
+ function tokenCharge($array)
+ {
+
+ //add tx_ref to the paylaod
+ if (empty($array['tx_ref'])) {
+ $array['tx_ref'] = $this->payment->txref;
+ }
+
+ if (gettype($array['amount']) !== "integer") {
+ return ' Error:
+ Amount needs to be an integer.
+
';
+ }
+
+ if (!isset($array['token']) || !isset($array['currency']) || !isset($array['country']) ||
+ !isset($array['amount']) || !isset($array['email'])) {
+ return ' Error:
+ Missing Param in the Payload. Please check you payload.
+
';
+ }
+ //set the payment handler
+ $this->payment->eventHandler(new TkEventHandler)
+ //set the endpoint for the api call
+ ->setEndPoint("v3/tokenized-charges");
+ //returns the value from the results
+ //you can choose to store the returned value in a variable and validate within this function
+ TkEventHandler::startRecording();
+ $response = $this->payment->tokenCharge($array);
+ TkEventHandler::sendAnalytics('Initiate-Token-charge');
+
+ return $response;
+ }
+
+
+ function updateEmailTiedToToken($data)
+ {
+
+ //set the payment handler
+ $this->payment->eventHandler(new TkEventHandler)
+ //set the endpoint for the api call
+ ->setEndPoint("v2/gpx/tokens/embed_token/update_customer");
+ //returns the value from the results
+ //you can choose to store the returned value in a variable and validate within this function
+ TkEventHandler::startRecording();
+ $response = $this->payment->postURL($data);
+ TkEventHandler::sendAnalytics('Update-Email-tied-to-Token');
+
+ return $response;
+
+ }
+
+ function bulkCharge($data)
+ {
+ //https://api.ravepay.co/flwv3-pug/getpaidx/api/tokenized/charge_bulk
+ //set the payment handler
+ $this->payment->eventHandler(new TkEventHandler)
+ //set the endpoint for the api call
+ ->setEndPoint("flwv3-pug/getpaidx/api/tokenized/charge_bulk");
+
+ TkEventHandler::startRecording();
+ $response = $this->payment->bulkCharges($data);
+ TkEventHandler::sendAnalytics('Initiate-Tokenized-Bulk-charge');
+
+ return $response;
+
+ }
+
+ function bulkChargeStatus($data)
+ {
+ //https://api.ravepay.co/flwv3-pug/getpaidx/api/tokenized/charge_bulk
+ //set the payment handler
+ $this->payment->eventHandler(new TkEventHandler)
+ //set the endpoint for the api call
+ ->setEndPoint("flwv3-pug/getpaidx/api/tokenized/charge_bulk");
+
+// tkEventHandler::startRecording();
+ $response = $this->payment->bulkCharges($data);
+// tkEventHandler::sendAnalytics('Get-Tokenized-Bulk-charge-status');
+
+ return $response;
+ }
+
+ function verifyTransaction()
+ {
+ //verify the charge
+ return $this->payment->verifyTransaction($this->payment->txref);//Uncomment this line if you need it
+ }
+
+
+}
+
diff --git a/library/TokinizedCharge.php b/library/TokinizedCharge.php
deleted file mode 100644
index 3b42d95..0000000
--- a/library/TokinizedCharge.php
+++ /dev/null
@@ -1,189 +0,0 @@
-onFailure($transactionData);
- }
- }
-
- /**
- * This is called only when a transaction failed
- * */
- function onFailure($transactionData)
- {
- self::sendAnalytics("Initiate-Tokenized-charge-error");
- // Get the transaction from your DB using the transaction reference (txref)
- // Update the db transaction record (includeing parameters that didn't exist before the transaction is completed. for audit purpose)
- // You can also redirect to your failure page from here
-
- }
-
- /**
- * This is called when a transaction is requeryed from the payment gateway
- * */
- function onRequery($transactionReference)
- {
- // Do something, anything!
- }
-
- /**
- * This is called a transaction requery returns with an error
- * */
- function onRequeryError($requeryResponse)
- {
- // Do something, anything!
- }
-
- /**
- * This is called when a transaction is canceled by the user
- * */
- function onCancel($transactionReference)
- {
- // Do something, anything!
- // Note: Somethings a payment can be successful, before a user clicks the cancel button so proceed with caution
-
- }
-
- /**
- * This is called when a transaction doesn't return with a success or a failure response. This can be a timedout transaction on the Rave server or an abandoned transaction by the customer.
- * */
- function onTimeout($transactionReference, $data)
- {
- // Get the transaction from your DB using the transaction reference (txref)
- // Queue it for requery. Preferably using a queue system. The requery should be about 15 minutes after.
- // Ask the customer to contact your support and you should escalate this issue to the flutterwave support team. Send this as an email and as a notification on the page. just incase the page timesout or disconnects
-
- }
-}
-
-
-class TokinizedCharge
-{
- protected $payment;
-
- function __construct()
- {
- $this->payment = new Rave($_ENV['SECRET_KEY']);
- }
-
- function tokenCharge($array)
- {
-
- //add tx_ref to the paylaod
- if (!isset($array['tx_ref']) || empty($array['tx_ref'])) {
- $array['tx_ref'] = $this->payment->txref;
- }
-
- if (gettype($array['amount']) !== "integer") {
- return ' Error:
- Amount needs to be an integer.
-
';
- }
-
- if (!isset($array['token']) || !isset($array['currency']) || !isset($array['country']) || !isset($array['amount']) || !isset($array['email'])) {
- return ' Error:
- Missing Param in the Payload. Please check you payload.
-
';
- }
- //set the payment handler
- $this->payment->eventHandler(new tkEventHandler)
- //set the endpoint for the api call
- ->setEndPoint("v3/tokenized-charges");
- //returns the value from the results
- //you can choose to store the returned value in a variable and validate within this function
- tkEventHandler::startRecording();
- $response = $this->payment->tokenCharge($array);
- tkEventHandler::sendAnalytics('Initiate-Token-charge');
-
- return $response;
- }
-
-
- function updateEmailTiedToToken($data)
- {
-
- //set the payment handler
- $this->payment->eventHandler(new tkEventHandler)
- //set the endpoint for the api call
- ->setEndPoint("v2/gpx/tokens/embed_token/update_customer");
- //returns the value from the results
- //you can choose to store the returned value in a variable and validate within this function
- tkEventHandler::startRecording();
- $response = $this->payment->postURL($data);
- tkEventHandler::sendAnalytics('Update-Email-tied-to-Token');
-
- return $response;
-
- }
-
- function bulkCharge($data)
- {
- //https://api.ravepay.co/flwv3-pug/getpaidx/api/tokenized/charge_bulk
- //set the payment handler
- $this->payment->eventHandler(new tkEventHandler)
- //set the endpoint for the api call
- ->setEndPoint("flwv3-pug/getpaidx/api/tokenized/charge_bulk");
-
- tkEventHandler::startRecording();
- $response = $this->payment->bulkCharges($data);
- tkEventHandler::sendAnalytics('Initiate-Tokenized-Bulk-charge');
-
- return $response;
-
- }
-
- function bulkChargeStatus($data)
- {
- //https://api.ravepay.co/flwv3-pug/getpaidx/api/tokenized/charge_bulk
- //set the payment handler
- $this->payment->eventHandler(new tkEventHandler)
- //set the endpoint for the api call
- ->setEndPoint("flwv3-pug/getpaidx/api/tokenized/charge_bulk");
-
-// tkEventHandler::startRecording();
- $response = $this->payment->bulkCharges($data);
-// tkEventHandler::sendAnalytics('Get-Tokenized-Bulk-charge-status');
-
- return $response;
- }
-
- function verifyTransaction()
- {
- //verify the charge
- return $this->payment->verifyTransaction($this->payment->txref);//Uncomment this line if you need it
- }
-
-
-}
-
-
-?>
diff --git a/library/TransactionVerification.php b/library/TransactionVerification.php
index 0870286..d43f6f5 100644
--- a/library/TransactionVerification.php
+++ b/library/TransactionVerification.php
@@ -5,81 +5,8 @@
//uncomment if you need this
//define("BASEPATH", 1);//Allow direct access to rave.php and raveEventHandler.php
-require_once('rave.php');
-require_once('raveEventHandlerInterface.php');
-require_once('EventTracker.php');
-
-class transactionVerificationEventHandler implements EventHandlerInterface
-{
- use EventTracker;
-
- /**
- * This is called only when a transaction is successful
- * */
- function onSuccessful($transactionData)
- {
- // 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
- // Comfirm that the transaction is successful
- // Confirm that the chargecode is 00 or 0
- // 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 (includeing parameters that didn't exist before the transaction is completed. for audit purpose)
- // Give value for the transaction
- // Update the transaction to note that you have given value for the transaction
- // You can also redirect to your success page from here
- self::sendAnalytics("Transaction-Verification");
- }
-
- /**
- * This is called only when a transaction failed
- * */
- function onFailure($transactionData)
- {
- // Get the transaction from your DB using the transaction reference (txref)
- // Update the db transaction record (includeing parameters that didn't exist before the transaction is completed. for audit purpose)
- // You can also redirect to your failure page from here
- self::sendAnalytics("Transaction-Verification-error");
- }
-
- /**
- * This is called when a transaction is requeryed from the payment gateway
- * */
- function onRequery($transactionReference)
- {
- // Do something, anything!
- }
-
- /**
- * This is called a transaction requery returns with an error
- * */
- function onRequeryError($requeryResponse)
- {
- // Do something, anything!
- }
-
- /**
- * This is called when a transaction is canceled by the user
- * */
- function onCancel($transactionReference)
- {
- // Do something, anything!
- // Note: Somethings a payment can be successful, before a user clicks the cancel button so proceed with caution
-
- }
-
- /**
- * This is called when a transaction doesn't return with a success or a failure response. This can be a timedout transaction on the Rave server or an abandoned transaction by the customer.
- * */
- function onTimeout($transactionReference, $data)
- {
- // Get the transaction from your DB using the transaction reference (txref)
- // Queue it for requery. Preferably using a queue system. The requery should be about 15 minutes after.
- // Ask the customer to contact your support and you should escalate this issue to the flutterwave support team. Send this as an email and as a notification on the page. just incase the page timesout or disconnects
-
- }
-}
+use Flutterwave\EventHandlers\TransactionVerificationEventHandler;
class TransactionVerification
{
@@ -93,11 +20,11 @@ function __construct()
function transactionVerify($id)
{
//set the payment handler
- $this->validate->eventHandler(new transactionVerificationEventHandler);
+ $this->validate->eventHandler(new TransactionVerificationEventHandler);
//returns the value from the results
- transactionVerificationEventHandler::startRecording();
+ TransactionVerificationEventHandler::startRecording();
$response = $this->validate->verifyTransaction($id);
- transactionVerificationEventHandler::sendAnalytics('Verify-Transaction');
+ TransactionVerificationEventHandler::sendAnalytics('Verify-Transaction');
return $response;
}
diff --git a/library/Transactions.php b/library/Transactions.php
index f329203..ba0ceec 100644
--- a/library/Transactions.php
+++ b/library/Transactions.php
@@ -1,96 +1,24 @@
history = new Rave($_ENV['SECRET_KEY']);
}
function viewTransactions(){
//set the payment handler
- $this->history->eventHandler(new transactionVerificationEventHandler)
+ $this->history->eventHandler(new TransactionVerificationEventHandler)
//set the endpoint for the api call
->setEndPoint("v3/transactions");
//returns the value from the results
- transactionVerificationEventHandler::startRecording();
+ TransactionVerificationEventHandler::startRecording();
$response = $this->history->getAllTransactions();
- transactionVerificationEventHandler::sendAnalytics("Get-All-Transactions");
+ TransactionVerificationEventHandler::sendAnalytics("Get-All-Transactions");
return $response;
}
@@ -104,28 +32,28 @@ function getTransactionFee($array = array()){
}
- $this->history->eventHandler(new transactionVerificationEventHandler)
+ $this->history->eventHandler(new TransactionVerificationEventHandler)
//set the endpoint for the api call
->setEndPoint("v3/transactions/fee");
//returns the value from the results
- transactionVerificationEventHandler::startRecording();
+ TransactionVerificationEventHandler::startRecording();
$response = $this->history->getTransactionFee($array);
- transactionVerificationEventHandler::sendAnalytics("Get-Transaction-Fee");
+ TransactionVerificationEventHandler::sendAnalytics("Get-Transaction-Fee");
return $response;
}
function verifyTransaction($id){
- $this->history->eventHandler(new transactionVerificationEventHandler)
+ $this->history->eventHandler(new TransactionVerificationEventHandler)
//set the endpoint for the api call
->setEndPoint("v3/transactions/".$id."/verify");
//returns the value from the results
- transactionVerificationEventHandler::startRecording();
+ TransactionVerificationEventHandler::startRecording();
$response = $this->history->verifyTransaction($id);
- transactionVerificationEventHandler::sendAnalytics("Verify-Transaction");
+ TransactionVerificationEventHandler::sendAnalytics("Verify-Transaction");
return $response;
}
@@ -138,14 +66,14 @@ function viewTimeline($array = array()){
';
}
- $this->history->eventHandler(new transactionVerificationEventHandler)
+ $this->history->eventHandler(new TransactionVerificationEventHandler)
//set the endpoint for the api call
->setEndPoint("v3/transactions/".$array['id']."/events");
//returns the value from the results
- transactionVerificationEventHandler::startRecording();
+ TransactionVerificationEventHandler::startRecording();
$response = $this->history->transactionTimeline();
- transactionVerificationEventHandler::sendAnalytics("View-Transaction-Timeline");
+ TransactionVerificationEventHandler::sendAnalytics("View-Transaction-Timeline");
return $response;
}
diff --git a/library/Transfer.php b/library/Transfer.php
index 179382f..553f004 100644
--- a/library/Transfer.php
+++ b/library/Transfer.php
@@ -5,82 +5,7 @@
//uncomment if you need this
//define("BASEPATH", 1);//Allow direct access to rave.php and raveEventHandler.php
-require_once('rave.php');
-require_once('raveEventHandlerInterface.php');
-require_once('EventTracker.php');
-
-class transferEventHandler implements EventHandlerInterface
-{
- use EventTracker;
-
- /**
- * This is called only when a transaction is successful
- * @param array
- * */
- function onSuccessful($transactionData)
- {
- // 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
- // Comfirm that the transaction is successful
- // Confirm that the chargecode is 00 or 0
- // 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 (includeing parameters that didn't exist before the transaction is completed. for audit purpose)
- // Give value for the transaction
- // Update the transaction to note that you have given value for the transaction
- // You can also redirect to your success page from here
- self::sendAnalytics("Initiate-Transfer");
- }
-
- /**
- * This is called only when a transaction failed
- * */
- function onFailure($transactionData)
- {
- // Get the transaction from your DB using the transaction reference (txref)
- // Update the db transaction record (includeing parameters that didn't exist before the transaction is completed. for audit purpose)
- // You can also redirect to your failure page from here
- self::sendAnalytics("Initiate-Transfer-error");
-
- }
-
- /**
- * This is called when a transaction is requeryed from the payment gateway
- * */
- function onRequery($transactionReference)
- {
- // Do something, anything!
- }
-
- /**
- * This is called a transaction requery returns with an error
- * */
- function onRequeryError($requeryResponse)
- {
- // Do something, anything!
- }
-
- /**
- * This is called when a transaction is canceled by the user
- * */
- function onCancel($transactionReference)
- {
- // Do something, anything!
- // Note: Somethings a payment can be successful, before a user clicks the cancel button so proceed with caution
-
- }
-
- /**
- * This is called when a transaction doesn't return with a success or a failure response. This can be a timedout transaction on the Rave server or an abandoned transaction by the customer.
- * */
- function onTimeout($transactionReference, $data)
- {
- // Get the transaction from your DB using the transaction reference (txref)
- // Queue it for requery. Preferably using a queue system. The requery should be about 15 minutes after.
- // Ask the customer to contact your support and you should escalate this issue to the flutterwave support team. Send this as an email and as a notification on the page. just incase the page timesout or disconnects
-
- }
-}
+use Flutterwave\EventHandlers\TransferEventHandler;
class Transfer
{
@@ -95,13 +20,13 @@ function __construct()
function singleTransfer($array)
{
//set the payment handler
- $this->transfer->eventHandler(new transferEventHandler)
+ $this->transfer->eventHandler(new TransferEventHandler)
//set the endpoint for the api call
->setEndPoint("v3/transfers");
//returns the value from the results
- transferEventHandler::startRecording();
+ TransferEventHandler::startRecording();
$response = $this->transfer->transferSingle($array);
- transferEventHandler::sendAnalytics('Initiate-Single-Transfer');
+ TransferEventHandler::sendAnalytics('Initiate-Single-Transfer');
return $response;
}
@@ -110,26 +35,26 @@ function singleTransfer($array)
function bulkTransfer($array)
{
//set the payment handler
- $this->transfer->eventHandler(new transferEventHandler)
+ $this->transfer->eventHandler(new TransferEventHandler)
//set the endpoint for the api call
->setEndPoint("v3/bulk-transfers");
//returns the value from the results
- transferEventHandler::startRecording();
+ TransferEventHandler::startRecording();
$response = $this->transfer->transferBulk($array);
- transferEventHandler::sendAnalytics('Initiate-Bulk-Transfer');
+ TransferEventHandler::sendAnalytics('Initiate-Bulk-Transfer');
return $response;
}
function listTransfers($array = array('url' => 'blank'))
{
- $this->transfer->eventHandler(new transferEventHandler)
+ $this->transfer->eventHandler(new TransferEventHandler)
//set the endpoint for the api call
->setEndPoint("v3/transfers");
- transferEventHandler::startRecording();
+ TransferEventHandler::startRecording();
$response = $this->transfer->listTransfers($array);
- transferEventHandler::sendAnalytics('List-Transfer');
+ TransferEventHandler::sendAnalytics('List-Transfer');
return $response;
@@ -142,13 +67,13 @@ function bulkTransferStatus($array)
{
//set the payment handler
- $this->transfer->eventHandler(new transferEventHandler)
+ $this->transfer->eventHandler(new TransferEventHandler)
//set the endpoint for the api call
->setEndPoint("v3/bulk-transfers");
- transferEventHandler::startRecording();
+ TransferEventHandler::startRecording();
$response = $this->transfer->bulkTransferStatus($array);
- transferEventHandler::sendAnalytics('Bulk-Transfer-Status');
+ TransferEventHandler::sendAnalytics('Bulk-Transfer-Status');
return $response;
}
@@ -161,13 +86,13 @@ function getTransferFee($array)
}
//set the payment handler
- $this->transfer->eventHandler(new transferEventHandler)
+ $this->transfer->eventHandler(new TransferEventHandler)
//set the endpoint for the api call
->setEndPoint("v3/transfers/fee");
- transferEventHandler::startRecording();
+ TransferEventHandler::startRecording();
$response = $this->transfer->applicableFees($array);
- transferEventHandler::sendAnalytics('Get-Transfer-Fee');
+ TransferEventHandler::sendAnalytics('Get-Transfer-Fee');
return $response;
}
@@ -177,14 +102,14 @@ function getBanksForTransfer($data = array("country" => 'NG'))
{
//set the payment handler
- $this->transfer->eventHandler(new transferEventHandler)
+ $this->transfer->eventHandler(new TransferEventHandler)
//set the endpoint for the api call
->setEndPoint("v2/banks/" . $data['country'] . "/");
- transferEventHandler::startRecording();
+ TransferEventHandler::startRecording();
$response= $this->transfer->getBanksForTransfer();
- transferEventHandler::sendAnalytics('Get-Banks-For-Transfer');
+ TransferEventHandler::sendAnalytics('Get-Banks-For-Transfer');
return $response;
}
@@ -199,4 +124,3 @@ function verifyTransaction()
}
-?>
diff --git a/library/Ussd.php b/library/Ussd.php
index 67162ee..13d2eb2 100644
--- a/library/Ussd.php
+++ b/library/Ussd.php
@@ -4,82 +4,7 @@
//uncomment if you need this
//define("BASEPATH", 1);//Allow direct access to rave.php and raveEventHandler.php
-require_once('rave.php');
-require_once('raveEventHandlerInterface.php');
-require_once('EventTracker.php');
-
-class ussdEventHandler implements EventHandlerInterface
-{
- use EventTracker;
-
- /**
- * This is called only when a transaction is successful
- * */
- function onSuccessful($transactionData)
- {
- // 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
- // Comfirm that the transaction is successful
- // Confirm that the chargecode is 00 or 0
- // 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 (includeing parameters that didn't exist before the transaction is completed. for audit purpose)
- // Give value for the transaction
- // Update the transaction to note that you have given value for the transaction
- // You can also redirect to your success page from here
-
- self::sendAnalytics("Initiate-USSD-transfer");
- }
-
- /**
- * This is called only when a transaction failed
- * */
- function onFailure($transactionData)
- {
- self::sendAnalytics("Initiate-USSD-transfer-error");
- // Get the transaction from your DB using the transaction reference (txref)
- // Update the db transaction record (includeing parameters that didn't exist before the transaction is completed. for audit purpose)
- // You can also redirect to your failure page from here
-
- }
-
- /**
- * This is called when a transaction is requeryed from the payment gateway
- * */
- function onRequery($transactionReference)
- {
- // Do something, anything!
- }
-
- /**
- * This is called a transaction requery returns with an error
- * */
- function onRequeryError($requeryResponse)
- {
- // Do something, anything!
- }
-
- /**
- * This is called when a transaction is canceled by the user
- * */
- function onCancel($transactionReference)
- {
- // Do something, anything!
- // Note: Somethings a payment can be successful, before a user clicks the cancel button so proceed with caution
-
- }
-
- /**
- * This is called when a transaction doesn't return with a success or a failure response. This can be a timedout transaction on the Rave server or an abandoned transaction by the customer.
- * */
- function onTimeout($transactionReference, $data)
- {
- // Get the transaction from your DB using the transaction reference (txref)
- // Queue it for requery. Preferably using a queue system. The requery should be about 15 minutes after.
- // Ask the customer to contact your support and you should escalate this issue to the flutterwave support team. Send this as an email and as a notification on the page. just incase the page timesout or disconnects
-
- }
-}
+use Flutterwave\EventHandlers\UssdEventHandler;
class Ussd
{
@@ -97,19 +22,19 @@ function ussd($array)
$this->payment->type = 'ussd';
//add tx_ref to the paylaod
- if (!isset($array['tx_ref']) || empty($array['tx_ref'])) {
+ if (empty($array['tx_ref'])) {
$array['tx_ref'] = $this->payment->txref;
}
//set the payment handler
- $this->payment->eventHandler(new ussdEventHandler)
+ $this->payment->eventHandler(new UssdEventHandler)
//set the endpoint for the api call
->setEndPoint("v3/charges?type=" . $this->payment->type);
//returns the value from the results
- ussdEventHandler::startRecording();
+ UssdEventHandler::startRecording();
$response= $this->payment->chargePayment($array);
- ussdEventHandler::sendAnalytics('Initiate-USSD-Transfer');
+ UssdEventHandler::sendAnalytics('Initiate-USSD-Transfer');
return $response;
@@ -122,5 +47,3 @@ function verifyTransaction($id)
}
}
-
-?>
diff --git a/library/VirtualAccount.php b/library/VirtualAccount.php
index 1ede108..4e59fed 100644
--- a/library/VirtualAccount.php
+++ b/library/VirtualAccount.php
@@ -2,87 +2,14 @@
namespace Flutterwave;
-require_once('rave.php');
-require_once('raveEventHandlerInterface.php');
-require_once('EventTracker.php');
-
-class virtualAccountEventHandler implements EventHandlerInterface
-{
- use EventTracker;
-
- /**
- * This is called only when a transaction is successful
- * */
- function onSuccessful($transactionData)
- {
- // 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
- // Comfirm that the transaction is successful
- // Confirm that the chargecode is 00 or 0
- // 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 (includeing parameters that didn't exist before the transaction is completed. for audit purpose)
- // Give value for the transaction
- // Update the transaction to note that you have given value for the transaction
- // You can also redirect to your success page from here
- self::sendAnalytics("Virtual-Account");
- }
-
- /**
- * This is called only when a transaction failed
- * */
- function onFailure($transactionData)
- {
- // Get the transaction from your DB using the transaction reference (txref)
- // Update the db transaction record (includeing parameters that didn't exist before the transaction is completed. for audit purpose)
- // You can also redirect to your failure page from here
- self::sendAnalytics("Virtual-Account-error");
- }
-
- /**
- * This is called when a transaction is requeryed from the payment gateway
- * */
- function onRequery($transactionReference)
- {
- // Do something, anything!
- }
-
- /**
- * This is called a transaction requery returns with an error
- * */
- function onRequeryError($requeryResponse)
- {
- // Do something, anything!
- }
-
- /**
- * This is called when a transaction is canceled by the user
- * */
- function onCancel($transactionReference)
- {
- // Do something, anything!
- // Note: Somethings a payment can be successful, before a user clicks the cancel button so proceed with caution
-
- }
-
- /**
- * This is called when a transaction doesn't return with a success or a failure response. This can be a timedout transaction on the Rave server or an abandoned transaction by the customer.
- * */
- function onTimeout($transactionReference, $data)
- {
- // Get the transaction from your DB using the transaction reference (txref)
- // Queue it for requery. Preferably using a queue system. The requery should be about 15 minutes after.
- // Ask the customer to contact your support and you should escalate this issue to the flutterwave support team. Send this as an email and as a notification on the page. just incase the page timesout or disconnects
-
- }
-}
+use Flutterwave\EventHandlers\UssdEventHandler;
+use Flutterwave\EventHandlers\VirtualAccountEventHandler;
class VirtualAccount
{
- function __construct()
- {
+ function __construct() {
$this->va = new Rave($_ENV['SECRET_KEY']);
}
@@ -90,8 +17,7 @@ function __construct()
* Creating the VirtualAccount
*/
- function createvirtualAccount($userdata)
- {
+ function createvirtualAccount($userdata) {
if (!isset($userdata['email']) || !isset($userdata['duration']) || !isset($userdata['frequency'])
|| !isset($userdata['amount'])) {
@@ -101,58 +27,55 @@ function createvirtualAccount($userdata)
}
- $this->va->eventHandler(new virtualAccountEventHandler)
+ $this->va->eventHandler(new VirtualAccountEventHandler)
//set the endpoint for the api call
->setEndPoint("v3/virtual-account-numbers");
//returns the value of the result.
- ussdEventHandler::startRecording();
+ UssdEventHandler::startRecording();
$response = $this->va->createVirtualAccount($userdata);
- ussdEventHandler::sendAnalytics('Create-Virtual-Account');
+ UssdEventHandler::sendAnalytics('Create-Virtual-Account');
return $response;
}
- function createBulkAccounts($array)
- {
+ function createBulkAccounts($array) {
- $this->va->eventHandler(new virtualAccountEventHandler)
+ $this->va->eventHandler(new VirtualAccountEventHandler)
//set the endpoint for the api call
->setEndPoint("v3/bulk-virtual-account-numbers");
//returns the value of the result.
- ussdEventHandler::startRecording();
+ UssdEventHandler::startRecording();
$response = $this->va->createBulkAccounts($array);
- ussdEventHandler::sendAnalytics('Create-Bulk-Virtual-Account');
+ UssdEventHandler::sendAnalytics('Create-Bulk-Virtual-Account');
return $response;
}
- function getBulkAccounts($array)
- {
+ function getBulkAccounts($array) {
if (!isset($array['batch_id'])) {
return ' Error:
The following body params are required: batch_id
';
}
- $this->va->eventHandler(new virtualAccountEventHandler)
+ $this->va->eventHandler(new VirtualAccountEventHandler)
//set the endpoint for the api call
->setEndPoint("v3/bulk-virtual-account-numbers/" . $array['batch_id']);
//returns the value of the result.
- ussdEventHandler::startRecording();
+ UssdEventHandler::startRecording();
$response = $this->va->getBulkAccounts($array);
- ussdEventHandler::sendAnalytics('Get-Bulk-Virtual-Account');
+ UssdEventHandler::sendAnalytics('Get-Bulk-Virtual-Account');
return $response;
}
- function getAccountNumber($array)
- {
+ function getAccountNumber($array) {
if (!isset($array['order_ref'])) {
return ' Error:
@@ -160,14 +83,14 @@ function getAccountNumber($array)
';
}
- $this->va->eventHandler(new virtualAccountEventHandler)
+ $this->va->eventHandler(new VirtualAccountEventHandler)
//set the endpoint for the api call
->setEndPoint("v3/virtual-account-numbers/" . $array['order_ref']);
//returns the value of the result.
- ussdEventHandler::startRecording();
+ UssdEventHandler::startRecording();
$response = $this->va->getvAccountsNum();
- ussdEventHandler::sendAnalytics('Get-Virtual-Account-number');
+ UssdEventHandler::sendAnalytics('Get-Virtual-Account-number');
return $response;
}
diff --git a/library/VirtualCards.php b/library/VirtualCard.php
similarity index 98%
rename from library/VirtualCards.php
rename to library/VirtualCard.php
index 28a2404..d018f0b 100644
--- a/library/VirtualCards.php
+++ b/library/VirtualCard.php
@@ -5,8 +5,7 @@
//uncomment if you need this
//define("BASEPATH", 1);//Allow direct access to rave.php and raveEventHandler.php
-require_once('rave.php');
-require_once('EventTracker.php');
+use Flutterwave\EventHandlers\EventTracker;
class VirtualCard
{
@@ -173,4 +172,3 @@ function block_unblock_card($array)
}
-?>
diff --git a/library/VoucherPayment.php b/library/VoucherPayment.php
index f0d1fbb..22d44fd 100644
--- a/library/VoucherPayment.php
+++ b/library/VoucherPayment.php
@@ -1,114 +1,31 @@
onFailure($transactionData);
- }
- }
-
- /**
- * This is called only when a transaction failed
- * */
- function onFailure($transactionData)
- {
- // Get the transaction from your DB using the transaction reference (txref)
- // Update the db transaction record (includeing parameters that didn't exist before the transaction is completed. for audit purpose)
- // You can also redirect to your failure page from here
- self::sendAnalytics("Initiate-Voucher-Payment-error");
-
- }
-
- /**
- * This is called when a transaction is requeryed from the payment gateway
- * */
- function onRequery($transactionReference)
- {
- // Do something, anything!
- }
-
- /**
- * This is called a transaction requery returns with an error
- * */
- function onRequeryError($requeryResponse)
- {
- // Do something, anything!
- }
-
- /**
- * This is called when a transaction is canceled by the user
- * */
- function onCancel($transactionReference)
- {
- // Do something, anything!
- // Note: Somethings a payment can be successful, before a user clicks the cancel button so proceed with caution
-
- }
-
- /**
- * This is called when a transaction doesn't return with a success or a failure response. This can be a timedout transaction on the Rave server or an abandoned transaction by the customer.
- * */
- function onTimeout($transactionReference, $data)
- {
- // Get the transaction from your DB using the transaction reference (txref)
- // Queue it for requery. Preferably using a queue system. The requery should be about 15 minutes after.
- // Ask the customer to contact your support and you should escalate this issue to the flutterwave support team. Send this as an email and as a notification on the page. just incase the page timesout or disconnects
-
- }
-}
+use Flutterwave\EventHandlers\VoucherEventHandler;
class VoucherPayment
{
- function __construct()
- {
+ function __construct() {
$this->payment = new Rave($_ENV['SECRET_KEY']);
}
- function voucher($array)
- {
-
-
+ function voucher($array) {
//add tx_ref to the paylaod
- if (!isset($array['tx_ref']) || empty($array['tx_ref'])) {
+ if (empty($array['tx_ref'])) {
$array['tx_ref'] = $this->payment->txref;
}
$this->payment->type = 'voucher_payment';
- $this->payment->eventHandler(new voucherEventHandler)
+ $this->payment->eventHandler(new VoucherEventHandler)
//set the endpoint for the api call
->setEndPoint("v3/charges?type=" . $this->payment->type);
//returns the value from the results
- voucherEventHandler::startRecording();
+ VoucherEventHandler::startRecording();
$response = $this->payment->chargePayment($array);
- voucherEventHandler::sendAnalytics("Initiate-Voucher-Payment");
+ VoucherEventHandler::sendAnalytics("Initiate-Voucher-Payment");
return $response;
}
@@ -117,8 +34,7 @@ function voucher($array)
* After validation then verify the charge with the txRef
* You can write out your function to execute when the verification is successful in the onSuccessful function
***/
- function verifyTransaction($id)
- {
+ function verifyTransaction($id) {
//verify the charge
return $this->payment->verifyTransaction($id);//Uncomment this line if you need it
}
diff --git a/playground/AccountPayment.php b/playground/AccountPayment.php
index f79f0f6..b63b33a 100644
--- a/playground/AccountPayment.php
+++ b/playground/AccountPayment.php
@@ -6,7 +6,9 @@
DEFINE('DS', DIRECTORY_SEPARATOR);
require("../library/AccountPayment.php");
-use Flutterwave\Account;
+
+use Flutterwave\EventHandlers\EventHandlers\EventHandlers\EventHandlers\EventHandlers\AccountPayment;
+
//The data variable holds the payload
@@ -27,7 +29,7 @@
]
);
-$payment = new Account();
+$payment = new AccountPayment();
$result = $payment->accountCharge($data);
$sera = serialize($payment);
diff --git a/playground/Bill.php b/playground/Bill.php
index c8b0e70..74e02ba 100644
--- a/playground/Bill.php
+++ b/playground/Bill.php
@@ -4,7 +4,8 @@
include('partials/header.php');//this is just to load the bootstrap and css.
require("../library/Bill.php");
-use Flutterwave\Bill;
+
+use Flutterwave\EventHandlers\EventHandlers\EventHandlers\EventHandlers\EventHandlers\Bill;
//sample payload for payBill()
$data = array(
diff --git a/playground/Ebill.php b/playground/Ebill.php
index 1a0a490..ee4ac6a 100644
--- a/playground/Ebill.php
+++ b/playground/Ebill.php
@@ -4,7 +4,8 @@
include('partials/header.php');//this is just to load the bootstrap and css.
require("../library/Ebill.php");
-use Flutterwave\Ebill;
+
+use Flutterwave\EventHandlers\EventHandlers\EventHandlers\EventHandlers\EventHandlers\Ebill;
//sample payload for payBill()
$data = array(
diff --git a/playground/Mobilemoney.php b/playground/Mobilemoney.php
index bd42303..83d4c10 100644
--- a/playground/Mobilemoney.php
+++ b/playground/Mobilemoney.php
@@ -3,7 +3,9 @@
include('partials/header.php');//this is just to load the bootstrap and css.
require("../library/MobileMoney.php");
-use Flutterwave\MobileMoney;
+
+use Flutterwave\EventHandlers\EventHandlers\EventHandlers\EventHandlers\EventHandlers\MobileMoney;
+
//The data variable holds the payload
$data = array(
"order_id" => "USS_URG_89245453s2323",
diff --git a/playground/Mpesa.php b/playground/Mpesa.php
index e0caabe..d4e2b81 100644
--- a/playground/Mpesa.php
+++ b/playground/Mpesa.php
@@ -6,7 +6,9 @@
require("../library/Mpesa.php");
-use Flutterwave\Mpesa;
+
+use Flutterwave\EventHandlers\EventHandlers\EventHandlers\EventHandlers\EventHandlers\Mpesa;
+
//The data variable holds the payload
$data = array(
"amount" => "1500",
diff --git a/playground/Preexample.php b/playground/Preexample.php
index e693bc1..1dfc447 100644
--- a/playground/Preexample.php
+++ b/playground/Preexample.php
@@ -3,7 +3,7 @@
include('partials/header.php');//this is just to load the bootstrap and css.
require("../library/Preauth.php");
-use Flutterwave\Preauth;
+use Flutterwave\EventHandlers\EventHandlers\EventHandlers\EventHandlers\EventHandlers\Preauth;
$payment = new Preauth();
diff --git a/playground/TokenCharge.php b/playground/TokenCharge.php
index b80ce03..116c4ba 100644
--- a/playground/TokenCharge.php
+++ b/playground/TokenCharge.php
@@ -5,8 +5,10 @@
-require("../library/TokinizedCharge.php");
-use Flutterwave\TokinizedCharge;
+require("../library/TokenizedCharge.php");
+
+use Flutterwave\EventHandlers\EventHandlers\EventHandlers\EventHandlers\EventHandlers\TokenizedCharge;
+
//The data variable holds the payload
$data = array(
"token"=> "flw-t1nf-1ff187b04cecb4acff4ac62c2b6f7784-m03k",
@@ -20,7 +22,7 @@
"device_fingerprint" =>"62wd23423rq324323qew1"
);
-$payment = new TokinizedCharge();
+$payment = new TokenizedCharge();
$result = $payment->tokenCharge($data);//initiates the charge
$verify = $payment->verifyTransaction();
diff --git a/playground/Transactions.php b/playground/Transactions.php
index 34e2d33..9b3f2d0 100644
--- a/playground/Transactions.php
+++ b/playground/Transactions.php
@@ -3,7 +3,9 @@
include('partials/header.php');//this is just to load the bootstrap and css.
require("../library/Transactions.php");
-use Flutterwave\Transactions;
+
+use Flutterwave\EventHandlers\EventHandlers\EventHandlers\EventHandlers\EventHandlers\Transactions;
+
//The data variable holds the payload
$data = array(
'amount'=> 1000
diff --git a/playground/Transfer.php b/playground/Transfer.php
index 9e8a053..62f86b7 100644
--- a/playground/Transfer.php
+++ b/playground/Transfer.php
@@ -6,7 +6,9 @@
require("../library/Transfer.php");
-use Flutterwave\Transfer;
+
+use Flutterwave\EventHandlers\EventHandlers\EventHandlers\EventHandlers\EventHandlers\Transfer;
+
//sample payload for payBill()
$data = array(
"account_bank"=> "044",
diff --git a/playground/Ussd.php b/playground/Ussd.php
index 75642a0..1485385 100644
--- a/playground/Ussd.php
+++ b/playground/Ussd.php
@@ -6,7 +6,9 @@
require("../library/Ussd.php");
-use Flutterwave\Ussd;
+
+use Flutterwave\EventHandlers\EventHandlers\EventHandlers\EventHandlers\EventHandlers\Ussd;
+
//The data variable holds the payload
$data = array(
"tx_ref" => "MC-15852309v5050e8",
diff --git a/playground/VoucherPayment.php b/playground/VoucherPayment.php
index bea2f03..a729115 100644
--- a/playground/VoucherPayment.php
+++ b/playground/VoucherPayment.php
@@ -6,7 +6,9 @@
require("../library/VoucherPayment.php");
-use Flutterwave\VoucherPayment;
+
+use Flutterwave\EventHandlers\EventHandlers\EventHandlers\EventHandlers\EventHandlers\VoucherPayment;
+
//The data variable holds the payload
$data = array(
//"public_key": "FLWPUBK-xxxxxxxxxxxxxxxxxxxxx-X"//you can ommit the public key as the key is take from your .env file
diff --git a/playground/achPayment.php b/playground/achPayment.php
index 7dbd55c..cf76482 100644
--- a/playground/achPayment.php
+++ b/playground/achPayment.php
@@ -6,7 +6,9 @@
DEFINE('DS', DIRECTORY_SEPARATOR);
require("../library/AchPayment.php");
-use Flutterwave\Ach;
+
+use Flutterwave\EventHandlers\EventHandlers\EventHandlers\EventHandlers\EventHandlers\AchPayment;
+
//The data variable holds the payload
@@ -23,7 +25,7 @@
"redirect_url" => "http://ekene.com/u/payment-completed",
);
-$payment = new Ach();
+$payment = new AchPayment();
$result = $payment->achCharge($data);
echo '
diff --git a/playground/bvn.php b/playground/bvn.php
index a810ce5..34a7313 100644
--- a/playground/bvn.php
+++ b/playground/bvn.php
@@ -3,7 +3,9 @@
include('partials/header.php');//this is just to load the bootstrap and css.
require("../library/bvn.php");
-use Flutterwave\Bvn;
+
+use Flutterwave\EventHandlers\EventHandlers\EventHandlers\EventHandlers\EventHandlers\Bvn;
+
//The data variable holds the payload
$bvn_number = "123456789";
$bvn = new Bvn();
diff --git a/playground/card.php b/playground/card.php
index 65c8d2e..ba7df31 100644
--- a/playground/card.php
+++ b/playground/card.php
@@ -7,7 +7,8 @@
require("../library/CardPayment.php");
require("testcards.php");
-use Flutterwave\Card;
+
+use Flutterwave\EventHandlers\EventHandlers\EventHandlers\EventHandlers\EventHandlers\CardPayment;
//check the file testcards.php for the sample request...
//The data variable holds the payload
@@ -17,7 +18,7 @@
if (isset($_POST['charge'])){
$card_option = $_POST['token'];
- $payment = new Card();
+ $payment = new CardPayment();
$result = $payment->cardCharge($cards[$card_option]);
if(gettype($result) == 'string'){
diff --git a/playground/paymentPlan.php b/playground/paymentPlan.php
index 361e46d..443db60 100644
--- a/playground/paymentPlan.php
+++ b/playground/paymentPlan.php
@@ -4,7 +4,8 @@
include('partials/header.php');//this is just to load the bootstrap and css.
require("../library/PaymentPlan.php");
-use Flutterwave\PaymentPlan;
+
+use Flutterwave\EventHandlers\EventHandlers\EventHandlers\EventHandlers\EventHandlers\PaymentPlan;
//sample payload for payBill()
$data = array(
diff --git a/playground/preauth.php b/playground/preauth.php
index c487522..fdd3ab4 100644
--- a/playground/preauth.php
+++ b/playground/preauth.php
@@ -7,7 +7,8 @@
require("../library/Preauth.php");
require("testcards.php");
-use Flutterwave\Preauth;
+
+use Flutterwave\EventHandlers\EventHandlers\EventHandlers\EventHandlers\EventHandlers\Preauth;
//check the file testcards.php for the sample request...
//The data variable holds the payload
diff --git a/playground/recipient.php b/playground/recipient.php
index a7cbf34..0d58cea 100644
--- a/playground/recipient.php
+++ b/playground/recipient.php
@@ -6,7 +6,9 @@
require("../library/Recipient.php");
-use Flutterwave\Recipient;
+
+use Flutterwave\EventHandlers\EventHandlers\EventHandlers\EventHandlers\EventHandlers\Recipient;
+
//sample payload for payBill()
$data = array(
"account_bank"=> "044",
diff --git a/playground/subaccount.php b/playground/subaccount.php
index 17b7acd..41e18d6 100644
--- a/playground/subaccount.php
+++ b/playground/subaccount.php
@@ -3,7 +3,9 @@
include('partials/header.php');//this is just to load the bootstrap and css.
require("../library/Subaccount.php");
-use Flutterwave\Subaccount;
+
+use Flutterwave\EventHandlers\EventHandlers\EventHandlers\EventHandlers\EventHandlers\Subaccount;
+
//The data variable holds the payload
$data = array(
"account_bank"=> "044",
diff --git a/playground/subscription.php b/playground/subscription.php
index 43fbae1..abcafb1 100644
--- a/playground/subscription.php
+++ b/playground/subscription.php
@@ -6,7 +6,9 @@
require("../library/Subscription.php");
-use Flutterwave\Subscription;
+
+use Flutterwave\EventHandlers\EventHandlers\EventHandlers\EventHandlers\EventHandlers\Subscription;
+
//sample payload for payBill()
$id = 1112; //Id of subscription plan
$cid = 2222;
diff --git a/playground/virtualAccount.php b/playground/virtualAccount.php
index 450fb4a..74e9302 100644
--- a/playground/virtualAccount.php
+++ b/playground/virtualAccount.php
@@ -4,7 +4,8 @@
include('partials/header.php');//this is just to load the bootstrap and css.
require("../library/VirtualAccount.php");
-use Flutterwave\VirtualAccount;
+
+use Flutterwave\EventHandlers\EventHandlers\EventHandlers\EventHandlers\EventHandlers\VirtualAccount;
//sample payload for payBill()
$data = array(
diff --git a/playground/virtualCard.php b/playground/virtualCard.php
index 8bedbfa..1f15793 100644
--- a/playground/virtualCard.php
+++ b/playground/virtualCard.php
@@ -6,7 +6,9 @@
require("../library/VirtualCards.php");
-use Flutterwave\VirtualCard;
+
+use Flutterwave\EventHandlers\EventHandlers\EventHandlers\EventHandlers\EventHandlers\VirtualCard;
+
//The data variable holds the payload
$data = array(
"currency"=>"NGN",
diff --git a/processPayment.php b/processPayment.php
index bb1605b..9e7d2fc 100644
--- a/processPayment.php
+++ b/processPayment.php
@@ -1,35 +1,29 @@
status === 'successful'){
- if($transactionData->currency == $_SESSION['currency'] && $transactionData->amount == $_SESSION['amount']){
-
- if($_SESSION['publicKey']){
- header('Location: '.getURL($_SESSION['successurl'], array('event' => 'successful')));
+ if ($transactionData->status === 'successful') {
+ if ($transactionData->currency == $_SESSION['currency'] && $transactionData->amount == $_SESSION['amount']) {
+
+ if ($_SESSION['publicKey']) {
+ header('Location: ' . getURL($_SESSION['successurl'], array('event' => 'successful')));
$_SESSION = array();
session_destroy();
}
- }else{
- if($_SESSION['publicKey']){
- header('Location: '.getURL($_SESSION['failureurl'], array('event' => 'suspicious')));
+ } else {
+ if ($_SESSION['publicKey']) {
+ header('Location: ' . getURL($_SESSION['failureurl'], array('event' => 'suspicious')));
$_SESSION = array();
session_destroy();
}
- }
- }else{
- $this->onFailure($transactionData);
- }
+ }
+ } else {
+ $this->onFailure($transactionData);
+ }
}
-
+
/**
* This is called only when a transaction failed
* */
- function onFailure($transactionData){
+ function onFailure($transactionData) {
// Get the transaction from your DB using the transaction reference (txref)
// Update the db transaction record (includeing parameters that didn't exist before the transaction is completed. for audit purpose)
// You can also redirect to your failure page from here
- if($_SESSION['publicKey']){
- header('Location: '.getURL($_SESSION['failureurl'], array('event' => 'failed')));
+ if ($_SESSION['publicKey']) {
+ header('Location: ' . getURL($_SESSION['failureurl'], array('event' => 'failed')));
$_SESSION = array();
session_destroy();
}
}
-
+
/**
* This is called when a transaction is requeryed from the payment gateway
* */
- function onRequery($transactionReference){
+ function onRequery($transactionReference) {
// Do something, anything!
}
-
+
/**
* This is called a transaction requery returns with an error
* */
- function onRequeryError($requeryResponse){
+ function onRequeryError($requeryResponse) {
echo 'the transaction was not found';
}
-
+
/**
* This is called when a transaction is canceled by the user
* */
- function onCancel($transactionReference){
+ function onCancel($transactionReference) {
// Do something, anything!
// Note: Somethings a payment can be successful, before a user clicks the cancel button so proceed with caution
- if($_SESSION['publicKey']){
- header('Location: '.getURL($_SESSION['failureurl'], array('event' => 'canceled')));
+ if ($_SESSION['publicKey']) {
+ header('Location: ' . getURL($_SESSION['failureurl'], array('event' => 'canceled')));
$_SESSION = array();
session_destroy();
}
}
-
+
/**
* This is called when a transaction doesn't return with a success or a failure response. This can be a timedout transaction on the Rave server or an abandoned transaction by the customer.
* */
- function onTimeout($transactionReference, $data){
+ function onTimeout($transactionReference, $data) {
// Get the transaction from your DB using the transaction reference (txref)
// Queue it for requery. Preferably using a queue system. The requery should be about 15 minutes after.
// Ask the customer to contact your support and you should escalate this issue to the flutterwave support team. Send this as an email and as a notification on the page. just incase the page timesout or disconnects
- if($_SESSION['publicKey']){
- header('Location: '.getURL($_SESSION['failureurl'], array('event' => 'timedout')));
+ if ($_SESSION['publicKey']) {
+ header('Location: ' . getURL($_SESSION['failureurl'], array('event' => 'timedout')));
$_SESSION = array();
session_destroy();
}
}
}
-if(isset($postData['amount'])){
+if (isset($postData['amount'])) {
// Make payment
$payment
- ->eventHandler(new myEventHandler)
- ->setAmount($postData['amount'])
- ->setPaymentOptions($postData['payment_options']) // value can be card, account or both
- ->setDescription($postData['description'])
- ->setLogo($postData['logo'])
- ->setTitle($postData['title'])
- ->setCountry($postData['country'])
- ->setCurrency($postData['currency'])
- ->setEmail($postData['email'])
- ->setFirstname($postData['firstname'])
- ->setLastname($postData['lastname'])
- ->setPhoneNumber($postData['phonenumber'])
- ->setPayButtonText($postData['pay_button_text'])
- ->setRedirectUrl($URL)
- // ->setMetaData(array('metaname' => 'SomeDataName', 'metavalue' => 'SomeValue')) // can be called multiple times. Uncomment this to add meta datas
- // ->setMetaData(array('metaname' => 'SomeOtherDataName', 'metavalue' => 'SomeOtherValue')) // can be called multiple times. Uncomment this to add meta datas
- ->initialize();
-}else{
- if(isset($getData['cancelled'])){
+ ->eventHandler(new myEventHandler)
+ ->setAmount($postData['amount'])
+ ->setPaymentOptions($postData['payment_options']) // value can be card, account or both
+ ->setDescription($postData['description'])
+ ->setLogo($postData['logo'])
+ ->setTitle($postData['title'])
+ ->setCountry($postData['country'])
+ ->setCurrency($postData['currency'])
+ ->setEmail($postData['email'])
+ ->setFirstname($postData['firstname'])
+ ->setLastname($postData['lastname'])
+ ->setPhoneNumber($postData['phonenumber'])
+ ->setPayButtonText($postData['pay_button_text'])
+ ->setRedirectUrl($URL)
+ // ->setMetaData(array('metaname' => 'SomeDataName', 'metavalue' => 'SomeValue')) // can be called multiple times. Uncomment this to add meta datas
+ // ->setMetaData(array('metaname' => 'SomeOtherDataName', 'metavalue' => 'SomeOtherValue')) // can be called multiple times. Uncomment this to add meta datas
+ ->initialize();
+} else {
+ if (isset($getData['cancelled'])) {
// Handle canceled payments
$payment
- ->eventHandler(new myEventHandler)
- ->paymentCanceled($getData['cancelled']);
- }elseif(isset($getData['tx_ref'])){
+ ->eventHandler(new myEventHandler)
+ ->paymentCanceled($getData['cancelled']);
+ } elseif (isset($getData['tx_ref'])) {
// Handle completed payments
$payment->logger->notice('Payment completed. Now requerying payment.');
$payment
- ->eventHandler(new myEventHandler)
- ->requeryTransaction($getData['transaction_id']);
- }else{
+ ->eventHandler(new myEventHandler)
+ ->requeryTransaction($getData['transaction_id']);
+ } else {
$payment->logger->warn('Stop!!! Please pass the txref parameter!');
echo 'Stop!!! Please pass the txref parameter!';
}
}
-?>
diff --git a/tests/VirtualCardTest.php b/tests/VirtualCardTest.php
index e428bc0..6b5f658 100644
--- a/tests/VirtualCardTest.php
+++ b/tests/VirtualCardTest.php
@@ -1,7 +1,7 @@