1. Go to this page and download the library: Download zfhassaan/alfa library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use zfhassaan\Alfapay\AlfaPay;
public function get_token(){
// generate random transaction/order number
$transNum = rand(0,17866120);
// get AuthToken from AlfaPay API
$alfa = new AlfaPay();
$response = $alfa->setTransactionReferenceNumber($transNum)->getToken();
//
if( $response != null && $response->success == 'true' ) {
return $response->AuthToken;
} else {
// log error
if( $response == null ) {
abort(403, 'Error: Timeout connection. Auth Token not generated.');
} else {
abort(403, 'Error: '.$response->ErrorMessage.'. Auth Token does not generated.');
}
}
}
public function process(){
$alfa->setAuthToken($this->get_token());
$alfa->setCurrency('PKR');
$alfa->setTransactionReferenceNumber($request->TransctionReferenceNumber);
$alfa->setTransactionType($request->TransactionTypeId);
$alfa->setAmount($request->Amount);
$alfa->setMobileNumber($request->MobileNumber);
$alfa->setEmail($request->Email);
$alfa->setCountryCode('164'); // Pakistan = 164
$alfa->sendTransactionRequest();
// return $alfa->sendTransactionRequest();
$transactionResponse = $alfa->sendTransactionRequest();
if($transactionResponse != null && $transactionResponse->success = 'true') {
$TransactionReferenceNumber = $transactionResponse->TransactionReferenceNumber;
$TransactionTypeId = $transactionResponse->TransactionTypeId;
$HashKey = $transactionResponse->HashKey;
$AuthToken = $request->AuthToken;
// Can return it in a view to send next request for OTP
// It depends on the developer how to utilize it.
}
abort(404,$transactionResponse);
}
public function otp(Request $request) {
$this->validate($request,[
'OTP' => 'actionReferenceNumber'=>'st->TransactionReferenceNumber);
$alfa->setTransactionType($request->TransactionTypeId);
$alfa->setHashKey($request->HashKey);
$alfa->setSMSOTP($request->OTP);
$alfa->setAuthToken($request->AuthToken);
$processResponse = $alfa->processTransaction();
if($processResponse != null && property_exists($processResposne, 'response_code'))
{
try{
$currency = $alfa->getCurrency('PKR');
$paidAmount = $processResponse->transaction_amount;
$apiResponse = serialize($processResponse);
session()->flash('success', 'Payment Success');
// Return with currency, paid Amount , apiResponse, ProcessResponse or
// compact it in views to show Thank you ( Order Confirmation page )
} catch(\Exception $e) {
abort(403, 'Error: ', $e->getMessage());
}
} else {
abort(403, 'Error: '.$processResponse->ErrorMessage.'. Transaction OTP not completed');
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.