⚝
One Hat Cyber Team
⚝
Your IP:
216.73.216.142
Server IP:
217.76.53.76
Server:
Linux vmi1397931.contaboserver.net 5.4.0-105-generic #119-Ubuntu SMP Mon Mar 7 18:49:24 UTC 2022 x86_64
Server Software:
Apache
PHP Version:
8.2.27
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
www
/
wwwroot
/
onlinestore.ng
/
app
/
Http
/
Controllers
/
View File Name :
ToyyibpayController.php
type == 'company') { // $payment_setting = Utility::getAdminPaymentSetting(); // } else { // $payment_setting = Utility::getCompanyPaymentSetting($this->invoiceData); // } $payment_setting = Utility::getAdminPaymentSetting(); $this->secretKey = isset($payment_setting['toyyibpay_secret_key']) ? $payment_setting['toyyibpay_secret_key'] : ''; $this->categoryCode = isset($payment_setting['toyyibpay_category_code']) ? $payment_setting['toyyibpay_category_code'] : ''; $this->is_enabled = isset($payment_setting['is_toyyibpay_enabled']) ? $payment_setting['is_toyyibpay_enabled'] : 'off'; } public function index() { return view('payment'); } public function toyyibpayPaymentPrepare(Request $request) { try { $planID = \Illuminate\Support\Facades\Crypt::decrypt($request->plan_id); $plan = Plan::find($planID); if ($plan) { $get_amount = $plan->price; if (!empty($request->coupon)) { $coupons = Coupon::where('code', strtoupper($request->coupon))->where('is_active', '1')->first(); if (!empty($coupons)) { $usedCoupun = $coupons->used_coupon(); $discount_value = ($plan->price / 100) * $coupons->discount; $get_amount = $plan->price - $discount_value; if ($coupons->limit == $usedCoupun) { return redirect()->back()->with('error', __('This coupon code has expired.')); } } else { return redirect()->back()->with('error', __('This coupon code is invalid or has expired.')); } } $coupon = (empty($request->coupon)) ? "0" : $request->coupon; $this->callBackUrl = route('plan.toyyibpay.callback', [$plan->id, $get_amount, $coupon]); $this->returnUrl = route('plan.toyyibpay.callback', [$plan->id, $get_amount, $coupon]); $Date = date('d-m-Y'); $ammount = $get_amount; $billName = $plan->name; $description = $plan->name; $billExpiryDays = 3; $billExpiryDate = date('d-m-Y', strtotime($Date . ' + 3 days')); $billContentEmail = "Thank you for purchasing our product!"; $some_data = array( 'userSecretKey' => $this->secretKey, 'categoryCode' => $this->categoryCode, 'billName' => $billName, 'billDescription' => $description, 'billPriceSetting' => 1, 'billPayorInfo' => 1, 'billAmount' => 100 * $ammount, 'billReturnUrl' => $this->returnUrl, 'billCallbackUrl' => $this->callBackUrl, 'billExternalReferenceNo' => 'AFR341DFI', 'billTo' => \Auth::user()->name, 'billEmail' => \Auth::user()->email, 'billPhone' => '000000000', 'billSplitPayment' => 0, 'billSplitPaymentArgs' => '', 'billPaymentChannel' => '0', 'billContentEmail' => $billContentEmail, 'billChargeToCustomer' => 1, 'billExpiryDate' => $billExpiryDate, 'billExpiryDays' => $billExpiryDays ); $curl = curl_init(); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_URL, 'https://toyyibpay.com/index.php/api/createBill'); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $some_data); $result = curl_exec($curl); $info = curl_getinfo($curl); curl_close($curl); $obj = json_decode($result); return redirect('https://toyyibpay.com/' . $obj[0]->BillCode); } else { return redirect()->route('plans.index')->with('error', __('Plan is deleted.')); } } catch (Exception $e) { return redirect()->route('plans.index')->with('error', __($e->getMessage())); } } public function toyyibpayPlanGetPayment(Request $request, $planId, $getAmount, $couponCode) { if ($couponCode != 0) { $coupons = Coupon::where('code', strtoupper($couponCode))->where('is_active', '1')->first(); $request['coupon_id'] = $coupons->id; } else { $coupons = null; } $plan = Plan::find($planId); $user = auth()->user(); $admin_payment_setting = Utility::getAdminPaymentSetting(); // $request['status_id'] = 1; // 1=success, 2=pending, 3=fail try { $orderID = strtoupper(str_replace('.', '', uniqid('', true))); if ($request->status_id == 3) { $statuses = 'Fail'; $order = new PlanOrder(); $order->order_id = $orderID; $order->name = $user->name; $order->card_number = ''; $order->card_exp_month = ''; $order->card_exp_year = ''; $order->plan_name = $plan->name; $order->plan_id = $plan->id; $order->price = $getAmount; $order->price_currency = isset($admin_payment_setting['currency']) && !empty($admin_payment_setting['currency']) ? $admin_payment_setting['currency'] : 'USD'; $order->payment_type = __('Toyyibpay'); $order->payment_status = $statuses; $order->receipt = ''; $order->user_id = $user->id; $order->save(); return redirect()->route('plans.index')->with('error', __('Your Transaction is fail please try again')); } else if ($request->status_id == 2) { $statuses = 'pandding'; $order = new PlanOrder(); $order->order_id = $orderID; $order->name = $user->name; $order->card_number = ''; $order->card_exp_month = ''; $order->card_exp_year = ''; $order->plan_name = $plan->name; $order->plan_id = $plan->id; $order->price = $getAmount; $order->price_currency = isset($admin_payment_setting['currency']) && !empty($admin_payment_setting['currency']) ? $admin_payment_setting['currency'] : 'USD'; $order->payment_type = __('Toyyibpay'); $order->payment_status = $statuses; $order->receipt = ''; $order->user_id = $user->id; $order->save(); return redirect()->route('plans.index')->with('error', __('Your transaction on pending')); } else if ($request->status_id == 1) { $statuses = 'success'; $order = new PlanOrder(); $order->order_id = $orderID; $order->name = $user->name; $order->card_number = ''; $order->card_exp_month = ''; $order->card_exp_year = ''; $order->plan_name = $plan->name; $order->plan_id = $plan->id; $order->price = $getAmount; $order->price_currency = isset($admin_payment_setting['currency']) && !empty($admin_payment_setting['currency']) ? $admin_payment_setting['currency'] : 'USD'; $order->payment_type = __('Toyyibpay'); $order->payment_status = $statuses; $order->receipt = ''; $order->user_id = $user->id; $order->save(); $assignPlan = $user->assignPlan($plan->id); $coupons = Coupon::find($request->coupon_id); if (!empty($request->coupon_id)) { if (!empty($coupons)) { $userCoupon = new UserCoupon(); $userCoupon->user = $user->id; $userCoupon->coupon = $coupons->id; $userCoupon->order = $orderID; $userCoupon->save(); $usedCoupun = $coupons->used_coupon(); if ($coupons->limit <= $usedCoupun) { $coupons->is_active = 0; $coupons->save(); } } } Utility::referralTransaction($plan); if ($assignPlan['is_success']) { return redirect()->route('plans.index')->with('success', __('Plan activated Successfully.')); } else { return redirect()->route('plans.index')->with('error', __($assignPlan['error'])); } } else { return redirect()->route('plans.index')->with('error', __('Plan is deleted.')); } } catch (Exception $e) { return redirect()->route('plans.index')->with('error', __($e->getMessage())); } } public function toyyibpaypayment(Request $request, $slug){ try { $cart = session()->get($slug); $products = $cart['products']; $customers = $cart['customer']; $store = Store::where('slug', $slug)->first(); $companyPaymentSetting = Utility::getPaymentSetting($store->id); $total_tax = $sub_total = $total = $sub_tax = 0; $product_name = []; $product_id = []; foreach ($products as $key => $product) { if ($product['variant_id'] != 0) { $product_name[] = $product['product_name']; $product_id[] = $product['id']; foreach ($product['tax'] as $tax) { $sub_tax = ($product['variant_price'] * $product['quantity'] * $tax['tax']) / 100; $total_tax += $sub_tax; } $totalprice = $product['variant_price'] * $product['quantity']; $total += $totalprice; } else { $product_name[] = $product['product_name']; $product_id[] = $product['id']; foreach ($product['tax'] as $tax) { $sub_tax = ($product['price'] * $product['quantity'] * $tax['tax']) / 100; $total_tax += $sub_tax; } $totalprice = $product['price'] * $product['quantity']; $total += $totalprice; } } if ($products) { $get_amount = $total + $total_tax; if (isset($cart['coupon'])) { if ($cart['coupon']['coupon']['enable_flat'] == 'off') { $discount_value = ($get_amount / 100) * $cart['coupon']['coupon']['discount']; $get_amount = $get_amount - $discount_value; } else { $discount_value = $cart['coupon']['coupon']['flat_discount']; $get_amount = $get_amount - $discount_value; } } if (isset($cart['shipping']) && isset($cart['shipping']['shipping_id']) && !empty($cart['shipping'])) { $shipping = Shipping::find($cart['shipping']['shipping_id']); if (!empty($shipping)) { $get_amount = $get_amount + $shipping->price; } } // $coupon = (isset($cart['coupon'])) ? "0" : $request->coupon; $this->callBackUrl = route('toyyibpay.callback', [ $store->slug, $get_amount]); $this->returnUrl = route('toyyibpay.callback', [ $store->slug, $get_amount]); $Date = date('d-m-Y'); $ammount = $get_amount; $billName = $product['product_name']; $description = $product['product_name']; $billExpiryDays = 3; $billExpiryDate = date('d-m-Y', strtotime($Date . ' + 3 days')); $billContentEmail = "Thank you for purchasing our product!"; $some_data = array( 'userSecretKey' => $companyPaymentSetting['toyyibpay_secret_key'], 'categoryCode' =>$companyPaymentSetting['toyyibpay_category_code'], 'billName' => $billName, 'billDescription' => $description, 'billPriceSetting' => 1, 'billPayorInfo' => 1, 'billAmount' => 100 * $ammount, 'billReturnUrl' => $this->returnUrl, 'billCallbackUrl' => $this->callBackUrl, 'billExternalReferenceNo' => 'AFR341DFI', 'billTo' => $customers['name'], 'billEmail' => $customers['email'], 'billPhone' => str_replace(array("+", "(", ")","-"), "", $customers['phone']), 'billSplitPayment' => 0, 'billSplitPaymentArgs' => '', 'billPaymentChannel' => '0', 'billContentEmail' => $billContentEmail, 'billChargeToCustomer' => 1, 'billExpiryDate' => $billExpiryDate, 'billExpiryDays' => $billExpiryDays ); $curl = curl_init(); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_URL, 'https://toyyibpay.com/index.php/api/createBill'); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $some_data); $result = curl_exec($curl); $info = curl_getinfo($curl); curl_close($curl); $obj = json_decode($result); return redirect('https://toyyibpay.com/' . $obj[0]->BillCode); } else { return redirect()->back()->with('error', __('product is not found.')); } } catch (\Throwable $e) { return redirect()->back()->with('error', __($e->getMessage())); } } public function toyyibpaycallpack(Request $request , $slug, $get_amount){ $pay_id = $request->transaction_id; $cart = session()->get($slug); $store = Store::where('slug', $slug)->first(); // $request['status_id'] = 1; $cust_details = $cart['customer']; if(!empty($cart)) { $products = $cart['products']; } else { return redirect()->back()->with('error', __('Please add to product into cart')); } if(isset($cart['coupon']['data_id'])) { $coupon = ProductCoupon::where('id', $cart['coupon']['data_id'])->first(); } else { $coupon = ''; } $product_name = []; $product_id = []; $preference_data = []; foreach($products as $key => $product) { if($product['variant_id'] == 0) { $new_qty = $product['originalquantity'] - $product['quantity']; $product_edit = Product::find($product['product_id']); $product_edit->quantity = $new_qty; $product_edit->save(); $product_name[] = $product['product_name']; $product_id[] = $product['id']; } elseif($product['variant_id'] != 0) { $new_qty = $product['originalvariantquantity'] - $product['quantity']; $product_variant = ProductVariantOption::find($product['variant_id']); $product_variant->quantity = $new_qty; $product_variant->save(); $product_name[] = $product['product_name']; $product_id[] = $product['id']; } } if(isset($cart['shipping']) && isset($cart['shipping']['shipping_id']) && !empty($cart['shipping'])) { $shipping = Shipping::find($cart['shipping']['shipping_id']); // $totalprice = $price + $shipping->price; $shipping_name = $shipping->name; $shipping_price = $shipping->price; $shipping_data = json_encode( [ 'shipping_name' => $shipping_name, 'shipping_price' => $shipping_price, 'location_id' => $cart['shipping']['location_id'], ] ); } else { $shipping_data = ''; } if($products){ try{ if (Utility::CustomerAuthCheck($store->slug)) { $customer = Auth::guard('customers')->user()->id; }else{ $customer = 0; } if ($request->status_id == 3) { return redirect()->route('store-payment.payment',[$slug])->with('error','Your Transaction is fail please try again'); } elseif($request->status_id == 2){ return redirect()->route('store-payment.payment',[$slug])->with('error','Your Transaction is pending'); } elseif($request->status_id == 1){ $customer = Auth::guard('customers')->user(); $order = new Order(); $order->order_id = time(); $order->name = isset($cust_details['name']) ? $cust_details['name'] : '' ; $order->email = isset($cust_details['email']) ? $cust_details['email'] : ''; $order->card_number = ''; $order->card_exp_month = ''; $order->card_exp_year = ''; $order->status = 'pending'; $order->user_address_id = isset($cust_details['id']) ? $cust_details['id'] : ''; $order->shipping_data = $shipping_data; $order->product_id = implode(',', $product_id); $order->price = $get_amount; $order->coupon = isset($cart['coupon']['data_id']) ? $cart['coupon']['data_id'] : ''; $order->coupon_json = json_encode($coupon); $order->discount_price = isset($cart['coupon']['discount_price']) ? $cart['coupon']['discount_price'] : ''; $order->product = json_encode($products); $order->price_currency = $store->currency_code; $order->txn_id = isset($pay_id) ? $pay_id : ''; $order->payment_type = 'Toyyibpay'; $order->payment_status = 'approved'; $order->receipt = ''; $order->user_id = $store['id']; $order->customer_id = isset($customer->id) ? $customer->id : ''; $order->save(); //webhook $module = 'New Order'; $webhook = Utility::webhook($module, $store->id); if ($webhook) { $parameter = json_encode($order); // // 1 parameter is URL , 2 parameter is data , 3 parameter is method $status = Utility::WebhookCall($webhook['url'], $parameter, $webhook['method']); if ($status != true) { $msg = 'Webhook call failed.'; } } if ((!empty(Auth::guard('customers')->user()) && $store->is_checkout_login_required == 'on') ){ foreach($products as $product_id) { $purchased_products = new PurchasedProducts(); $purchased_products->product_id = $product_id['product_id']; $purchased_products->customer_id = $customer->id; $purchased_products->order_id = $order->id; $purchased_products->save(); } } $order_email = $order->email; $owner=User::find($store->created_by); $owner_email=$owner->email; $order_id = Crypt::encrypt($order->id); // if(isset($store->mail_driver) && !empty($store->mail_driver)) // { $dArr = [ 'order_name' => $order->name, ]; $resp = Utility::sendEmailTemplate('Order Created', $order_email, $dArr, $store, $order_id); $resp1=Utility::sendEmailTemplate('Order Created For Owner', $owner_email, $dArr, $store, $order_id); // } if(isset($store->is_twilio_enabled) && $store->is_twilio_enabled=="on") { Utility::order_create_owner($order,$owner,$store); Utility::order_create_customer($order,$customer,$store); } $msg = redirect()->route( 'store-complete.complete', [ $store->slug, Crypt::encrypt($order->id), ] )->with('success', __('Transaction has been success')); session()->forget($slug); return $msg; }else{ return redirect()->route('store-payment.payment',[$slug])->with('error', __('Transaction Unsuccesfull')); } }catch(\Exception $e){ return redirect()->back()->with('error', $e->getMessage()); } } else{ return redirect()->back()->with('error', __('Transaction Unsuccesfull')); } } }