[php] intergasi duitku
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
- public function store(Request $request)
- {
- // dd($request->all());
- $duitkuConfig = new \Duitku\Config(config('duitku.merchant_key'), config('duitku.merchant_code'));
- // true for sandbox mode, false for production mode
- $duitkuConfig->setSandboxMode(config('duitku.sandbox_mode'));
- // set sanitizer (default : true)
- $duitkuConfig->setSanitizedMode(true);
- // set log parameter (default : true)
- $duitkuConfig->setDuitkuLogs(false);
- DB::transaction(function () use ($duitkuConfig, $request) {
- $tahun = date("Y");
- $paymentAmount = $request->grand_total;
- $email = $request->email;
- $merchantOrderId = 'INV-' . time();
- $productDetails = "Pembayaran untuk Invoice : " . $merchantOrderId;
- $customerVaName = $request->name;
- $callbackUrl = config('app.url') . '/callback'; // url for callback
- $returnUrl = config('app.url') . '/account/transactions/' . $merchantOrderId; // url for redirect
- $expiryPeriod = 1440; // set the expired time in minutes
- //create transaction
- $transaction = Transaction::create([
- 'invoice' => $merchantOrderId,
- 'user_id' => auth()->user()->id,
- 'province_id' => $request->province_id,
- 'city_id' => $request->city_id,
- 'tahun' => $tahun,
- 'weight' => $request->weight,
- 'courier_name' => $request->courier_name,
- 'courier_service' => $request->courier_service,
- 'courier_cost' => $request->courier_cost,
- 'grand_total' => $request->grand_total,
- 'address' => $request->address,
- 'cek_ts' => 1,
- 'status' => 'UNPAID',
- ]);
- //create transaction details & item details
- // Item Details
- $item_details = [];
- foreach (Cart::with('product')->where('user_id', auth()->user()->id)->get() as $cart) {
- //insert product ke table transaction_details
- $transaction->transactionDetails()->create([
- 'transaction_id' => $transaction->id,
- 'product_id' => $cart->product->id,
- 'product_image' => basename($cart->product_image),
- 'size' => $cart->size,
- 'qty' => $cart->qty,
- 'price' => $cart->price,
- 'tahun' => $cart->tahun,
- ]);
- //assign item details
- $item_details[] = array(
- 'name' => $cart->product->title,
- 'price' => $cart->price,
- 'quantity' => $cart->qty,
- );
- }
- //remove data carts
- Cart::with('product')->where('user_id', auth()->user()->id)->delete();
- //push ongkir to items details
- array_push($item_details);
- $customerDetail = array(
- 'firstName' => $request->name,
- 'email' => $request->email,
- 'billingAddress' => array(
- 'firstName' => $request->name,
- 'address' => $request->address,
- ),
- 'shippingAddress' => array(
- 'firstName' => $request->name,
- 'address' => $request->address,
- ),
- );
- $payload = array(
- 'paymentAmount' => $paymentAmount,
- 'merchantOrderId' => $merchantOrderId,
- 'productDetails' => $productDetails,
- 'customerVaName' => $customerVaName,
- 'email' => $email,
- 'itemDetails' => $item_details,
- 'customerDetail' => $customerDetail,
- 'callbackUrl' => $callbackUrl,
- 'returnUrl' => $returnUrl,
- 'expiryPeriod' => $expiryPeriod
- );
- try {
- // createInvoice Request
- $responseDuitkuPop = \Duitku\Pop::createInvoice($payload, $duitkuConfig);
- //get reference
- $getReference = json_decode($responseDuitkuPop, true);
- //insert reference to table transactions
- $transaction->reference = $getReference['reference'];
- $transaction->save();
- //make response "invoice"
- $this->response['invoice'] = $transaction->invoice;
- } catch (Exception $e) {
- echo $e->getMessage();
- }
- });
- return redirect()->route('account.transactions.show', $this->response);
- }
Editor
You can edit this paste and save as new:
File Description
- intergasi duitku
- Paste Code
- 19 Apr-2024
- 5.19 Kb
You can Share it:
Latest Code Pastes