api_key = 'abecfd0c-98d8-4635-abc2-2fcba8c60c11'; $this->XSignature_Key = 'S-GWr7z03XjAhqPsFfu_H5nQ'; $this->collection_id = 'bwdtejv0'; }else{ $this->api_key = 'f3e82fe1-a422-4660-97f0-65cc59ff6c47'; $this->XSignature_Key = 'S-alZUbzmD2_TF3vmrRqgehQ'; $this->collection_id = 'lx_bplsb'; } } public function biditem() { $currentdate = Carbon::now(); $currentdate = $currentdate->toDateString(); // dd($currentdate->toDateString()); $lelong = Lelong::where('tarikh_lelong','=',$currentdate)->get(); $arrayID = []; foreach($lelong as $data) { array_push($arrayID,$data->id); } $lelongbid = LelongBid::whereIn('lelong_id',$arrayID) ->join('lelongbidmarhun','lelongbid.id','=','lelongbidmarhun.lelongbid_id') ->get(); $surat = LelongBid::whereIn('lelong_id',$arrayID)->get(); if(sizeof($lelongbid)!=0) { return response()->json([ 'success' => true, 'lelong' => $lelong, 'surat' => $surat, 'item' => $lelongbid ]); } else { return response()->json([ 'success' => false, 'message' => 'No Data', ], 401); } } public function karat() { $jenisemas = JenisEmas::all(); $jeniskarat = JenisKarat::all(); if(sizeof($jenisemas)!=0 && sizeof($jeniskarat)!=0 ) { return response()->json([ 'success' => true, 'karat' => $jeniskarat, 'emas' => $jenisemas ]); } else { return response()->json([ 'success' => false, 'message' => 'No Data', ], 401); } } public function testbillplz() { return view('pembayaran.testbillplz'); } public function feepayment(Request $request) { $arraycollection_id = array(); $http = new HttpMethodsClient( new GuzzleHttpClient(), new GuzzleMessageFactory() ); $billplz = new Client($http, $this->api_key); if(config('app.env') != 'production'){ $billplz->useSandbox(); } $billplz->useVersion('v4'); $bill = $billplz->bill(); $current = Carbon::now(); $current = new Carbon(); $day = $current->day; $month = $current->month; $year = $current->format('y'); $total_bayaran = 1100; $collection_id = $this->collection_id; $response = $bill->create( $collection_id, $request->email, $request->notel, $request->name, Money::MYR($total_bayaran), route('pay.callback'), 'Bayaran Borang', ['redirect_url' => route('pay.paymentStatus')] // ['redirect_url' => url('http://localhost:8080/test')] ); // dd($response); $previous_siri = Resit::orderBy('id','desc')->first(); if($previous_siri){ $nosiri = $previous_siri->id + 1; }else{ $nosiri = 1; } $billcode = $response->toArray(); // dd($billcode); // $billcode['redirect_url'] = 'http://192.168.0.10:8003/api/pembayaran/response'; // dd($billcode); $reference_no = 'LPKB' . $day . $month . $year . sprintf("%08d", $nosiri); // $response2 = $bill->get($billcode['id']); // dd($response2->toArray()); $resit = new Resit; $resit->user_id = $request->user_id; $resit->lelong_id = $request->lelong_id; $resit->reference_no = $reference_no; $resit->billplz_id = $billcode['id']; $resit->resit_type = 1; $resit->total_payment = 10; $resit->save(); // return redirect($billcode['url'] . '?auto_submit=true'); return response()->json([ 'success' => true, 'message' => $billcode['url'], ], 201); // return view('pembayaran.result.berjaya',compact('arraybayaran')); } public function callback(Request $request){ // dd('hye callback'); $http = new HttpMethodsClient( new GuzzleHttpClient(), new GuzzleMessageFactory() ); $billplz = new Client($http, $this->api_key); if(config('app.env') != 'production'){ $billplz->useSandbox(); } $billplz->useVersion('v4'); $bill = $billplz->bill(); $data = $bill->webhook($request->toArray()); if($data['billplz']['paid'] == 'true'){ $resit = Resit::where('billplz_id','=',$data['billplz']['id'])->first(); $resit->status = 'PAID'; $resit->paid_at = $data['billplz']['paid_at']; $resit->save(); $payment = new Payment; $payment->user_id = $resit->user_id; $payment->lelong_id = $resit->lelong_id; $payment->total_payment = $resit->total_payment; $payment->resit_id = $resit->id; $payment->status_payment_opt = 2; //bayar secara online 2 $payment->status = 1; //fee rm10 - 1 $payment->remark = 'BAYARAN ONLINE'; $payment->save(); event(new PaymentNotify('PAID',$resit->user_id,$payment->id)); $success = true; $result = $resit->toArray(); // return response()->json([ // 'success' => true, // 'resit' => $resit // ]); return view('pembida.feePaymentResult',compact('data', 'result', 'success')); }else{ $resit = Resit::where('billplz_id','=',$data['billplz']['id'])->first(); $resit->status = 'UNSUCCESSFUL'; $resit->paid_at = null; $resit->save(); $result = $resit->toArray(); $success = false; event(new PaymentNotify('UNSUCCESSFUL',$resit->user_id,'')); // return response()->json([ // 'success' => false, // 'resit' => $resit // ]); return view('pembida.feePaymentResult',compact('data', 'result', 'success')); } } public function response(Request $request){ // dd('hye response'); $http = new HttpMethodsClient( new GuzzleHttpClient(), new GuzzleMessageFactory() ); $billplz = new Client($http, $this->api_key); if(config('app.env') != 'production'){ $billplz->useSandbox(); } $billplz->useVersion('v4'); $bill = $billplz->bill(); $req = $request->toArray(); $response = $bill->get($req['billplz']['id']); $data = $response->toArray(); // dd($data); if($data['paid'] == 'true'){ $resit = Resit::where('billplz_id','=',$data['id'])->first(); $resit->status = 'PAID'; $resit->paid_at = $data['paid_at']; $resit->save(); $payment = new Payment; $payment->user_id = $resit->user_id; $payment->lelong_id = $resit->lelong_id; $payment->total_payment = $resit->total_payment; $payment->resit_id = $resit->id; $payment->status_payment_opt = 2; //bayar secara online 2 $payment->status = 1; //fee rm10 - 1 $payment->remark = 'BAYARAN ONLINE'; $payment->save(); event(new PaymentNotify('PAID',$resit->user_id,$payment->id)); $success = true; $result = $resit->toArray(); // return response()->json([ // 'success' => true, // 'resit' => $resit // ]); return view('pembida.feePaymentResult',compact('data', 'result', 'success')); // return redirect()->to('http://localhost:8080/test')->with(['resit'=>$resit]); }else{ $resit = Resit::where('billplz_id','=',$data['id'])->first(); $resit->status = 'UNSUCCESSFUL'; $resit->paid_at = null; $resit->save(); $result = $resit->toArray(); $success = false; event(new PaymentNotify('UNSUCCESSFUL',$resit->user_id,'')); // return response()->json([ // 'success' => false, // 'resit' => $resit // ]); return view('pembida.feePaymentResult',compact('data', 'result', 'success')); } } public function bidpayment(Request $request) { $arraycollection_id = array(); $http = new HttpMethodsClient( new GuzzleHttpClient(), new GuzzleMessageFactory() ); $billplz = new Client($http, $this->api_key); if(config('app.env') != 'production'){ $billplz->useSandbox(); } $billplz->useVersion('v4'); $bill = $billplz->bill(); $current = Carbon::now(); $current = new Carbon(); $day = $current->day; $month = $current->month; $year = $current->format('y'); $total_bayaran = ($request->total)*100+100; // dump($request->total); // dd($total_bayaran); $collection_id = $this->collection_id; $response = $bill->create( $collection_id, $request->email, $request->notel, $request->name, Money::MYR($total_bayaran), route('pay.bidcallback'), 'Bayaran Bidaan', ['redirect_url' => route('pay.bidpaymentStatus')] ); // dd($response->toArray()); $previous_siri = Resit::orderBy('id','desc')->first(); if($previous_siri){ $nosiri = $previous_siri->id + 1; }else{ $nosiri = 1; } $billcode = $response->toArray(); // dd($billcode); // $billcode['redirect_url'] = 'http://192.168.0.10:8003/api/pembayaran/response'; // dd($billcode); $reference_no = 'LPKB' . $day . $month . $year . sprintf("%08d", $nosiri); // $response2 = $bill->get($billcode['id']); // dd($response2->toArray()); $resit = new Resit; $resit->user_id = $request->user_id; $resit->lelong_id = $request->lelong_id; $resit->reference_no = $reference_no; $resit->billplz_id = $billcode['id']; $resit->resit_type = 2; //billplz resit for bid payment $resit->total_payment = $request->total; $resit->invoice_id = $request->invoice_id; $resit->invoice_no = $request->invoice_no; $resit->save(); // dd($resit); // $selectedSag = []; $selectedSag = $request->sag; // dd($selectedSag); foreach ($selectedSag as $index) { $payment = new Payment; $payment->user_id = $request->user_id; $payment->lelong_id = $request->lelong_id; $payment->kodcaw = $index['kodcaw']; $payment->lelongbid_id = $index['lelongbid_id']; $payment->norujukan = $index['norujukan']; $payment->total_payment = $index['total_payment']; $payment->status_payment_opt = 2; //bayar secara online 2 $payment->status = 0; //0-unpaid //1-fee //2-bid $payment->remark = ''; $payment->resit_id = $resit->id; $payment->save(); } // return redirect($billcode['url'] . '?auto_submit=true'); return response()->json([ 'success' => true, 'message' => $billcode['url'], ], 201); // return view('pembayaran.result.berjaya',compact('arraybayaran')); } public function bidcallback(Request $request) { // dd('hye callback'); $http = new HttpMethodsClient( new GuzzleHttpClient(), new GuzzleMessageFactory() ); $billplz = new Client($http, $this->api_key); if (config('app.env') != 'production') { $billplz->useSandbox(); } $billplz->useVersion('v4'); $bill = $billplz->bill(); $data = $bill->webhook($request->toArray()); if ($data['billplz']['paid'] == 'true') { $resit = Resit::where('billplz_id', '=', $data['billplz']['id'])->first(); $resit->status = 'PAID'; $resit->paid_at = $data['billplz']['paid_at']; $resit->save(); $resitoriginal = Resit::where('user_id', $resit->user_id) ->where('lelong_id', $resit->lelong_id) ->where('resit_type', 2) ->first(); // $resitoriginal->total_payment = $resitoriginal->total_payment + $resit->total_payment; // $resitoriginal->save(); // $payment = new Payment; // $payment->user_id = $resitoriginal->user_id; // $payment->lelong_id = $resitoriginal->lelong_id; // $payment->total_payment = $resit->total_payment; // $payment->resit_id = $resitoriginal->id; // $payment->status_payment_opt = 2; //bayar secara online 2 // $payment->status = 1; //fee rm10 - 1 // $payment->remark = 'BAYARAN ONLINE'; // $payment->save(); $payment = Payment::where('lelong_id', $resit->lelong_id) ->where('user_id', $resit->user_id) ->where('resit_id', $resit->id) ->get(); foreach ($payment as $index) { $index->status = 2; //0-unpaid //1-fee //2-bid $index->remark = "BERJAYA BAYARAN ONLINE"; $index->update(); // $updateTag = LelongBid::where('lelongbid.norujukan', $index->norujukan)->first(); // $updateTag->status_payment = 2; // $updateTag->save(); // $lelongbidder = $updateTag->lelongbidder; // $lelongbidder->status_payment = 2; // $lelongbidder->payment_id = $index->id; // $lelongbidder->save(); $updateTagBid = LelongBid::where('norujukan', $index->norujukan)->first(); $updateTagBid->status_payment = 2; $updateTagBid->save(); $updateTagBidder = LelongBidder::where('lelongbid_id', $updateTagBid->id) ->where('user_id', $resit->user_id)->first(); $updateTagBidder->status_payment = 2; $updateTagBidder->payment_id = $index->id; $updateTagBidder->save(); } event(new PaymentNotify('PAID', $resit->user_id, $payment)); $success = true; $result = $resit->toArray(); // return response()->json([ // 'success' => true, // 'resit' => $resit // ]); return view('pembida.feePaymentResult', compact('data', 'result', 'success')); } else { $resit = Resit::where('billplz_id', '=', $data['billplz']['id'])->first(); $resit->status = 'UNSUCCESSFUL'; $resit->paid_at = null; $resit->save(); event(new PaymentNotify('UNSUCCESSFUL', $resit->user_id, '')); $result = $resit->toArray(); $success = false; // return response()->json([ // 'success' => false, // 'resit' => $resit // ]); return view('pembida.feePaymentResult', compact('data', 'result', 'success')); } } public function bidresponse(Request $request) { // dd($request->all()); $http = new HttpMethodsClient( new GuzzleHttpClient(), new GuzzleMessageFactory() ); $billplz = new Client($http, $this->api_key); if (config('app.env') != 'production') { $billplz->useSandbox(); } $billplz->useVersion('v4'); $bill = $billplz->bill(); $req = $request->toArray(); $response = $bill->get($req['billplz']['id']); $data = $response->toArray(); if ($data['paid'] == 'true' || $data['paid_at'] != null) { $resit = Resit::where('billplz_id', '=', $data['id'])->first(); $resit->status = 'PAID'; $resit->paid_at = $data['paid_at']; $resit->save(); $resitoriginal = Resit::where('user_id', $resit->user_id) ->where('lelong_id', $resit->lelong_id) ->where('resit_type', 2) ->first(); // $resitoriginal->total_payment = $resitoriginal->total_payment + $resit->total_payment; // $resitoriginal->save(); // $payment = new Payment; // $payment->user_id = $resitoriginal->user_id; // $payment->lelong_id = $resitoriginal->lelong_id; // $payment->total_payment = $resit->total_payment; // $payment->resit_id = $resitoriginal->id; // $payment->status_payment_opt = 2; //bayar secara online 2 // $payment->status = 1; //fee rm10 - 1 // $payment->remark = 'BAYARAN ONLINE'; // $payment->save(); $payment = Payment::where('lelong_id', $resit->lelong_id) ->where('user_id', $resit->user_id) ->where('resit_id', $resit->id) ->get(); foreach ($payment as $index) { $index->status = 2; //0-unpaid //1-fee //2-bid $index->remark = "BERJAYA BAYARAN ONLINE"; $index->update(); // $updateTag = LelongBid::where('lelongbid.norujukan', $index->norujukan)->first(); // $updateTag->status_payment = 2; // $updateTag->save(); // $lelongbidder = $updateTag->lelongbidder; // $lelongbidder->status_payment = 2; // $lelongbidder->payment_id = $index->id; // $lelongbidder->save(); $updateTagBid = LelongBid::where('norujukan', $index->norujukan)->first(); $updateTagBid->status_payment = 2; $updateTagBid->save(); $updateTagBidder = LelongBidder::where('lelongbid_id', $updateTagBid->id) ->where('user_id', $resit->user_id)->first(); $updateTagBidder->status_payment = 2; $updateTagBidder->payment_id = $index->id; $updateTagBidder->save(); } event(new PaymentNotify('PAID', $resit->user_id, $payment)); $success = true; $result = $resit->toArray(); $resit->response = json_encode($data); $resit->save(); // return response()->json([ // 'success' => true, // 'resit' => $resit // ]); return view('pembida.feePaymentResult', compact('data', 'result', 'success')); } else { $resit = Resit::where('billplz_id', '=', $data['id'])->first(); $resit->status = 'UNSUCCESSFUL'; $resit->paid_at = null; $resit->response = json_encode($data); $resit->save(); event(new PaymentNotify('UNSUCCESSFUL', $resit->user_id, '')); $result = $resit->toArray(); $success = false; // return response()->json([ // 'success' => false, // 'resit' => $resit // ]); return view('pembida.feePaymentResult', compact('data', 'result', 'success')); } } // BillplzService.php atau ApiController.php public function processPaidResit(array $data) { $currentdate = Carbon::now(); $currentdate = $currentdate->toDateTimeString(); $loguser = new LogUser; $loguser->user_id = User::where('name','System')->first()->id; $loguser->date = $currentdate; $loguser->username = 'System'; $loguser->nama_user = 'System'; $loguser->norujukan = $data['billplz']['id']; $loguser->nota = 'Callback Resit Billplz Telah Bayar : Billplz_id -'.$data['billplz']['id']; $loguser->save(); $resit = Resit::where('billplz_id', '=', $data['billplz']['id'])->first(); if (!$resit) { return false; } $resit->status = 'PAID'; $resit->paid_at = $data['billplz']['paid_at']; $resit->save(); $resitoriginal = Resit::where('user_id', $resit->user_id) ->where('lelong_id', $resit->lelong_id) ->where('resit_type', 2) ->first(); $payment = Payment::where('lelong_id', $resit->lelong_id) ->where('user_id', $resit->user_id) ->where('resit_id', $resit->id) ->get(); foreach ($payment as $index) { $index->status = 2; $index->remark = "BERJAYA BAYARAN ONLINE"; $index->update(); $updateTagBid = LelongBid::where('norujukan', $index->norujukan)->first(); if ($updateTagBid) { $updateTagBid->status_payment = 2; $updateTagBid->save(); $updateTagBidder = LelongBidder::where('lelongbid_id', $updateTagBid->id) ->where('user_id', $resit->user_id)->first(); if ($updateTagBidder) { $updateTagBidder->status_payment = 2; $updateTagBidder->payment_id = $index->id; $updateTagBidder->save(); } } } event(new PaymentNotify('PAID', $resit->user_id, $payment)); return true; } }