1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-12 22:22:32 +01:00

Merge pull request #7255 from turbo124/v5-develop

Stripe SEPA multiple sepa tokens
This commit is contained in:
David Bomba 2022-03-03 12:56:00 +11:00 committed by GitHub
commit b27e602183
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 480 additions and 41 deletions

View File

@ -149,7 +149,9 @@ class ContactLoginController extends Controller
return redirect(session()->get('url.intended'));
}
return redirect(route('client.dashboard'));
$this->setRedirectPath();
return redirect($this->redirectTo);
}
public function logout()

View File

@ -24,8 +24,10 @@ use App\Http\Requests\Credit\ShowCreditRequest;
use App\Http\Requests\Credit\StoreCreditRequest;
use App\Http\Requests\Credit\UpdateCreditRequest;
use App\Http\Requests\Credit\UploadCreditRequest;
use App\Jobs\Credit\ZipCredits;
use App\Jobs\Entity\EmailEntity;
use App\Jobs\Invoice\EmailCredit;
use App\Jobs\Invoice\ZipInvoices;
use App\Models\Account;
use App\Models\Client;
use App\Models\Credit;
@ -505,12 +507,30 @@ class CreditController extends BaseController
$ids = request()->input('ids');
$credits = Credit::withTrashed()->whereIn('id', $this->transformKeys($ids));
$credits = Credit::withTrashed()->whereIn('id', $this->transformKeys($ids))->company()->get();
if (! $credits) {
return response()->json(['message' => ctrans('texts.no_credits_found')]);
}
/*
* Download Invoice/s
*/
if ($action == 'bulk_download' && $credits->count() > 1) {
$credits->each(function ($credit) {
if (auth()->user()->cannot('view', $credit)) {
nlog("access denied");
return response()->json(['message' => ctrans('text.access_denied')]);
}
});
ZipCredits::dispatch($credits, $credits->first()->company, auth()->user());
return response()->json(['message' => ctrans('texts.sent_message')], 200);
}
$credits->each(function ($credit, $key) use ($action) {
if (auth()->user()->can('edit', $credit)) {
$this->performAction($credit, $action, true);

View File

@ -27,6 +27,7 @@ use App\Http\Requests\Quote\StoreQuoteRequest;
use App\Http\Requests\Quote\UpdateQuoteRequest;
use App\Http\Requests\Quote\UploadQuoteRequest;
use App\Jobs\Invoice\ZipInvoices;
use App\Jobs\Quote\ZipQuotes;
use App\Models\Account;
use App\Models\Client;
use App\Models\Invoice;
@ -527,14 +528,14 @@ class QuoteController extends BaseController
* Download Invoice/s
*/
if ($action == 'download' && $quotes->count() >= 1) {
if ($action == 'bulk_download' && $quotes->count() >= 1) {
$quotes->each(function ($quote) {
if (auth()->user()->cannot('view', $quote)) {
return response()->json(['message'=> ctrans('texts.access_denied')]);
}
});
ZipInvoices::dispatch($quotes, $quotes->first()->company, auth()->user());
ZipQuotes::dispatch($quotes, $quotes->first()->company, auth()->user());
return response()->json(['message' => ctrans('texts.sent_message')], 200);
}

View File

@ -140,6 +140,10 @@ class Wave extends BaseImport implements ImportInterface
$entity_type = 'vendor';
$data = $this->getCsvData($entity_type);
if(!is_array($data))
return;
$data = $this->preTransform($data, $entity_type);
if (empty($data)) {

View File

@ -31,19 +31,30 @@ class InvoiceTransformer extends BaseTransformer {
throw new ImportException( 'Invoice number already exists' );
}
if(array_key_exists('Invoice Date', $invoice_data))
$date_key = 'Invoice Date';
else
$date_key = 'Transaction Date';
if(array_key_exists('Customer Name', $invoice_data))
$customer_key = 'Customer Name';
else
$customer_key = 'Customer';
$transformed = [
'company_id' => $this->company->id,
'client_id' => $this->getClient( $customer_name = $this->getString( $invoice_data, 'Customer' ), null ),
'client_id' => $this->getClient( $customer_name = $this->getString( $invoice_data, $customer_key ), null ),
'number' => $invoice_number = $this->getString( $invoice_data, 'Invoice Number' ),
'date' => date( 'Y-m-d', strtotime( $invoice_data['Transaction Date'] ) ) ?: now()->format('Y-m-d'), //27-01-2022
'date' => date( 'Y-m-d', strtotime( $invoice_data[$date_key] ) ) ?: now()->format('Y-m-d'), //27-01-2022
'currency_id' => $this->getCurrencyByCode( $invoice_data, 'Currency' ),
'status_id' => Invoice::STATUS_SENT,
'due_date' => array_key_exists('Due Date', $invoice_data) ? date( 'Y-m-d', strtotime( $invoice_data['Due Date'] ) ) : null,
];
$line_items = [];
$payments = [];
foreach ( $line_items_data as $record ) {
if ( $record['Account Type'] === 'Income' ) {
if (array_key_exists('Account Type', $record) && $record['Account Type'] === 'Income' ) {
$description = $this->getString( $record, 'Transaction Line Description' );
// Remove duplicate data from description
@ -63,13 +74,31 @@ class InvoiceTransformer extends BaseTransformer {
'quantity' => 1,
];
} elseif ( $record['Account Type'] === 'System Receivable Invoice' ) {
} elseif (array_key_exists('Account Type', $record) && $record['Account Type'] === 'System Receivable Invoice' ) {
// This is a payment
$payments[] = [
'date' => date( 'Y-m-d', strtotime( $invoice_data['Transaction Date'] ) ),
'date' => date( 'Y-m-d', strtotime( $invoice_data[$date_key] ) ),
'amount' => $this->getFloat( $record, 'Amount (One column)' ),
];
}
else {
//could be a generate invoices.csv file
$line_items[] = [
'notes' => 'Imported Invoice',
'cost' => $this->getFloat( $record, 'Invoice Total' ),
'tax_name1' => 'Tax',
'tax_rate1' => round($this->getFloat( $record, 'Invoice Tax Total' ) / $this->getFloat( $record, 'Invoice Total' ) * 100,2),
'quantity' => 1,
];
if($record['Invoice Paid'] > 0){
$payments[] = [
'date' => date( 'Y-m-d', strtotime( $record['Last Payment Date'] ) ),
'amount' => $this->getFloat( $record, 'Invoice Paid' ),
];
}
}
}
$transformed['line_items'] = $line_items;

View File

@ -0,0 +1,123 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Jobs\Credit;
use App\Jobs\Entity\CreateEntityPdf;
use App\Jobs\Mail\NinjaMailerJob;
use App\Jobs\Mail\NinjaMailerObject;
use App\Jobs\Util\UnlinkFile;
use App\Libraries\MultiDB;
use App\Mail\DownloadCredits;
use App\Models\Company;
use App\Models\User;
use App\Utils\TempFile;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Storage;
use ZipArchive;
class ZipCredits implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public $credits;
private $company;
private $user;
public $settings;
public $tries = 1;
/**
* @param $invoices
* @param Company $company
* @param $email
* @deprecated confirm to be deleted
* Create a new job instance.
*
*/
public function __construct($credits, Company $company, User $user)
{
$this->credits = $credits;
$this->company = $company;
$this->user = $user;
$this->settings = $company->settings;
}
/**
* Execute the job.
*
* @return void
* @throws \ZipStream\Exception\FileNotFoundException
* @throws \ZipStream\Exception\FileNotReadableException
* @throws \ZipStream\Exception\OverflowException
*/
public function handle()
{
MultiDB::setDb($this->company->db);
# create new zip object
$zipFile = new \PhpZip\ZipFile();
$file_name = date('Y-m-d').'_'.str_replace(' ', '_', trans('texts.credits')).'.zip';
$invitation = $this->credits->first()->invitations->first();
$path = $this->credits->first()->client->quote_filepath($invitation);
$this->credits->each(function ($credit){
CreateEntityPdf::dispatchNow($credit->invitations()->first());
});
try{
foreach ($this->credits as $credit) {
$download_file = file_get_contents($credit->pdf_file_path($invitation, 'url', true));
$zipFile->addFromString(basename($credit->pdf_file_path($invitation)), $download_file);
}
Storage::put($path.$file_name, $zipFile->outputAsString());
$nmo = new NinjaMailerObject;
$nmo->mailable = new DownloadCredits(Storage::url($path.$file_name), $this->company);
$nmo->to_user = $this->user;
$nmo->settings = $this->settings;
$nmo->company = $this->company;
NinjaMailerJob::dispatch($nmo);
UnlinkFile::dispatch(config('filesystems.default'), $path.$file_name)->delay(now()->addHours(1));
}
catch(\PhpZip\Exception\ZipException $e){
// handle exception
}
finally{
$zipFile->close();
}
}
}

View File

@ -11,9 +11,11 @@
namespace App\Jobs\Invoice;
use App\Jobs\Entity\CreateEntityPdf;
use App\Jobs\Mail\NinjaMailerJob;
use App\Jobs\Mail\NinjaMailerObject;
use App\Jobs\Util\UnlinkFile;
use App\Libraries\MultiDB;
use App\Mail\DownloadInvoices;
use App\Models\Company;
use App\Models\User;
@ -39,6 +41,8 @@ class ZipInvoices implements ShouldQueue
public $settings;
public $tries = 1;
/**
* @param $invoices
* @param Company $company
@ -69,41 +73,51 @@ class ZipInvoices implements ShouldQueue
public function handle()
{
# create new zip object
$zip = new ZipArchive();
MultiDB::setDb($this->company->db);
# create new zip object
$zipFile = new \PhpZip\ZipFile();
$file_name = date('Y-m-d').'_'.str_replace(' ', '_', trans('texts.invoices')).'.zip';
$invitation = $this->invoices->first()->invitations->first();
$path = $this->invoices->first()->client->invoice_filepath($invitation);
$file_name = date('Y-m-d').'_'.str_replace(' ', '_', trans('texts.invoices')).'.zip';
$tmp_file = @tempnam('.', '');
$zip->open($tmp_file , ZipArchive::OVERWRITE);
# loop through each file
foreach ($this->invoices as $invoice) {
$this->invoices->each(function ($invoice){
CreateEntityPdf::dispatchNow($invoice->invitations()->first());
});
try{
$inv = $invoice->invitations->first();
foreach ($this->invoices as $invoice) {
$download_file = file_get_contents($invoice->pdf_file_path($invitation, 'url', true));
$zipFile->addFromString(basename($invoice->pdf_file_path($invitation)), $download_file);
# download file
$download_file = file_get_contents($invoice->pdf_file_path($inv, 'url', true));
}
#add it to the zip
$zip->addFromString(basename($invoice->pdf_file_path($inv)), $download_file);
Storage::put($path.$file_name, $zipFile->outputAsString());
$nmo = new NinjaMailerObject;
$nmo->mailable = new DownloadInvoices(Storage::url($path.$file_name), $this->company);
$nmo->to_user = $this->user;
$nmo->settings = $this->settings;
$nmo->company = $this->company;
NinjaMailerJob::dispatch($nmo);
UnlinkFile::dispatch(config('filesystems.default'), $path.$file_name)->delay(now()->addHours(1));
}
catch(\PhpZip\Exception\ZipException $e){
// handle exception
}
finally{
$zipFile->close();
}
# close zip
$zip->close();
Storage::put($path.$file_name, file_get_contents($tmp_file));
$nmo = new NinjaMailerObject;
$nmo->mailable = new DownloadInvoices(Storage::url($path.$file_name), $this->company);
$nmo->to_user = $this->user;
$nmo->settings = $this->settings;
$nmo->company = $this->company;
NinjaMailerJob::dispatch($nmo);
UnlinkFile::dispatch(config('filesystems.default'), $path.$file_name)->delay(now()->addHours(1));
}
}

View File

@ -0,0 +1,124 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Jobs\Quote;
use App\Jobs\Entity\CreateEntityPdf;
use App\Jobs\Mail\NinjaMailerJob;
use App\Jobs\Mail\NinjaMailerObject;
use App\Jobs\Util\UnlinkFile;
use App\Libraries\MultiDB;
use App\Mail\DownloadQuotes;
use App\Models\Company;
use App\Models\User;
use App\Utils\TempFile;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Storage;
use ZipArchive;
class ZipQuotes implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public $quotes;
private $company;
private $user;
public $settings;
public $tries = 1;
/**
* @param $invoices
* @param Company $company
* @param $email
* @deprecated confirm to be deleted
* Create a new job instance.
*
*/
public function __construct($quotes, Company $company, User $user)
{
$this->quotes = $quotes;
$this->company = $company;
$this->user = $user;
$this->settings = $company->settings;
}
/**
* Execute the job.
*
* @return void
* @throws \ZipStream\Exception\FileNotFoundException
* @throws \ZipStream\Exception\FileNotReadableException
* @throws \ZipStream\Exception\OverflowException
*/
public function handle()
{
MultiDB::setDb($this->company->db);
# create new zip object
$zipFile = new \PhpZip\ZipFile();
$file_name = date('Y-m-d').'_'.str_replace(' ', '_', trans('texts.quotes')).'.zip';
$invitation = $this->quotes->first()->invitations->first();
$path = $this->quotes->first()->client->quote_filepath($invitation);
$this->quotes->each(function ($quote){
CreateEntityPdf::dispatchNow($quote->invitations()->first());
});
try{
foreach ($this->quotes as $quote) {
$download_file = file_get_contents($quote->pdf_file_path($invitation, 'url', true));
$zipFile->addFromString(basename($quote->pdf_file_path($invitation)), $download_file);
}
Storage::put($path.$file_name, $zipFile->outputAsString());
$nmo = new NinjaMailerObject;
$nmo->mailable = new DownloadQuotes(Storage::url($path.$file_name), $this->company);
$nmo->to_user = $this->user;
$nmo->settings = $this->settings;
$nmo->company = $this->company;
NinjaMailerJob::dispatch($nmo);
UnlinkFile::dispatch(config('filesystems.default'), $path.$file_name)->delay(now()->addHours(1));
}
catch(\PhpZip\Exception\ZipException $e){
// handle exception
}
finally{
$zipFile->close();
}
}
}

View File

@ -0,0 +1,53 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Mail;
use App\Models\Company;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\App;
class DownloadCredits extends Mailable
{
// use Queueable, SerializesModels;
public $file_path;
public $company;
public function __construct($file_path, Company $company)
{
$this->file_path = $file_path;
$this->company = $company;
}
/**
* Build the message.
*/
public function build()
{
App::setLocale($this->company->getLocale());
return $this->from(config('mail.from.address'), config('mail.from.name'))
->subject(ctrans('texts.download_files'))
->view('email.admin.download_credits', [
'url' => $this->file_path,
'logo' => $this->company->present()->logo,
'whitelabel' => $this->company->account->isPaid() ? true : false,
'settings' => $this->company->settings,
'greeting' => $this->company->present()->name(),
]);
}
}

View File

@ -1,4 +1,13 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Mail;

View File

@ -0,0 +1,53 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Mail;
use App\Models\Company;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\App;
class DownloadQuotes extends Mailable
{
// use Queueable, SerializesModels;
public $file_path;
public $company;
public function __construct($file_path, Company $company)
{
$this->file_path = $file_path;
$this->company = $company;
}
/**
* Build the message.
*/
public function build()
{
App::setLocale($this->company->getLocale());
return $this->from(config('mail.from.address'), config('mail.from.name'))
->subject(ctrans('texts.download_files'))
->view('email.admin.download_quotes', [
'url' => $this->file_path,
'logo' => $this->company->present()->logo,
'whitelabel' => $this->company->account->isPaid() ? true : false,
'settings' => $this->company->settings,
'greeting' => $this->company->present()->name(),
]);
}
}

View File

@ -60,7 +60,9 @@ class CreditCard
{
$description = $this->stripe->decodeUnicodeString(ctrans('texts.invoices') . ': ' . collect($data['invoices'])->pluck('invoice_number')) . " for client {$this->stripe->client->present()->name()}";
// $description = $this->stripe->decodeUnicodeString(ctrans('texts.invoices') . ': ' . collect($data['invoices'])->pluck('invoice_number')) . " for client {$this->stripe->client->present()->name()}";
$invoice_numbers = collect($data['invoices'])->pluck('invoice_number')->implode(',');
$description = "Invoices: {$invoice_numbers} for {$data['total']['amount_with_fee']} for client {$this->stripe->client->present()->name()}";
$payment_intent_data = [

File diff suppressed because one or more lines are too long

View File

@ -27,7 +27,7 @@
"/js/clients/payments/square-credit-card.js": "/js/clients/payments/square-credit-card.js?id=8f05ce6bd2d6cae7e5f2",
"/js/clients/statements/view.js": "/js/clients/statements/view.js?id=4ed4c8a09803ddd0a9a7",
"/js/clients/payments/razorpay-aio.js": "/js/clients/payments/razorpay-aio.js?id=c36ab5621413ef1de7c8",
"/js/clients/payments/stripe-sepa.js": "/js/clients/payments/stripe-sepa.js?id=da7b16ffaf5645535c7c",
"/js/clients/payments/stripe-sepa.js": "/js/clients/payments/stripe-sepa.js?id=9134495bcbfdd3e25aef",
"/js/clients/payment_methods/authorize-checkout-card.js": "/js/clients/payment_methods/authorize-checkout-card.js?id=61becda97682c7909f29",
"/js/clients/payments/stripe-giropay.js": "/js/clients/payments/stripe-giropay.js?id=2a973971ed2b890524ee",
"/js/clients/payments/stripe-acss.js": "/js/clients/payments/stripe-acss.js?id=41367f4e80e52a0ab436",

View File

@ -97,8 +97,6 @@ class ProcessSEPA {
document.getElementById('pay-now').addEventListener('click', (e) => {
console.log(document.querySelector('input[name=token]').value);
if (document.querySelector('input[name=token]').value.length !== 0) {
document.getElementById('pay-now').disabled = true;
@ -199,6 +197,10 @@ class ProcessSEPA {
tokenBillingCheckbox.value;
}
if(document.querySelector('input[name=token]').value.length > 2){
document.querySelector('input[name="store_card"]').value = false;
}
document.getElementById('server-response').submit();
}

View File

@ -4566,6 +4566,9 @@ $LANG = array(
'upgrade_to_add_company' => 'Upgrade your plan to add companies',
'file_saved_in_downloads_folder' => 'The file has been saved in the downloads folder',
'small' => 'Small',
'quotes_backup_subject' => 'Your quotes are ready for download',
'credits_backup_subject' => 'Your credits are ready for download',
);
return $LANG;

View File

@ -5,7 +5,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Invoice Ninja</title>
<title></title>
</head>
<div id="content-wrapper">