66 lines
2.1 KiB
PHP
66 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Cartables\Harim;
|
|
|
|
use App\Exceptions\ProhibitedAction;
|
|
use Illuminate\Support\Facades\App;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Illuminate\Support\Facades\URL;
|
|
|
|
class HarimPaymentService
|
|
{
|
|
/**
|
|
* @throws ProhibitedAction
|
|
*/
|
|
public function invoiceBillApi($national_id, $payment_amount): int|string
|
|
{
|
|
if (App::isProduction())
|
|
{
|
|
try {
|
|
$payload = array(
|
|
'username' => config('harim_web_services.Harim_Payment.username'),
|
|
'password' => config('harim_web_services.Harim_Payment.PASSWORD'),
|
|
'amount' => $payment_amount,
|
|
'serial' => "12345",
|
|
'type' => 1,
|
|
'instanceid' => 123,
|
|
'ownerid' => $national_id,
|
|
'calculationBox' => "{\"rows\":[{\"amount\":" . $payment_amount . ",\"code\":\"7070011026200593\"}]}"
|
|
);
|
|
|
|
$response = Http::retry(3, 100)->withBody(http_build_query($payload))
|
|
->post(config('harim_web_services.Harim_Payment.url'));
|
|
|
|
return $response->body();
|
|
|
|
}
|
|
catch (\Throwable $th) {
|
|
throw new ProhibitedAction('خطا در ارتباط با سرویس پرداخت');
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
public function callPaymentStatusBillApi($bill_code)
|
|
{
|
|
if (App::isProduction())
|
|
{
|
|
try {
|
|
$username = config('harim_web_services.Harim_Payment.username');
|
|
$password = config('harim_web_services.Harim_Payment.PASSWORD');
|
|
$url = config('harim_web_services.Harim_Payment.url');
|
|
|
|
$result = "{$url}/{$username}/{$password}/{$bill_code}";
|
|
|
|
$response = Http::timeout(10)->get($result);
|
|
|
|
|
|
return $response;
|
|
} catch (\Throwable $th) {
|
|
abort(500);
|
|
}
|
|
}
|
|
return json_encode(['isPayed' => 1]);
|
|
}
|
|
}
|