public function sanitize() { $input = $this->all(); $invitation = Invitation::with('invoice.invoice_items', 'invoice.client.currency', 'invoice.client.account.currency', 'invoice.client.account.account_gateways.gateway')->where('invitation_key', '=', $this->invitation_key)->firstOrFail(); $input['invitation'] = $invitation; $input['gateway_type'] = session($invitation->id . 'gateway_type'); $this->replace($input); return $this->all(); }
public function markBounced($messageId, $error) { $invitation = Invitation::with('user', 'invoice', 'contact')->whereMessageId($messageId)->first(); if (!$invitation) { return false; } $invitation->email_error = $error; $invitation->save(); $this->userMailer->sendEmailBounced($invitation); return true; }
public function clientIndex() { $invitationKey = Session::get('invitation_key'); if (!$invitationKey) { return Redirect::to('/setup'); } $invitation = Invitation::with('account')->where('invitation_key', '=', $invitationKey)->first(); $color = $invitation->account->primary_color ? $invitation->account->primary_color : '#0b4d78'; $data = ['color' => $color, 'hideLogo' => Session::get('white_label'), 'title' => trans('texts.invoices'), 'entityType' => ENTITY_INVOICE, 'columns' => Utils::trans(['invoice_number', 'invoice_date', 'invoice_total', 'balance_due', 'due_date'])]; return View::make('public_list', $data); }
public function offsite_payment() { $payerId = Request::query('PayerID'); $token = Request::query('token'); if (!$token) { $token = Session::pull('transaction_reference'); } if (!$token) { return redirect(NINJA_WEB_URL); } $invitation = Invitation::with('invoice.client.currency', 'invoice.client.account.account_gateways.gateway')->where('transaction_reference', '=', $token)->firstOrFail(); $invoice = $invitation->invoice; $accountGateway = $invoice->client->account->getGatewayByType(Session::get('payment_type')); $gateway = self::createGateway($accountGateway); try { if (method_exists($gateway, 'completePurchase')) { $details = self::getPaymentDetails($invitation); $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); } } else { $payment = self::createPayment($invitation, $token, $payerId); Session::flash('message', trans('texts.applied_payment')); 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); } }
public function offsite_payment() { $payerId = Request::query('PayerID'); $token = Request::query('token'); if (!$token) { $token = Session::pull('transaction_reference'); } if (!$token) { return redirect(NINJA_WEB_URL); } $invitation = Invitation::with('invoice.client.currency', 'invoice.client.account.account_gateways.gateway')->where('transaction_reference', '=', $token)->firstOrFail(); $invoice = $invitation->invoice; $accountGateway = $invoice->client->account->getGatewayByType(Session::get('payment_type')); $gateway = $this->paymentService->createGateway($accountGateway); // Check for Dwolla payment error if ($accountGateway->isGateway(GATEWAY_DWOLLA) && Input::get('error')) { $this->error('Dwolla', Input::get('error_description'), $accountGateway); return Redirect::to('view/' . $invitation->invitation_key); } try { if (method_exists($gateway, 'completePurchase')) { $details = $this->paymentService->getPaymentDetails($invitation); $response = $gateway->completePurchase($details)->send(); $ref = $response->getTransactionReference(); if ($response->isSuccessful()) { $payment = $this->paymentService->createPayment($invitation, $ref, $payerId); Session::flash('message', trans('texts.applied_payment')); return Redirect::to('view/' . $invitation->invitation_key); } else { $this->error('offsite', $response->getMessage(), $accountGateway); return Redirect::to('view/' . $invitation->invitation_key); } } else { $payment = $this->paymentService->createPayment($invitation, $token, $payerId); Session::flash('message', trans('texts.applied_payment')); return Redirect::to('view/' . $invitation->invitation_key); } } catch (\Exception $e) { $this->error('Offsite-uncaught', false, $accountGateway, $e); return Redirect::to('view/' . $invitation->invitation_key); } }
public function offsite_payment() { $payerId = Request::query('PayerID'); $token = Request::query('token'); if (!$token) { $token = Session::pull('transaction_reference'); } if (!$token) { return redirect(NINJA_WEB_URL); } $invitation = Invitation::with('invoice.client.currency', 'invoice.client.account.account_gateways.gateway')->where('transaction_reference', '=', $token)->firstOrFail(); $invoice = $invitation->invoice; $client = $invoice->client; $account = $client->account; if ($payerId) { $paymentType = PAYMENT_TYPE_PAYPAL; } else { $paymentType = Session::get($invitation->id . 'payment_type'); } if (!$paymentType) { $this->error('No-Payment-Type', false, false); return Redirect::to($invitation->getLink()); } $accountGateway = $account->getGatewayByType($paymentType); $gateway = $this->paymentService->createGateway($accountGateway); // Check for Dwolla payment error if ($accountGateway->isGateway(GATEWAY_DWOLLA) && Input::get('error')) { $this->error('Dwolla', Input::get('error_description'), $accountGateway); return Redirect::to($invitation->getLink()); } // PayFast transaction referencce if ($accountGateway->isGateway(GATEWAY_PAYFAST) && Request::has('pt')) { $token = Request::query('pt'); } try { if (method_exists($gateway, 'completePurchase') && !$accountGateway->isGateway(GATEWAY_TWO_CHECKOUT) && !$accountGateway->isGateway(GATEWAY_CHECKOUT_COM)) { $details = $this->paymentService->getPaymentDetails($invitation, $accountGateway); $response = $this->paymentService->completePurchase($gateway, $accountGateway, $details, $token); $ref = $response->getTransactionReference() ?: $token; if ($response->isCancelled()) { // do nothing } elseif ($response->isSuccessful()) { $payment = $this->paymentService->createPayment($invitation, $accountGateway, $ref, $payerId); Session::flash('message', trans('texts.applied_payment')); } else { $this->error('offsite', $response->getMessage(), $accountGateway); } return Redirect::to($invitation->getLink()); } else { $payment = $this->paymentService->createPayment($invitation, $accountGateway, $token, $payerId); Session::flash('message', trans('texts.applied_payment')); return Redirect::to($invitation->getLink()); } } catch (\Exception $e) { $this->error('Offsite-uncaught', false, $accountGateway, $e); return Redirect::to($invitation->getLink()); } }
/** * @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); } }
public function approve($invitationKey) { $invitation = Invitation::with('invoice.invoice_items', 'invoice.invitations')->where('invitation_key', '=', $invitationKey)->firstOrFail(); $invoice = $invitation->invoice; if ($invoice->is_quote && !$invoice->quote_invoice_id) { Event::fire(new QuoteApproved($invoice)); Activity::approveQuote($invitation); $invoice = $this->invoiceRepo->cloneInvoice($invoice, $invoice->id); Session::flash('message', trans('texts.converted_to_invoice')); foreach ($invoice->invitations as $invitationClone) { if ($invitation->contact_id == $invitationClone->contact_id) { $invitationKey = $invitationClone->invitation_key; } } } return Redirect::to("view/{$invitationKey}"); }
public function approve($invitationKey) { $invitation = Invitation::with('invoice.invoice_items', 'invoice.invitations')->where('invitation_key', '=', $invitationKey)->firstOrFail(); $invoice = $invitation->invoice; $invitationKey = $this->invoiceService->approveQuote($invoice, $invitation); Session::flash('message', trans('texts.quote_is_approved')); return Redirect::to("view/{$invitationKey}"); }