68 lines
2.3 KiB
PHP
68 lines
2.3 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' => config('harim_web_services.Harim_Payment.serial'),
|
|
'type' => 1,
|
|
'instanceid' => config('harim_web_services.Harim_Payment.instanceid'),
|
|
'ownerid' => $national_id,
|
|
'calculationBox' => "{\"rows\":[{\"amount\":" . $payment_amount . ",\"code\":\"7070011026200593\"}]}"
|
|
);
|
|
|
|
$response = Http::withBody(http_build_query($payload))
|
|
->throw()
|
|
->withoutVerifying()
|
|
->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}";
|
|
|
|
return Http::get($result)
|
|
->throw()
|
|
->body();
|
|
|
|
}catch (\Throwable $th) {
|
|
throw new ProhibitedAction('خطا در دریافت');
|
|
}
|
|
}
|
|
return json_encode(['isPayed' => 1]);
|
|
}
|
|
}
|