Files
exchange-2.0/app/Classes/Modules/Billplzs/Services/CreatesBillplzBill.php
T

42 lines
1.5 KiB
PHP

<?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 $bankCode, string $billNumber) {
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,
'redirect_url' => config('billplz.redirect_url'),
'callback_url' => config('billplz.callback_url'),
'reference_1_label' => 'Bank Code',
'reference_1' => $bankCode,
'reference_2_label' => 'Bill Number',
'reference_2' => $billNumber
]);
if($response->successful()){
$data = $response->json();
$data['url'] = $data['url'].'?auto_submit=true';
return (object) $data;
}else{
return null;
}
}catch(\Exception $exception){
throw new MalformedRequestException('Unable to get correct response from billplz server');
}
}
}