merged main to feature split

This commit is contained in:
Hafifie PKB
2025-01-20 15:32:40 +08:00
40 changed files with 1407 additions and 329 deletions
+79 -19
View File
@@ -6,6 +6,8 @@ use App\Models\TransactionOnlineStatus;
use Billplz\Client;
use Carbon\Carbon;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Session;
class BillplzService
{
@@ -14,24 +16,14 @@ class BillplzService
public $callbackUrl;
public $paymentTitle;
public $redirectUrl;
public $company;
public function __construct()
public function __construct(string $company)
{
$appEnvironment = config('app.env');
$billplzConfig = $appEnvironment == 'production' ? config('services.billplz.production') : config('services.billplz.sandbox');
$client = Client::make($billplzConfig['api_key'], $billplzConfig['x_signature']);
$client->useVersion('v4');
if ($appEnvironment != 'production') {
$client->useSandbox();
}
$this->callbackUrl = route('pay.callback');
$this->redirectUrl = ['redirect_url' => route('pay.paymentStatus')];
$this->paymentTitle = "Pembayaran Ansuran";
$this->config = $billplzConfig;
$this->client = $client;
$this->company = $company;
$this->setupBillplzClient($company);
$this->setupUrls();
$this->paymentTitle = config('services.billplz.paymentTitle');
}
public function getCollections()
@@ -39,8 +31,9 @@ class BillplzService
return $this->client->collection()->all()->toArray();
}
public function createBill(array $data)
public function createBill(array $data,string $company)
{
$composed_data = [
$this->config['collection_id'],
...$data,
@@ -94,6 +87,8 @@ class BillplzService
public function webhook($request)
{
// $this->setCompany(Session::get('company'));
// $this->setupBillplzClient($this->company);
try {
$response = $this->client->webhook($request);
@@ -145,13 +140,21 @@ class BillplzService
public function getArrahnTransactions($queryData)
{
$query_all = [];
if(isset($queryData['date'])){
return Http::arrahn()->get('/api/transaction/online/query', ['date' => $queryData['date']])->json();
$pkb_query = Http::arrahn()->get('/api/transaction/online/query', ['date' => $queryData['date']])->json();
$koop_query = Http::arrahn_koop()->get('/api/transaction/online/query', ['date' => $queryData['date']])->json();
$query_all = array_merge($pkb_query,$koop_query);
}
if(isset($queryData['billId'])){
return Http::arrahn()->get('/api/transaction/online/query', ['billId' => $queryData['billId']])->json();
$pkb_query = Http::arrahn()->get('/api/transaction/online/query', ['billId' => $queryData['billId']])->json();
$koop_query = Http::arrahn_koop()->get('/api/transaction/online/query', ['billId' => $queryData['billId']])->json();
$query_all = array_merge($pkb_query,$koop_query);
}
return $query_all;
}
public function getBillplzTransactionReview($date)
@@ -252,4 +255,61 @@ class BillplzService
{
return array_map(fn($x) => $this->client->bill()->get($x)->toArray(), $billIds);
}
protected function setupBillplzClient($company)
{
$appEnvironment = config('app.env');
$billplzEnvironments = [
'PKB' => ($appEnvironment === 'production') ? config('services.billplz.production') : config('services.billplz.sandbox'),
'KOPKB' => ($appEnvironment === 'production') ? config('services.billplz.production_kopkb') : config('services.billplz.sandbox_kopkb'),
];
$billplzConfig = $appEnvironment === 'production'
? ($billplzEnvironments[$company] ?? config('services.billplz.production'))
: ($billplzEnvironments[$company] ?? config('services.billplz.sandbox'));
$client = Client::make($billplzConfig['api_key'], ($this->isBase64($billplzConfig['x_signature'])) ? $billplzConfig['x_signature'] : base64_encode($billplzConfig['x_signature']));
$client->useVersion('v4');
if ($appEnvironment !== 'production') {
$client->useSandbox();
}
$this->config = $billplzConfig;
$this->client = $client;
}
protected function setupUrls()
{
$this->callbackUrl = route('pay.callback');
$this->redirectUrl = ['redirect_url' => route('pay.paymentStatus')];
}
protected function isBase64($string) {
if($this->isBase64UrlSafe($string)){
return true;
}
if (preg_match('/^[A-Za-z0-9+\/=]+$/', $string)) {
return base64_encode(base64_decode($string, true)) === $string;
}
return false;
}
protected function isBase64UrlSafe($string) {
// Convert URL-safe Base64 to standard Base64
$standardBase64 = str_replace(['-', '_'], ['+', '/'], $string);
// Add padding if necessary
$remainder = strlen($standardBase64) % 4;
if ($remainder > 0) {
$standardBase64 .= str_repeat('=', 4 - $remainder);
}
// Attempt to decode the string
$decoded = base64_decode($standardBase64, true);
return $decoded !== false; // Return true if it successfully decodes
}
}
+22 -6
View File
@@ -3,6 +3,7 @@
namespace App\Services;
use App\Http\Controllers\InformationController;
use App\Models\CompanyStatus;
use Illuminate\Http\Client\Pool;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Http;
@@ -23,6 +24,9 @@ class PembiayaanService
}
$pembiayaan = array_filter($getPembiayaan(), fn($x) => $x->hargajualan != null || $x->hargajualan != 0);
// $pembiayaan_filter = array_filter($getPembiayaan(),fn($x) => $x->tag_syarikat == CompanyStatus::COM_PKB);
// $pembiayaan_koop = array_filter($getPembiayaan(),fn($x) => $x->tag_syarikat == CompanyStatus::COM_PKB);
$pembiayaan = $this->setUpahTawarruq($pembiayaan);
$pembiayaan = $this->formatPembiayaanData($pembiayaan);
$pembiayaan = $this->checkPembiayaanPaymentDisabled($pembiayaan);
@@ -44,7 +48,12 @@ class PembiayaanService
$getUpahTawarruqPerPembiayaan = function ($x) use ($getJenisKeuntungan) {
$jenisKeuntungan = $getJenisKeuntungan($x);
$upahTawarruq = Http::arrahn()->get('/api/upahtawarruq/' . $x->kodcaw . '/' . $x->norujukan, ['jeniskeuntungan' => $jenisKeuntungan])->json();
$CallableHttp = $x->tag_syarikat == CompanyStatus::COM_PKB
? Http::arrahn()
: Http::arrahn_koop();
$upahTawarruq = $CallableHttp->get('/api/upahtawarruq/' . $x->kodcaw . '/' . $x->norujukan, ['jeniskeuntungan' => $jenisKeuntungan])->json();
if ($jenisKeuntungan == 'onepercent') {
$x->upah_tawarruq = $upahTawarruq['keuntungan'] + $upahTawarruq['ujrah'];
@@ -62,7 +71,10 @@ class PembiayaanService
private function formatPembiayaanData($pembiayaan)
{
$allCawangan = Http::arrahn()->get('/api/cawangan')->json();
$arrahnCawangan = Http::arrahn()->get('/api/cawangan')->json();
$arrahnKoopCawangan = Http::arrahn_koop()->get('/api/cawangan')->json();
$allCawangan = array_merge($arrahnCawangan, $arrahnKoopCawangan);
$setCawanganFullName = function ($pembiayaan) use ($allCawangan) {
$cawangan = array_filter($allCawangan, fn($x) => $x['kodcaw'] === $pembiayaan->kodcaw);
@@ -100,13 +112,17 @@ class PembiayaanService
return $formatted;
}
public function getMarhunModalData($norujukan)
public function getMarhunModalData($norujukan,$tagsyarikat)
{
$gadaianDetails = Http::arrahn()->get('/api/gadai/norujukan/' . $norujukan)->json()[0][0];
$CallableHttp = $tagsyarikat == CompanyStatus::COM_PKB
? Http::arrahn()
: Http::arrahn_koop();
$gadaianDetails = $CallableHttp->get('/api/gadai/norujukan/' . $norujukan)->json()[0][0];
$attachCawanganName = function ($x) use ($gadaianDetails) {
$x['cawangan_name'] = Http::arrahn()->get('/api/cawangan/detail/' . $gadaianDetails['kodcaw'])->json()[0]['cawangan'];
$attachCawanganName = function ($x) use ($gadaianDetails,$CallableHttp) {
$x['cawangan_name'] = $CallableHttp->get('/api/cawangan/detail/' . $gadaianDetails['kodcaw'])->json()[0]['cawangan'];
return $x;
};