JFIFxxC      C  " }!1AQa"q2#BR$3br %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz w!1AQaq"2B #3Rbrplan_id); $authuser = \Auth::user(); $plan = Plan::find($planID); if ($plan) { $get_amount = $plan->price; // if (Auth::user()->phone == null) { // return redirect()->back()->with('failed', __('Please add phone number to your profile.')); // } try { 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.')); } if ($get_amount <= 0) { $authuser = \Auth::user(); $authuser->plan = $plan->id; $authuser->save(); $assignPlan = $authuser->assignPlan($plan->id); if ($assignPlan['is_success'] == true && !empty($plan)) { if (!empty($authuser->payment_subscription_id) && $authuser->payment_subscription_id != '') { try { $authuser->cancel_subscription($authuser->id); } catch (\Exception $exception) { \Log::debug($exception->getMessage()); } } $orderID = strtoupper(str_replace('.', '', uniqid('', true))); $userCoupon = new UserCoupon(); $userCoupon->user = $authuser->id; $userCoupon->coupon = $coupons->id; $userCoupon->order = $orderID; $userCoupon->save(); Order::create( [ 'order_id' => $orderID, 'name' => null, 'email' => null, 'card_number' => null, 'card_exp_month' => null, 'card_exp_year' => null, 'plan_name' => $plan->name, 'plan_id' => $plan->id, 'price' => $get_amount == null ? 0 : $get_amount, 'price_currency' => !empty($payment_setting['currency']) ? $payment_setting['currency'] : 'USD', 'txn_id' => '', 'payment_type' => 'Aamarpay', 'payment_status' => 'success', 'receipt' => null, 'user_id' => $authuser->id, ] ); $assignPlan = $authuser->assignPlan($plan->id); return redirect()->route('plans.index')->with('success', __('Plan Successfully Activated')); } } } else { return redirect()->back()->with('error', __('This coupon code is invalid or has expired.')); } } $coupon = (empty($request->coupon)) ? "0" : $request->coupon; $orderID = strtoupper(str_replace('.', '', uniqid('', true))); $fields = array( 'store_id' => $aamarpay_store_id, //store id will be aamarpay, contact integration@aamarpay.com for test/live id 'amount' => $get_amount, //transaction amount 'payment_type' => '', //no need to change 'currency' => $currency, //currenct will be USD/BDT 'tran_id' => $orderID, //transaction id must be unique from your end 'cus_name' => $authuser->name, //customer name 'cus_email' => $authuser->email, //customer email address 'cus_add1' => '', //customer address 'cus_add2' => '', //customer address 'cus_city' => '', //customer city 'cus_state' => '', //state 'cus_postcode' => '', //postcode or zipcode 'cus_country' => '', //country 'cus_phone' => '1234567890', //customer phone number 'success_url' => route('pay.aamarpay.success', Crypt::encrypt(['response' => 'success', 'coupon' => $coupon, 'plan_id' => $plan->id, 'price' => $get_amount, 'order_id' => $orderID])), //your success route 'fail_url' => route('pay.aamarpay.success', Crypt::encrypt(['response' => 'failure', 'coupon' => $coupon, 'plan_id' => $plan->id, 'price' => $get_amount, 'order_id' => $orderID])), //your fail route 'cancel_url' => route('pay.aamarpay.success', Crypt::encrypt(['response' => 'cancel'])), //your cancel url 'signature_key' => $aamarpay_signature_key, 'desc' => $aamarpay_description, ); //signature key will provided aamarpay, contact integration@aamarpay.com for test/live signature key $fields_string = http_build_query($fields); $ch = curl_init(); curl_setopt($ch, CURLOPT_VERBOSE, true); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $url_forward = str_replace('"', '', stripslashes(curl_exec($ch))); curl_close($ch); $this->redirect_to_merchant($url_forward); } catch (\Exception $e) { return redirect()->back()->with('error', $e); } } else { return redirect()->route('plans.index')->with('error', __('Plan is deleted.')); } } function redirect_to_merchant($url) { $token = csrf_token(); ?>
where('is_active', '1')->first(); $request['coupon_id'] = $coupons->id; } else { $coupons = null; } Utility::referralTransaction($plan); $order = new Order(); $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 = !empty($payment_setting['currency']) ? $payment_setting['currency'] : 'USD'; $order->payment_type = __('Aamarpay'); $order->payment_status = 'success'; $order->txn_id = ''; $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(); } } } if ($assignPlan['is_success']) { return redirect()->route('plans.index')->with('success', __('Plan activated Successfully.')); } else { return redirect()->route('plans.index')->with('error', __($assignPlan['error'])); } } elseif ($data['response'] == "cancel") { return redirect()->route('plans.index')->with('error', __('Your payment is cancel')); } else { return redirect()->route('plans.index')->with('error', __('Your Transaction is fail please try again')); } } }