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'); }
@else<a class="label label-sm label-danger" >Not Live</a> @endif </td> <td>{{ $val->paid_amount}}</td> <td> {{ $val->amount_to_project_owner }}</td> <td>{{ $val->site_commission }}</td> <td>{{ $val->created_at }}</td> <td>@if($val->status == 'Pledged') <code>{{ $val->status }}</code> @else {{ $val->status }} @endif</td> <td> @if( $val->rewards_log_during_payment_id > 0 ) <?php $rewardLogRow = \App\Models\RewardsLogDuringPayment::where('id', $val->rewards_log_during_payment_id)->first(); $rewardLogRowDecodedObj = json_decode($rewardLogRow->array_obj); $reward_id = $rewardLogRowDecodedObj->reward_id; if (isset($reward_id) && $reward_id > 0) { $rewardRow = \App\Models\Reward::where('id', $reward_id)->first(); echo $_settings_data->site_currency_symbol . $rewardRow->pledge_amount . ' + ' . $rewardRow->short_note; } else { echo 'n/a'; } ?> @else n/a @endif