/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $apiContext = new \PayPal\Rest\ApiContext(new \PayPal\Auth\OAuthTokenCredential('ATGFkB2ea6f0pM92jwBqkZ17kxsiftDvUhLHyXson-10AUs7n5TocpEc0sis7Cl_fMIxS8uQO04kPP8Q', 'ENP_JPkc3e4Yl6VeHZ_0vgvEh0SYdtzkMvw_VGBrr2nJ67sg9RuKB_YF7y_k4bj-4t2U-_23MaAGV3vD')); $status = ''; if (isset($_GET['success']) && $_GET['success'] == 'true') { $transaction = new Transaction(); $amount = new Amount(); $paymentId = $_GET['paymentId']; $payment = Payment::get($paymentId, $apiContext); $amount->setCurrency($payment->transactions[0]->amount->getCurrency()); $amount->setTotal($payment->transactions[0]->amount->getTotal()); $amount->setDetails($payment->transactions[0]->amount->getDetails()); $transaction->setAmount($amount); $execution = new PaymentExecution(); $execution->setPayerId($_GET['PayerID']); $execution->addTransaction($transaction); $rifas = $payment->transactions[0]->description; $rifas = explode(',', $rifas); $aux = 0; try { foreach ($rifas as $rifa) { $aux = Rifa::find($rifa); if ($aux->user_id == NULL) { $aux->user_id = Auth::user()->id; $aux->save(); } else { $status = 'Numeros de rifas ja foram escolhidos por outra pessoa, por favor escolha novamente.'; return view('confirmacao')->with('status', $status); } } $result = $payment->execute($execution, $apiContext); try { $payment = Payment::get($paymentId, $apiContext); } catch (Exception $ex) { $status = 'Pagamento ainda sem confirmacao'; } } catch (Exception $ex) { $status = 'Compra nao foi executada'; } if ($result->state == "approved") { $status = 'Compra feita com sucesso!'; $aux = 1; } return view('confirmacao')->with('status', $status)->with('aux', $aux); } else { $status = 'Compra cancelada pelo usuario'; return view('confirmacao')->with('status', $status); } }
public function checkout($id) { $acao = Acao::find($id); $aux = Rifa::find($_POST['checkbox'])->where('user_id', NULL); $checkboxCount = count($aux); if ($checkboxCount == 0) { return back(); } $rifasstr = ''; $rifas = ''; $key = $checkboxCount; $total = number_format($acao->valor_rifa * $checkboxCount, 2); foreach ($aux as $rifa) { if ($key > 1) { $rifasstr .= $rifa->nome_rifa . ","; $rifas .= $rifa->id . ","; $key--; } else { $rifasstr .= $rifa->nome_rifa; $rifas .= $rifa->id; } } return view('checkout', compact('acao', 'checkboxCount', 'rifasstr', 'rifas', 'total')); }