public function offsite_payment() { $payerId = Request::query('PayerID'); $token = Request::query('token'); $invitation = Invitation::with('invoice.client.currency', 'invoice.client.account.account_gateways.gateway')->where('transaction_reference', '=', $token)->firstOrFail(); $invoice = $invitation->invoice; $accountGateway = $invoice->client->account->account_gateways[0]; $gateway = self::createGateway($accountGateway); try { $details = self::getPaymentDetails($invoice); $response = $gateway->completePurchase($details)->send(); $ref = $response->getTransactionReference(); if ($response->isSuccessful()) { $payment = self::createPayment($invitation, $ref, $payerId); Session::flash('message', trans('texts.applied_payment')); return Redirect::to('view/' . $invitation->invitation_key); } else { $errorMessage = trans('texts.payment_error') . "\n\n" . $response->getMessage(); Session::flash('error', $errorMessage); Utils::logError($errorMessage); return Redirect::to('view/' . $invitation->invitation_key); } } catch (\Exception $e) { $errorMessage = trans('texts.payment_error'); Session::flash('error', $errorMessage); Utils::logError($errorMessage . "\n\n" . $e->getMessage()); return Redirect::to('view/' . $invitation->invitation_key); } }