Skip to content

Commit

Permalink
Merge pull request #39 from salvationarinze/master
Browse files Browse the repository at this point in the history
Fix: PSR-4 compliance
  • Loading branch information
salvationarinze authored Jun 30, 2022
2 parents e31c6fa + 5c03d50 commit 6662946
Show file tree
Hide file tree
Showing 72 changed files with 1,874 additions and 2,038 deletions.
49 changes: 25 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down Expand Up @@ -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(
Expand All @@ -325,7 +324,7 @@ $data = array(
]
);

$payment = new Account();
$payment = new AccountPayment();
$result = $payment->accountCharge($data);

if(isset($result['data'])){
Expand All @@ -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(
Expand All @@ -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'])){
Expand All @@ -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(
Expand All @@ -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'];

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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();
Expand All @@ -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(
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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",
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"homepage": "https://github.com/Flutterwave/Flutterwave-PHP-v3",
"autoload": {
"psr-4": {
"Flutterwave\\": "library/Rave"
"Flutterwave\\": "library/"
}
},
"require": {
Expand Down
97 changes: 8 additions & 89 deletions library/AccountPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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'];
Expand All @@ -117,25 +36,25 @@ 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");
} else {
$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;
}

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

Expand All @@ -155,4 +74,4 @@ function verifyTransaction($id)
}


?>

Loading

0 comments on commit 6662946

Please sign in to comment.