diff --git a/.env.example b/.env.example index 47a20e74..5bf2187f 100644 --- a/.env.example +++ b/.env.example @@ -50,4 +50,9 @@ FILESYSTEM_DRIVER="documents" JWT_SECRET= JWT_TTL=1440 -IS_PRODUCTION=false \ No newline at end of file +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" \ No newline at end of file diff --git a/app/Classes/Modules/Billplzs/ControllersLogic/CreateBillplzBillLogic.php b/app/Classes/Modules/Billplzs/ControllersLogic/CreateBillplzBillLogic.php new file mode 100644 index 00000000..b1333cf6 --- /dev/null +++ b/app/Classes/Modules/Billplzs/ControllersLogic/CreateBillplzBillLogic.php @@ -0,0 +1,56 @@ + '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]); + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Billplzs/Services/CreatesBillplzBill.php b/app/Classes/Modules/Billplzs/Services/CreatesBillplzBill.php new file mode 100644 index 00000000..0bab471f --- /dev/null +++ b/app/Classes/Modules/Billplzs/Services/CreatesBillplzBill.php @@ -0,0 +1,39 @@ +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'); + } + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Billplzs/CreateBillplzBillController.php b/app/Http/Controllers/Billplzs/CreateBillplzBillController.php new file mode 100644 index 00000000..cd62cfec --- /dev/null +++ b/app/Http/Controllers/Billplzs/CreateBillplzBillController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/config/billplz.php b/config/billplz.php new file mode 100644 index 00000000..5166a59e --- /dev/null +++ b/config/billplz.php @@ -0,0 +1,10 @@ + 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' +]; \ No newline at end of file diff --git a/routes/api.php b/routes/api.php index 146d519a..08c0231d 100644 --- a/routes/api.php +++ b/routes/api.php @@ -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'; diff --git a/routes/billplz.php b/routes/billplz.php new file mode 100644 index 00000000..cee3c778 --- /dev/null +++ b/routes/billplz.php @@ -0,0 +1,9 @@ + 'billplz', 'as' => 'billplz.', 'namespace' => 'Billplzs'], function () { + Route::group(['prefix' => 'bill', 'as' => 'bill.'], function () { + Route::post('/create', 'CreateBillplzBillController@create')->name('create'); + }); +}); \ No newline at end of file