PHP code example of zfhassaan / easypaisa
1. Go to this page and download the library: Download zfhassaan/easypaisa 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/ */
zfhassaan / easypaisa example snippets
php artisan vendor:publish
try {
$easypaisa = new Easypaisa;
$response = $easypaisa->sendRequest($request->all());
$responseCode = $response['responseCode'];
$responseDesc = $response['responseDesc'];
if ($responseCode != '0000') {
return response()->json(['status' => false, 'message' => $responseDesc], Response::HTTP_NOT_ACCEPTABLE);
}
$result = [
'status_code' => '00',
'status_msg' => $response['responseDesc'],
'transaction_id' => $response['transactionId'],
'code' => $response['responseCode'],
'message' => $response['responseDesc'],
'basket_id' => strip_tags($request['orderId'])
];
return response()->json($result);
} catch (\Exception $e) {
return response()->json(['status' => false, 'message' => 'Error Processing Your Request.'], 500);
}
$credentials = $this->getCredentials();
$data = [
'orderId' => strip_tags($request['orderId']),
'storeId' => $this->getStoreId(),
'transactionAmount' => strip_tags($request['amount']),
'transactionType' => 'MA',
'mobileAccountNo' => strip_tags($request['mobileAccountNo']),
'emailAddress' => strip_tags($request['emailAddress'])
];
$response = Http::timeout(60)->withHeaders([
'credentials' => $credentials,
'Content-Type' => 'application/json'
])->post($this->getApiUrl(), $data);
$result = $response->json();
return $result;
$data['amount'] = strip_tags($request['amount']); //Last two digits will be considered as Decimal
$data['orderRefNum'] = strip_tags($request['orderRefNum']); // You can customize it (only Max 20 Alpha-Numeric characters)
$data['paymentMethod'] = 'InitialRequest';
$data['postBackURL'] = $this->getCallbackUrl();
$data['storeId'] = $this->getStoreId();
$data['timeStamp'] = $this->getTimestamp();
$hashk = $this->gethashRequest($data);
$data['encryptedHashRequest'] = $hashk;
$data['mobileAccountNo'] = '';
return $this->getCheckoutUrl($data);
<form action="" method="POST" target="_blank">
@csrf
<input name="transactionAmount" value=""/>
<input name="orderId" value="" hidden = "true"/>
<input name="storeId" value="" hidden = "true"/>
<input name="mobileAccountNo" value=""/>
<input name="emailAddress" value=""/>
<input name="postBackURL" value="" hidden = "true"/>
<input type="submit" src=”checkout-button-with-logo.png border=”0” name= “pay”>
</form>
public function index(Request $request)
{
$easypaisa = new Easypaisa();
$response = $easypaisa->sendHostedRequest($request->all());
return redirect()->away($response,302);
}