mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-05 18:52:44 +01:00
Auto billing for stripe
This commit is contained in:
parent
dc63e533df
commit
d8a13e6cb2
@ -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;
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
50
app/PaymentDrivers/Stripe/Charge.php
Normal file
50
app/PaymentDrivers/Stripe/Charge.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com)
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
namespace App\PaymentDrivers\Stripe;
|
||||
|
||||
use App\Models\ClientGatewayToken;
|
||||
use App\PaymentDrivers\StripePaymentDriver;
|
||||
|
||||
class Charge
|
||||
{
|
||||
/** @var StripePaymentDriver */
|
||||
public $stripe;
|
||||
|
||||
public function __construct(StripePaymentDriver $stripe)
|
||||
{
|
||||
$this->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));
|
||||
}
|
||||
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user