diff --git a/app/Listeners/Invoice/InvoiceEmailedNotification.php b/app/Listeners/Invoice/InvoiceEmailedNotification.php index ec20f01f79d4..d4ad6b320fc9 100644 --- a/app/Listeners/Invoice/InvoiceEmailedNotification.php +++ b/app/Listeners/Invoice/InvoiceEmailedNotification.php @@ -46,13 +46,13 @@ class InvoiceEmailedNotification implements ShouldQueue $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 && $first_notification_sent === true) { unset($methods[$key]); @@ -61,7 +61,7 @@ class InvoiceEmailedNotification implements ShouldQueue //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; } diff --git a/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php b/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php index c7767f45e273..f961857f148b 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; } } diff --git a/app/PaymentDrivers/AuthorizePaymentDriver.php b/app/PaymentDrivers/AuthorizePaymentDriver.php index 26df0695feea..079dbc7a5852 100644 --- a/app/PaymentDrivers/AuthorizePaymentDriver.php +++ b/app/PaymentDrivers/AuthorizePaymentDriver.php @@ -143,7 +143,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 000000000000..03d7b09c2b0f --- /dev/null +++ b/app/PaymentDrivers/Stripe/Charge.php @@ -0,0 +1,50 @@ +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()}"; + + $response = $this->stripe->charges->create([ + 'amount' => $this->stripe->convertToStripeAmount($amount, $this->stripe->client->currency()->precision), + 'currency' => $this->stripe->client->getCurrencyCode(), + 'source' => $cgt->token, + 'description' => $description, + ]); + + info(print_r($response,1)); + } + +} diff --git a/app/PaymentDrivers/StripePaymentDriver.php b/app/PaymentDrivers/StripePaymentDriver.php index d0c96407d0d1..b27967dae0fc 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; @@ -366,7 +367,10 @@ 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)->tokenBilling($cgt, $amount, $invoice); + } } diff --git a/app/Services/Invoice/AutoBillInvoice.php b/app/Services/Invoice/AutoBillInvoice.php index 30eec874b51c..e82a122a8000 100644 --- a/app/Services/Invoice/AutoBillInvoice.php +++ b/app/Services/Invoice/AutoBillInvoice.php @@ -47,8 +47,10 @@ 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){ + info("either no gateway token record OR tokenbilling not implemented"); return $this->invoice; + } if($this->invoice->partial){ $fee = $gateway_token->gateway->calcGatewayFee($this->invoice->partial);