1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-21 00:41:34 +02:00

Merge pull request #3906 from turbo124/v2

Stripe - Autobilling
This commit is contained in:
David Bomba 2020-07-15 15:05:42 +10:00 committed by GitHub
commit 0ff8b68fbe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
30 changed files with 751 additions and 140 deletions

View File

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

View File

@ -45,10 +45,12 @@ class InvitationController extends Controller
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})]);

View File

@ -122,12 +122,16 @@ 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 ;
$this->entity_transformer = InvoiceTransformer::class ;

View File

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

View File

@ -53,7 +53,6 @@ class EntityPaidMailer extends BaseMailerJob implements ShouldQueue
*/
public function handle()
{
info("entity paid mailer");
//Set DB
//
MultiDB::setDb($this->company->db);

View File

@ -56,7 +56,6 @@ class EntitySentMailer extends BaseMailerJob implements ShouldQueue
*/
public function handle()
{
info("entity sent mailer");
//Set DB
MultiDB::setDb($this->company->db);

View File

@ -57,8 +57,6 @@ class EntityViewedMailer extends BaseMailerJob implements ShouldQueue
public function handle()
{
info("entity viewed mailer");
//Set DB
MultiDB::setDb($this->company->db);

View File

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

View File

@ -42,7 +42,7 @@ class InvitationViewedListener implements ShouldQueue
{
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);

View File

@ -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(),

View File

@ -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()
{

View File

@ -37,4 +37,9 @@ class GatewayType extends StaticModel
{
return $this->belongsTo(Gateway::class);
}
public function payment_methods()
{
return $this->hasMany(PaymentType::class);
}
}

View File

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

View File

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

View File

@ -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(),

View File

@ -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(),

View File

@ -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(),

View File

@ -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(),

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;
}
}
@ -207,7 +209,6 @@ class AuthorizeCreditCard
'code' => $response->getTransactionResponse()->getMessages()[0]->getCode(),
'description' => $response->getTransactionResponse()->getMessages()[0]->getDescription(),
'invoices' => $vars['hashed_ids'],
];
}

View File

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

View File

@ -0,0 +1,512 @@
<?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\Events\Payment\PaymentWasCreated;
use App\Jobs\Util\SystemLogger;
use App\Models\ClientGatewayToken;
use App\Models\Invoice;
use App\Models\PaymentType;
use App\Models\SystemLog;
use App\PaymentDrivers\StripePaymentDriver;
use App\Utils\Ninja;
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()}";
$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] =>
// )

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

View File

@ -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,30 +66,40 @@ 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);

View File

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

View File

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

View File

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

View File

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

View File

@ -36,7 +36,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/simple-line-icons/2.4.1/css/simple-line-icons.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css">
<link rel="canonical" href="{{ config('ninja.app_url') }}/{{ request()->path() }}"/>
<link rel="canonical" href="{{ config('ninja.app_url') }}{{ request()->path() }}"/>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

View File

@ -35,7 +35,7 @@
<meta property="og:site_name" content="Invoice Ninja"/>
<meta property="og:url" content="{{ config('ninja.app_url') }}"/>
<meta property="og:title" content="Invoice Ninja"/>
<meta property="og:image" content="{{ config('ninja.app_url') }}/images/logo.png"/>
<meta property="og:image" content="{{ config('ninja.app_url') }}images/logo.png"/>
<meta property="og:description" content="Create. Send. Get Paid."/>
--/>
<!-- http://realfavicongenerator.net -->
@ -57,7 +57,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/simple-line-icons/2.4.1/css/simple-line-icons.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css">
<link rel="canonical" href="{{ config('ninja.app_url') }}/{{ request()->path() }}"/>
<link rel="canonical" href="{{ config('ninja.app_url') }}{{ request()->path() }}"/>
<link rel="stylesheet" href="{{ mix('/css/ninja.min.css') }}">
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>

View File

@ -54,7 +54,7 @@
<link href="{{ mix('css/app.css') }}" rel="stylesheet">
{{-- <link href="{{ mix('favicon.png') }}" rel="shortcut icon" type="image/png"> --}}
<link rel="canonical" href="{{ config('ninja.app_url') }}/{{ request()->path() }}"/>
<link rel="canonical" href="{{ config('ninja.app_url') }}{{ request()->path() }}"/>
{{-- Feel free to push anything to header using @push('header') --}}
@stack('head')