/** * @param bool $invitationKey * @param mixed $gatewayTypeAlias * @return \Illuminate\Http\RedirectResponse */ public function offsitePayment($invitationKey = false, $gatewayTypeAlias = false) { $invitationKey = $invitationKey ?: Session::get('invitation_key'); $invitation = Invitation::with('invoice.invoice_items', 'invoice.client.currency', 'invoice.client.account.account_gateways.gateway')->where('invitation_key', '=', $invitationKey)->firstOrFail(); if (!$gatewayTypeAlias) { $gatewayTypeId = Session::get($invitation->id . 'gateway_type'); } elseif ($gatewayTypeAlias != GATEWAY_TYPE_TOKEN) { $gatewayTypeId = GatewayType::getIdFromAlias($gatewayTypeAlias); } else { $gatewayTypeId = $gatewayTypeAlias; } $paymentDriver = $invitation->account->paymentDriver($invitation, $gatewayTypeId); if ($error = Input::get('error_description') ?: Input::get('error')) { return $this->error($paymentDriver, $error); } try { if ($paymentDriver->completeOffsitePurchase(Input::all())) { Session::flash('message', trans('texts.applied_payment')); } return redirect()->to($invitation->getLink()); } catch (Exception $exception) { return $this->error($paymentDriver, $exception); } }
protected function paymentUrl($gatewayTypeAlias) { $account = $this->account(); $url = URL::to("/payment/{$this->invitation->invitation_key}/{$gatewayTypeAlias}"); $gatewayTypeId = GatewayType::getIdFromAlias($gatewayTypeAlias); // PayPal doesn't allow being run in an iframe so we need to open in new tab if ($gatewayTypeId === GATEWAY_TYPE_PAYPAL) { $url .= '#braintree_paypal'; if ($account->iframe_url) { return 'javascript:window.open("' . $url . '", "_blank")'; } } return $url; }