コード例 #1
0
ファイル: HomeController.php プロジェクト: udayc/travel
 public function postRefund(Request $request)
 {
     $transaction_id = $request->get('id');
     $error = '';
     $transaction_details = \App\Models\ProjectFund::findOrFail($transaction_id);
     $getProjectReceiverAccount = \App\Models\Project::where('id', $transaction_details->P_ID)->first();
     $getReceiverAccount = $getProjectReceiverAccount->user_id ? \App\Models\ReciverAccount::where('user_id', $getProjectReceiverAccount->user_id)->first() : Null;
     //dd($getReceiverAccount->secret_key);
     if ($getReceiverAccount->secret_key) {
         \Stripe\Stripe::setApiKey($getReceiverAccount->secret_key);
     }
     try {
         $paid_amount = $transaction_details->paid_amount * 100;
         $refund = \Stripe\Refund::create(array('amount' => $paid_amount, 'charge' => $transaction_details->transaction_id));
         //dd($refund->toArray());
         //updatating local table
         $cashWithDrawaldRequest = new \App\Models\CashWithdrawalsRequest();
         $cashWithDrawaldRequest->user_id = $getProjectReceiverAccount->user_id;
         $cashWithDrawaldRequest->status = 'request';
         $cashWithDrawaldRequest->project_fund_id = $transaction_id;
         if ($cashWithDrawaldRequest->save()) {
             $request->session()->flash('alert-success', 'Request for charge refunding is successfully posted . ');
             //return response(['msg' => 'success'   ]);
             return \Redirect::to('home/project-backed')->with('msg', 'success');
         } else {
             $request->session()->flash('alert-success', 'Request for charge refunding is not processed !');
             //return response(['msg' => 'failure'   ]);
             return \Redirect::to('home/project-backed')->with('stripe_errors', $error['message']);
         }
         ///update
     } catch (Exception $e) {
         //  dd("a");
         $e_json = $e->getMessage();
         $error = $e_json['error'];
         return response(['msg' => 'failure']);
         //return \Redirect::to('home/project-backed')->with('stripe_errors',$error['message'])	;
     }
     //dd($refund->_lastResponse);
 }
コード例 #2
0
ファイル: CheckoutController.php プロジェクト: udayc/travel
 public function postPayments(Request $request)
 {
     $authId = Auth::user()->id;
     //dd($authId);
     //$getReceiverAccount = \App\Models\ReciverAccount::where('user_id' , $authId)->first();
     //dd($getReceiverAccount);
     $rewardLogId = $request->input('_log_id_');
     $rewardLogRow = \App\Models\RewardsLogDuringPayment::where('id', $rewardLogId)->first();
     $rewardLogRowDecodedObj = json_decode($rewardLogRow->array_obj);
     $project_id = $rewardLogRowDecodedObj->project_id;
     $backingAmount = $rewardLogRowDecodedObj->backing->amount;
     $stripeToken = $request->input('stripeToken');
     $currency = $request->input('currency');
     $error = '';
     $post = \App\Models\Project::findOrFail($rewardLogRowDecodedObj->project_id);
     $getReceiverAccount = $post->user_id ? \App\Models\ReciverAccount::where('user_id', $post->user_id)->first() : Null;
     if ($getReceiverAccount->secret_key) {
         //\Stripe\Stripe::setApiKey(\Config::get('stripe.stripe.secret'));
         \Stripe\Stripe::setApiKey($getReceiverAccount->secret_key);
     }
     try {
         // throw new Exception("The Stripe Token was not generated correctly");
         $post = \App\Models\Project::findOrFail($project_id);
         $charge = \Stripe\Charge::create(array("amount" => $backingAmount * 100, "currency" => $currency, "capture" => false, "card" => $stripeToken, "description" => 'Captured  amount #' . $backingAmount . $currency . ' for pledge project-id #' . $project_id), array('idempotency_key' => $this->generateRandomString()));
         //echo $charge->status;
         //dd($charge);
         if ($charge->status == 'succeeded') {
             $transactionId = $charge->id;
             $actionMsg_1 = Auth::user()->name . ' has pledged for project  # ' . $post->name;
             $actionMsg_2 = Auth::user()->name . ' has invested ' . $backingAmount . $currency . ' for project  # ' . $post->name;
             $settingsRow = \App\Setting::where('config_key', 'commission_from_each_fund')->first();
             $commissionVal = $settingsRow->config_value;
             $projectFunds = new \App\Models\ProjectFund();
             $projectFunds->P_ID = $project_id;
             $projectFunds->U_ID = Auth::user()->id;
             $projectFunds->paid_amount = $backingAmount;
             $projectFunds->site_commission = $backingAmount * $commissionVal / 100;
             $projectFunds->amount_to_project_owner = $backingAmount - $backingAmount * $commissionVal / 100;
             $projectFunds->status = 'Pledged';
             $projectFunds->rewards_log_during_payment_id = $rewardLogId;
             $projectFunds->transaction_id = $transactionId;
             $projectFunds->save();
             // commission_from_each_fund
             \Event::fire('transaction.log', new \App\Events\Transaction($request, ['transaction_id' => $transactionId, 'user_id' => Auth::user()->id, 'msg' => $actionMsg_1, 'credit' => '0.00', 'debit' => $backingAmount, 'status' => 'Pledged']));
             \Event::fire('activity.log', new \App\Events\Activity($request, ['project_id' => $project_id, 'user_id' => Auth::user()->id, 'action' => 'invested', 'msg' => $actionMsg_2]));
         }
     } catch (Exception $e) {
         $e_json = $e->getMessage();
         $error = $e_json['error'];
         return \Redirect::to('checkout/payments')->withInput()->with('stripe_errors', $error['message']);
     }
     return \Redirect::to('checkout/success');
 }