Inheritance: extends Eloquen\Eloquent
コード例 #1
0
 public function columns()
 {
     return [['name', function ($model) {
         if ($model->deleted_at) {
             return $model->name;
         } elseif ($model->gateway_id != GATEWAY_WEPAY) {
             return link_to("gateways/{$model->public_id}/edit", $model->name)->toHtml();
         } else {
             $accountGateway = AccountGateway::find($model->id);
             $config = $accountGateway->getConfig();
             $endpoint = WEPAY_ENVIRONMENT == WEPAY_STAGE ? 'https://stage.wepay.com/' : 'https://www.wepay.com/';
             $wepayAccountId = $config->accountId;
             $wepayState = isset($config->state) ? $config->state : null;
             $linkText = $model->name;
             $url = $endpoint . 'account/' . $wepayAccountId;
             $html = link_to($url, $linkText, ['target' => '_blank'])->toHtml();
             try {
                 if ($wepayState == 'action_required') {
                     $updateUri = $endpoint . 'api/account_update/' . $wepayAccountId . '?redirect_uri=' . urlencode(URL::to('gateways'));
                     $linkText .= ' <span style="color:#d9534f">(' . trans('texts.action_required') . ')</span>';
                     $url = $updateUri;
                     $html = "<a href=\"{$url}\">{$linkText}</a>";
                     $model->setupUrl = $url;
                 } elseif ($wepayState == 'pending') {
                     $linkText .= ' (' . trans('texts.resend_confirmation_email') . ')';
                     $model->resendConfirmationUrl = $url = URL::to("gateways/{$accountGateway->public_id}/resend_confirmation");
                     $html = link_to($url, $linkText)->toHtml();
                 }
             } catch (\WePayException $ex) {
             }
             return $html;
         }
     }], ['limit', function ($model) {
         $accountGateway = AccountGateway::find($model->id);
         $paymentDriver = $accountGateway->paymentDriver();
         $gatewayTypes = $paymentDriver->gatewayTypes();
         $gatewayTypes = array_diff($gatewayTypes, array(GATEWAY_TYPE_TOKEN));
         $html = '';
         foreach ($gatewayTypes as $gatewayTypeId) {
             $accountGatewaySettings = AccountGatewaySettings::scope()->where('account_gateway_settings.gateway_type_id', '=', $gatewayTypeId)->first();
             $gatewayType = GatewayType::find($gatewayTypeId);
             if (count($gatewayTypes) > 1) {
                 if ($html) {
                     $html .= '<br>';
                 }
                 $html .= $gatewayType->name . ' &mdash; ';
             }
             if ($accountGatewaySettings && $accountGatewaySettings->min_limit !== null && $accountGatewaySettings->max_limit !== null) {
                 $html .= Utils::formatMoney($accountGatewaySettings->min_limit) . ' - ' . Utils::formatMoney($accountGatewaySettings->max_limit);
             } elseif ($accountGatewaySettings && $accountGatewaySettings->min_limit !== null) {
                 $html .= trans('texts.min_limit', array('min' => Utils::formatMoney($accountGatewaySettings->min_limit)));
             } elseif ($accountGatewaySettings && $accountGatewaySettings->max_limit !== null) {
                 $html .= trans('texts.max_limit', array('max' => Utils::formatMoney($accountGatewaySettings->max_limit)));
             } else {
                 $html .= trans('texts.no_limit');
             }
         }
         return $html;
     }]];
 }
コード例 #2
0
 public function run()
 {
     Eloquent::unguard();
     $gateway_types = [['alias' => 'credit_card', 'name' => 'Credit Card'], ['alias' => 'bank_transfer', 'name' => 'Bank Transfer'], ['alias' => 'paypal', 'name' => 'PayPal'], ['alias' => 'bitcoin', 'name' => 'Bitcoin'], ['alias' => 'dwolla', 'name' => 'Dwolla']];
     foreach ($gateway_types as $gateway_type) {
         $record = GatewayType::where('name', '=', $gateway_type['name'])->first();
         if (!$record) {
             GatewayType::create($gateway_type);
         }
     }
 }
コード例 #3
0
 /**
  * @param $template
  * @param array $data
  * @return mixed|string
  */
 public function processVariables($template, array $data)
 {
     /** @var \App\Models\Account $account */
     $account = $data['account'];
     /** @var \App\Models\Client $client */
     $client = $data['client'];
     /** @var \App\Models\Invitation $invitation */
     $invitation = $data['invitation'];
     $invoice = $invitation->invoice;
     $passwordHTML = isset($data['password']) ? '<p>' . trans('texts.password') . ': ' . $data['password'] . '<p>' : false;
     $documentsHTML = '';
     if ($account->hasFeature(FEATURE_DOCUMENTS) && $invoice->hasDocuments()) {
         $documentsHTML .= trans('texts.email_documents_header') . '<ul>';
         foreach ($invoice->documents as $document) {
             $documentsHTML .= '<li><a href="' . HTML::entities($document->getClientUrl($invitation)) . '">' . HTML::entities($document->name) . '</a></li>';
         }
         foreach ($invoice->expenses as $expense) {
             foreach ($expense->documents as $document) {
                 $documentsHTML .= '<li><a href="' . HTML::entities($document->getClientUrl($invitation)) . '">' . HTML::entities($document->name) . '</a></li>';
             }
         }
         $documentsHTML .= '</ul>';
     }
     $variables = ['$footer' => $account->getEmailFooter(), '$client' => $client->getDisplayName(), '$account' => $account->getDisplayName(), '$dueDate' => $account->formatDate($invoice->due_date), '$invoiceDate' => $account->formatDate($invoice->invoice_date), '$contact' => $invitation->contact->getDisplayName(), '$firstName' => $invitation->contact->first_name, '$amount' => $account->formatMoney($data['amount'], $client), '$invoice' => $invoice->invoice_number, '$quote' => $invoice->invoice_number, '$link' => $invitation->getLink(), '$password' => $passwordHTML, '$viewLink' => $invitation->getLink() . '$password', '$viewButton' => Form::emailViewButton($invitation->getLink(), $invoice->getEntityType()) . '$password', '$paymentLink' => $invitation->getLink('payment') . '$password', '$paymentButton' => Form::emailPaymentButton($invitation->getLink('payment')) . '$password', '$customClient1' => $account->custom_client_label1, '$customClient2' => $account->custom_client_label2, '$customInvoice1' => $account->custom_invoice_text_label1, '$customInvoice2' => $account->custom_invoice_text_label2, '$documents' => $documentsHTML, '$autoBill' => empty($data['autobill']) ? '' : $data['autobill'], '$portalLink' => $invitation->contact->link, '$portalButton' => Form::emailViewButton($invitation->contact->link, 'portal')];
     // Add variables for available payment types
     foreach (Gateway::$gatewayTypes as $type) {
         if ($type == GATEWAY_TYPE_TOKEN) {
             continue;
         }
         $camelType = Utils::toCamelCase(GatewayType::getAliasFromId($type));
         $variables["\${$camelType}Link"] = $invitation->getLink('payment') . "/{$type}";
         $variables["\${$camelType}Button"] = Form::emailPaymentButton($invitation->getLink('payment') . "/{$type}");
     }
     $includesPasswordPlaceholder = strpos($template, '$password') !== false;
     $str = str_replace(array_keys($variables), array_values($variables), $template);
     if (!$includesPasswordPlaceholder && $passwordHTML) {
         $pos = strrpos($str, '$password');
         if ($pos !== false) {
             $str = substr_replace($str, $passwordHTML, $pos, 9);
         }
     }
     $str = str_replace('$password', '', $str);
     $str = autolink($str, 100);
     return $str;
 }
コード例 #4
0
 /**
  * @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);
     }
 }
コード例 #5
0
 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;
 }