diff --git a/app/Console/Commands/DemoMode.php b/app/Console/Commands/DemoMode.php
index c5008f547..b878949ce 100644
--- a/app/Console/Commands/DemoMode.php
+++ b/app/Console/Commands/DemoMode.php
@@ -7,6 +7,7 @@ use App\Events\Invoice\InvoiceWasCreated;
use App\Factory\InvoiceFactory;
use App\Factory\InvoiceItemFactory;
use App\Helpers\Invoice\InvoiceSum;
+use App\Jobs\Util\VersionCheck;
use App\Models\CompanyToken;
use App\Models\Country;
use App\Models\Product;
@@ -77,6 +78,7 @@ class DemoMode extends Command
$this->info("Seeding Random Data");
$this->createSmallAccount();
+ VersionCheck::dispatchNow();
}
diff --git a/app/Http/Controllers/ClientPortal/InvitationController.php b/app/Http/Controllers/ClientPortal/InvitationController.php
index 8258c04f5..8061672d3 100644
--- a/app/Http/Controllers/ClientPortal/InvitationController.php
+++ b/app/Http/Controllers/ClientPortal/InvitationController.php
@@ -44,11 +44,13 @@ class InvitationController extends Controller
} else {
auth()->guard('contact')->login($invitation->contact, true);
}
-
- if (!request()->has('silent')) {
+
+ if (!request()->has('silent') && !$invitation->viewed_date) {
+// if (!request()->has('silent')) {
+
$invitation->markViewed();
- event(new InvitationWasViewed($entity, $invitation, $entity->company, Ninja::eventVars()));
+ event(new InvitationWasViewed($invitation->{$entity}, $invitation, $invitation->{$entity}->company, Ninja::eventVars()));
}
return redirect()->route('client.'.$entity.'.show', [$entity => $this->encodePrimaryKey($invitation->{$key})]);
diff --git a/app/Http/Controllers/EmailController.php b/app/Http/Controllers/EmailController.php
index 62760c5ac..8bfa7ffef 100644
--- a/app/Http/Controllers/EmailController.php
+++ b/app/Http/Controllers/EmailController.php
@@ -122,11 +122,15 @@ class EmailController extends BaseController
$invitation->contact->notify((new SendGenericNotification($invitation, $entity_string, $subject, $body))->delay($when));
- EntitySentMailer::dispatch($invitation, $entity_string, $entity_obj->user, $invitation->company);
-
}
});
+
+ /*Only notify the admin ONCE, not once per contact/invite*/
+ $invitation = $entity_obj->invitations->first();
+
+ EntitySentMailer::dispatch($invitation, $entity_string, $entity_obj->user, $invitation->company);
+
if ($this instanceof Invoice) {
$this->entity_type = Invoice::class ;
diff --git a/app/Http/Controllers/SetupController.php b/app/Http/Controllers/SetupController.php
index 43a8378fd..84f3fdd63 100644
--- a/app/Http/Controllers/SetupController.php
+++ b/app/Http/Controllers/SetupController.php
@@ -62,8 +62,13 @@ class SetupController extends Controller
$mail_driver = 'log';
}
+ $url = $request->input('url');
+
+ if(substr($url, -1) != '/')
+ $url = $url . '/';
+
$_ENV['APP_KEY'] = config('app.key');
- $_ENV['APP_URL'] = $request->input('url');
+ $_ENV['APP_URL'] = $url;
$_ENV['APP_DEBUG'] = $request->input('debug') ? 'true' : 'false';
$_ENV['REQUIRE_HTTPS'] = $request->input('https') ? 'true' : 'false';
$_ENV['DB_TYPE'] = 'mysql';
diff --git a/app/Jobs/Mail/EntityPaidMailer.php b/app/Jobs/Mail/EntityPaidMailer.php
index a2175f204..573d0a0c5 100644
--- a/app/Jobs/Mail/EntityPaidMailer.php
+++ b/app/Jobs/Mail/EntityPaidMailer.php
@@ -53,7 +53,6 @@ class EntityPaidMailer extends BaseMailerJob implements ShouldQueue
*/
public function handle()
{
- info("entity paid mailer");
//Set DB
//
MultiDB::setDb($this->company->db);
diff --git a/app/Jobs/Mail/EntitySentMailer.php b/app/Jobs/Mail/EntitySentMailer.php
index 2eee1d4d6..9680851a3 100644
--- a/app/Jobs/Mail/EntitySentMailer.php
+++ b/app/Jobs/Mail/EntitySentMailer.php
@@ -56,7 +56,6 @@ class EntitySentMailer extends BaseMailerJob implements ShouldQueue
*/
public function handle()
{
- info("entity sent mailer");
//Set DB
MultiDB::setDb($this->company->db);
diff --git a/app/Jobs/Mail/EntityViewedMailer.php b/app/Jobs/Mail/EntityViewedMailer.php
index c5fd76e36..be1102a94 100644
--- a/app/Jobs/Mail/EntityViewedMailer.php
+++ b/app/Jobs/Mail/EntityViewedMailer.php
@@ -57,8 +57,6 @@ class EntityViewedMailer extends BaseMailerJob implements ShouldQueue
public function handle()
{
- info("entity viewed mailer");
-
//Set DB
MultiDB::setDb($this->company->db);
diff --git a/app/Listeners/Invoice/InvoiceEmailedNotification.php b/app/Listeners/Invoice/InvoiceEmailedNotification.php
index 5673afb03..d4ad6b320 100644
--- a/app/Listeners/Invoice/InvoiceEmailedNotification.php
+++ b/app/Listeners/Invoice/InvoiceEmailedNotification.php
@@ -44,23 +44,26 @@ class InvoiceEmailedNotification implements ShouldQueue
{
MultiDB::setDb($event->company->db);
+ $first_notification_sent = true;
- foreach ($invitation->company->company_users as $company_user) {
+ foreach ($event->invitation->company->company_users as $company_user) {
$user = $company_user->user;
- $notification = new EntitySentNotification($invitation, 'invoice');
+ $notification = new EntitySentNotification($event->invitation, 'invoice');
- $methods = $this->findUserNotificationTypes($invitation, $company_user, 'invoice', ['all_notifications', 'invoice_sent']);
+ $methods = $this->findUserNotificationTypes($event->invitation, $company_user, 'invoice', ['all_notifications', 'invoice_sent']);
- if (($key = array_search('mail', $methods)) !== false) {
+ if (($key = array_search('mail', $methods)) !== false && $first_notification_sent === true) {
unset($methods[$key]);
//Fire mail notification here!!!
//This allows us better control of how we
//handle the mailer
- EntitySentMailer::dispatch($invitation, 'invoice', $user, $invitation->company);
+ EntitySentMailer::dispatch($event->invitation, 'invoice', $user, $event->invitation->company);
+ $first_notification_sent = false;
+
}
$notification->method = $methods;
diff --git a/app/Listeners/Misc/InvitationViewedListener.php b/app/Listeners/Misc/InvitationViewedListener.php
index 394474432..1997c2baf 100644
--- a/app/Listeners/Misc/InvitationViewedListener.php
+++ b/app/Listeners/Misc/InvitationViewedListener.php
@@ -40,9 +40,9 @@ class InvitationViewedListener implements ShouldQueue
*/
public function handle($event)
{
- MultiDB::setDb($event->company->db);
+ MultiDB::setDb($event->company->db);
- $entity_name = $event->entity;
+ $entity_name = lcfirst(class_basename($event->entity));
$invitation = $event->invitation;
$notification = new EntityViewedNotification($invitation, $entity_name);
@@ -57,7 +57,7 @@ class InvitationViewedListener implements ShouldQueue
unset($methods[$key]);
EntityViewedMailer::dispatch($invitation, $entity_name, $company_user->user, $invitation->company);
-
+
}
$notification->method = $methods;
diff --git a/app/Mail/Admin/EntityPaidObject.php b/app/Mail/Admin/EntityPaidObject.php
index 449931c8d..237fbc36e 100644
--- a/app/Mail/Admin/EntityPaidObject.php
+++ b/app/Mail/Admin/EntityPaidObject.php
@@ -85,7 +85,8 @@ class EntityPaidObject
'invoice' => $invoice_texts,
]
),
- 'url' => config('ninja.app_url') . '/payments/' . $this->payment->hashed_id,
+ 'url' => config('ninja.app_url'),
+ // 'url' => config('ninja.app_url') . '/payments/' . $this->payment->hashed_id, //because we have no deep linking we cannot use this
'button' => ctrans('texts.view_payment'),
'signature' => $settings->email_signature,
'logo' => $this->company->present()->logo(),
diff --git a/app/Models/CreditInvitation.php b/app/Models/CreditInvitation.php
index 3220a5687..c1171e752 100644
--- a/app/Models/CreditInvitation.php
+++ b/app/Models/CreditInvitation.php
@@ -42,37 +42,37 @@ class CreditInvitation extends BaseModel
return CreditInvitation::class;
}
- public function getSignatureDateAttribute($value)
- {
- if (!$value) {
- return (new Carbon($value))->format('Y-m-d');
- }
- return $value;
- }
+ // public function getSignatureDateAttribute($value)
+ // {
+ // if (!$value) {
+ // return (new Carbon($value))->format('Y-m-d');
+ // }
+ // return $value;
+ // }
- public function getSentDateAttribute($value)
- {
- if (!$value) {
- return (new Carbon($value))->format('Y-m-d');
- }
- return $value;
- }
+ // public function getSentDateAttribute($value)
+ // {
+ // if (!$value) {
+ // return (new Carbon($value))->format('Y-m-d');
+ // }
+ // return $value;
+ // }
- public function getViewedDateAttribute($value)
- {
- if (!$value) {
- return (new Carbon($value))->format('Y-m-d');
- }
- return $value;
- }
+ // public function getViewedDateAttribute($value)
+ // {
+ // if (!$value) {
+ // return (new Carbon($value))->format('Y-m-d');
+ // }
+ // return $value;
+ // }
- public function getOpenedDateAttribute($value)
- {
- if (!$value) {
- return (new Carbon($value))->format('Y-m-d');
- }
- return $value;
- }
+ // public function getOpenedDateAttribute($value)
+ // {
+ // if (!$value) {
+ // return (new Carbon($value))->format('Y-m-d');
+ // }
+ // return $value;
+ // }
public function entityType()
{
diff --git a/app/Models/GatewayType.php b/app/Models/GatewayType.php
index f87ee10df..e3e6c5b26 100644
--- a/app/Models/GatewayType.php
+++ b/app/Models/GatewayType.php
@@ -37,4 +37,9 @@ class GatewayType extends StaticModel
{
return $this->belongsTo(Gateway::class);
}
+
+ public function payment_methods()
+ {
+ return $this->hasMany(PaymentType::class);
+ }
}
diff --git a/app/Models/InvoiceInvitation.php b/app/Models/InvoiceInvitation.php
index e41a310d1..466ec9fd7 100644
--- a/app/Models/InvoiceInvitation.php
+++ b/app/Models/InvoiceInvitation.php
@@ -41,37 +41,37 @@ class InvoiceInvitation extends BaseModel
return InvoiceInvitation::class;
}
- public function getSignatureDateAttribute($value)
- {
- if (!$value) {
- return (new Carbon($value))->format('Y-m-d');
- }
- return $value;
- }
+ // public function getSignatureDateAttribute($value)
+ // {
+ // if (!$value) {
+ // return (new Carbon($value))->format('Y-m-d');
+ // }
+ // return $value;
+ // }
- public function getSentDateAttribute($value)
- {
- if (!$value) {
- return (new Carbon($value))->format('Y-m-d');
- }
- return $value;
- }
+ // public function getSentDateAttribute($value)
+ // {
+ // if (!$value) {
+ // return (new Carbon($value))->format('Y-m-d');
+ // }
+ // return $value;
+ // }
- public function getViewedDateAttribute($value)
- {
- if (!$value) {
- return (new Carbon($value))->format('Y-m-d');
- }
- return $value;
- }
+ // public function getViewedDateAttribute($value)
+ // {
+ // if (!$value) {
+ // return (new Carbon($value))->format('Y-m-d');
+ // }
+ // return $value;
+ // }
- public function getOpenedDateAttribute($value)
- {
- if (!$value) {
- return (new Carbon($value))->format('Y-m-d');
- }
- return $value;
- }
+ // public function getOpenedDateAttribute($value)
+ // {
+ // if (!$value) {
+ // return (new Carbon($value))->format('Y-m-d');
+ // }
+ // return $value;
+ // }
public function entityType()
{
@@ -130,6 +130,12 @@ class InvoiceInvitation extends BaseModel
$this->save();
}
+ public function markOpened()
+ {
+ $this->opened_date = Carbon::now();
+ $this->save();
+ }
+
public function pdf_file_path()
{
$storage_path = Storage::url($this->invoice->client->invoice_filepath() . $this->invoice->number . '.pdf');
diff --git a/app/Models/QuoteInvitation.php b/app/Models/QuoteInvitation.php
index b8b37cda9..5bef00af9 100644
--- a/app/Models/QuoteInvitation.php
+++ b/app/Models/QuoteInvitation.php
@@ -36,37 +36,37 @@ class QuoteInvitation extends BaseModel
return QuoteInvitation::class;
}
- public function getSignatureDateAttribute($value)
- {
- if (!$value) {
- return (new Carbon($value))->format('Y-m-d');
- }
- return $value;
- }
+ // public function getSignatureDateAttribute($value)
+ // {
+ // if (!$value) {
+ // return (new Carbon($value))->format('Y-m-d');
+ // }
+ // return $value;
+ // }
- public function getSentDateAttribute($value)
- {
- if (!$value) {
- return (new Carbon($value))->format('Y-m-d');
- }
- return $value;
- }
+ // public function getSentDateAttribute($value)
+ // {
+ // if (!$value) {
+ // return (new Carbon($value))->format('Y-m-d');
+ // }
+ // return $value;
+ // }
- public function getViewedDateAttribute($value)
- {
- if (!$value) {
- return (new Carbon($value))->format('Y-m-d');
- }
- return $value;
- }
+ // public function getViewedDateAttribute($value)
+ // {
+ // if (!$value) {
+ // return (new Carbon($value))->format('Y-m-d');
+ // }
+ // return $value;
+ // }
- public function getOpenedDateAttribute($value)
- {
- if (!$value) {
- return (new Carbon($value))->format('Y-m-d');
- }
- return $value;
- }
+ // public function getOpenedDateAttribute($value)
+ // {
+ // if (!$value) {
+ // return (new Carbon($value))->format('Y-m-d');
+ // }
+ // return $value;
+ // }
public function entityType()
{
@@ -125,7 +125,7 @@ class QuoteInvitation extends BaseModel
$storage_path = Storage::url($this->quote->client->quote_filepath() . $this->quote->number . '.pdf');
if (!Storage::exists($this->quote->client->quote_filepath() . $this->quote->number . '.pdf')) {
- event(new QuoteWasUpdated($this, $this->company, Ninja::eventVars()));
+ event(new QuoteWasUpdated($this->quote, $this->company, Ninja::eventVars()));
CreateQuotePdf::dispatchNow($this);
}
diff --git a/app/Notifications/Admin/InvoiceSentNotification.php b/app/Notifications/Admin/InvoiceSentNotification.php
index 245d4f6d8..100d6e020 100644
--- a/app/Notifications/Admin/InvoiceSentNotification.php
+++ b/app/Notifications/Admin/InvoiceSentNotification.php
@@ -85,7 +85,7 @@ class InvoiceSentNotification extends Notification implements ShouldQueue
'invoice' => $this->invoice->number,
]
),
- 'url' => config('ninja.app_url') . '/invoices/' . $this->invoice->hashed_id,
+ 'url' => config('ninja.app_url') . 'invoices/' . $this->invoice->hashed_id,
'button' => ctrans('texts.view_invoice'),
'signature' => $this->settings->email_signature,
'logo' => $this->company->present()->logo(),
diff --git a/app/Notifications/Admin/InvoiceViewedNotification.php b/app/Notifications/Admin/InvoiceViewedNotification.php
index 5bc49983f..f12492991 100644
--- a/app/Notifications/Admin/InvoiceViewedNotification.php
+++ b/app/Notifications/Admin/InvoiceViewedNotification.php
@@ -85,7 +85,7 @@ class InvoiceViewedNotification extends Notification implements ShouldQueue
'invoice' => $this->invoice->number,
]
),
- 'url' => config('ninja.app_url') . '/invoices/' . $this->invoice->hashed_id,
+ 'url' => config('ninja.app_url') . 'invoices/' . $this->invoice->hashed_id,
'button' => ctrans('texts.view_invoice'),
'signature' => $this->settings->email_signature,
'logo' => $this->company->present()->logo(),
diff --git a/app/Notifications/Admin/NewPartialPaymentNotification.php b/app/Notifications/Admin/NewPartialPaymentNotification.php
index 5298eb5ce..384857195 100644
--- a/app/Notifications/Admin/NewPartialPaymentNotification.php
+++ b/app/Notifications/Admin/NewPartialPaymentNotification.php
@@ -83,7 +83,7 @@ class NewPartialPaymentNotification extends Notification implements ShouldQueue
'invoice' => $invoice_texts,
]
),
- 'url' => config('ninja.app_url') . '/payments/' . $this->payment->hashed_id,
+ 'url' => config('ninja.app_url') . 'payments/' . $this->payment->hashed_id,
'button' => ctrans('texts.view_payment'),
'signature' => $this->settings->email_signature,
'logo' => $this->company->present()->logo(),
diff --git a/app/Notifications/Admin/NewPaymentNotification.php b/app/Notifications/Admin/NewPaymentNotification.php
index ca0c77f36..f3e3ee302 100644
--- a/app/Notifications/Admin/NewPaymentNotification.php
+++ b/app/Notifications/Admin/NewPaymentNotification.php
@@ -86,7 +86,7 @@ class NewPaymentNotification extends Notification implements ShouldQueue
'invoice' => $invoice_texts,
]
),
- 'url' => config('ninja.app_url') . '/payments/' . $this->payment->hashed_id,
+ 'url' => config('ninja.app_url') . 'payments/' . $this->payment->hashed_id,
'button' => ctrans('texts.view_payment'),
'signature' => $this->settings->email_signature,
'logo' => $this->company->present()->logo(),
diff --git a/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php b/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php
index c7767f45e..2105ca383 100644
--- a/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php
+++ b/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php
@@ -124,10 +124,12 @@ class AuthorizeCreditCard
SystemLogger::dispatch($logger_message, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_SUCCESS, SystemLog::TYPE_AUTHORIZE, $this->authorize->client);
-
+ return true;
}
else {
+
+ return false;
}
}
@@ -207,7 +209,6 @@ class AuthorizeCreditCard
'code' => $response->getTransactionResponse()->getMessages()[0]->getCode(),
'description' => $response->getTransactionResponse()->getMessages()[0]->getDescription(),
'invoices' => $vars['hashed_ids'],
-
];
}
diff --git a/app/PaymentDrivers/AuthorizePaymentDriver.php b/app/PaymentDrivers/AuthorizePaymentDriver.php
index da502665b..f0644e642 100644
--- a/app/PaymentDrivers/AuthorizePaymentDriver.php
+++ b/app/PaymentDrivers/AuthorizePaymentDriver.php
@@ -14,6 +14,7 @@ namespace App\PaymentDrivers;
use App\Models\ClientGatewayToken;
use App\Models\GatewayType;
+use App\Models\Invoice;
use App\Models\Payment;
use App\PaymentDrivers\Authorize\AuthorizeCreditCard;
use App\PaymentDrivers\Authorize\AuthorizePaymentMethod;
@@ -36,6 +37,10 @@ class AuthorizePaymentDriver extends BaseDriver
public $merchant_authentication;
+ public $token_billing = true;
+
+ public $can_authorise_credit_card = true;
+
public static $methods = [
GatewayType::CREDIT_CARD => AuthorizeCreditCard::class,
];
@@ -142,7 +147,7 @@ class AuthorizePaymentDriver extends BaseDriver
{
$this->setPaymentMethod($cgt->gateway_type_id);
- $this->payment_method->tokenBilling($cgt, $amount, $invoice);
+ return $this->payment_method->tokenBilling($cgt, $amount, $invoice);
}
}
diff --git a/app/PaymentDrivers/Stripe/Charge.php b/app/PaymentDrivers/Stripe/Charge.php
new file mode 100644
index 000000000..38aa4d0b3
--- /dev/null
+++ b/app/PaymentDrivers/Stripe/Charge.php
@@ -0,0 +1,512 @@
+stripe = $stripe;
+ }
+
+ /**
+ * Create a charge against a payment method
+ * @return bool success/failure
+ */
+ public function tokenBilling(ClientGatewayToken $cgt, $amount, ?Invoice $invoice)
+ {
+
+ if($invoice)
+ $description = "Invoice {$invoice->number} for {$amount} for client {$this->stripe->client->present()->name()}";
+ else
+ $description = "Payment with no invoice for amount {$amount} for client {$this->stripe->client->present()->name()}";
+
+ $this->stripe->init();
+
+ $local_stripe = new \Stripe\StripeClient(
+ $this->stripe->company_gateway->getConfigField('apiKey')
+ );
+
+ $response = null;
+
+ try {
+
+ $response = $local_stripe->paymentIntents->create([
+ 'amount' => $this->stripe->convertToStripeAmount($amount, $this->stripe->client->currency()->precision),
+ 'currency' => $this->stripe->client->getCurrencyCode(),
+ 'payment_method' => $cgt->token,
+ 'customer' => $cgt->gateway_customer_reference,
+ 'confirm' => true,
+ 'description' => $description,
+ ]);
+
+ SystemLogger::dispatch($response, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_SUCCESS, SystemLog::TYPE_STRIPE, $this->stripe->client);
+
+
+ } catch(\Stripe\Exception\CardException $e) {
+ // Since it's a decline, \Stripe\Exception\CardException will be caught
+
+ $data = [
+ 'status' => $e->getHttpStatus(),
+ 'error_type' => $e->getError()->type,
+ 'error_code' => $e->getError()->code,
+ 'param' => $e->getError()->param,
+ 'message' => $e->getError()->message
+ ];
+
+ SystemLogger::dispatch($data, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_STRIPE, $this->stripe->client);
+
+ } catch (\Stripe\Exception\RateLimitException $e) {
+ // Too many requests made to the API too quickly
+
+ $data = [
+ 'status' => '',
+ 'error_type' => '',
+ 'error_code' => '',
+ 'param' => '',
+ 'message' => 'Too many requests made to the API too quickly'
+ ];
+
+ SystemLogger::dispatch($data, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_STRIPE, $this->stripe->client);
+
+ } catch (\Stripe\Exception\InvalidRequestException $e) {
+ // Invalid parameters were supplied to Stripe's API
+ //
+ $data = [
+ 'status' => '',
+ 'error_type' => '',
+ 'error_code' => '',
+ 'param' => '',
+ 'message' => 'Invalid parameters were supplied to Stripe\'s API'
+ ];
+
+ SystemLogger::dispatch($data, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_STRIPE, $this->stripe->client);
+
+ } catch (\Stripe\Exception\AuthenticationException $e) {
+ // Authentication with Stripe's API failed
+
+ $data = [
+ 'status' => '',
+ 'error_type' => '',
+ 'error_code' => '',
+ 'param' => '',
+ 'message' => 'Authentication with Stripe\'s API failed'
+ ];
+
+ SystemLogger::dispatch($data, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_STRIPE, $this->stripe->client);
+
+ } catch (\Stripe\Exception\ApiConnectionException $e) {
+ // Network communication with Stripe failed
+
+ $data = [
+ 'status' => '',
+ 'error_type' => '',
+ 'error_code' => '',
+ 'param' => '',
+ 'message' => 'Network communication with Stripe failed'
+ ];
+
+ SystemLogger::dispatch($data, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_STRIPE, $this->stripe->client);
+
+ } catch (\Stripe\Exception\ApiErrorException $e) {
+
+ $data = [
+ 'status' => '',
+ 'error_type' => '',
+ 'error_code' => '',
+ 'param' => '',
+ 'message' => 'API Error'
+ ];
+
+ SystemLogger::dispatch($data, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_STRIPE, $this->stripe->client);
+
+ } catch (Exception $e) {
+ // Something else happened, completely unrelated to Stripe
+ //
+ $data = [
+ 'status' => '',
+ 'error_type' => '',
+ 'error_code' => '',
+ 'param' => '',
+ 'message' => $e->getMessage(),
+ ];
+
+ SystemLogger::dispatch($data, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_STRIPE, $this->stripe->client);
+ }
+
+ if(!$response)
+ return false;
+
+ $payment_method_type = $response->charges->data[0]->payment_method_details->card->brand;
+ info($payment_method_type);
+
+ $data = [
+ 'gateway_type_id' => $cgt->gateway_type_id,
+ 'type_id' => $this->transformPaymentTypeToConstant($payment_method_type),
+ 'transaction_reference' => $response->charges->data[0]->id,
+ ];
+
+ $payment = $this->stripe->createPaymentRecord($data, $amount);
+
+ if($invoice)
+ $this->stripe->attachInvoices($payment, $invoice->hashed_id);
+
+ $payment->service()->updateInvoicePayment();
+
+ event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars()));
+
+ return $payment;
+ }
+
+
+ private function formatGatewayResponse($data, $vars)
+ {
+ $response = $data['response'];
+
+ return [
+ 'transaction_reference' => $response->getTransactionResponse()->getTransId(),
+ 'amount' => $vars['amount'],
+ 'auth_code' => $response->getTransactionResponse()->getAuthCode(),
+ 'code' => $response->getTransactionResponse()->getMessages()[0]->getCode(),
+ 'description' => $response->getTransactionResponse()->getMessages()[0]->getDescription(),
+ 'invoices' => $vars['hashed_ids'],
+ ];
+ }
+
+ private function transformPaymentTypeToConstant($type)
+ {
+ switch ($type) {
+ case 'visa':
+ return PaymentType::VISA;
+ break;
+ case 'mastercard':
+ return PaymentType::MASTERCARD;
+ break;
+ default:
+ return PaymentType::CREDIT_CARD_OTHER;
+ break;
+ }
+ }
+
+}
+
+ // const CREDIT = 1;
+ // const ACH = 4;
+ // const VISA = 5;
+ // const MASTERCARD = 6;
+ // const AMERICAN_EXPRESS = 7;
+ // const DISCOVER = 8;
+ // const DINERS = 9;
+ // const EUROCARD = 10;
+ // const NOVA = 11;
+ // const CREDIT_CARD_OTHER = 12;
+ // const PAYPAL = 13;
+ // const CARTE_BLANCHE = 16;
+ // const UNIONPAY = 17;
+ // const JCB = 18;
+ // const LASER = 19;
+ // const MAESTRO = 20;
+ // const SOLO = 21;
+ // const SWITCH = 22;
+ // const ALIPAY = 27;
+ // const SOFORT = 28;
+ // const SEPA = 29;
+ // const GOCARDLESS = 30;
+ // const CRYPTO = 31;
+
+// {
+// "id": "ch_1H4lp42eZvKYlo2Ch5igaUwg",
+// "object": "charge",
+// "amount": 2000,
+// "amount_refunded": 0,
+// "application": null,
+// "application_fee": null,
+// "application_fee_amount": null,
+// "balance_transaction": "txn_19XJJ02eZvKYlo2ClwuJ1rbA",
+// "billing_details": {
+// "address": {
+// "city": null,
+// "country": null,
+// "line1": null,
+// "line2": null,
+// "postal_code": "45465",
+// "state": null
+// },
+// "email": null,
+// "name": null,
+// "phone": null
+// },
+// "calculated_statement_descriptor": null,
+// "captured": false,
+// "created": 1594724238,
+// "currency": "usd",
+// "customer": null,
+// "description": "My First Test Charge (created for API docs)",
+// "disputed": false,
+// "failure_code": null,
+// "failure_message": null,
+// "fraud_details": {},
+// "invoice": null,
+// "livemode": false,
+// "metadata": {},
+// "on_behalf_of": null,
+// "order": null,
+// "outcome": null,
+// "paid": true,
+// "payment_intent": null,
+// "payment_method": "card_1F8MLI2eZvKYlo2CvsyCzps2",
+// "payment_method_details": {
+// "card": {
+// "brand": "visa",
+// "checks": {
+// "address_line1_check": null,
+// "address_postal_code_check": "pass",
+// "cvc_check": null
+// },
+// "country": "US",
+// "exp_month": 12,
+// "exp_year": 2023,
+// "fingerprint": "Xt5EWLLDS7FJjR1c",
+// "funding": "credit",
+// "installments": null,
+// "last4": "4242",
+// "network": "visa",
+// "three_d_secure": null,
+// "wallet": null
+// },
+// "type": "card"
+// },
+// "receipt_email": null,
+// "receipt_number": null,
+// "receipt_url": "https://pay.stripe.com/receipts/acct_1032D82eZvKYlo2C/ch_1H4lp42eZvKYlo2Ch5igaUwg/rcpt_He3wuRQtzvT2Oi4OAYQSpajtmteo55J",
+// "refunded": false,
+// "refunds": {
+// "object": "list",
+// "data": [],
+// "has_more": false,
+// "url": "/v1/charges/ch_1H4lp42eZvKYlo2Ch5igaUwg/refunds"
+// },
+// "review": null,
+// "shipping": null,
+// "source_transfer": null,
+// "statement_descriptor": null,
+// "statement_descriptor_suffix": null,
+// "status": "succeeded",
+// "transfer_data": null,
+// "transfer_group": null,
+// "source": "tok_visa"
+// }
+//
+//
+// [2020-07-14 23:06:47] local.INFO: Stripe\PaymentIntent Object
+// (
+// [id] => pi_1H4xD0Kmol8YQE9DKhrvV6Nc
+// [object] => payment_intent
+// [allowed_source_types] => Array
+// (
+// [0] => card
+// )
+
+// [amount] => 1000
+// [amount_capturable] => 0
+// [amount_received] => 1000
+// [application] =>
+// [application_fee_amount] =>
+// [canceled_at] =>
+// [cancellation_reason] =>
+// [capture_method] => automatic
+// [charges] => Stripe\Collection Object
+// (
+// [object] => list
+// [data] => Array
+// (
+// [0] => Stripe\Charge Object
+// (
+// [id] => ch_1H4xD0Kmol8YQE9Ds9b1ZWjw
+// [object] => charge
+// [amount] => 1000
+// [amount_refunded] => 0
+// [application] =>
+// [application_fee] =>
+// [application_fee_amount] =>
+// [balance_transaction] => txn_1H4xD1Kmol8YQE9DE9qFoO0R
+// [billing_details] => Stripe\StripeObject Object
+// (
+// [address] => Stripe\StripeObject Object
+// (
+// [city] =>
+// [country] =>
+// [line1] =>
+// [line2] =>
+// [postal_code] => 42334
+// [state] =>
+// )
+
+// [email] =>
+// [name] => sds
+// [phone] =>
+// )
+
+// [calculated_statement_descriptor] => NODDY
+// [captured] => 1
+// [created] => 1594768006
+// [currency] => usd
+// [customer] => cus_He4VEiYldHJWqG
+// [description] => Invoice 0023 for 10 for client Corwin Group
+// [destination] =>
+// [dispute] =>
+// [disputed] =>
+// [failure_code] =>
+// [failure_message] =>
+// [fraud_details] => Array
+// (
+// )
+
+// [invoice] =>
+// [livemode] =>
+// [metadata] => Stripe\StripeObject Object
+// (
+// )
+
+// [on_behalf_of] =>
+// [order] =>
+// [outcome] => Stripe\StripeObject Object
+// (
+// [network_status] => approved_by_network
+// [reason] =>
+// [risk_level] => normal
+// [risk_score] => 13
+// [seller_message] => Payment complete.
+// [type] => authorized
+// )
+
+// [paid] => 1
+// [payment_intent] => pi_1H4xD0Kmol8YQE9DKhrvV6Nc
+// [payment_method] => pm_1H4mNAKmol8YQE9DUMRsuTXs
+// [payment_method_details] => Stripe\StripeObject Object
+// (
+// [card] => Stripe\StripeObject Object
+// (
+// [brand] => visa
+// [checks] => Stripe\StripeObject Object
+// (
+// [address_line1_check] =>
+// [address_postal_code_check] => pass
+// [cvc_check] =>
+// )
+
+// [country] => US
+// [exp_month] => 4
+// [exp_year] => 2024
+// [fingerprint] => oCjEXlb4syFKwgbJ
+// [funding] => credit
+// [installments] =>
+// [last4] => 4242
+// [network] => visa
+// [three_d_secure] =>
+// [wallet] =>
+// )
+
+// [type] => card
+// )
+
+// [receipt_email] =>
+// [receipt_number] =>
+// [receipt_url] => https://pay.stripe.com/receipts/acct_19DXXPKmol8YQE9D/ch_1H4xD0Kmol8YQE9Ds9b1ZWjw/rcpt_HeFiiwzRZtnOpvHyohNN5JXtCYe8Rdc
+// [refunded] =>
+// [refunds] => Stripe\Collection Object
+// (
+// [object] => list
+// [data] => Array
+// (
+// )
+
+// [has_more] =>
+// [total_count] => 0
+// [url] => /v1/charges/ch_1H4xD0Kmol8YQE9Ds9b1ZWjw/refunds
+// )
+
+// [review] =>
+// [shipping] =>
+// [source] =>
+// [source_transfer] =>
+// [statement_descriptor] =>
+// [statement_descriptor_suffix] =>
+// [status] => succeeded
+// [transfer_data] =>
+// [transfer_group] =>
+// )
+
+// )
+
+// [has_more] =>
+// [total_count] => 1
+// [url] => /v1/charges?payment_intent=pi_1H4xD0Kmol8YQE9DKhrvV6Nc
+// )
+
+// [client_secret] => pi_1H4xD0Kmol8YQE9DKhrvV6Nc_secret_TyE8n3Y3oaMqgqQvXvtKDOnYT
+// [confirmation_method] => automatic
+// [created] => 1594768006
+// [currency] => usd
+// [customer] => cus_He4VEiYldHJWqG
+// [description] => Invoice 0023 for 10 for client Corwin Group
+// [invoice] =>
+// [last_payment_error] =>
+// [livemode] =>
+// [metadata] => Stripe\StripeObject Object
+// (
+// )
+
+// [next_action] =>
+// [next_source_action] =>
+// [on_behalf_of] =>
+// [payment_method] => pm_1H4mNAKmol8YQE9DUMRsuTXs
+// [payment_method_options] => Stripe\StripeObject Object
+// (
+// [card] => Stripe\StripeObject Object
+// (
+// [installments] =>
+// [network] =>
+// [request_three_d_secure] => automatic
+// )
+
+// )
+
+// [payment_method_types] => Array
+// (
+// [0] => card
+// )
+
+// [receipt_email] =>
+// [review] =>
+// [setup_future_usage] =>
+// [shipping] =>
+// [source] =>
+// [statement_descriptor] =>
+// [statement_descriptor_suffix] =>
+// [status] => succeeded
+// [transfer_data] =>
+// [transfer_group] =>
+// )
\ No newline at end of file
diff --git a/app/PaymentDrivers/StripePaymentDriver.php b/app/PaymentDrivers/StripePaymentDriver.php
index d0c96407d..523d9a894 100644
--- a/app/PaymentDrivers/StripePaymentDriver.php
+++ b/app/PaymentDrivers/StripePaymentDriver.php
@@ -27,6 +27,7 @@ use App\Models\PaymentType;
use App\Models\SystemLog;
use App\PaymentDrivers\Stripe\ACH;
use App\PaymentDrivers\Stripe\Alipay;
+use App\PaymentDrivers\Stripe\Charge;
use App\PaymentDrivers\Stripe\CreditCard;
use App\PaymentDrivers\Stripe\SOFORT;
use App\PaymentDrivers\Stripe\Utilities;
@@ -41,11 +42,11 @@ class StripePaymentDriver extends BasePaymentDriver
{
use MakesHash, Utilities;
- protected $refundable = true;
+ public $refundable = true;
- protected $token_billing = true;
+ public $token_billing = true;
- protected $can_authorise_credit_card = true;
+ public $can_authorise_credit_card = true;
protected $customer_reference = 'customerReferenceParam';
@@ -366,7 +367,35 @@ class StripePaymentDriver extends BasePaymentDriver
return response([], 200);
}
- public function tokenBilling(ClientGatewayToken $cgt, float $amount) {}
+ public function tokenBilling(ClientGatewayToken $cgt, float $amount, ?Invoice $invoice = null)
+ {
+ return (new Charge($this))->tokenBilling($cgt, $amount, $invoice);
+ }
+ /**
+ * Creates a payment record for the given
+ * data array.
+ *
+ * @param array $data An array of payment attributes
+ * @param float $amount The amount of the payment
+ * @return Payment The payment object
+ */
+ public function createPaymentRecord($data, $amount) :?Payment
+ {
+ $payment = PaymentFactory::create($this->client->company_id, $this->client->user_id);
+ $payment->client_id = $this->client->id;
+ $payment->company_gateway_id = $this->company_gateway->id;
+ $payment->status_id = Payment::STATUS_COMPLETED;
+ $payment->gateway_type_id = $data['gateway_type_id'];
+ $payment->type_id = $data['type_id'];
+ $payment->currency_id = $this->client->getSetting('currency_id');
+ $payment->date = Carbon::now();
+ $payment->transaction_reference = $data['transaction_reference'];
+ $payment->amount = $amount;
+ $payment->client->getNextPaymentNumber($this->client);
+ $payment->save();
+
+ return $payment;
+ }
}
diff --git a/app/Services/Invoice/AutoBillInvoice.php b/app/Services/Invoice/AutoBillInvoice.php
index 30eec874b..cc8ec5f8d 100644
--- a/app/Services/Invoice/AutoBillInvoice.php
+++ b/app/Services/Invoice/AutoBillInvoice.php
@@ -47,10 +47,11 @@ class AutoBillInvoice extends AbstractService
else
return $this->invoice->service()->markPaid()->save();
- if(!$gateway_token)
+ if(!$gateway_token || !$gateway_token->gateway->driver($this->client)->token_billing){
return $this->invoice;
+ }
- if($this->invoice->partial){
+ if($this->invoice->partial > 0){
$fee = $gateway_token->gateway->calcGatewayFee($this->invoice->partial);
$amount = $this->invoice->partial + $fee;
}
@@ -65,29 +66,39 @@ class AutoBillInvoice extends AbstractService
if($fee > 0)
$this->addFeeToInvoice($fee);
- $response = $gateway_token->gateway->driver($this->client)->tokenBilling($gateway_token, $amount, $this->invoice);
+ $payment = $gateway_token->gateway->driver($this->client)->tokenBilling($gateway_token, $amount, $this->invoice);
- //if response was successful, toggle the fee type_id to paid
+ if($payment){
+
+ $this->invoice->service()->toggleFeesPaid()->save();
+
+ }
+ else
+ {
+ //autobill failed
+ }
+
+
+ return $this->invoice;
}
+ /**
+ * Harvests a client gateway token which passes the
+ * necessary filters for an $amount
+ *
+ * @param float $amount The amount to charge
+ * @return ClientGatewayToken The client gateway token
+ */
private function getGateway($amount)
{
- // $gateway_tokens = $this->client->gateway_tokens()->orderBy('is_default', 'DESC');
-
- // return $gateway_tokens->filter(function ($token) use ($amount){
-
- // return $this->validGatewayLimits($token, $amount);
-
- // })->all()->first();
-
-
$gateway_tokens = $this->client->gateway_tokens()->orderBy('is_default', 'DESC')->get();
foreach($gateway_tokens as $gateway_token)
{
- if($this->validGatewayLimits($gateway_token, $amount))
+ if($this->validGatewayLimits($gateway_token, $amount)){
return $gateway_token;
+ }
}
}
@@ -150,7 +161,7 @@ class AutoBillInvoice extends AbstractService
$this->invoice->line_items = $new_items;
$this->invoice->save();
- $this->invoice = $this->invoice->calc()->getInvoice()->save();
+ $this->invoice = $this->invoice->calc()->getInvoice();
if($starting_amount != $this->invoice->amount && $this->invoice->status_id != Invoice::STATUS_DRAFT){
$this->invoice->client->service()->updateBalance($this->invoice->amount - $starting_amount)->save();
@@ -174,7 +185,7 @@ class AutoBillInvoice extends AbstractService
if(isset($cg->fees_and_limits))
$fees_and_limits = $cg->fees_and_limits->{"1"};
else
- $passes = true;
+ return true;
if ((property_exists($fees_and_limits, 'min_limit')) && $fees_and_limits->min_limit !== null && $amount < $fees_and_limits->min_limit) {
info("amount {$amount} less than ". $fees_and_limits->min_limit);
diff --git a/app/Services/Invoice/InvoiceService.php b/app/Services/Invoice/InvoiceService.php
index c1999ec42..40d587733 100644
--- a/app/Services/Invoice/InvoiceService.php
+++ b/app/Services/Invoice/InvoiceService.php
@@ -178,6 +178,33 @@ class InvoiceService
return $this;
}
+ public function toggleFeesPaid()
+ {
+
+ $this->invoice->line_items = collect($this->invoice->line_items)
+ ->where('type_id',3)->map(function ($item) {
+
+ $item->type_id=4;
+ return $item;
+
+ })->toArray();
+
+ return $this;
+ }
+
+ public function removeUnpaidGatewayFees()
+ {
+
+ $this->invoice->line_items = collect($this->invoice->line_items)
+ ->reject(function ($item) {
+
+ return $item->type_id == 3;
+
+ })->toArray();
+
+ return $this;
+ }
+
public function clearPartial()
{
$this->invoice->partial = null;
diff --git a/app/Utils/HtmlEngine.php b/app/Utils/HtmlEngine.php
index 337c170d4..fc922bc5f 100644
--- a/app/Utils/HtmlEngine.php
+++ b/app/Utils/HtmlEngine.php
@@ -496,7 +496,8 @@ class HtmlEngine
*/
public function generateAppUrl()
{
- return rtrim(config('ninja.app_url'), "/");
+ //return rtrim(config('ninja.app_url'), "/");
+ return config('ninja.app_url');
}
/**
diff --git a/app/Utils/Traits/Inviteable.php b/app/Utils/Traits/Inviteable.php
index 2a674d581..42811e385 100644
--- a/app/Utils/Traits/Inviteable.php
+++ b/app/Utils/Traits/Inviteable.php
@@ -55,14 +55,14 @@ trait Inviteable
switch ($this->company->portal_mode) {
case 'subdomain':
- return $domain .'/client/'. $entity_type .'/'. $this->key;
+ return $domain .'client/'. $entity_type .'/'. $this->key;
break;
case 'iframe':
- return $domain .'/client/'. $entity_type .'/'. $this->key;
+ return $domain .'client/'. $entity_type .'/'. $this->key;
//return $domain . $entity_type .'/'. $this->contact->client->client_hash .'/'. $this->key;
break;
case 'domain':
- return $domain .'/client/'. $entity_type .'/'. $this->key;
+ return $domain .'client/'. $entity_type .'/'. $this->key;
break;
}
diff --git a/app/Utils/Traits/MakesInvoiceValues.php b/app/Utils/Traits/MakesInvoiceValues.php
index c82470795..626241f57 100644
--- a/app/Utils/Traits/MakesInvoiceValues.php
+++ b/app/Utils/Traits/MakesInvoiceValues.php
@@ -749,7 +749,8 @@ trait MakesInvoiceValues
*/
public function generateAppUrl()
{
- return rtrim(config('ninja.app_url'), "/");
+ //return rtrim(config('ninja.app_url'), "/");
+ return config('ninja.app_url');
}
/**
diff --git a/resources/views/layouts/guest.blade.php b/resources/views/layouts/guest.blade.php
index 6db093859..8187713a2 100644
--- a/resources/views/layouts/guest.blade.php
+++ b/resources/views/layouts/guest.blade.php
@@ -36,7 +36,7 @@
-
+
diff --git a/resources/views/layouts/master.blade.php b/resources/views/layouts/master.blade.php
index 72325ca5f..0928ce4db 100644
--- a/resources/views/layouts/master.blade.php
+++ b/resources/views/layouts/master.blade.php
@@ -35,7 +35,7 @@
-
+
--/>
@@ -57,7 +57,7 @@
-
+
diff --git a/resources/views/portal/ninja2020/layout/clean.blade.php b/resources/views/portal/ninja2020/layout/clean.blade.php
index e6862eacd..8ad112620 100644
--- a/resources/views/portal/ninja2020/layout/clean.blade.php
+++ b/resources/views/portal/ninja2020/layout/clean.blade.php
@@ -54,7 +54,7 @@
{{-- --}}
-
+
{{-- Feel free to push anything to header using @push('header') --}}
@stack('head')