[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: TelebirrIntegrationTrait.php
<?php namespace App\PaymentChannels\Drivers\Telebirr; use GuzzleHttp\Client; use Illuminate\Support\Facades\Http; trait TelebirrIntegrationTrait { public function applyFabricToken() { $response = Http::withHeaders([ 'Content-Type' => 'application/json', 'X-APP-Key' => $this->fabric_app_id, ]) ->post($this->base_url . '/payment/v1/token', [ 'appSecret' => $this->app_secret, ]); dd($response); $client = new Client(); $response = $client->post($this->base_url . "/payment/v1/token", [ 'headers' => [ 'Content-Type' => 'application/json', 'X-APP-Key' => $this->fabric_app_id, ], 'json' => [ 'appSecret' => $this->app_secret, ] ]); dd($response); return json_decode($response->getBody(), true); } public function createOrder($title, $amount, $returnUrl) { $applyFabricTokenResult = $this->applyFabricToken(); $fabricToken = $applyFabricTokenResult['token']; $createOrderResult = $this->requestCreateOrder($fabricToken, $title, $amount, $returnUrl); $prepayId = $createOrderResult['biz_content']['prepay_id']; $rawRequest = $this->createRawRequest($prepayId); $url = $this->base_url . $rawRequest . "&version=1.0&trade_type=Checkout"; dd($url); return $url; } private function requestCreateOrder($fabricToken, $title, $amount, $returnUrl) { $client = new Client(); $response = $client->post($this->base_url . "/payment/v1/merchant/preOrder", [ 'headers' => [ 'Content-Type' => 'application/json', 'X-APP-Key' => $this->fabric_app_id, 'Authorization' => $fabricToken, ], 'json' => [ 'timestamp' => time(), 'nonce_str' => bin2hex(random_bytes(16)), 'method' => 'payment.preorder', 'version' => '1.0', 'biz_content' => [ 'notify_url' => $returnUrl, 'appid' => $this->merchant_app_id, 'merch_code' => $this->merchant_code, 'merch_order_id' => $this->order->id, 'trade_type' => 'Checkout', 'title' => $title, 'total_amount' => $amount, 'trans_currency' => $this->currency, 'timeout_express' => '120m', 'business_type' => 'BuyGoods', 'redirect_url' => $returnUrl, 'callback_info' => 'From web', ], 'sign' => $this->signRequestObject([ 'timestamp' => time(), 'nonce_str' => bin2hex(random_bytes(16)), 'method' => 'payment.preorder', 'version' => '1.0', ]), 'sign_type' => 'SHA256WithRSA', ] ]); return json_decode($response->getBody(), true); } private function createRawRequest($prepayId) { $map = [ 'appid' => $this->merchant_app_id, 'merch_code' => $this->merchant_code, 'nonce_str' => bin2hex(random_bytes(16)), 'prepay_id' => $prepayId, 'timestamp' => time(), "sign_type" => "SHA256WithRSA" ]; $sign = $this->signRequestObject($map); // Order by ASCII in array ksort($map); return http_build_query($map) . "&sign=" . $sign . "&sign_type=SHA256WithRSA"; } private function signRequestObject($data) { $exclude_fields = array("sign", "sign_type", "header", "refund_info", "openType", "raw_request"); ksort($data); $stringApplet = ''; foreach ($data as $key => $values) { if (in_array($key, $exclude_fields)) { continue; } if ($key == "biz_content") { foreach ($values as $value => $single_value) { if ($stringApplet == '') { $stringApplet = $value . '=' . $single_value; } else { $stringApplet = $stringApplet . '&' . $value . '=' . $single_value; } } } else { if ($stringApplet == '') { $stringApplet = $key . '=' . $values; } else { $stringApplet = $stringApplet . '&' . $key . '=' . $values; } } } $sortedString = $this->sortedString($stringApplet); return $this->signWithPrivateKey($sortedString); } private function sortedString($stringApplet) { $stringExplode = ''; $sortedArray = explode("&", $stringApplet); sort($sortedArray); foreach ($sortedArray as $x => $x_value) { if ($stringExplode == '') { $stringExplode = $x_value; } else { $stringExplode = $stringExplode . '&' . $x_value; } } return $stringExplode; } private function signWithPrivateKey($data) { $privateKey = '-----BEGIN PRIVATE KEY----- ' . $this->private_key . ' -----END PRIVATE KEY-----'; // dont format. this is correct $privateKey = openssl_pkey_get_private($privateKey); if (!$privateKey) { dd("Error loading PrivateKey"); } openssl_sign($data, $signature, $privateKey, OPENSSL_ALGO_SHA256); openssl_free_key($privateKey); return base64_encode($signature); } }
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: premium320.web-hosting.com
Server IP: 66.29.153.54
PHP Version: 8.2.29
Server Software: LiteSpeed
System: Linux premium320.web-hosting.com 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
HDD Total: 97.87 GB
HDD Free: 76.85 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Enabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes (py3)
gcc:
Yes
pkexec:
No
git:
Yes
User Info
Username: aoneqssk
User ID (UID): 1285
Group ID (GID): 1290
Script Owner UID: 1285
Current Dir Owner: 1285