1
0
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:
David Bomba 2020-07-14 22:50:16 +10:00
parent dc63e533df
commit d8a13e6cb2
6 changed files with 66 additions and 8 deletions

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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);
}
}

View 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));
}
}

View File

@ -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);
}
}

View File

@ -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);