From 9d551b6e1dab4083b51877389c6c69adbb1ce4f8 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 11 Oct 2021 07:32:13 +1100 Subject: [PATCH 1/3] Prevent duplicate payment records on hosted Stripe checkouts --- app/PaymentDrivers/Stripe/Bancontact.php | 4 ++++ app/PaymentDrivers/Stripe/EPS.php | 4 ++++ app/PaymentDrivers/Stripe/GIROPAY.php | 4 ++++ app/PaymentDrivers/Stripe/PRZELEWY24.php | 4 ++++ app/PaymentDrivers/Stripe/iDeal.php | 4 ++++ 5 files changed, 20 insertions(+) diff --git a/app/PaymentDrivers/Stripe/Bancontact.php b/app/PaymentDrivers/Stripe/Bancontact.php index c54592d8d4a1..cfcab8361ab1 100644 --- a/app/PaymentDrivers/Stripe/Bancontact.php +++ b/app/PaymentDrivers/Stripe/Bancontact.php @@ -87,6 +87,10 @@ class Bancontact { /* @todo: https://github.com/invoiceninja/invoiceninja/pull/3789/files#r436175798 */ + //catch duplicate submissions. + if(Payment::where('transaction_reference', $payment_intent)->exists()) + return redirect()->route('client.payments.index'); + $this->stripe->init(); $data = [ diff --git a/app/PaymentDrivers/Stripe/EPS.php b/app/PaymentDrivers/Stripe/EPS.php index 10e7b560e22f..f9e294862b08 100644 --- a/app/PaymentDrivers/Stripe/EPS.php +++ b/app/PaymentDrivers/Stripe/EPS.php @@ -89,6 +89,10 @@ class EPS $this->stripe->init(); + //catch duplicate submissions. + if(Payment::where('transaction_reference', $payment_intent)->exists()) + return redirect()->route('client.payments.index'); + $data = [ 'payment_method' => $payment_intent, 'payment_type' => PaymentType::EPS, diff --git a/app/PaymentDrivers/Stripe/GIROPAY.php b/app/PaymentDrivers/Stripe/GIROPAY.php index ceb2b9f09ca8..840c4a3c2c87 100644 --- a/app/PaymentDrivers/Stripe/GIROPAY.php +++ b/app/PaymentDrivers/Stripe/GIROPAY.php @@ -89,6 +89,10 @@ class GIROPAY $this->stripe->init(); + //catch duplicate submissions. + if(Payment::where('transaction_reference', $payment_intent)->exists()) + return redirect()->route('client.payments.index'); + $data = [ 'payment_method' => $payment_intent, 'payment_type' => PaymentType::GIROPAY, diff --git a/app/PaymentDrivers/Stripe/PRZELEWY24.php b/app/PaymentDrivers/Stripe/PRZELEWY24.php index bff777fa4b3c..67dbf4516854 100644 --- a/app/PaymentDrivers/Stripe/PRZELEWY24.php +++ b/app/PaymentDrivers/Stripe/PRZELEWY24.php @@ -89,6 +89,10 @@ class PRZELEWY24 $this->stripe->init(); + //catch duplicate submissions. + if(Payment::where('transaction_reference', $payment_intent)->exists()) + return redirect()->route('client.payments.index'); + $data = [ 'payment_method' => $payment_intent, 'payment_type' => PaymentType::PRZELEWY24, diff --git a/app/PaymentDrivers/Stripe/iDeal.php b/app/PaymentDrivers/Stripe/iDeal.php index 35f10c5f6779..d19971c065c9 100644 --- a/app/PaymentDrivers/Stripe/iDeal.php +++ b/app/PaymentDrivers/Stripe/iDeal.php @@ -89,6 +89,10 @@ class iDeal $this->stripe->init(); + //catch duplicate submissions. + if(Payment::where('transaction_reference', $payment_intent)->exists()) + return redirect()->route('client.payments.index'); + $data = [ 'payment_method' => $payment_intent, 'payment_type' => PaymentType::IDEAL, From 543288c5251ebb719296fcf7e237d93d8438ba2f Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 11 Oct 2021 13:19:38 +1100 Subject: [PATCH 2/3] Refactor PDF generation into common .env var --- app/Http/Controllers/PreviewController.php | 4 ++-- app/Utils/SystemHealth.php | 4 ++-- app/Utils/Traits/GeneratesCounter.php | 13 +++++++++++++ config/ninja.php | 4 ++-- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/PreviewController.php b/app/Http/Controllers/PreviewController.php index 710fdfa76131..e5a55fb19c9f 100644 --- a/app/Http/Controllers/PreviewController.php +++ b/app/Http/Controllers/PreviewController.php @@ -380,11 +380,11 @@ class PreviewController extends BaseController return $maker->getCompiledHTML(); } - if (config('ninja.phantomjs_pdf_generation')) { + if (config('ninja.phantomjs_pdf_generation') || config('ninja.pdf_generator') == 'phantom') { return (new Phantom)->convertHtmlToPdf($maker->getCompiledHTML(true)); } - if(config('ninja.invoiceninja_hosted_pdf_generation')){ + if(config('ninja.invoiceninja_hosted_pdf_generation') || config('ninja.pdf_generator') == 'hosted_ninja'){ return (new NinjaPdf())->build($maker->getCompiledHTML(true)); } diff --git a/app/Utils/SystemHealth.php b/app/Utils/SystemHealth.php index 4e61b40a369b..4a25261fc266 100644 --- a/app/Utils/SystemHealth.php +++ b/app/Utils/SystemHealth.php @@ -89,9 +89,9 @@ class SystemHealth public static function getPdfEngine() { - if(config('ninja.invoiceninja_hosted_pdf_generation')) + if(config('ninja.invoiceninja_hosted_pdf_generation') || config('ninja.pdf_generator') == 'hosted_ninja') return 'Invoice Ninja Hosted PDF Generator'; - elseif(config('ninja.phantomjs_pdf_generation')) + elseif(config('ninja.phantomjs_pdf_generation') || config('ninja.pdf_generator') == 'phantom') return 'Phantom JS Web Generator'; else return 'SnapPDF PDF Generator'; diff --git a/app/Utils/Traits/GeneratesCounter.php b/app/Utils/Traits/GeneratesCounter.php index 3877bdf40826..591dd49a98c6 100644 --- a/app/Utils/Traits/GeneratesCounter.php +++ b/app/Utils/Traits/GeneratesCounter.php @@ -713,6 +713,19 @@ trait GeneratesCounter $replace[] = $client->id_number; } + $search[] = '{$user_custom1}'; + $replace[] = $entity->user->custom_value1; + + $search[] = '{$user_custom2}'; + $replace[] = $entity->user->custom_value2; + + $search[] = '{$user_custom3}'; + $replace[] = $entity->user->custom_value3; + + $search[] = '{$client_custom4}'; + $replace[] = $entity->user->custom_value4; + + return str_replace($search, $replace, $pattern); } } diff --git a/config/ninja.php b/config/ninja.php index e697e0714395..ad3356e0a75d 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -33,7 +33,8 @@ return [ 'enabled_modules' => 32767, 'phantomjs_key' => env('PHANTOMJS_KEY', 'a-demo-key-with-low-quota-per-ip-address'), 'phantomjs_secret' => env('PHANTOMJS_SECRET', false), - 'phantomjs_pdf_generation' => env('PHANTOMJS_PDF_GENERATION', true), + 'phantomjs_pdf_generation' => env('PHANTOMJS_PDF_GENERATION', false), + 'pdf_generator' => env('PDF_GENERATOR', false), 'trusted_proxies' => env('TRUSTED_PROXIES', false), 'is_docker' => env('IS_DOCKER', false), 'local_download' => env('LOCAL_DOWNLOAD', false), @@ -173,6 +174,5 @@ return [ 'ninja_default_company_id' => env('NINJA_COMPANY_ID', null), 'ninja_default_company_gateway_id' => env('NINJA_COMPANY_GATEWAY_ID', null), 'ninja_hosted_secret' => env('NINJA_HOSTED_SECRET', null), - 'pdf_generator' => env('PDF_GENERATOR', false), 'internal_queue_enabled' => env('INTERNAL_QUEUE_ENABLED', true), ]; From 4345dece14fb6e3e07e8ad4d28a2e99f6c011d10 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 11 Oct 2021 17:05:14 +1100 Subject: [PATCH 3/3] Minor fixes for double payments --- app/Services/Invoice/ApplyPaymentAmount.php | 2 +- app/Services/Invoice/MarkPaid.php | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/Services/Invoice/ApplyPaymentAmount.php b/app/Services/Invoice/ApplyPaymentAmount.php index 2671b6209977..e63de5e8b59a 100644 --- a/app/Services/Invoice/ApplyPaymentAmount.php +++ b/app/Services/Invoice/ApplyPaymentAmount.php @@ -46,7 +46,7 @@ class ApplyPaymentAmount extends AbstractService } /*Don't double pay*/ - if ($this->invoice->statud_id == Invoice::STATUS_PAID) { + if ($this->invoice->status_id == Invoice::STATUS_PAID) { return $this->invoice; } diff --git a/app/Services/Invoice/MarkPaid.php b/app/Services/Invoice/MarkPaid.php index 8b8d700c6b1d..f3c23ab5b07f 100644 --- a/app/Services/Invoice/MarkPaid.php +++ b/app/Services/Invoice/MarkPaid.php @@ -43,7 +43,7 @@ class MarkPaid extends AbstractService } /*Don't double pay*/ - if ($this->invoice->statud_id == Invoice::STATUS_PAID) { + if ($this->invoice->status_id == Invoice::STATUS_PAID) { return $this->invoice; } @@ -96,7 +96,6 @@ class MarkPaid extends AbstractService ->save(); $this->invoice->service()->workFlow()->save(); - // InvoiceWorkflowSettings::dispatchNow($this->invoice); return $this->invoice; }