Last active
April 11, 2021 07:03
-
-
Save elsayed85/10598e552ed826620480af71d406fd22 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| return [ | |
| "vapulus" => [ | |
| "baseurl" => "https://api.vapulus.com:1338/", | |
| "failUrl" => "", | |
| "successUrl" => "", | |
| 'app_id' => env('VAPULUS_AppID'), | |
| 'password' => env('VAPULUS_password'), | |
| 'hash' => env('VAPULUS_HASH') | |
| ] | |
| ]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class vapulus | |
| { | |
| private $baseUrl; | |
| private $successUrl; | |
| private $failUrl; | |
| public function __construct() | |
| { | |
| $this->baseUrl = config('payment.vapulus.baseurl'); | |
| $this->successUrl = config('payment.vapulus.successUrl'); | |
| $this->failUrl = config('payment.vapulus.failUrl'); | |
| } | |
| public function userInfo($userId) | |
| { | |
| return $this->HTTPPost('userInfo', ['userId' => $userId]); | |
| } | |
| // CARDS | |
| public function addCard(array $data) | |
| { | |
| return $this->HTTPPost('makeTransaction', $data); | |
| } | |
| public function cardInfo($userId, $cardId) | |
| { | |
| return $this->HTTPPost('cardInfo', ['userId' => $userId, 'cardId' => $cardId]); | |
| } | |
| // OTB | |
| public function validateOTP(array $data) | |
| { | |
| return $this->HTTPPost('validateOTP', $data); | |
| } | |
| public function resendCode(array $data) | |
| { | |
| return $this->HTTPPost('resendCode', $data); | |
| } | |
| // PAYMENT | |
| public function makePayment(array $data) | |
| { | |
| return $this->HTTPPost('makePayment', $data); | |
| } | |
| // TRANSACTIONS | |
| public function makeTransaction(array $data, $amount) | |
| { | |
| $data['onAccept'] = $this->successUrl; | |
| $data['onFail'] = $this->failUrl; | |
| $data['amount'] = $amount; | |
| return $this->HTTPPost('makeTransaction', $data); | |
| } | |
| public function transactionsList($userId, array $data) | |
| { | |
| return $this->HTTPPost('transactions/list', array_merge(['userId' => $userId], $data)); | |
| } | |
| public function transactionInfo($transactionId) | |
| { | |
| return $this->HTTPPost('transactionInfo', ['transactionId' => $transactionId]); | |
| } | |
| public function transactionStatus($transactionId, $merchantId) | |
| { | |
| return $this->HTTPPost('transaction/status', ['transactionId' => $transactionId, 'merchantId' => $merchantId]); | |
| } | |
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
| public function generateHash($postData) | |
| { | |
| ksort($postData); | |
| $message = ""; | |
| $appendAmp = 0; | |
| foreach ($postData as $key => $value) { | |
| if (strlen($value) > 0) { | |
| if ($appendAmp == 0) { | |
| $message .= $key . '=' . $value; | |
| $appendAmp = 1; | |
| } else { | |
| $message .= '&' . $key . "=" . $value; | |
| } | |
| } | |
| } | |
| $secret = pack('H*', config('payment.vapulus.hash')); | |
| return hash_hmac('sha256', $message, $secret); | |
| } | |
| function HTTPPost($url, array $params) | |
| { | |
| $url = $this->baseUrl . $url; | |
| $params['hashSecret'] = $this->generateHash($params); | |
| $params['appId'] = config('payment.vapulus.app_id'); | |
| $params['password'] = config('payment.vapulus.password'); | |
| $query = http_build_query($params); | |
| $ch = curl_init(); | |
| curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
| curl_setopt($ch, CURLOPT_HEADER, false); | |
| curl_setopt($ch, CURLOPT_URL, $url); | |
| curl_setopt($ch, CURLOPT_POST, true); | |
| curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | |
| curl_setopt($ch, CURLOPT_POSTFIELDS, $query); | |
| $response = curl_exec($ch); | |
| curl_close($ch); | |
| $resp = json_decode($response); | |
| return $resp; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment