mirror of
https://gitlab.com/uldvstar/exchange-2.0.git
synced 2026-08-19 04:24:16 +00:00
create billplz create bill api
This commit is contained in:
+6
-1
@@ -50,4 +50,9 @@ FILESYSTEM_DRIVER="documents"
|
||||
JWT_SECRET=
|
||||
JWT_TTL=1440
|
||||
|
||||
IS_PRODUCTION=false
|
||||
IS_PRODUCTION=false
|
||||
|
||||
BILLPLZ_BASE_URL="https://www.billplz-sandbox.com"
|
||||
BILLPLZ_API_KEY="0fa4c710-761b-4a7a-a501-c2c2d02643d5"
|
||||
BILLPLZ_COLLECTION_ID="hev2wdjy"
|
||||
BILLPLZ_CALLBACK_URL="localhost:9003"
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Billplzs\ControllersLogic;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
|
||||
use App\Classes\Modules\Billplzs\Services\CreatesBillplzBill;
|
||||
|
||||
use ErrorException;
|
||||
use App\Classes\Exceptions\MalformedRequestException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CreateBillplzBillLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Created Billplz Bill',
|
||||
'message' => 'You have successfully created a new Bill'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CreatesBillplzBill */
|
||||
private $createsBillplzBill;
|
||||
|
||||
/**
|
||||
* CreateBookingLogic constructor.
|
||||
* @param CreatesBillplzBill $createsBillplzBill
|
||||
*/
|
||||
public function __construct(CreatesBillplzBill $createsBillplzBill)
|
||||
{
|
||||
$this->createsBillplzBill = $createsBillplzBill;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws \App\Classes\Exceptions\AccessForbiddenException
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$billPlz = $this->createsBillplzBill->execute($request->user()->name, $request->user()->email, $request->input('billNumber'), 200, $request->input('bankName'));
|
||||
|
||||
if(!$billPlz) throw new MalformedRequestException('Unable to get correct response from billplz server.');
|
||||
|
||||
return $this->response(['data' => $billPlz]);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Billplzs\Services;
|
||||
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class CreatesBillplzBill
|
||||
{
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(string $name, string $email, string $description, float $amount, string $bank_code) {
|
||||
try{
|
||||
$response = Http::withBasicAuth(config('billplz.api_key').':', '')->post(config('billplz.base_url').'/api/v3/bills', [
|
||||
'collection_id' => config('billplz.collection_id'),
|
||||
'name' => $name,
|
||||
'email' => $email,
|
||||
'description' => $description,
|
||||
'amount' => $amount,
|
||||
'callback_url' => config('billplz.callback_url'),
|
||||
'reference_1_label' => 'Bank Code',
|
||||
'reference_1' => config('billplz.'.strtolower($bank_code))
|
||||
]);
|
||||
|
||||
if($response->successful()){
|
||||
$data = $response->json();
|
||||
|
||||
$data['url'] = $data['url'].'?auto_submit=true';
|
||||
|
||||
return $data;
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
}catch(\Exception $exception){
|
||||
throw new MalformedRequestException('Unable to get correct response from billplz server');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Billplzs;
|
||||
|
||||
use App\Classes\Modules\Billplzs\ControllersLogic\CreateBillplzBillLogic;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CreateBillplzBillController
|
||||
{
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param BillplzBillLogic $logic
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function create(Request $request, CreateBillplzBillLogic $logic): JsonResponse {
|
||||
return $logic->execute($request);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'base_url' => env('BILLPLZ_BASE_URL', 'https://www.billplz-sandbox.com'),
|
||||
'api_key' => env('BILLPLZ_API_KEY', '0fa4c710-761b-4a7a-a501-c2c2d02643d5'),
|
||||
'collection_id' => env('BILLPLZ_COLLECTION_ID', 'hev2wdjy'),
|
||||
'callback_url' => env('BILLPLZ_CALLBACK_URL', 'localhost'),
|
||||
'maybank' => 'MB2U0227',
|
||||
'cimb' => 'BCBB0235'
|
||||
];
|
||||
@@ -47,6 +47,8 @@ Route::group(['middleware' => 'api', 'prefix' => 'v1', 'as' => 'api.'], function
|
||||
|
||||
require __DIR__ . '/announcement.php';
|
||||
|
||||
require __DIR__ . '/billplz.php';
|
||||
|
||||
// require __DIR__ . '/wallet.php';
|
||||
// require __DIR__ . '/rate.php';
|
||||
// require __DIR__ . '/receipt.php';
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
Route::group(['prefix' => 'billplz', 'as' => 'billplz.', 'namespace' => 'Billplzs'], function () {
|
||||
Route::group(['prefix' => 'bill', 'as' => 'bill.'], function () {
|
||||
Route::post('/create', 'CreateBillplzBillController@create')->name('create');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user