From c26afd69e2d35032ec149cdfa62d0cfb83741fb1 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 15 Oct 2021 18:47:41 +1100 Subject: [PATCH 01/11] Fixes for Payment Webhooks --- app/Http/Controllers/ClientPortal/PaymentController.php | 4 +++- app/PaymentDrivers/BaseDriver.php | 6 +++--- app/PaymentDrivers/BasePaymentDriver.php | 4 +++- app/Services/Invoice/ApplyPaymentAmount.php | 6 ++++-- app/Services/Invoice/AutoBillInvoice.php | 3 +++ app/Services/Invoice/MarkPaid.php | 4 +++- app/Services/Payment/PaymentService.php | 6 ++++-- 7 files changed, 23 insertions(+), 10 deletions(-) diff --git a/app/Http/Controllers/ClientPortal/PaymentController.php b/app/Http/Controllers/ClientPortal/PaymentController.php index fcdbeacff4cd..f5cb923d5d68 100644 --- a/app/Http/Controllers/ClientPortal/PaymentController.php +++ b/app/Http/Controllers/ClientPortal/PaymentController.php @@ -114,7 +114,7 @@ class PaymentController extends Controller } else { $payment = PaymentFactory::create($payment_hash->fee_invoice->company_id, $payment_hash->fee_invoice->user_id); $payment->client_id = $payment_hash->fee_invoice->client_id; - $payment->save(); + $payment->saveQuietly(); $payment_hash->payment_id = $payment->id; $payment_hash->save(); @@ -122,6 +122,8 @@ class PaymentController extends Controller $payment = $payment->service()->applyCredits($payment_hash)->save(); + event('eloquent.created: App\Models\Payment', $payment); + if (property_exists($payment_hash->data, 'billing_context')) { $billing_subscription = \App\Models\Subscription::find($payment_hash->data->billing_context->subscription_id); diff --git a/app/PaymentDrivers/BaseDriver.php b/app/PaymentDrivers/BaseDriver.php index 0e31981497c9..547638f0e1cb 100644 --- a/app/PaymentDrivers/BaseDriver.php +++ b/app/PaymentDrivers/BaseDriver.php @@ -236,7 +236,7 @@ class BaseDriver extends AbstractPaymentDriver $payment->type_id = $data['payment_type']; $payment->transaction_reference = $data['transaction_reference']; $payment->client_contact_id = $client_contact_id; - $payment->save(); + $payment->saveQuietly(); $this->payment_hash->payment_id = $payment->id; $this->payment_hash->save(); @@ -248,6 +248,8 @@ class BaseDriver extends AbstractPaymentDriver $payment->service()->updateInvoicePayment($this->payment_hash); + event('eloquent.created: App\Models\Payment', $payment); + if ($this->client->getSetting('client_online_payment_notification')) $payment->service()->sendEmail(); @@ -392,11 +394,9 @@ class BaseDriver extends AbstractPaymentDriver public function clientPaymentFailureMailer($error) { -nlog("outside"); if ($this->payment_hash && is_array($this->payment_hash->invoices())) { -nlog("inside"); $nmo = new NinjaMailerObject; $nmo->mailable = new NinjaMailer((new ClientPaymentFailureObject($this->client, $error, $this->client->company, $this->payment_hash))->build()); diff --git a/app/PaymentDrivers/BasePaymentDriver.php b/app/PaymentDrivers/BasePaymentDriver.php index 18a6cc1b3c89..2c21a228eff9 100644 --- a/app/PaymentDrivers/BasePaymentDriver.php +++ b/app/PaymentDrivers/BasePaymentDriver.php @@ -273,7 +273,9 @@ class BasePaymentDriver $paid_invoices = $payment_hash->invoices(); $invoices = Invoice::whereIn('id', $this->transformKeys(array_column($paid_invoices, 'invoice_id')))->withTrashed()->get(); $payment->invoices()->sync($invoices); - $payment->save(); + $payment->saveQuietly(); + + event('eloquent.created: App\Models\Payment', $payment); return $payment; } diff --git a/app/Services/Invoice/ApplyPaymentAmount.php b/app/Services/Invoice/ApplyPaymentAmount.php index e63de5e8b59a..4a71ae6c85d5 100644 --- a/app/Services/Invoice/ApplyPaymentAmount.php +++ b/app/Services/Invoice/ApplyPaymentAmount.php @@ -65,7 +65,7 @@ class ApplyPaymentAmount extends AbstractService $payment->currency_id = $this->invoice->client->getSetting('currency_id'); $payment->is_manual = true; /* Create a payment relationship to the invoice entity */ - $payment->save(); + $payment->saveQuietly(); $this->setExchangeRate($payment); @@ -103,6 +103,8 @@ class ApplyPaymentAmount extends AbstractService $this->invoice->service()->workFlow()->save(); + event('eloquent.created: App\Models\Payment', $payment); + return $this->invoice; } @@ -120,7 +122,7 @@ class ApplyPaymentAmount extends AbstractService //$payment->exchange_currency_id = $client_currency; // 23/06/2021 $payment->exchange_currency_id = $company_currency; - $payment->save(); + $payment->saveQuietly(); } diff --git a/app/Services/Invoice/AutoBillInvoice.php b/app/Services/Invoice/AutoBillInvoice.php index 7b6bef89196b..98d003507ea4 100644 --- a/app/Services/Invoice/AutoBillInvoice.php +++ b/app/Services/Invoice/AutoBillInvoice.php @@ -175,6 +175,8 @@ class AutoBillInvoice extends AbstractService } + event('eloquent.created: App\Models\Payment', $payment); + $payment->ledger() ->updatePaymentBalance($amount * -1) ->save(); @@ -190,6 +192,7 @@ class AutoBillInvoice extends AbstractService ->updateCreditBalance($amount * -1, "Credit {$current_credit->number} used to pay down Invoice {$this->invoice->number}") ->save(); + event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars())); return $this->invoice diff --git a/app/Services/Invoice/MarkPaid.php b/app/Services/Invoice/MarkPaid.php index 654facfbc4f8..8f3db22f8921 100644 --- a/app/Services/Invoice/MarkPaid.php +++ b/app/Services/Invoice/MarkPaid.php @@ -64,7 +64,7 @@ class MarkPaid extends AbstractService if((int)$payment_type_id > 0) $payment->type_id = (int)$payment_type_id; - $payment->save(); + $payment->saveQuietly(); $this->setExchangeRate($payment); @@ -73,6 +73,8 @@ class MarkPaid extends AbstractService 'amount' => $payment->amount, ]); + event('eloquent.created: App\Models\Payment', $payment); + $this->invoice->next_send_date = null; $this->invoice->service() diff --git a/app/Services/Payment/PaymentService.php b/app/Services/Payment/PaymentService.php index 5e89ea905c31..39df23ef77ff 100644 --- a/app/Services/Payment/PaymentService.php +++ b/app/Services/Payment/PaymentService.php @@ -39,12 +39,14 @@ class PaymentService $payment->transaction_reference = ctrans('texts.manual_entry'); $payment->currency_id = $invoice->client->getSetting('currency_id'); /* Create a payment relationship to the invoice entity */ - $payment->save(); + $payment->saveQuietly(); $payment->invoices()->attach($invoice->id, [ 'amount' => $payment->amount, ]); + event('eloquent.created: App\Models\Payment', $payment); + return $payment; } @@ -145,7 +147,7 @@ class PaymentService public function save() { - $this->payment->save(); + $this->payment->saveQuietly(); return $this->payment->fresh(); } From b57159b362d122cdf4675e3f8faba6ade0a3a6f1 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 16 Oct 2021 10:01:44 +1100 Subject: [PATCH 02/11] Minor fixes for invitations --- app/Factory/ClientContactFactory.php | 1 + app/Services/Invoice/CreateInvitations.php | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/Factory/ClientContactFactory.php b/app/Factory/ClientContactFactory.php index 40769d92667e..328b20a8440a 100644 --- a/app/Factory/ClientContactFactory.php +++ b/app/Factory/ClientContactFactory.php @@ -24,6 +24,7 @@ class ClientContactFactory $client_contact->company_id = $company_id; $client_contact->contact_key = Str::random(40); $client_contact->id = 0; + $client_contact->send_email = true; return $client_contact; } diff --git a/app/Services/Invoice/CreateInvitations.php b/app/Services/Invoice/CreateInvitations.php index 00d45257c268..2f659f0d272d 100644 --- a/app/Services/Invoice/CreateInvitations.php +++ b/app/Services/Invoice/CreateInvitations.php @@ -43,9 +43,9 @@ class CreateInvitations extends AbstractService } $contacts->each(function ($contact) { - $invitation = InvoiceInvitation::whereCompanyId($this->invoice->company_id) - ->whereClientContactId($contact->id) - ->whereInvoiceId($this->invoice->id) + $invitation = InvoiceInvitation::where('company_id', $this->invoice->company_id) + ->where('client_contact_id', $contact->id) + ->where('invoice_id', $this->invoice->id) ->withTrashed() ->first(); From eaf6d53d8c986e050308375a4f85b352332eb9ff Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 16 Oct 2021 12:02:17 +1100 Subject: [PATCH 03/11] Expense default amount --- app/Factory/RecurringExpenseToExpenseFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Factory/RecurringExpenseToExpenseFactory.php b/app/Factory/RecurringExpenseToExpenseFactory.php index 76a3b0456e9e..bd8bc6516414 100644 --- a/app/Factory/RecurringExpenseToExpenseFactory.php +++ b/app/Factory/RecurringExpenseToExpenseFactory.php @@ -38,7 +38,7 @@ class RecurringExpenseToExpenseFactory $expense->date = now()->format('Y-m-d'); $expense->payment_date = $recurring_expense->payment_date; $expense->amount = $recurring_expense->amount; - $expense->foreign_amount = $recurring_expense->foreign_amount; + $expense->foreign_amount = $recurring_expense->foreign_amount ?: 0; $expense->private_notes = $recurring_expense->private_notes; $expense->public_notes = $recurring_expense->public_notes; $expense->transaction_reference = $recurring_expense->transaction_reference; From 653dbc5acce15a545aa2e7ce579eca3d7e0596dc Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 16 Oct 2021 12:19:27 +1100 Subject: [PATCH 04/11] Filter account deletion emails --- app/Http/Controllers/CompanyController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/CompanyController.php b/app/Http/Controllers/CompanyController.php index 5ac5ed157a78..54b04308325e 100644 --- a/app/Http/Controllers/CompanyController.php +++ b/app/Http/Controllers/CompanyController.php @@ -499,7 +499,7 @@ class CompanyController extends BaseController $account->delete(); - if(Ninja::isHosted()) + if(Ninja::isHosted() && $request->has('cancellation_message') && strlen($request->input('cancellation_message')) > 1) \Modules\Admin\Jobs\Account\NinjaDeletedAccount::dispatch($account_key, $request->all()); LightLogs::create(new AccountDeleted()) From 94785fae503c2e235175bd5e2cfa4f6f523bda49 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 16 Oct 2021 13:29:04 +1100 Subject: [PATCH 05/11] Minor fixes for gelf output --- config/logging.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/logging.php b/config/logging.php index 4c6c4233642f..808a7d604a5c 100644 --- a/config/logging.php +++ b/config/logging.php @@ -129,7 +129,7 @@ return [ // This optional option determines the channel name sent with the // message in the 'facility' field. Default is equal to app.env // configuration value - 'name' => 'my-custom-name', + 'name' => 'v5_app', // This optional option determines the system name sent with the // message in the 'source' field. When forgotten or set to null, From ba2f78dad054975e2d0a622ccdd2a9c010a9a2e6 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 17 Oct 2021 13:49:32 +1100 Subject: [PATCH 06/11] Refactor counter/patterns to allow User variables --- app/Console/Commands/DemoMode.php | 2 +- app/Console/Kernel.php | 5 + .../Requests/Credit/StoreCreditRequest.php | 7 +- app/Jobs/Quote/ApplyQuoteNumber.php | 4 +- app/Jobs/RecurringInvoice/SendRecurring.php | 5 +- .../Authorize/AuthorizeCreditCard.php | 2 +- app/PaymentDrivers/BaseDriver.php | 5 +- app/PaymentDrivers/Stripe/Charge.php | 309 +----------------- .../Migration/PaymentMigrationRepository.php | 2 +- app/Repositories/PaymentRepository.php | 2 +- app/Services/Credit/ApplyNumber.php | 2 +- app/Services/Invoice/ApplyRecurringNumber.php | 4 +- app/Services/Payment/ApplyNumber.php | 2 +- app/Services/Quote/ApplyNumber.php | 4 +- app/Services/Recurring/ApplyNumber.php | 2 +- app/Utils/Traits/GeneratesCounter.php | 107 ++++-- app/Utils/Traits/Payment/Refundable.php | 4 +- 17 files changed, 110 insertions(+), 358 deletions(-) diff --git a/app/Console/Commands/DemoMode.php b/app/Console/Commands/DemoMode.php index 0740a56b4f3a..c57d084b696b 100644 --- a/app/Console/Commands/DemoMode.php +++ b/app/Console/Commands/DemoMode.php @@ -486,7 +486,7 @@ class DemoMode extends Command if (rand(0, 1)) { $invoice->assigned_user_id = $assigned_user_id; } - $invoice->number = $this->getNextRecurringInvoiceNumber($client); + $invoice->number = $this->getNextRecurringInvoiceNumber($client, $invoice); $invoice->save(); } diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index bd082fb5459a..b82ae84f16a4 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -70,9 +70,14 @@ class Kernel extends ConsoleKernel $schedule->job(new SchedulerCheck)->daily()->withoutOverlapping(); + if(Ninja::isSelfHost()) + { + $schedule->call(function () { Account::whereNotNull('id')->update(['is_scheduler_running' => true]); })->everyFiveMinutes(); + + } /* Run hosted specific jobs */ if (Ninja::isHosted()) { diff --git a/app/Http/Requests/Credit/StoreCreditRequest.php b/app/Http/Requests/Credit/StoreCreditRequest.php index b0961ea76e79..ead68530b7a8 100644 --- a/app/Http/Requests/Credit/StoreCreditRequest.php +++ b/app/Http/Requests/Credit/StoreCreditRequest.php @@ -16,6 +16,7 @@ use App\Http\ValidationRules\Credit\UniqueCreditNumberRule; use App\Models\Credit; use App\Utils\Traits\CleanLineItems; use App\Utils\Traits\MakesHash; +use Illuminate\Validation\Rule; class StoreCreditRequest extends Request { @@ -53,7 +54,11 @@ class StoreCreditRequest extends Request $rules['client_id'] = 'required|exists:clients,id,company_id,'.auth()->user()->company()->id; - $rules['number'] = new UniqueCreditNumberRule($this->all()); + // $rules['number'] = new UniqueCreditNumberRule($this->all()); + $rules['number'] = ['nullable', Rule::unique('credits')->where('company_id', auth()->user()->company()->id)]; + + + $rules['line_items'] = 'array'; return $rules; diff --git a/app/Jobs/Quote/ApplyQuoteNumber.php b/app/Jobs/Quote/ApplyQuoteNumber.php index f605e9bb07b2..a046e5f62315 100644 --- a/app/Jobs/Quote/ApplyQuoteNumber.php +++ b/app/Jobs/Quote/ApplyQuoteNumber.php @@ -65,11 +65,11 @@ class ApplyQuoteNumber implements ShouldQueue switch ($this->settings->quote_number_applied) { case 'when_saved': - $this->quote->number = $this->getNextQuoteNumber($this->quote->client); + $this->quote->number = $this->getNextQuoteNumber($this->quote->client, $this->quote); break; case 'when_sent': if ($this->quote->status_id == Quote::STATUS_SENT) { - $this->quote->number = $this->getNextQuoteNumber($this->quote->client); + $this->quote->number = $this->getNextQuoteNumber($this->quote->client, $this->quote); } break; diff --git a/app/Jobs/RecurringInvoice/SendRecurring.php b/app/Jobs/RecurringInvoice/SendRecurring.php index 878db0fd8b2c..441c4f2b5769 100644 --- a/app/Jobs/RecurringInvoice/SendRecurring.php +++ b/app/Jobs/RecurringInvoice/SendRecurring.php @@ -126,7 +126,7 @@ class SendRecurring implements ShouldQueue if ($invitation->contact && !$invitation->contact->trashed() && strlen($invitation->contact->email) >=1 && $invoice->client->getSetting('auto_email_invoice')) { try{ - EmailEntity::dispatch($invitation, $invoice->company); + EmailEntity::dispatch($invitation, $invoice->company)->delay(now()->addSeconds(1)); } catch(\Exception $e) { nlog($e->getMessage()); @@ -152,9 +152,6 @@ class SendRecurring implements ShouldQueue } - //important catch all here - we should never leave contacts send_email to false incase they are permanently set to false in the future. - // $this->recurring_invoice->client->contacts()->update(['send_email' => true]); - } public function failed($exception = null) diff --git a/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php b/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php index a7f006e2529d..e357d8682163 100644 --- a/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php +++ b/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php @@ -214,7 +214,7 @@ class AuthorizeCreditCard PaymentFailureMailer::dispatch($this->authorize->client, $response->getTransId(), $this->authorize->client->company, $amount); - $payment_hash = PaymentHash::whereRaw('BINARY `hash`= ?', [$request->input('payment_hash')])->firstOrFail(); + $payment_hash = PaymentHash::where('hash', $request->input('payment_hash'))->firstOrFail(); $vars = [ 'invoices' => $payment_hash->invoices(), diff --git a/app/PaymentDrivers/BaseDriver.php b/app/PaymentDrivers/BaseDriver.php index 547638f0e1cb..a572030dcc03 100644 --- a/app/PaymentDrivers/BaseDriver.php +++ b/app/PaymentDrivers/BaseDriver.php @@ -373,11 +373,14 @@ class BaseDriver extends AbstractPaymentDriver } else $error = $e->getMessage(); + $amount = array_sum(array_column($this->payment_hash->invoices(), 'amount')) + $this->payment_hash->fee_total; + + PaymentFailureMailer::dispatch( $gateway->client, $error, $gateway->client->company, - $this->payment_hash + $amount ); SystemLogger::dispatch( diff --git a/app/PaymentDrivers/Stripe/Charge.php b/app/PaymentDrivers/Stripe/Charge.php index 57c1a1bcf7b2..5984a5c80d6d 100644 --- a/app/PaymentDrivers/Stripe/Charge.php +++ b/app/PaymentDrivers/Stripe/Charge.php @@ -81,13 +81,8 @@ class Charge 'description' => $description, ]; - nlog("Stripe tokenBilling payload"); - - nlog($data); - $response = $this->stripe->createPaymentIntent($data, $this->stripe->stripe_connect_auth); - // $response = $local_stripe->paymentIntents->create($data); - + SystemLogger::dispatch($response, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_SUCCESS, SystemLog::TYPE_STRIPE, $this->stripe->client, $this->stripe->client->company); } catch (\Exception $e) { @@ -136,7 +131,6 @@ class Charge } $payment_method_type = $response->charges->data[0]->payment_method_details->card->brand; - //nlog($payment_method_type); $data = [ 'gateway_type_id' => $cgt->gateway_type_id, @@ -183,303 +177,4 @@ class Charge 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] => -// ) +} \ No newline at end of file diff --git a/app/Repositories/Migration/PaymentMigrationRepository.php b/app/Repositories/Migration/PaymentMigrationRepository.php index 9225d4095bd5..32c253e14758 100644 --- a/app/Repositories/Migration/PaymentMigrationRepository.php +++ b/app/Repositories/Migration/PaymentMigrationRepository.php @@ -107,7 +107,7 @@ class PaymentMigrationRepository extends BaseRepository /*Ensure payment number generated*/ if (! $payment->number || strlen($payment->number) == 0) { - $payment->number = $payment->client->getNextPaymentNumber($payment->client); + $payment->number = $payment->client->getNextPaymentNumber($payment->client, $payment); } $invoice_totals = 0; diff --git a/app/Repositories/PaymentRepository.php b/app/Repositories/PaymentRepository.php index c2fc9501288a..3cfa82879142 100644 --- a/app/Repositories/PaymentRepository.php +++ b/app/Repositories/PaymentRepository.php @@ -111,7 +111,7 @@ class PaymentRepository extends BaseRepository { /*Ensure payment number generated*/ if (! $payment->number || strlen($payment->number) == 0) { - $payment->number = $payment->client->getNextPaymentNumber($payment->client); + $payment->number = $payment->client->getNextPaymentNumber($payment->client, $payment); } /*Set local total variables*/ diff --git a/app/Services/Credit/ApplyNumber.php b/app/Services/Credit/ApplyNumber.php index 021ff2009d8a..8bb190952118 100644 --- a/app/Services/Credit/ApplyNumber.php +++ b/app/Services/Credit/ApplyNumber.php @@ -37,7 +37,7 @@ class ApplyNumber extends AbstractService return $this->credit; } - $this->credit->number = $this->getNextCreditNumber($this->client); + $this->credit->number = $this->getNextCreditNumber($this->client, $this->credit); return $this->credit; } diff --git a/app/Services/Invoice/ApplyRecurringNumber.php b/app/Services/Invoice/ApplyRecurringNumber.php index d8a12d3b86c2..1c26e7f60ba1 100644 --- a/app/Services/Invoice/ApplyRecurringNumber.php +++ b/app/Services/Invoice/ApplyRecurringNumber.php @@ -39,11 +39,11 @@ class ApplyRecurringNumber extends AbstractService switch ($this->client->getSetting('counter_number_applied')) { case 'when_saved': - $this->invoice->number = $this->getNextRecurringInvoiceNumber($this->client); + $this->invoice->number = $this->getNextRecurringInvoiceNumber($this->client, $this->invoice); break; case 'when_sent': if ($this->invoice->status_id == Invoice::STATUS_SENT) { - $this->invoice->number = $this->getNextRecurringInvoiceNumber($this->client); + $this->invoice->number = $this->getNextRecurringInvoiceNumber($this->client, $this->invoice); } break; diff --git a/app/Services/Payment/ApplyNumber.php b/app/Services/Payment/ApplyNumber.php index 3d1e5e17e0d0..2f773dcb02fe 100644 --- a/app/Services/Payment/ApplyNumber.php +++ b/app/Services/Payment/ApplyNumber.php @@ -34,7 +34,7 @@ class ApplyNumber extends AbstractService return $this->payment; } - $this->payment->number = $this->getNextPaymentNumber($this->client); + $this->payment->number = $this->getNextPaymentNumber($this->client, $this->payment); return $this->payment; } diff --git a/app/Services/Quote/ApplyNumber.php b/app/Services/Quote/ApplyNumber.php index 401ee5b9155c..d7a8a0055a6c 100644 --- a/app/Services/Quote/ApplyNumber.php +++ b/app/Services/Quote/ApplyNumber.php @@ -33,11 +33,11 @@ class ApplyNumber switch ($this->client->getSetting('counter_number_applied')) { case 'when_saved': - $quote->number = $this->getNextQuoteNumber($this->client); + $quote->number = $this->getNextQuoteNumber($this->client, $quote); break; case 'when_sent': if ($quote->status_id == Quote::STATUS_SENT) { - $quote->number = $this->getNextQuoteNumber($this->client); + $quote->number = $this->getNextQuoteNumber($this->client, $quote); } break; diff --git a/app/Services/Recurring/ApplyNumber.php b/app/Services/Recurring/ApplyNumber.php index a1f37761ea03..1e95c6d47a22 100644 --- a/app/Services/Recurring/ApplyNumber.php +++ b/app/Services/Recurring/ApplyNumber.php @@ -36,7 +36,7 @@ class ApplyNumber extends AbstractService if ($this->recurring_entity->number != '') return $this->recurring_entity; - $this->recurring_entity->number = $this->getNextRecurringInvoiceNumber($this->client); + $this->recurring_entity->number = $this->getNextRecurringInvoiceNumber($this->client, $this->recurring_entity); return $this->recurring_entity; } diff --git a/app/Utils/Traits/GeneratesCounter.php b/app/Utils/Traits/GeneratesCounter.php index 591dd49a98c6..b55d9d719940 100644 --- a/app/Utils/Traits/GeneratesCounter.php +++ b/app/Utils/Traits/GeneratesCounter.php @@ -172,7 +172,9 @@ trait GeneratesCounter */ public function getNextInvoiceNumber(Client $client, ?Invoice $invoice, $is_recurring = false) :string { - return $this->getNextEntityNumber(Invoice::class, $client, $is_recurring); + $entity_number = $this->getNextEntityNumber(Invoice::class, $client, $is_recurring); + + return $this->replaceUserVars($invoice, $entity_number); } /** @@ -182,9 +184,12 @@ trait GeneratesCounter * * @return string The next credit number. */ - public function getNextCreditNumber(Client $client) :string + public function getNextCreditNumber(Client $client, ?Credit $credit) :string { - return $this->getNextEntityNumber(Credit::class, $client); + $entity_number = $this->getNextEntityNumber(Credit::class, $client); + + return $this->replaceUserVars($credit, $entity_number); + } /** @@ -194,19 +199,28 @@ trait GeneratesCounter * * @return string The next credit number. */ - public function getNextQuoteNumber(Client $client) + public function getNextQuoteNumber(Client $client, ?Quote $quote) { - return $this->getNextEntityNumber(Quote::class, $client); + $entity_number = $this->getNextEntityNumber(Quote::class, $client); + + return $this->replaceUserVars($quote, $entity_number); + } - public function getNextRecurringInvoiceNumber(Client $client) + public function getNextRecurringInvoiceNumber(Client $client, $recurring_invoice) { - return $this->getNextEntityNumber(RecurringInvoice::class, $client); + $entity_number = $this->getNextEntityNumber(RecurringInvoice::class, $client); + + return $this->replaceUserVars($recurring_invoice, $entity_number); + } - public function getNextRecurringQuoteNumber(Client $client) + public function getNextRecurringQuoteNumber(Client $client, ?RecurringQuote $recurring_quote) { - return $this->getNextEntityNumber(RecurringQuote::class, $client); + $entity_number = $this->getNextEntityNumber(RecurringQuote::class, $client); + + return $this->replaceUserVars($recurring_quote, $entity_number); + } /** @@ -216,9 +230,12 @@ trait GeneratesCounter * * @return string The next payment number. */ - public function getNextPaymentNumber(Client $client) :string + public function getNextPaymentNumber(Client $client, ?Payment $payment) :string { - return $this->getNextEntityNumber(Payment::class, $client); + $entity_number = $this->getNextEntityNumber(Payment::class, $client); + + return $this->replaceUserVars($payment, $entity_number); + } /** @@ -241,7 +258,10 @@ trait GeneratesCounter $this->incrementCounter($setting_entity, 'client_number_counter'); - return $client_number; + $entity_number = $client_number; + + return $this->replaceUserVars($client, $entity_number); + } @@ -262,7 +282,10 @@ trait GeneratesCounter $this->incrementCounter($vendor->company, 'vendor_number_counter'); - return $vendor_number; + $entity_number = $vendor_number; + + return $this->replaceUserVars($vendor, $entity_number); + } /** @@ -281,7 +304,10 @@ trait GeneratesCounter $this->incrementCounter($project->company, 'project_number_counter'); - return $project_number; + $entity_number = $project_number; + + return $this->replaceUserVars($project, $entity_number); + } @@ -302,7 +328,10 @@ trait GeneratesCounter $this->incrementCounter($task->company, 'task_number_counter'); - return $task_number; + $entity_number = $task_number; + + return $this->replaceUserVars($task, $entity_number); + } /** @@ -322,7 +351,10 @@ trait GeneratesCounter $this->incrementCounter($expense->company, 'expense_number_counter'); - return $expense_number; + $entity_number = $expense_number; + + return $this->replaceUserVars($expense, $entity_number); + } /** @@ -351,7 +383,10 @@ trait GeneratesCounter $this->incrementCounter($expense->company, 'recurring_expense_number_counter'); - return $expense_number; + $entity_number = $expense_number; + + return $this->replaceUserVars($expense, $entity_number); + } @@ -713,19 +748,31 @@ 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); } + + private function replaceUserVars($entity, $pattern) + { + + if(!$entity) + return $pattern; + + $search = []; + $replace = []; + + $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[] = '{$user_custom4}'; + $replace[] = $entity->user->custom_value4; + + return str_replace($search, $replace, $pattern); + + } } diff --git a/app/Utils/Traits/Payment/Refundable.php b/app/Utils/Traits/Payment/Refundable.php index b4dc1e74aa84..23157fde9f43 100644 --- a/app/Utils/Traits/Payment/Refundable.php +++ b/app/Utils/Traits/Payment/Refundable.php @@ -65,7 +65,7 @@ trait Refundable $line_items[] = $credit_line_item; $credit_note->save(); - $credit_note->number = $this->client->getNextCreditNumber($this->client); + $credit_note->number = $this->client->getNextCreditNumber($this->client, $credit_note); $credit_note->save(); $this->createActivity($data, $credit_note->id); @@ -165,7 +165,7 @@ trait Refundable $credit_note->line_items = $line_items; $credit_note->save(); - $credit_note->number = $this->client->getNextCreditNumber($this->client); + $credit_note->number = $this->client->getNextCreditNumber($this->client, $credit_note); $credit_note->save(); if ($data['gateway_refund'] !== false && $total_refund > 0) { From 895cc7d926f2578e2378540f883ee9f296c9e914 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 17 Oct 2021 13:59:43 +1100 Subject: [PATCH 07/11] Minor fixes for tests --- app/Jobs/Mail/PaymentFailureMailer.php | 2 ++ app/PaymentDrivers/Braintree/CreditCard.php | 12 +++++------- tests/MockAccountData.php | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/Jobs/Mail/PaymentFailureMailer.php b/app/Jobs/Mail/PaymentFailureMailer.php index 4b02e29742d8..a6051962e1d1 100644 --- a/app/Jobs/Mail/PaymentFailureMailer.php +++ b/app/Jobs/Mail/PaymentFailureMailer.php @@ -98,5 +98,7 @@ class PaymentFailureMailer implements ShouldQueue } }); + + //add client payment failures here. } } diff --git a/app/PaymentDrivers/Braintree/CreditCard.php b/app/PaymentDrivers/Braintree/CreditCard.php index d31b771bcf12..2455eb176e59 100644 --- a/app/PaymentDrivers/Braintree/CreditCard.php +++ b/app/PaymentDrivers/Braintree/CreditCard.php @@ -116,6 +116,11 @@ class CreditCard throw new PaymentFailed(ctrans('texts.generic_gateway_error'), $e->getCode()); } + PaymentFailureMailer::dispatch($this->braintree->client, + $e->getMessage(), + $this->braintree->client->company, + $this->braintree->payment_hash->data->amount_with_fee); + throw new PaymentFailed($e->getMessage(), $e->getCode()); } @@ -197,13 +202,6 @@ class CreditCard { PaymentFailureMailer::dispatch($this->braintree->client, $response->transaction->additionalProcessorResponse, $this->braintree->client->company, $this->braintree->payment_hash->data->amount_with_fee); - PaymentFailureMailer::dispatch( - $this->braintree->client, - $response, - $this->braintree->client->company, - $this->braintree->payment_hash->data->amount_with_fee, - ); - $message = [ 'server_response' => $response, 'data' => $this->braintree->payment_hash->data, diff --git a/tests/MockAccountData.php b/tests/MockAccountData.php index 5c2fd1066bc2..4582ab1f2dba 100644 --- a/tests/MockAccountData.php +++ b/tests/MockAccountData.php @@ -397,7 +397,7 @@ trait MockAccountData $this->quote = $this->quote_calc->getQuote(); $this->quote->status_id = Quote::STATUS_SENT; - $this->quote->number = $this->getNextQuoteNumber($this->client); + $this->quote->number = $this->getNextQuoteNumber($this->client, $this->quote); //$this->quote->service()->createInvitations()->markSent(); @@ -448,7 +448,7 @@ trait MockAccountData $this->client->service()->adjustCreditBalance($this->credit->balance)->save(); $this->credit->ledger()->updateCreditBalance($this->credit->balance)->save(); - $this->credit->number = $this->getNextCreditNumber($this->client); + $this->credit->number = $this->getNextCreditNumber($this->client, $this->credit); CreditInvitation::factory()->create([ From 68a8715c6d07c0f878dc31593d556225de1dc264 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 17 Oct 2021 14:21:13 +1100 Subject: [PATCH 08/11] Fixes for tests --- app/Factory/CloneQuoteToInvoiceFactory.php | 2 + .../StoreRecurringExpenseRequest.php | 4 ++ app/Repositories/BaseRepository.php | 2 +- app/Services/Invoice/ApplyPaymentAmount.php | 2 +- app/Services/Invoice/MarkPaid.php | 2 +- app/Utils/Traits/GeneratesCounter.php | 2 +- tests/Feature/PaymentTest.php | 2 +- tests/Unit/GeneratesCounterTest.php | 38 ++++++++++++------- 8 files changed, 36 insertions(+), 18 deletions(-) diff --git a/app/Factory/CloneQuoteToInvoiceFactory.php b/app/Factory/CloneQuoteToInvoiceFactory.php index b04b8104253d..4b0eb4f91e62 100644 --- a/app/Factory/CloneQuoteToInvoiceFactory.php +++ b/app/Factory/CloneQuoteToInvoiceFactory.php @@ -32,7 +32,9 @@ class CloneQuoteToInvoiceFactory // unset($quote_array['public_notes']); unset($quote_array['footer']); unset($quote_array['design_id']); + unset($quote_array['user']); + foreach ($quote_array as $key => $value) { $invoice->{$key} = $value; } diff --git a/app/Http/Requests/RecurringExpense/StoreRecurringExpenseRequest.php b/app/Http/Requests/RecurringExpense/StoreRecurringExpenseRequest.php index e34918245585..675827b6cada 100644 --- a/app/Http/Requests/RecurringExpense/StoreRecurringExpenseRequest.php +++ b/app/Http/Requests/RecurringExpense/StoreRecurringExpenseRequest.php @@ -63,6 +63,10 @@ class StoreRecurringExpenseRequest extends Request if(array_key_exists('color', $input) && is_null($input['color'])) $input['color'] = ''; + if(array_key_exists('foreign_amount', $input) && is_null($input['foreign_amount'])) + $input['foreign_amount'] = 0; + + $this->replace($input); } diff --git a/app/Repositories/BaseRepository.php b/app/Repositories/BaseRepository.php index ac8c453ed81d..d75e03f7e6f6 100644 --- a/app/Repositories/BaseRepository.php +++ b/app/Repositories/BaseRepository.php @@ -209,7 +209,7 @@ class BaseRepository if(!$model->id) $this->new_model = true; - + $model->saveQuietly(); /* Model now persisted, now lets do some child tasks */ diff --git a/app/Services/Invoice/ApplyPaymentAmount.php b/app/Services/Invoice/ApplyPaymentAmount.php index 4a71ae6c85d5..1250bb506c4f 100644 --- a/app/Services/Invoice/ApplyPaymentAmount.php +++ b/app/Services/Invoice/ApplyPaymentAmount.php @@ -58,7 +58,7 @@ class ApplyPaymentAmount extends AbstractService $payment->amount = $this->amount; $payment->applied = min($this->amount, $this->invoice->balance); - $payment->number = $this->getNextPaymentNumber($this->invoice->client); + $payment->number = $this->getNextPaymentNumber($this->invoice->client, $payment); $payment->status_id = Payment::STATUS_COMPLETED; $payment->client_id = $this->invoice->client_id; $payment->transaction_reference = ctrans('texts.manual_entry'); diff --git a/app/Services/Invoice/MarkPaid.php b/app/Services/Invoice/MarkPaid.php index 8f3db22f8921..a78ba98b2c80 100644 --- a/app/Services/Invoice/MarkPaid.php +++ b/app/Services/Invoice/MarkPaid.php @@ -52,7 +52,7 @@ class MarkPaid extends AbstractService $payment->amount = $this->invoice->balance; $payment->applied = $this->invoice->balance; - $payment->number = $this->getNextPaymentNumber($this->invoice->client); + $payment->number = $this->getNextPaymentNumber($this->invoice->client, $payment); $payment->status_id = Payment::STATUS_COMPLETED; $payment->client_id = $this->invoice->client_id; $payment->transaction_reference = ctrans('texts.manual_entry'); diff --git a/app/Utils/Traits/GeneratesCounter.php b/app/Utils/Traits/GeneratesCounter.php index b55d9d719940..1a7039c27a58 100644 --- a/app/Utils/Traits/GeneratesCounter.php +++ b/app/Utils/Traits/GeneratesCounter.php @@ -215,7 +215,7 @@ trait GeneratesCounter } - public function getNextRecurringQuoteNumber(Client $client, ?RecurringQuote $recurring_quote) + public function getNextRecurringQuoteNumber(Client $client, $recurring_quote) { $entity_number = $this->getNextEntityNumber(RecurringQuote::class, $client); diff --git a/tests/Feature/PaymentTest.php b/tests/Feature/PaymentTest.php index 8afad2a18e9f..1fe76bf7bfe8 100644 --- a/tests/Feature/PaymentTest.php +++ b/tests/Feature/PaymentTest.php @@ -698,7 +698,7 @@ class PaymentTest extends TestCase $payment->amount = 10; $payment->client_id = $client->id; $payment->date = now(); - $payment->number = $client->getNextPaymentNumber($client); + $payment->number = $client->getNextPaymentNumber($client, $payment); $payment->save(); $data = [ diff --git a/tests/Unit/GeneratesCounterTest.php b/tests/Unit/GeneratesCounterTest.php index ead294b9425b..34205857bdcf 100644 --- a/tests/Unit/GeneratesCounterTest.php +++ b/tests/Unit/GeneratesCounterTest.php @@ -12,6 +12,7 @@ namespace Tests\Unit; use App\DataMapper\ClientSettings; use App\Factory\ClientFactory; +use App\Factory\QuoteFactory; use App\Factory\VendorFactory; use App\Models\Client; use App\Models\Company; @@ -184,24 +185,22 @@ class GeneratesCounterTest extends TestCase public function testQuoteNumberValue() { + $quote = Quote::factory()->create([ + 'user_id' => $this->client->user_id, + 'company_id' => $this->client->company_id, + 'client_id' => $this->client->id + ]); - $quote_number = $this->getNextQuoteNumber($this->client->fresh()); + $quote_number = $this->getNextQuoteNumber($this->client->fresh(), $quote); $this->assertEquals($quote_number, 0002); - // nlog(Quote::all()->pluck('number')); - // $quote_number = $this->getNextQuoteNumber($this->client->fresh()); - - // nlog($this->company->settings->quote_number_counter); - - // nlog(Quote::all()->pluck('number')); - - // $this->assertEquals($quote_number, '0003'); } public function testInvoiceNumberPattern() { + $settings = $this->client->company->settings; $settings->invoice_number_counter = 1; $settings->invoice_number_pattern = '{$year}-{$counter}'; @@ -234,8 +233,15 @@ class GeneratesCounterTest extends TestCase $this->client->save(); $this->client->fresh(); - $quote_number = $this->getNextQuoteNumber($this->client); - $quote_number2 = $this->getNextQuoteNumber($this->client); + $quote = Quote::factory()->create([ + 'user_id' => $this->client->user_id, + 'company_id' => $this->client->company_id, + 'client_id' => $this->client->id + ]); + + + $quote_number = $this->getNextQuoteNumber($this->client, $quote); + $quote_number2 = $this->getNextQuoteNumber($this->client, $quote); $this->assertEquals($quote_number, date('Y').'-0001'); $this->assertEquals($quote_number2, date('Y').'-0002'); @@ -257,8 +263,14 @@ class GeneratesCounterTest extends TestCase $gs->settings = $settings; $gs->save(); - $quote_number = $this->getNextQuoteNumber($this->client); - $quote_number2 = $this->getNextQuoteNumber($this->client); + $quote = Quote::factory()->create([ + 'user_id' => $this->client->user_id, + 'company_id' => $this->client->company_id, + 'client_id' => $this->client->id + ]); + + $quote_number = $this->getNextQuoteNumber($this->client, $quote); + $quote_number2 = $this->getNextQuoteNumber($this->client, $quote); $this->assertEquals($quote_number, date('Y').'-1000'); $this->assertEquals($quote_number2, date('Y').'-1001'); From 6641320567742b04c8ddcb4844c4325fb8b8c9d5 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 17 Oct 2021 21:40:40 +1100 Subject: [PATCH 09/11] Refactor for payment failure mailers --- app/Jobs/Mail/PaymentFailedMailer.php | 109 ++++++ app/Jobs/Mail/PaymentFailureMailer.php | 2 +- app/Mail/Admin/PaymentFailureObject.php | 45 +-- app/Models/Client.php | 24 -- app/Models/CompanyGateway.php | 8 +- .../Authorize/AuthorizeCreditCard.php | 13 +- app/PaymentDrivers/BaseDriver.php | 24 +- app/PaymentDrivers/BasePaymentDriver.php | 315 ------------------ app/PaymentDrivers/Braintree/ACH.php | 12 +- app/PaymentDrivers/Braintree/CreditCard.php | 14 +- app/PaymentDrivers/Braintree/PayPal.php | 10 +- app/PaymentDrivers/BraintreePaymentDriver.php | 3 +- app/PaymentDrivers/CheckoutCom/CreditCard.php | 4 +- app/PaymentDrivers/CheckoutCom/Utilities.php | 11 +- .../CheckoutComPaymentDriver.php | 18 +- app/PaymentDrivers/Eway/CreditCard.php | 1 - app/PaymentDrivers/Eway/Token.php | 9 +- app/PaymentDrivers/GoCardless/ACH.php | 12 +- .../GoCardlessPaymentDriver.php | 8 +- app/PaymentDrivers/Mollie/Bancontact.php | 9 +- app/PaymentDrivers/Mollie/BankTransfer.php | 9 +- app/PaymentDrivers/Mollie/CreditCard.php | 12 +- app/PaymentDrivers/Mollie/IDEAL.php | 9 +- app/PaymentDrivers/Mollie/KBC.php | 9 +- app/PaymentDrivers/MolliePaymentDriver.php | 8 +- app/PaymentDrivers/PayFast/CreditCard.php | 12 +- app/PaymentDrivers/PayFast/Token.php | 96 ------ .../PayPalExpressPaymentDriver.php | 7 +- app/PaymentDrivers/PayTrace/CreditCard.php | 1 - app/PaymentDrivers/Razorpay/Hosted.php | 10 +- app/PaymentDrivers/Sample/CreditCard.php | 1 - app/PaymentDrivers/SquarePaymentDriver.php | 8 +- app/PaymentDrivers/Stripe/ACH.php | 9 +- app/PaymentDrivers/Stripe/Alipay.php | 10 +- app/PaymentDrivers/Stripe/ApplePay.php | 1 - app/PaymentDrivers/Stripe/Bancontact.php | 8 +- app/PaymentDrivers/Stripe/Connect/Verify.php | 1 - app/PaymentDrivers/Stripe/CreditCard.php | 10 +- app/PaymentDrivers/Stripe/EPS.php | 8 +- app/PaymentDrivers/Stripe/GIROPAY.php | 8 +- app/PaymentDrivers/Stripe/PRZELEWY24.php | 8 +- app/PaymentDrivers/Stripe/SEPA.php | 8 +- app/PaymentDrivers/Stripe/SOFORT.php | 8 +- app/PaymentDrivers/Stripe/iDeal.php | 8 +- app/PaymentDrivers/WePay/ACH.php | 19 ++ app/PaymentDrivers/WePay/CreditCard.php | 59 +++- app/PaymentDrivers/WePay/WePayCommon.php | 11 +- app/Services/Invoice/AutoBillInvoice.php | 2 +- 48 files changed, 293 insertions(+), 718 deletions(-) create mode 100644 app/Jobs/Mail/PaymentFailedMailer.php delete mode 100644 app/PaymentDrivers/BasePaymentDriver.php diff --git a/app/Jobs/Mail/PaymentFailedMailer.php b/app/Jobs/Mail/PaymentFailedMailer.php new file mode 100644 index 000000000000..5512c4b1a986 --- /dev/null +++ b/app/Jobs/Mail/PaymentFailedMailer.php @@ -0,0 +1,109 @@ +payment_hash = $payment_hash; + $this->client = $client; + $this->error = $error; + $this->company = $company; + + } + + /** + * Execute the job. + * + * @return void + */ + public function handle() + { + + //Set DB + MultiDB::setDb($this->company->db); + + $settings = $this->client->getMergedSettings(); + $amount = 0; + + if($this->payment_hash) + $amount = array_sum(array_column($this->payment_hash->invoices(), 'amount')) + $this->payment_hash->fee_total; + + //iterate through company_users + $this->company->company_users->each(function ($company_user) use($amount, $settings){ + + //determine if this user has the right permissions + $methods = $this->findCompanyUserNotificationType($company_user, ['payment_failure','all_notifications']); + + //if mail is a method type -fire mail!! + if (($key = array_search('mail', $methods)) !== false) { + unset($methods[$key]); + + $mail_obj = (new PaymentFailureObject($this->client, $this->error, $this->company, $amount, $this->payment_hash))->build(); + + $nmo = new NinjaMailerObject; + $nmo->mailable = new NinjaMailer($mail_obj); + $nmo->company = $this->company; + $nmo->to_user = $company_user->user; + $nmo->settings = $settings; + + NinjaMailerJob::dispatch($nmo); + + } + }); + + //add client payment failures here. + } + + + +} diff --git a/app/Jobs/Mail/PaymentFailureMailer.php b/app/Jobs/Mail/PaymentFailureMailer.php index a6051962e1d1..c54fb042377a 100644 --- a/app/Jobs/Mail/PaymentFailureMailer.php +++ b/app/Jobs/Mail/PaymentFailureMailer.php @@ -86,7 +86,7 @@ class PaymentFailureMailer implements ShouldQueue if (($key = array_search('mail', $methods)) !== false) { unset($methods[$key]); - $mail_obj = (new PaymentFailureObject($this->client, $this->error, $this->company, $this->amount))->build(); + $mail_obj = (new PaymentFailureObject($this->client, $this->error, $this->company, $this->amount, null))->build(); $nmo = new NinjaMailerObject; $nmo->mailable = new NinjaMailer($mail_obj); diff --git a/app/Mail/Admin/PaymentFailureObject.php b/app/Mail/Admin/PaymentFailureObject.php index 45068871bcf6..9094536ed1ff 100644 --- a/app/Mail/Admin/PaymentFailureObject.php +++ b/app/Mail/Admin/PaymentFailureObject.php @@ -11,25 +11,29 @@ namespace App\Mail\Admin; +use App\Models\Client; +use App\Models\Company; use App\Models\Invoice; +use App\Models\PaymentHash; use App\Utils\Ninja; use App\Utils\Number; use App\Utils\Traits\MakesHash; -use stdClass; use Illuminate\Support\Facades\App; +use stdClass; class PaymentFailureObject { use MakesHash; - public $client; + public Client $client; - public $error; + public string $error; - public $company; + public Company $company; public $amount; + public PaymentHash $payment_hash; // private $invoices; /** @@ -40,7 +44,7 @@ class PaymentFailureObject * @param $company * @param $amount */ - public function __construct($client, $error, $company, $amount) + public function __construct(Client $client, string $error, Company $company, $amount, ?PaymentHash $payment_hash) { $this->client = $client; @@ -52,6 +56,8 @@ class PaymentFailureObject $this->company = $company; + $this->payment_hash = $payment_hash; + } public function build() @@ -65,8 +71,6 @@ class PaymentFailureObject /* Set customized translations _NOW_ */ $t->replace(Ninja::transformTranslations($this->company->settings)); - // $this->invoices = Invoice::whereIn('id', $this->transformKeys(array_column($this->payment_hash->invoices(), 'invoice_id')))->get(); - $mail_obj = new stdClass; $mail_obj->amount = $this->getAmount(); $mail_obj->subject = $this->getSubject(); @@ -106,32 +110,33 @@ class PaymentFailureObject 'client' => $this->client->present()->name() ] ), - 'message' => $this->error, + 'content' => ctrans( + 'texts.notification_invoice_payment_failed', + [ + 'client' => $this->client->present()->name(), + 'invoice' => $this->getDescription(), + 'amount' => Number::formatMoney($this->amount, $this->client) + ]), 'signature' => $signature, 'logo' => $this->company->present()->logo(), 'settings' => $this->client->getMergedSettings(), 'whitelabel' => $this->company->account->isPaid() ? true : false, 'url' => config('ninja.app_url'), 'button' => ctrans('texts.login'), - 'additional_info' => $this->buildFailedInvoices() + 'additional_info' => $this->error ]; return $data; } - private function buildFailedInvoices() + + public function getDescription(bool $abbreviated = false) { + if(!$this->payment_hash) + return ""; - $text = ''; - - // foreach($this->invoices as $invoice) - // { - - // $text .= ctrans('texts.notification_invoice_payment_failed_subject', ['invoice' => $invoice->number]) . "\n"; - - // } - - return $text; + return \implode(', ', collect($this->payment_hash->invoices())->pluck('invoice_number')->toArray()); } + } diff --git a/app/Models/Client.php b/app/Models/Client.php index aaf56737c465..1a739f288604 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -519,31 +519,7 @@ class Client extends BaseModel implements HasLocalePreference } return null; - // $company_gateways = $this->getSetting('company_gateway_ids'); - // if (strlen($company_gateways) >= 1) { - // $transformed_ids = $this->transformKeys(explode(',', $company_gateways)); - // $gateways = $this->company - // ->company_gateways - // ->whereIn('id', $transformed_ids) - // ->sortby(function ($model) use ($transformed_ids) { - // return array_search($model->id, $transformed_ids); - // }); - // } else { - // $gateways = $this->company->company_gateways; - // } - - // foreach ($gateways as $gateway) { - // if ($this->currency()->code == 'USD' && in_array(GatewayType::BANK_TRANSFER, $gateway->driver($this)->gatewayTypeEnabled(GatewayType::BANK_TRANSFER))) { - // return $gateway; - // } - - // if ($this->currency()->code == 'EUR' && in_array(GatewayType::SEPA, $gateway->driver($this)->gatewayTypeEnabled(GatewayType::SEPA))) { - // return $gateway; - // } - // } - - // return null; } public function getBankTransferMethodType() diff --git a/app/Models/CompanyGateway.php b/app/Models/CompanyGateway.php index 5be23f8a6a6d..6c51acedf4bd 100644 --- a/app/Models/CompanyGateway.php +++ b/app/Models/CompanyGateway.php @@ -12,7 +12,6 @@ namespace App\Models; use App\Models\GatewayType; -use App\PaymentDrivers\BasePaymentDriver; use App\Utils\Number; use Illuminate\Database\Eloquent\SoftDeletes; use stdClass; @@ -134,11 +133,10 @@ class CompanyGateway extends BaseModel $class = 'App\\PaymentDrivers\\'.$this->gateway->provider.'PaymentDriver'; $class = str_replace('_', '', $class); - if (class_exists($class)) { + if (class_exists($class)) return $class; - } else { - return BasePaymentDriver::class; - } + + throw new \Exception("Payment Driver does not exist"); } /** diff --git a/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php b/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php index e357d8682163..3c52fd146a0a 100644 --- a/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php +++ b/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php @@ -13,7 +13,6 @@ namespace App\PaymentDrivers\Authorize; use App\Exceptions\PaymentFailed; -use App\Jobs\Mail\PaymentFailureMailer; use App\Jobs\Util\SystemLogger; use App\Models\ClientGatewayToken; use App\Models\GatewayType; @@ -134,7 +133,15 @@ class AuthorizeCreditCard 'data' => $this->formatGatewayResponse($data, $vars), ]; - PaymentFailureMailer::dispatch($this->authorize->client, $response->getTransId(), $this->authorize->client->company, $amount); + $code = "Error"; + $description = "There was an error processing the payment"; + + if ($response->getErrors() != null) { + $code = $response->getErrors()[0]->getErrorCode(); + $description = $response->getErrors()[0]->getErrorText(); + } + + $this->authorize->sendFailureMail($description); SystemLogger::dispatch($logger_message, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_AUTHORIZE, $this->authorize->client, $this->authorize->client->company); @@ -212,7 +219,7 @@ class AuthorizeCreditCard $description = $response->getErrors()[0]->getErrorText(); } - PaymentFailureMailer::dispatch($this->authorize->client, $response->getTransId(), $this->authorize->client->company, $amount); + $this->authorize->sendFailureMail($description); $payment_hash = PaymentHash::where('hash', $request->input('payment_hash'))->firstOrFail(); diff --git a/app/PaymentDrivers/BaseDriver.php b/app/PaymentDrivers/BaseDriver.php index a572030dcc03..535546e3fb5c 100644 --- a/app/PaymentDrivers/BaseDriver.php +++ b/app/PaymentDrivers/BaseDriver.php @@ -19,7 +19,7 @@ use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest; use App\Jobs\Mail\NinjaMailer; use App\Jobs\Mail\NinjaMailerJob; use App\Jobs\Mail\NinjaMailerObject; -use App\Jobs\Mail\PaymentFailureMailer; +use App\Jobs\Mail\PaymentFailedMailer; use App\Jobs\Util\SystemLogger; use App\Mail\Admin\ClientPaymentFailureObject; use App\Models\Client; @@ -375,13 +375,7 @@ class BaseDriver extends AbstractPaymentDriver $amount = array_sum(array_column($this->payment_hash->invoices(), 'amount')) + $this->payment_hash->fee_total; - - PaymentFailureMailer::dispatch( - $gateway->client, - $error, - $gateway->client->company, - $amount - ); + $this->sendFailureMail($error); SystemLogger::dispatch( $gateway->payment_hash, @@ -395,6 +389,18 @@ class BaseDriver extends AbstractPaymentDriver throw new PaymentFailed($error, $e->getCode()); } + public function sendFailureMail(string $error) + { + + PaymentFailedMailer::dispatch( + $this->payment_hash, + $this->client->company, + $this->client, + $error + ); + + } + public function clientPaymentFailureMailer($error) { @@ -451,7 +457,7 @@ class BaseDriver extends AbstractPaymentDriver $this->unWindGatewayFees($this->payment_hash); - PaymentFailureMailer::dispatch($this->client, $error, $this->client->company, $this->payment_hash->data->amount_with_fee); + $this->sendFailureMail($error); $nmo = new NinjaMailerObject; $nmo->mailable = new NinjaMailer( (new ClientPaymentFailureObject($this->client, $error, $this->client->company, $this->payment_hash))->build() ); diff --git a/app/PaymentDrivers/BasePaymentDriver.php b/app/PaymentDrivers/BasePaymentDriver.php deleted file mode 100644 index 2c21a228eff9..000000000000 --- a/app/PaymentDrivers/BasePaymentDriver.php +++ /dev/null @@ -1,315 +0,0 @@ - $invoice->getRequestedAmount(), - 'currency' => $invoice->getCurrencyCode(), - 'returnUrl' => $completeUrl, - 'cancelUrl' => $this->invitation->getLink(), - 'description' => trans('texts.' . $invoice->getEntityType()) . " {$invoice->number}", - 'transactionId' => $invoice->number, - 'transactionType' => 'Purchase', - 'clientIp' => Request::getClientIp(), - ]; - */ -class BasePaymentDriver -{ - use SystemLogTrait; - use MakesHash; - - /* The company gateway instance*/ - public $company_gateway; - - /* The Omnipay payment driver instance*/ - protected $gateway; - - /* The Invitation */ - protected $invitation; - - /* Gateway capabilities */ - protected $refundable = false; - - /* Token billing */ - public $token_billing = false; - - /* Authorise payment methods */ - protected $can_authorise_credit_card = false; - - public function __construct(CompanyGateway $company_gateway, Client $client, $invitation = false) - { - $this->company_gateway = $company_gateway; - - $this->invitation = $invitation; - - $this->client = $client; - } - - /** - * Returns the Omnipay driver. - * @return stdClass Omnipay initialized object - */ - protected function gateway() - { - $this->gateway = Omnipay::create($this->company_gateway->gateway->provider); - $this->gateway->initialize((array) $this->company_gateway->getConfig()); - - return $this; - } - - /** - * Return the configuration fields for the - * Gatway. - * @return array The configuration fields - */ - public function getFields() - { - return $this->gateway->getDefaultParameters(); - } - - /** - * Returns the default gateway type. - */ - public function gatewayTypes() - { - return [ - GatewayType::CREDIT_CARD, - ]; - } - - public function getCompanyGatewayId(): int - { - return $this->company_gateway->id; - } - - /** - * Returns whether refunds are possible with the gateway. - * @return bool TRUE|FALSE - */ - public function getRefundable(): bool - { - return $this->refundable; - } - - /** - * Returns whether token billing is possible with the gateway. - * @return bool TRUE|FALSE - */ - public function getTokenBilling(): bool - { - return $this->token_billing; - } - - /** - * Returns whether gateway can - * authorise and credit card. - * @return bool [type] [description] - */ - public function canAuthoriseCreditCard(): bool - { - return $this->can_authorise_credit_card; - } - - /** - * Refunds a given payment. - * @param $payment - * @param int $amount - * @return false - */ - public function refundPayment($payment, $amount = 0) - { - if ($amount) { - $amount = min($amount, $payment->getCompletedAmount()); - } else { - $amount = $payment->getCompletedAmount(); - } - - if ($payment->is_deleted || ! $amount) { - return false; - } - - if ($payment->type_id == Payment::TYPE_CREDIT_CARD) { - return $payment->recordRefund($amount); - } - - $details = $this->refundDetails($payment, $amount); - $response = $this->gateway()->refund($details)->send(); - - if ($response->isSuccessful()) { - return $payment->recordRefund($amount); - } elseif ($this->attemptVoidPayment($response, $payment, $amount)) { - $details = ['transactionReference' => $payment->transaction_reference]; - $response = $this->gateway->void($details)->send(); - if ($response->isSuccessful()) { - return $payment->markVoided(); - } - } - - return false; - } - - protected function attemptVoidPayment($response, $payment, $amount) - { - // Partial refund not allowed for unsettled transactions - return $amount == $payment->amount; - } - - public function authorizeCreditCardView(array $data) - { - } - - public function authorizeCreditCardResponse($request) - { - } - - public function processPaymentView(array $data) - { - } - - public function processPaymentResponse($request) - { - } - - /** - * Return the contact if possible. - * - * @return ClientContact The ClientContact object - */ - public function getContact() - { - if ($this->invitation) { - return ClientContact::find($this->invitation->client_contact_id); - } elseif (auth()->guard('contact')->user()) { - return auth()->user(); - } else { - return false; - } - } - - /************************************* Omnipay ****************************************** - * authorize($options) - authorize an amount on the customer's card - * completeAuthorize($options) - handle return from off-site gateways after authorization - * capture($options) - capture an amount you have previously authorized - * purchase($options) - authorize and immediately capture an amount on the customer's card - * completePurchase($options) - handle return from off-site gateways after purchase - * refund($options) - refund an already processed transaction - * void($options) - generally can only be called up to 24 hours after submitting a transaction - * acceptNotification() - convert an incoming request from an off-site gateway to a generic notification object for further processing - * @param $input - * @return array - */ - - protected function paymentDetails($input): array - { - $data = [ - 'currency' => $this->client->getCurrencyCode(), - 'transactionType' => 'Purchase', - 'clientIp' => request()->getClientIp(), - ]; - - return $data; - } - - public function purchase($data, $items) - { - $this->gateway(); - - $response = $this->gateway - ->purchase($data) - ->setItems($items) - ->send(); - - return $response; - } - - public function completePurchase($data) - { - $this->gateway(); - - return $this->gateway - ->completePurchase($data) - ->send(); - } - - public function createPayment($data, $status = Payment::STATUS_COMPLETED): 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 = $status; - $payment->currency_id = $this->client->getSetting('currency_id'); - $payment->date = Carbon::now(); - - return $payment->service()->applyNumber()->save(); - } - - public function attachInvoices(Payment $payment, PaymentHash $payment_hash): Payment - { - $paid_invoices = $payment_hash->invoices(); - $invoices = Invoice::whereIn('id', $this->transformKeys(array_column($paid_invoices, 'invoice_id')))->withTrashed()->get(); - $payment->invoices()->sync($invoices); - $payment->saveQuietly(); - - event('eloquent.created: App\Models\Payment', $payment); - - return $payment; - } - - /** - * When a successful payment is made, we need to append the gateway fee - * to an invoice. - * - * @param PaymentResponseRequest $request The incoming payment request - * @return void Success/Failure - */ - public function confirmGatewayFee(PaymentResponseRequest $request) :void - { - /*Payment meta data*/ - $payment_hash = $request->getPaymentHash(); - - /*Payment invoices*/ - $payment_invoices = $payment_hash->invoices(); - - // /*Fee charged at gateway*/ - $fee_total = $payment_hash->fee_total; - - // Sum of invoice amounts - // $invoice_totals = array_sum(array_column($payment_invoices,'amount')); - - /*Hydrate invoices*/ - $invoices = Invoice::whereIn('id', $this->transformKeys(array_column($payment_invoices, 'invoice_id')))->withTrashed()->get(); - - $invoices->each(function ($invoice) use ($fee_total) { - if (collect($invoice->line_items)->contains('type_id', '3')) { - $invoice->service()->toggleFeesPaid()->save(); - $invoice->client->service()->updateBalance($fee_total)->save(); - $invoice->ledger()->updateInvoiceBalance($fee_total, "Gateway fee adjustment for Invoice {$invoice->number}"); - } - }); - } -} diff --git a/app/PaymentDrivers/Braintree/ACH.php b/app/PaymentDrivers/Braintree/ACH.php index 1a91473d5b07..25cd07e2cc4d 100644 --- a/app/PaymentDrivers/Braintree/ACH.php +++ b/app/PaymentDrivers/Braintree/ACH.php @@ -14,7 +14,6 @@ namespace App\PaymentDrivers\Braintree; use App\Exceptions\PaymentFailed; use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest; use App\Http\Requests\Request; -use App\Jobs\Mail\PaymentFailureMailer; use App\Jobs\Util\SystemLogger; use App\Models\ClientGatewayToken; use App\Models\GatewayType; @@ -158,15 +157,8 @@ class ACH implements MethodInterface private function processUnsuccessfulPayment($response) { - PaymentFailureMailer::dispatch($this->braintree->client, $response->transaction->additionalProcessorResponse, $this->braintree->client->company, $this->braintree->payment_hash->data->amount_with_fee); - - PaymentFailureMailer::dispatch( - $this->braintree->client, - $response, - $this->braintree->client->company, - $this->braintree->payment_hash->data->amount_with_fee, - ); - + $this->braintree->sendFailureMail($response->transaction->additionalProcessorResponse); + $message = [ 'server_response' => $response, 'data' => $this->braintree->payment_hash->data, diff --git a/app/PaymentDrivers/Braintree/CreditCard.php b/app/PaymentDrivers/Braintree/CreditCard.php index 2455eb176e59..a00dd398a7f9 100644 --- a/app/PaymentDrivers/Braintree/CreditCard.php +++ b/app/PaymentDrivers/Braintree/CreditCard.php @@ -16,7 +16,6 @@ namespace App\PaymentDrivers\Braintree; use App\Exceptions\PaymentFailed; use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest; use App\Http\Requests\Request; -use App\Jobs\Mail\PaymentFailureMailer; use App\Jobs\Util\SystemLogger; use App\Models\GatewayType; use App\Models\Payment; @@ -113,13 +112,13 @@ class CreditCard $result = $this->braintree->gateway->transaction()->sale($data); } catch(\Exception $e) { if ($e instanceof \Braintree\Exception\Authorization) { + + $this->braintree->sendFailureMail(ctrans('texts.generic_gateway_error')); + throw new PaymentFailed(ctrans('texts.generic_gateway_error'), $e->getCode()); } - PaymentFailureMailer::dispatch($this->braintree->client, - $e->getMessage(), - $this->braintree->client->company, - $this->braintree->payment_hash->data->amount_with_fee); + $this->braintree->sendFailureMail($e->getMessage()); throw new PaymentFailed($e->getMessage(), $e->getCode()); } @@ -167,6 +166,8 @@ class CreditCard return $response->paymentMethod->token; } + $this->braintree->sendFailureMail($response->message); + throw new PaymentFailed($response->message); } @@ -200,7 +201,8 @@ class CreditCard */ private function processUnsuccessfulPayment($response) { - PaymentFailureMailer::dispatch($this->braintree->client, $response->transaction->additionalProcessorResponse, $this->braintree->client->company, $this->braintree->payment_hash->data->amount_with_fee); + + $this->braintree->sendFailureMail($response->transaction->additionalProcessorResponse); $message = [ 'server_response' => $response, diff --git a/app/PaymentDrivers/Braintree/PayPal.php b/app/PaymentDrivers/Braintree/PayPal.php index ebba89ea5be8..94aa0fffd063 100644 --- a/app/PaymentDrivers/Braintree/PayPal.php +++ b/app/PaymentDrivers/Braintree/PayPal.php @@ -6,7 +6,6 @@ namespace App\PaymentDrivers\Braintree; use App\Exceptions\PaymentFailed; use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest; -use App\Jobs\Mail\PaymentFailureMailer; use App\Jobs\Util\SystemLogger; use App\Models\GatewayType; use App\Models\Payment; @@ -149,14 +148,7 @@ class PayPal private function processUnsuccessfulPayment($response) { - PaymentFailureMailer::dispatch($this->braintree->client, $response->message, $this->braintree->client->company, $this->braintree->payment_hash->data->amount_with_fee); - - PaymentFailureMailer::dispatch( - $this->braintree->client, - $response, - $this->braintree->client->company, - $this->braintree->payment_hash->data->amount_with_fee, - ); + $this->braintree->sendFailureMail($response->message); $message = [ 'server_response' => $response, diff --git a/app/PaymentDrivers/BraintreePaymentDriver.php b/app/PaymentDrivers/BraintreePaymentDriver.php index 2c5cc40a507b..d360bdf1f819 100644 --- a/app/PaymentDrivers/BraintreePaymentDriver.php +++ b/app/PaymentDrivers/BraintreePaymentDriver.php @@ -14,7 +14,6 @@ namespace App\PaymentDrivers; use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest; -use App\Jobs\Mail\PaymentFailureMailer; use App\Jobs\Util\SystemLogger; use App\Models\ClientGatewayToken; use App\Models\GatewayType; @@ -240,7 +239,7 @@ class BraintreePaymentDriver extends BaseDriver if (!$result->success) { $this->unWindGatewayFees($payment_hash); - PaymentFailureMailer::dispatch($this->client, $result->transaction->additionalProcessorResponse, $this->client->company, $this->payment_hash->data->amount_with_fee); + $this->sendFailureMail($result->transaction->additionalProcessorResponse); $message = [ 'server_response' => $result, diff --git a/app/PaymentDrivers/CheckoutCom/CreditCard.php b/app/PaymentDrivers/CheckoutCom/CreditCard.php index 4859e2f1cb9f..317153749afa 100644 --- a/app/PaymentDrivers/CheckoutCom/CreditCard.php +++ b/app/PaymentDrivers/CheckoutCom/CreditCard.php @@ -15,7 +15,6 @@ namespace App\PaymentDrivers\CheckoutCom; use App\Exceptions\PaymentFailed; use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest; use App\Http\Requests\Request; -use App\Jobs\Mail\PaymentFailureMailer; use App\Models\ClientGatewayToken; use App\Models\GatewayType; use App\PaymentDrivers\CheckoutComPaymentDriver; @@ -210,8 +209,9 @@ class CreditCard implements MethodInterface if ($response->status == 'Declined') { $this->checkout->unWindGatewayFees($this->checkout->payment_hash); - PaymentFailureMailer::dispatch($this->checkout->client, $response->response_summary, $this->checkout->client->company, $this->checkout->payment_hash->data->value); + $this->checkout->sendFailureMail($response->response_summary); + //@todo - this will double up the checkout . com failed mails $this->checkout->clientPaymentFailureMailer($response->status); return $this->processUnsuccessfulPayment($response); diff --git a/app/PaymentDrivers/CheckoutCom/Utilities.php b/app/PaymentDrivers/CheckoutCom/Utilities.php index a3e3fb4bba55..9790a5ca8d2d 100644 --- a/app/PaymentDrivers/CheckoutCom/Utilities.php +++ b/app/PaymentDrivers/CheckoutCom/Utilities.php @@ -13,7 +13,6 @@ namespace App\PaymentDrivers\CheckoutCom; use App\Exceptions\PaymentFailed; -use App\Jobs\Mail\PaymentFailureMailer; use App\Jobs\Util\SystemLogger; use App\Models\GatewayType; use App\Models\PaymentType; @@ -85,12 +84,8 @@ trait Utilities public function processUnsuccessfulPayment(Payment $_payment, $throw_exception = true) { - PaymentFailureMailer::dispatch( - $this->getParent()->client, - $_payment, - $this->getParent()->client->company, - $this->getParent()->payment_hash->data->value - ); + + $this->getParent()->sendFailureMail($_payment->status . " " . $_payment->response_summary); $message = [ 'server_response' => $_payment, @@ -107,7 +102,7 @@ trait Utilities ); if ($throw_exception) { - throw new PaymentFailed($_payment->status, $_payment->http_code); + throw new PaymentFailed($_payment->status . " " . $_payment->response_summary, $_payment->http_code); } } diff --git a/app/PaymentDrivers/CheckoutComPaymentDriver.php b/app/PaymentDrivers/CheckoutComPaymentDriver.php index 7b4f2aea4a6f..1cb3443c014f 100644 --- a/app/PaymentDrivers/CheckoutComPaymentDriver.php +++ b/app/PaymentDrivers/CheckoutComPaymentDriver.php @@ -15,7 +15,6 @@ namespace App\PaymentDrivers; use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest; use App\Http\Requests\Gateways\Checkout3ds\Checkout3dsRequest; use App\Http\Requests\Payments\PaymentWebhookRequest; -use App\Jobs\Mail\PaymentFailureMailer; use App\Jobs\Util\SystemLogger; use App\Models\ClientGatewayToken; use App\Models\Company; @@ -284,11 +283,7 @@ class CheckoutComPaymentDriver extends BaseDriver if ($response->status == 'Declined') { $this->unWindGatewayFees($payment_hash); - PaymentFailureMailer::dispatch( - $this->client, $response->response_summary, - $this->client->company, - $amount - ); + $this->sendFailureMail($response->status . " " . $response->response_summary); $message = [ 'server_response' => $response, @@ -319,7 +314,16 @@ class CheckoutComPaymentDriver extends BaseDriver 'message' => $message, ]; - SystemLogger::dispatch($data, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_CHECKOUT, $this->client, $this->client->company); + $this->sendFailureMail($message); + + SystemLogger::dispatch( + $data, + SystemLog::CATEGORY_GATEWAY_RESPONSE, + SystemLog::EVENT_GATEWAY_FAILURE, + SystemLog::TYPE_CHECKOUT, + $this->client, + $this->client->company + ); } } diff --git a/app/PaymentDrivers/Eway/CreditCard.php b/app/PaymentDrivers/Eway/CreditCard.php index eec96e743f42..3ef197c948c0 100644 --- a/app/PaymentDrivers/Eway/CreditCard.php +++ b/app/PaymentDrivers/Eway/CreditCard.php @@ -13,7 +13,6 @@ namespace App\PaymentDrivers\Eway; use App\Exceptions\PaymentFailed; -use App\Jobs\Mail\PaymentFailureMailer; use App\Jobs\Util\SystemLogger; use App\Models\ClientGatewayToken; use App\Models\GatewayType; diff --git a/app/PaymentDrivers/Eway/Token.php b/app/PaymentDrivers/Eway/Token.php index 9f9ac8ac2ae6..7b20629ca44f 100644 --- a/app/PaymentDrivers/Eway/Token.php +++ b/app/PaymentDrivers/Eway/Token.php @@ -13,7 +13,6 @@ namespace App\PaymentDrivers\Eway; use App\Exceptions\PaymentFailed; -use App\Jobs\Mail\PaymentFailureMailer; use App\Jobs\Util\SystemLogger; use App\Models\ClientGatewayToken; use App\Models\GatewayType; @@ -73,8 +72,8 @@ class Token $amount = array_sum(array_column($this->eway_driver->payment_hash->invoices(), 'amount')) + $this->eway_driver->payment_hash->fee_total; $data = [ - 'gateway_type_id' => $cgt->gateway_type_id, - 'payment_type' => GatewayType::CREDIT_CARD_OTHER, + 'gateway_type_id' => GatewayType::CREDIT_CARD, + 'payment_type' => PaymentType::CREDIT_CARD_OTHER, 'transaction_reference' => $response->Customer->Reference, 'amount' => $amount, ]; @@ -83,8 +82,8 @@ class Token $payment->meta = $cgt->meta; $payment->save(); - $payment_hash->payment_id = $payment->id; - $payment_hash->save(); + $this->eway_driver->payment_hash->payment_id = $payment->id; + $this->eway_driver->payment_hash->save(); return $payment; diff --git a/app/PaymentDrivers/GoCardless/ACH.php b/app/PaymentDrivers/GoCardless/ACH.php index 2dd94a453b25..2efd6f39a88b 100644 --- a/app/PaymentDrivers/GoCardless/ACH.php +++ b/app/PaymentDrivers/GoCardless/ACH.php @@ -15,7 +15,6 @@ namespace App\PaymentDrivers\GoCardless; use App\Exceptions\PaymentFailed; use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest; use App\Http\Requests\Request; -use App\Jobs\Mail\PaymentFailureMailer; use App\Jobs\Util\SystemLogger; use App\Models\ClientGatewayToken; use App\Models\GatewayType; @@ -228,15 +227,8 @@ class ACH implements MethodInterface */ public function processUnsuccessfulPayment(\GoCardlessPro\Resources\Payment $payment) { - PaymentFailureMailer::dispatch($this->go_cardless->client, $payment->status, $this->go_cardless->client->company, $this->go_cardless->payment_hash->data->amount_with_fee); - - PaymentFailureMailer::dispatch( - $this->go_cardless->client, - $payment, - $this->go_cardless->client->company, - $payment->amount - ); - + $this->go_cardless->sendFailureMail($payment->status); + $message = [ 'server_response' => $payment, 'data' => $this->go_cardless->payment_hash->data, diff --git a/app/PaymentDrivers/GoCardlessPaymentDriver.php b/app/PaymentDrivers/GoCardlessPaymentDriver.php index 770a272c7d37..190321b8832e 100644 --- a/app/PaymentDrivers/GoCardlessPaymentDriver.php +++ b/app/PaymentDrivers/GoCardlessPaymentDriver.php @@ -12,7 +12,6 @@ namespace App\PaymentDrivers; use App\Http\Requests\Payments\PaymentWebhookRequest; -use App\Jobs\Mail\PaymentFailureMailer; use App\Jobs\Util\SystemLogger; use App\Models\ClientGatewayToken; use App\Models\GatewayType; @@ -148,12 +147,7 @@ class GoCardlessPaymentDriver extends BaseDriver return $payment; } - PaymentFailureMailer::dispatch( - $this->client, - $payment->status, - $this->client->company, - $amount - ); + $this->sendFailureMail($payment->status); $message = [ 'server_response' => $payment, diff --git a/app/PaymentDrivers/Mollie/Bancontact.php b/app/PaymentDrivers/Mollie/Bancontact.php index ee2b3e2bd2da..d8a0eab78807 100644 --- a/app/PaymentDrivers/Mollie/Bancontact.php +++ b/app/PaymentDrivers/Mollie/Bancontact.php @@ -15,7 +15,6 @@ namespace App\PaymentDrivers\Mollie; use App\Exceptions\PaymentFailed; use App\Http\Requests\Request; use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest; -use App\Jobs\Mail\PaymentFailureMailer; use App\Jobs\Util\SystemLogger; use App\Models\GatewayType; use App\Models\Payment; @@ -109,12 +108,8 @@ class Bancontact implements MethodInterface */ public function processUnsuccessfulPayment(\Exception $exception): void { - PaymentFailureMailer::dispatch( - $this->mollie->client, - $exception->getMessage(), - $this->mollie->client->company, - $this->mollie->payment_hash->data->amount_with_fee - ); + + $this->mollie->sendFailureMail($exception->getMessage()); SystemLogger::dispatch( $exception->getMessage(), diff --git a/app/PaymentDrivers/Mollie/BankTransfer.php b/app/PaymentDrivers/Mollie/BankTransfer.php index 1cfb0651d13f..3002d201ca3e 100644 --- a/app/PaymentDrivers/Mollie/BankTransfer.php +++ b/app/PaymentDrivers/Mollie/BankTransfer.php @@ -15,7 +15,6 @@ namespace App\PaymentDrivers\Mollie; use App\Exceptions\PaymentFailed; use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest; use App\Http\Requests\Request; -use App\Jobs\Mail\PaymentFailureMailer; use App\Jobs\Util\SystemLogger; use App\Models\GatewayType; use App\Models\Payment; @@ -112,12 +111,8 @@ class BankTransfer implements MethodInterface */ public function processUnsuccessfulPayment(\Exception $e): void { - PaymentFailureMailer::dispatch( - $this->mollie->client, - $e->getMessage(), - $this->mollie->client->company, - $this->mollie->payment_hash->data->amount_with_fee - ); + + $this->mollie->sendFailureMail($e->getMessage()); SystemLogger::dispatch( $e->getMessage(), diff --git a/app/PaymentDrivers/Mollie/CreditCard.php b/app/PaymentDrivers/Mollie/CreditCard.php index f8f5f57f9cdb..7efbd17c915c 100644 --- a/app/PaymentDrivers/Mollie/CreditCard.php +++ b/app/PaymentDrivers/Mollie/CreditCard.php @@ -4,7 +4,6 @@ namespace App\PaymentDrivers\Mollie; use App\Exceptions\PaymentFailed; use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest; -use App\Jobs\Mail\PaymentFailureMailer; use App\Jobs\Util\SystemLogger; use App\Models\ClientGatewayToken; use App\Models\GatewayType; @@ -88,6 +87,8 @@ class CreditCard return redirect($payment->getCheckoutUrl()); } } catch (\Exception $e) { + + return $this->processUnsuccessfulPayment($e); } } @@ -142,6 +143,7 @@ class CreditCard return redirect($payment->getCheckoutUrl()); } } catch (\Exception $e) { + $this->processUnsuccessfulPayment($e); throw new PaymentFailed($e->getMessage(), $e->getCode()); @@ -196,12 +198,8 @@ class CreditCard public function processUnsuccessfulPayment(\Exception $e) { - PaymentFailureMailer::dispatch( - $this->mollie->client, - $e->getMessage(), - $this->mollie->client->company, - $this->mollie->payment_hash->data->amount_with_fee - ); + + $this->mollie->sendFailureMail($e->getMessage()); SystemLogger::dispatch( $e->getMessage(), diff --git a/app/PaymentDrivers/Mollie/IDEAL.php b/app/PaymentDrivers/Mollie/IDEAL.php index a7c95f310211..20ac61b3cebe 100644 --- a/app/PaymentDrivers/Mollie/IDEAL.php +++ b/app/PaymentDrivers/Mollie/IDEAL.php @@ -15,7 +15,6 @@ namespace App\PaymentDrivers\Mollie; use App\Exceptions\PaymentFailed; use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest; use App\Http\Requests\Request; -use App\Jobs\Mail\PaymentFailureMailer; use App\Jobs\Util\SystemLogger; use App\Models\GatewayType; use App\Models\Payment; @@ -109,12 +108,8 @@ class IDEAL implements MethodInterface */ public function processUnsuccessfulPayment(\Exception $exception): void { - PaymentFailureMailer::dispatch( - $this->mollie->client, - $exception->getMessage(), - $this->mollie->client->company, - $this->mollie->payment_hash->data->amount_with_fee - ); + + $this->mollie->sendFailureMail($exception->getMessage()); SystemLogger::dispatch( $exception->getMessage(), diff --git a/app/PaymentDrivers/Mollie/KBC.php b/app/PaymentDrivers/Mollie/KBC.php index bb2386c8b6e6..d608a62b89ca 100644 --- a/app/PaymentDrivers/Mollie/KBC.php +++ b/app/PaymentDrivers/Mollie/KBC.php @@ -15,7 +15,6 @@ namespace App\PaymentDrivers\Mollie; use App\Exceptions\PaymentFailed; use App\Http\Requests\Request; use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest; -use App\Jobs\Mail\PaymentFailureMailer; use App\Jobs\Util\SystemLogger; use App\Models\GatewayType; use App\Models\Payment; @@ -109,12 +108,8 @@ class KBC implements MethodInterface */ public function processUnsuccessfulPayment(\Exception $exception): void { - PaymentFailureMailer::dispatch( - $this->mollie->client, - $exception->getMessage(), - $this->mollie->client->company, - $this->mollie->payment_hash->data->amount_with_fee - ); + + $this->mollie->sendFailureMail($exception->getMessage()); SystemLogger::dispatch( $exception->getMessage(), diff --git a/app/PaymentDrivers/MolliePaymentDriver.php b/app/PaymentDrivers/MolliePaymentDriver.php index cb09fbb2db57..8ec71a6d2a18 100644 --- a/app/PaymentDrivers/MolliePaymentDriver.php +++ b/app/PaymentDrivers/MolliePaymentDriver.php @@ -15,7 +15,6 @@ namespace App\PaymentDrivers; use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest; use App\Http\Requests\Gateways\Mollie\Mollie3dsRequest; use App\Http\Requests\Payments\PaymentWebhookRequest; -use App\Jobs\Mail\PaymentFailureMailer; use App\Jobs\Util\SystemLogger; use App\Models\ClientGatewayToken; use App\Models\GatewayType; @@ -247,12 +246,7 @@ class MolliePaymentDriver extends BaseDriver $this->unWindGatewayFees($payment_hash); - PaymentFailureMailer::dispatch( - $this->client, - $payment->details, - $this->client->company, - $amount - ); + $this->sendFailureMail($payment->details); $message = [ 'server_response' => $payment, diff --git a/app/PaymentDrivers/PayFast/CreditCard.php b/app/PaymentDrivers/PayFast/CreditCard.php index 796c59ce4d19..be021760fa17 100644 --- a/app/PaymentDrivers/PayFast/CreditCard.php +++ b/app/PaymentDrivers/PayFast/CreditCard.php @@ -13,7 +13,6 @@ namespace App\PaymentDrivers\PayFast; use App\Exceptions\PaymentFailed; -use App\Jobs\Mail\PaymentFailureMailer; use App\Jobs\Util\SystemLogger; use App\Models\ClientGatewayToken; use App\Models\GatewayType; @@ -253,15 +252,8 @@ class CreditCard private function processUnsuccessfulPayment($server_response) { - PaymentFailureMailer::dispatch($this->payfast->client, $server_response->cancellation_reason, $this->payfast->client->company, $server_response->amount); - - PaymentFailureMailer::dispatch( - $this->payfast->client, - $server_response, - $this->payfast->client->company, - $server_response['amount_gross'] - ); - + $this->payfast->sendFailureMail($server_response->cancellation_reason); + $message = [ 'server_response' => $server_response, 'data' => $this->payfast->payment_hash->data, diff --git a/app/PaymentDrivers/PayFast/Token.php b/app/PaymentDrivers/PayFast/Token.php index 43208c58dd36..35433cae9fa8 100644 --- a/app/PaymentDrivers/PayFast/Token.php +++ b/app/PaymentDrivers/PayFast/Token.php @@ -13,7 +13,6 @@ namespace App\PaymentDrivers\PayFast; use App\Exceptions\PaymentFailed; -use App\Jobs\Mail\PaymentFailureMailer; use App\Jobs\Util\SystemLogger; use App\Models\ClientGatewayToken; use App\Models\GatewayType; @@ -32,45 +31,11 @@ class Token public $payfast; - //https://api.payfast.co.za/subscriptions/dc0521d3-55fe-269b-fa00-b647310d760f/adhoc - public function __construct(PayFastPaymentDriver $payfast) { $this->payfast = $payfast; } - // Attributes - // merchant-id - // integer, 8 char | REQUIRED - // Header, the Merchant ID as given by the PayFast system. - // version - // string | REQUIRED - // Header, the PayFast API version (i.e. v1). - // timestamp - // ISO-8601 date and time | REQUIRED - // Header, the current timestamp (YYYY-MM-DDTHH:MM:SS[+HH:MM]). - // signature - // string | REQUIRED - // Header, MD5 hash of the alphabetised submitted header and body variables, as well as the passphrase. Characters must be in lower case. - // amount - // integer | REQUIRED - // Body, the amount which the buyer must pay, in cents (ZAR), no decimals. - // item_name - // string, 100 char | REQUIRED - // Body, the name of the item being charged for. - // item_description - // string, 255 char | OPTIONAL - // Body, the description of the item being charged for. - // itn - // boolean | OPTIONAL - // Body, specify whether an ITN must be sent for the tokenization payment (true by default). - // m_payment_id - // string, 100 char | OPTIONAL - // Body, unique payment ID on the merchant’s system. - // cc_cvv - // numeric | OPTIONAL - - public function tokenBilling(ClientGatewayToken $cgt, PaymentHash $payment_hash) { @@ -89,10 +54,6 @@ class Token 'item_description' => ctrans('texts.invoices') . ': ' . collect($payment_hash->invoices())->pluck('invoice_number'), 'm_payment_id' => $payment_hash->hash, ]; - - nlog(array_merge($body, $header)); - - // $header['signature'] = md5( $this->generate_parameter_string(array_merge($header, $body), false) ); $header['signature'] = $this->payfast->generateTokenSignature(array_merge($body, $header)); @@ -100,63 +61,6 @@ class Token $result = $this->send($header, $body, $cgt->token); - nlog($result); - - // $api = new \PayFast\PayFastApi( - // [ - // 'merchantId' => $this->payfast->company_gateway->getConfigField('merchantId'), - // 'passPhrase' => $this->payfast->company_gateway->getConfigField('passPhrase'), - // 'testMode' => $this->payfast->company_gateway->getConfigField('testMode') - // ] - // ); - - // $adhocArray = $api - // ->subscriptions - // ->adhoc($cgt->token, ['amount' => $amount, 'item_name' => 'purchase']); - - - // nlog($adhocArray); - - - - // /*Refactor and push to BaseDriver*/ - // if ($data['response'] != null && $data['response']->getMessages()->getResultCode() == 'Ok') { - - // $response = $data['response']; - - // $this->storePayment($payment_hash, $data); - - // $vars = [ - // 'invoices' => $payment_hash->invoices(), - // 'amount' => $amount, - // ]; - - // $logger_message = [ - // 'server_response' => $response->getTransactionResponse()->getTransId(), - // 'data' => $this->formatGatewayResponse($data, $vars), - // ]; - - // SystemLogger::dispatch($logger_message, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_SUCCESS, SystemLog::TYPE_AUTHORIZE, $this->authorize->client, $this->authorize->client->company); - - // return true; - // } else { - - // $vars = [ - // 'invoices' => $payment_hash->invoices(), - // 'amount' => $amount, - // ]; - - // $logger_message = [ - // 'server_response' => $response->getTransactionResponse()->getTransId(), - // 'data' => $this->formatGatewayResponse($data, $vars), - // ]; - - // PaymentFailureMailer::dispatch($this->authorize->client, $response->getTransactionResponse()->getTransId(), $this->authorize->client->company, $amount); - - // SystemLogger::dispatch($logger_message, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_AUTHORIZE, $this->authorize->client, $this->authorize->client->company); - - // return false; - // } } protected function generate_parameter_string( $api_data, $sort_data_before_merge = true, $skip_empty_values = true ) { diff --git a/app/PaymentDrivers/PayPalExpressPaymentDriver.php b/app/PaymentDrivers/PayPalExpressPaymentDriver.php index 88de81b4823a..2ee33668b8d7 100644 --- a/app/PaymentDrivers/PayPalExpressPaymentDriver.php +++ b/app/PaymentDrivers/PayPalExpressPaymentDriver.php @@ -13,7 +13,6 @@ namespace App\PaymentDrivers; use App\Exceptions\PaymentFailed; -use App\Jobs\Mail\PaymentFailureMailer; use App\Jobs\Util\SystemLogger; use App\Models\GatewayType; use App\Models\Invoice; @@ -94,7 +93,7 @@ class PayPalExpressPaymentDriver extends BaseDriver return $response->redirect(); } - PaymentFailureMailer::dispatch($this->client, $response->getData(), $this->client->company, $data['total']['amount_with_fee']); + $this->sendFailureMail($response->getData()); $message = [ 'server_response' => $response->getMessage(), @@ -151,8 +150,8 @@ class PayPalExpressPaymentDriver extends BaseDriver if (!$response->isSuccessful()) { $data = $response->getData(); - - PaymentFailureMailer::dispatch($this->client, $response->getMessage(), $this->client->company, $this->payment_hash->data->amount); + + $this->sendFailureMail($response->getMessage()); $message = [ 'server_response' => $data['L_LONGMESSAGE0'], diff --git a/app/PaymentDrivers/PayTrace/CreditCard.php b/app/PaymentDrivers/PayTrace/CreditCard.php index f2a9a744aca7..3e00f657e881 100644 --- a/app/PaymentDrivers/PayTrace/CreditCard.php +++ b/app/PaymentDrivers/PayTrace/CreditCard.php @@ -13,7 +13,6 @@ namespace App\PaymentDrivers\PayTrace; use App\Exceptions\PaymentFailed; -use App\Jobs\Mail\PaymentFailureMailer; use App\Jobs\Util\SystemLogger; use App\Models\ClientGatewayToken; use App\Models\GatewayType; diff --git a/app/PaymentDrivers/Razorpay/Hosted.php b/app/PaymentDrivers/Razorpay/Hosted.php index 736a31c4e762..efb15074ca9d 100644 --- a/app/PaymentDrivers/Razorpay/Hosted.php +++ b/app/PaymentDrivers/Razorpay/Hosted.php @@ -16,7 +16,6 @@ namespace App\PaymentDrivers\Razorpay; use App\Exceptions\PaymentFailed; use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest; use App\Http\Requests\Request; -use App\Jobs\Mail\PaymentFailureMailer; use App\Jobs\Util\SystemLogger; use App\Models\GatewayType; use App\Models\Payment; @@ -163,12 +162,8 @@ class Hosted implements MethodInterface */ public function processUnsuccessfulPayment(\Exception $exception): void { - PaymentFailureMailer::dispatch( - $this->razorpay->client, - $exception->getMessage(), - $this->razorpay->client->company, - $this->razorpay->payment_hash->data->amount_with_fee - ); + + $this->razorpay->sendFailureMail($exception->getMessage()); SystemLogger::dispatch( $exception->getMessage(), @@ -180,5 +175,6 @@ class Hosted implements MethodInterface ); throw new PaymentFailed($exception->getMessage(), $exception->getCode()); + } } diff --git a/app/PaymentDrivers/Sample/CreditCard.php b/app/PaymentDrivers/Sample/CreditCard.php index 976ae402f2e8..201ca514b14f 100644 --- a/app/PaymentDrivers/Sample/CreditCard.php +++ b/app/PaymentDrivers/Sample/CreditCard.php @@ -13,7 +13,6 @@ namespace App\PaymentDrivers\Sample; use App\Exceptions\PaymentFailed; -use App\Jobs\Mail\PaymentFailureMailer; use App\Jobs\Util\SystemLogger; use App\Models\ClientGatewayToken; use App\Models\GatewayType; diff --git a/app/PaymentDrivers/SquarePaymentDriver.php b/app/PaymentDrivers/SquarePaymentDriver.php index 43d16b30089e..5970cfd491bb 100644 --- a/app/PaymentDrivers/SquarePaymentDriver.php +++ b/app/PaymentDrivers/SquarePaymentDriver.php @@ -12,7 +12,6 @@ namespace App\PaymentDrivers; use App\Http\Requests\Payments\PaymentWebhookRequest; -use App\Jobs\Mail\PaymentFailureMailer; use App\Jobs\Util\SystemLogger; use App\Models\ClientGatewayToken; use App\Models\GatewayType; @@ -167,12 +166,7 @@ class SquarePaymentDriver extends BaseDriver $this->unWindGatewayFees($payment_hash); - PaymentFailureMailer::dispatch( - $this->client, - $body->errors[0]->detail, - $this->client->company, - $amount - ); + $this->sendFailureMail($body->errors[0]->detail); $message = [ 'server_response' => $response, diff --git a/app/PaymentDrivers/Stripe/ACH.php b/app/PaymentDrivers/Stripe/ACH.php index e2e3c8941108..33fc448a1128 100644 --- a/app/PaymentDrivers/Stripe/ACH.php +++ b/app/PaymentDrivers/Stripe/ACH.php @@ -17,7 +17,6 @@ use App\Http\Requests\ClientPortal\PaymentMethod\VerifyPaymentMethodRequest; use App\Http\Requests\Request; use App\Jobs\Mail\NinjaMailerJob; use App\Jobs\Mail\NinjaMailerObject; -use App\Jobs\Mail\PaymentFailureMailer; use App\Jobs\Util\SystemLogger; use App\Mail\Gateways\ACHVerificationNotification; use App\Models\ClientGatewayToken; @@ -290,13 +289,7 @@ class ACH public function processUnsuccessfulPayment($state) { - - PaymentFailureMailer::dispatch( - $this->stripe->client, - $state['charge'], - $this->stripe->client->company, - $state['amount'] - ); + $this->stripe->sendFailureMail($state['charge']); $message = [ 'server_response' => $state['charge'], diff --git a/app/PaymentDrivers/Stripe/Alipay.php b/app/PaymentDrivers/Stripe/Alipay.php index 20f2c0e1ebf2..a3f5dd248bfc 100644 --- a/app/PaymentDrivers/Stripe/Alipay.php +++ b/app/PaymentDrivers/Stripe/Alipay.php @@ -14,7 +14,6 @@ namespace App\PaymentDrivers\Stripe; use App\Exceptions\PaymentFailed; use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest; -use App\Jobs\Mail\PaymentFailureMailer; use App\Jobs\Util\SystemLogger; use App\Models\GatewayType; use App\Models\Payment; @@ -98,14 +97,7 @@ class Alipay { $server_response = $this->stripe->payment_hash->data; - PaymentFailureMailer::dispatch($this->stripe->client, $server_response->redirect_status, $this->stripe->client->company, $server_response->amount); - - PaymentFailureMailer::dispatch( - $this->stripe->client, - $server_response, - $this->stripe->client->company, - $this->stripe->convertFromStripeAmount($this->stripe->payment_hash->data->stripe_amount, $this->stripe->client->currency()->precision, $this->stripe->client->currency()) - ); + $this->stripe->sendFailureMail($server_response->redirect_status); $message = [ 'server_response' => $server_response, diff --git a/app/PaymentDrivers/Stripe/ApplePay.php b/app/PaymentDrivers/Stripe/ApplePay.php index fcb702570dcb..658900cd5d47 100644 --- a/app/PaymentDrivers/Stripe/ApplePay.php +++ b/app/PaymentDrivers/Stripe/ApplePay.php @@ -14,7 +14,6 @@ namespace App\PaymentDrivers\Stripe; use App\Exceptions\PaymentFailed; use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest; -use App\Jobs\Mail\PaymentFailureMailer; use App\Jobs\Util\SystemLogger; use App\Models\GatewayType; use App\Models\Payment; diff --git a/app/PaymentDrivers/Stripe/Bancontact.php b/app/PaymentDrivers/Stripe/Bancontact.php index cfcab8361ab1..c269b286f7e0 100644 --- a/app/PaymentDrivers/Stripe/Bancontact.php +++ b/app/PaymentDrivers/Stripe/Bancontact.php @@ -13,7 +13,6 @@ namespace App\PaymentDrivers\Stripe; use App\Exceptions\PaymentFailed; -use App\Jobs\Mail\PaymentFailureMailer; use App\Jobs\Util\SystemLogger; use App\Models\GatewayType; use App\Models\Payment; @@ -119,12 +118,7 @@ class Bancontact { $server_response = $this->stripe->payment_hash->data; - PaymentFailureMailer::dispatch( - $this->stripe->client, - $server_response, - $this->stripe->client->company, - $this->stripe->convertFromStripeAmount($this->stripe->payment_hash->data->stripe_amount, $this->stripe->client->currency()->precision, $this->stripe->client->currency()) - ); + $this->stripe->sendFailureMail($server_response); $message = [ 'server_response' => $server_response, diff --git a/app/PaymentDrivers/Stripe/Connect/Verify.php b/app/PaymentDrivers/Stripe/Connect/Verify.php index daf443caec20..e957e6f5b248 100644 --- a/app/PaymentDrivers/Stripe/Connect/Verify.php +++ b/app/PaymentDrivers/Stripe/Connect/Verify.php @@ -18,7 +18,6 @@ use App\Http\Requests\ClientPortal\PaymentMethod\VerifyPaymentMethodRequest; use App\Http\Requests\Request; use App\Jobs\Mail\NinjaMailerJob; use App\Jobs\Mail\NinjaMailerObject; -use App\Jobs\Mail\PaymentFailureMailer; use App\Jobs\Util\SystemLogger; use App\Mail\Gateways\ACHVerificationNotification; use App\Models\ClientGatewayToken; diff --git a/app/PaymentDrivers/Stripe/CreditCard.php b/app/PaymentDrivers/Stripe/CreditCard.php index 41ee4ec4ae5c..f89e52688961 100644 --- a/app/PaymentDrivers/Stripe/CreditCard.php +++ b/app/PaymentDrivers/Stripe/CreditCard.php @@ -14,7 +14,6 @@ namespace App\PaymentDrivers\Stripe; use App\Exceptions\PaymentFailed; use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest; -use App\Jobs\Mail\PaymentFailureMailer; use App\Jobs\Util\SystemLogger; use App\Models\GatewayType; use App\Models\Payment; @@ -160,14 +159,7 @@ class CreditCard public function processUnsuccessfulPayment($server_response) { - PaymentFailureMailer::dispatch($this->stripe->client, $server_response->cancellation_reason, $this->stripe->client->company, $server_response->amount); - - PaymentFailureMailer::dispatch( - $this->stripe->client, - $server_response, - $this->stripe->client->company, - $server_response->amount - ); + $this->stripe->sendFailureMail($server_response->cancellation_reason); $message = [ 'server_response' => $server_response, diff --git a/app/PaymentDrivers/Stripe/EPS.php b/app/PaymentDrivers/Stripe/EPS.php index f9e294862b08..3d8f8323e7d6 100644 --- a/app/PaymentDrivers/Stripe/EPS.php +++ b/app/PaymentDrivers/Stripe/EPS.php @@ -13,7 +13,6 @@ namespace App\PaymentDrivers\Stripe; use App\Exceptions\PaymentFailed; -use App\Jobs\Mail\PaymentFailureMailer; use App\Jobs\Util\SystemLogger; use App\Models\GatewayType; use App\Models\Payment; @@ -119,12 +118,7 @@ class EPS { $server_response = $this->stripe->payment_hash->data; - PaymentFailureMailer::dispatch( - $this->stripe->client, - $server_response, - $this->stripe->client->company, - $this->stripe->convertFromStripeAmount($this->stripe->payment_hash->data->stripe_amount, $this->stripe->client->currency()->precision, $this->stripe->client->currency()) - ); + $this->stripe->sendFailureMail($server_response); $message = [ 'server_response' => $server_response, diff --git a/app/PaymentDrivers/Stripe/GIROPAY.php b/app/PaymentDrivers/Stripe/GIROPAY.php index 840c4a3c2c87..6894870af0a8 100644 --- a/app/PaymentDrivers/Stripe/GIROPAY.php +++ b/app/PaymentDrivers/Stripe/GIROPAY.php @@ -13,7 +13,6 @@ namespace App\PaymentDrivers\Stripe; use App\Exceptions\PaymentFailed; -use App\Jobs\Mail\PaymentFailureMailer; use App\Jobs\Util\SystemLogger; use App\Models\GatewayType; use App\Models\Payment; @@ -119,12 +118,7 @@ class GIROPAY { $server_response = $this->stripe->payment_hash->data; - PaymentFailureMailer::dispatch( - $this->stripe->client, - $server_response, - $this->stripe->client->company, - $this->stripe->convertFromStripeAmount($this->stripe->payment_hash->data->stripe_amount, $this->stripe->client->currency()->precision, $this->stripe->client->currency()) - ); + $this->stripe->sendFailureMail($server_response); $message = [ 'server_response' => $server_response, diff --git a/app/PaymentDrivers/Stripe/PRZELEWY24.php b/app/PaymentDrivers/Stripe/PRZELEWY24.php index 67dbf4516854..8ed4b76bc3a1 100644 --- a/app/PaymentDrivers/Stripe/PRZELEWY24.php +++ b/app/PaymentDrivers/Stripe/PRZELEWY24.php @@ -13,7 +13,6 @@ namespace App\PaymentDrivers\Stripe; use App\Exceptions\PaymentFailed; -use App\Jobs\Mail\PaymentFailureMailer; use App\Jobs\Util\SystemLogger; use App\Models\GatewayType; use App\Models\Payment; @@ -119,12 +118,7 @@ class PRZELEWY24 { $server_response = $this->stripe->payment_hash->data; - PaymentFailureMailer::dispatch( - $this->stripe->client, - $server_response, - $this->stripe->client->company, - $this->stripe->convertFromStripeAmount($this->stripe->payment_hash->data->stripe_amount, $this->stripe->client->currency()->precision, $this->stripe->client->currency()) - ); + $this->stripe->sendFailureMail($server_response); $message = [ 'server_response' => $server_response, diff --git a/app/PaymentDrivers/Stripe/SEPA.php b/app/PaymentDrivers/Stripe/SEPA.php index a20a61f290c5..251dbbb00bfa 100644 --- a/app/PaymentDrivers/Stripe/SEPA.php +++ b/app/PaymentDrivers/Stripe/SEPA.php @@ -13,7 +13,6 @@ namespace App\PaymentDrivers\Stripe; use App\Exceptions\PaymentFailed; use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest; -use App\Jobs\Mail\PaymentFailureMailer; use App\Jobs\Util\SystemLogger; use App\Models\GatewayType; use App\Models\Payment; @@ -120,12 +119,7 @@ class SEPA { $server_response = $this->stripe->payment_hash->data; - PaymentFailureMailer::dispatch( - $this->stripe->client, - $server_response, - $this->stripe->client->company, - $this->stripe->convertFromStripeAmount($this->stripe->payment_hash->data->stripe_amount, $this->stripe->client->currency()->precision, $this->stripe->client->currency()) - ); + $this->stripe->sendFailureMail($server_response); $message = [ 'server_response' => $server_response, diff --git a/app/PaymentDrivers/Stripe/SOFORT.php b/app/PaymentDrivers/Stripe/SOFORT.php index 43d25ab2634b..bf5c1e717d9a 100644 --- a/app/PaymentDrivers/Stripe/SOFORT.php +++ b/app/PaymentDrivers/Stripe/SOFORT.php @@ -13,7 +13,6 @@ namespace App\PaymentDrivers\Stripe; use App\Exceptions\PaymentFailed; -use App\Jobs\Mail\PaymentFailureMailer; use App\Jobs\Util\SystemLogger; use App\Models\GatewayType; use App\Models\Payment; @@ -115,12 +114,7 @@ class SOFORT { $server_response = $this->stripe->payment_hash->data; - PaymentFailureMailer::dispatch( - $this->stripe->client, - $server_response, - $this->stripe->client->company, - $this->stripe->convertFromStripeAmount($this->stripe->payment_hash->data->stripe_amount, $this->stripe->client->currency()->precision, $this->stripe->client->currency()) - ); + $this->stripe->sendFailureMail($server_response); $message = [ 'server_response' => $server_response, diff --git a/app/PaymentDrivers/Stripe/iDeal.php b/app/PaymentDrivers/Stripe/iDeal.php index d19971c065c9..1a26e03c18bd 100644 --- a/app/PaymentDrivers/Stripe/iDeal.php +++ b/app/PaymentDrivers/Stripe/iDeal.php @@ -13,7 +13,6 @@ namespace App\PaymentDrivers\Stripe; use App\Exceptions\PaymentFailed; -use App\Jobs\Mail\PaymentFailureMailer; use App\Jobs\Util\SystemLogger; use App\Models\GatewayType; use App\Models\Payment; @@ -119,12 +118,7 @@ class iDeal { $server_response = $this->stripe->payment_hash->data; - PaymentFailureMailer::dispatch( - $this->stripe->client, - $server_response, - $this->stripe->client->company, - $this->stripe->convertFromStripeAmount($this->stripe->payment_hash->data->stripe_amount, $this->stripe->client->currency()->precision, $this->stripe->client->currency()) - ); + $this->stripe->sendFailureMail($server_response); $message = [ 'server_response' => $server_response, diff --git a/app/PaymentDrivers/WePay/ACH.php b/app/PaymentDrivers/WePay/ACH.php index 3a8a14b5ad8e..ae49f350418d 100644 --- a/app/PaymentDrivers/WePay/ACH.php +++ b/app/PaymentDrivers/WePay/ACH.php @@ -13,9 +13,11 @@ namespace App\PaymentDrivers\WePay; use App\Exceptions\PaymentFailed; +use App\Jobs\Util\SystemLogger; use App\Models\ClientGatewayToken; use App\Models\GatewayType; use App\Models\Payment; +use App\Models\SystemLog; use App\PaymentDrivers\WePayPaymentDriver; use App\PaymentDrivers\WePay\WePayCommon; use App\Utils\Traits\MakesHash; @@ -68,6 +70,23 @@ class ACH ]); } catch(\Exception $e){ + + $this->wepay_payment_driver->sendFailureMail($e->getMessage()); + + $message = [ + 'server_response' => $e->getMessage(), + 'data' => $this->wepay_payment_driver->payment_hash->data, + ]; + + SystemLogger::dispatch( + $e->getMessage(), + SystemLog::CATEGORY_GATEWAY_RESPONSE, + SystemLog::EVENT_GATEWAY_FAILURE, + SystemLog::TYPE_WEPAY, + $this->wepay_payment_driver->client, + $this->wepay_payment_driver->client->company, + ); + throw new PaymentFailed($e->getMessage(), 400); } // display the response diff --git a/app/PaymentDrivers/WePay/CreditCard.php b/app/PaymentDrivers/WePay/CreditCard.php index 8209c71c3546..c2c74fc15140 100644 --- a/app/PaymentDrivers/WePay/CreditCard.php +++ b/app/PaymentDrivers/WePay/CreditCard.php @@ -14,7 +14,6 @@ namespace App\PaymentDrivers\WePay; use App\Exceptions\PaymentFailed; use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest; -use App\Jobs\Mail\PaymentFailureMailer; use App\Jobs\Util\SystemLogger; use App\Models\GatewayType; use App\Models\Payment; @@ -153,24 +152,48 @@ use WePayCommon; $app_fee = (config('ninja.wepay.fee_cc_multiplier') * $this->wepay_payment_driver->payment_hash->data->amount_with_fee) + config('ninja.wepay.fee_fixed'); // charge the credit card - $response = $this->wepay_payment_driver->wepay->request('checkout/create', array( - 'unique_id' => Str::random(40), - 'account_id' => $this->wepay_payment_driver->company_gateway->getConfigField('accountId'), - 'amount' => $this->wepay_payment_driver->payment_hash->data->amount_with_fee, - 'currency' => $this->wepay_payment_driver->client->getCurrencyCode(), - 'short_description' => 'Goods and services', - 'type' => 'goods', - 'fee' => [ - 'fee_payer' => config('ninja.wepay.fee_payer'), - 'app_fee' => $app_fee, - ], - 'payment_method' => array( - 'type' => 'credit_card', - 'credit_card' => array( - 'id' => $credit_card_id + + try { + $response = $this->wepay_payment_driver->wepay->request('checkout/create', array( + 'unique_id' => Str::random(40), + 'account_id' => $this->wepay_payment_driver->company_gateway->getConfigField('accountId'), + 'amount' => $this->wepay_payment_driver->payment_hash->data->amount_with_fee, + 'currency' => $this->wepay_payment_driver->client->getCurrencyCode(), + 'short_description' => 'Goods and services', + 'type' => 'goods', + 'fee' => [ + 'fee_payer' => config('ninja.wepay.fee_payer'), + 'app_fee' => $app_fee, + ], + 'payment_method' => array( + 'type' => 'credit_card', + 'credit_card' => array( + 'id' => $credit_card_id + ) ) - ) - )); + )); + } + catch(\Exception $e){ + + $this->wepay_payment_driver->sendFailureMail($e->getMessage()); + + $message = [ + 'server_response' => $e->getMessage(), + 'data' => $this->wepay_payment_driver->payment_hash->data, + ]; + + SystemLogger::dispatch( + $e->getMessage(), + SystemLog::CATEGORY_GATEWAY_RESPONSE, + SystemLog::EVENT_GATEWAY_FAILURE, + SystemLog::TYPE_WEPAY, + $this->wepay_payment_driver->client, + $this->wepay_payment_driver->client->company, + ); + + throw new PaymentFailed($e->getMessage(), 500); + + } /* Merge all data and store in the payment hash*/ $state = [ diff --git a/app/PaymentDrivers/WePay/WePayCommon.php b/app/PaymentDrivers/WePay/WePayCommon.php index 2cf843b43828..8555a0c95772 100644 --- a/app/PaymentDrivers/WePay/WePayCommon.php +++ b/app/PaymentDrivers/WePay/WePayCommon.php @@ -12,7 +12,6 @@ namespace App\PaymentDrivers\WePay; use App\Exceptions\PaymentFailed; -use App\Jobs\Mail\PaymentFailureMailer; use App\Jobs\Util\SystemLogger; use App\Models\GatewayType; use App\Models\PaymentType; @@ -21,7 +20,6 @@ use App\Models\SystemLog; trait WePayCommon { - private function processSuccessfulPayment($response, $payment_status, $gateway_type, $return_payment = false) { @@ -56,14 +54,7 @@ trait WePayCommon private function processUnSuccessfulPayment($response, $payment_status) { - PaymentFailureMailer::dispatch($this->wepay_payment_driver->client, $response->state, $this->wepay_payment_driver->client->company, $response->amount); - - PaymentFailureMailer::dispatch( - $this->wepay_payment_driver->client, - $response, - $this->wepay_payment_driver->client->company, - $response->gross - ); + $this->wepay_payment_driver->sendFailureMail($response->state); $message = [ 'server_response' => $response, diff --git a/app/Services/Invoice/AutoBillInvoice.php b/app/Services/Invoice/AutoBillInvoice.php index 98d003507ea4..ae84ea16462a 100644 --- a/app/Services/Invoice/AutoBillInvoice.php +++ b/app/Services/Invoice/AutoBillInvoice.php @@ -107,7 +107,7 @@ class AutoBillInvoice extends AbstractService /* Build payment hash */ $payment_hash = PaymentHash::create([ 'hash' => Str::random(64), - 'data' => ['invoices' => [['invoice_id' => $this->invoice->hashed_id, 'amount' => $amount]]], + 'data' => ['invoices' => [['invoice_id' => $this->invoice->hashed_id, 'amount' => $amount, 'invoice_number' => $this->invoice->number]]], 'fee_total' => $fee, 'fee_invoice_id' => $this->invoice->id, ]); From f962e3a2fa95c36d5743611fc6bab6c430b2d809 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 17 Oct 2021 22:21:56 +1100 Subject: [PATCH 10/11] Refactor for payment failure mailers --- app/Filters/QueryFilters.php | 2 +- app/PaymentDrivers/BaseDriver.php | 2 +- app/PaymentDrivers/Eway/CreditCard.php | 12 ++++++++++-- app/PaymentDrivers/Razorpay/Hosted.php | 3 +++ app/PaymentDrivers/Stripe/ACH.php | 2 +- 5 files changed, 16 insertions(+), 5 deletions(-) diff --git a/app/Filters/QueryFilters.php b/app/Filters/QueryFilters.php index c80c6b85ecd6..ac6318bcf98a 100644 --- a/app/Filters/QueryFilters.php +++ b/app/Filters/QueryFilters.php @@ -176,7 +176,7 @@ abstract class QueryFilters public function is_deleted($value) { - return $this->builder->where('is_deleted', $value); + return $this->builder->where('is_deleted', $value)->withTrashed(); } diff --git a/app/PaymentDrivers/BaseDriver.php b/app/PaymentDrivers/BaseDriver.php index 535546e3fb5c..57a288223532 100644 --- a/app/PaymentDrivers/BaseDriver.php +++ b/app/PaymentDrivers/BaseDriver.php @@ -474,7 +474,7 @@ class BaseDriver extends AbstractPaymentDriver $invoices->first()->invitations->each(function ($invitation) use ($nmo){ - if (!$invitation->contact->trashed() && $invitation->contact->email) { + if (!$invitation->contact->trashed()) { $nmo->to_user = $invitation->contact; NinjaMailerJob::dispatch($nmo); diff --git a/app/PaymentDrivers/Eway/CreditCard.php b/app/PaymentDrivers/Eway/CreditCard.php index 3ef197c948c0..f6c5fc273824 100644 --- a/app/PaymentDrivers/Eway/CreditCard.php +++ b/app/PaymentDrivers/Eway/CreditCard.php @@ -83,8 +83,12 @@ class CreditCard $response_status = ErrorCode::getStatus($response->ResponseMessage); - if(!$response_status['success']) - throw new PaymentFailed($response_status['message'], 400); + if(!$response_status['success']){ + + $this->eway_driver->sendFailureMail($response_status['message']); + + throw new PaymentFailed($response_status['message'], 400); + } //success $cgt = []; @@ -158,6 +162,8 @@ class CreditCard $this->logResponse($response, false); + $this->eway_driver->sendFailureMail($response_status['message']); + throw new PaymentFailed($response_status['message'], 400); } @@ -237,6 +243,8 @@ class CreditCard $this->logResponse($response, false); + $this->eway_driver->sendFailureMail($response_status['message']); + throw new PaymentFailed($response_status['message'], 400); } diff --git a/app/PaymentDrivers/Razorpay/Hosted.php b/app/PaymentDrivers/Razorpay/Hosted.php index efb15074ca9d..657cd4d5d76e 100644 --- a/app/PaymentDrivers/Razorpay/Hosted.php +++ b/app/PaymentDrivers/Razorpay/Hosted.php @@ -105,6 +105,9 @@ class Hosted implements MethodInterface ]); if (! property_exists($this->razorpay->payment_hash->data, 'order_id')) { + + $this->razorpay->sendFailureMail("Missing [order_id] property. "); + throw new PaymentFailed('Missing [order_id] property. Please contact the administrator. Reference: ' . $this->razorpay->payment_hash->hash); } diff --git a/app/PaymentDrivers/Stripe/ACH.php b/app/PaymentDrivers/Stripe/ACH.php index 33fc448a1128..a0568cb8f6ec 100644 --- a/app/PaymentDrivers/Stripe/ACH.php +++ b/app/PaymentDrivers/Stripe/ACH.php @@ -193,7 +193,7 @@ class ACH return $this->processUnsuccessfulPayment($state); } catch (Exception $e) { if ($e instanceof CardException) { - return redirect()->route('client.payment_methods.verification', ['payment_method' => $source->hashed_id, 'method' => GatewayType::BANK_TRANSFER]); + return redirect()->route('client.payment_methods.verification', ['payment_method' => $cgt->hashed_id, 'method' => GatewayType::BANK_TRANSFER]); } throw new PaymentFailed($e->getMessage(), $e->getCode()); From 741e43ddbe1fc4dd536341c420fbe487378dee7d Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 17 Oct 2021 22:30:48 +1100 Subject: [PATCH 11/11] version bump --- VERSION.txt | 2 +- app/Filters/QueryFilters.php | 15 ++++++++++++++- config/ninja.php | 4 ++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/VERSION.txt b/VERSION.txt index 57349115ece8..014a3048e716 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -5.3.23 \ No newline at end of file +5.3.24 \ No newline at end of file diff --git a/app/Filters/QueryFilters.php b/app/Filters/QueryFilters.php index ac6318bcf98a..bbb18e5cb713 100644 --- a/app/Filters/QueryFilters.php +++ b/app/Filters/QueryFilters.php @@ -176,7 +176,7 @@ abstract class QueryFilters public function is_deleted($value) { - return $this->builder->where('is_deleted', $value)->withTrashed(); + return $this->builder->where('is_deleted', $value); } @@ -207,4 +207,17 @@ abstract class QueryFilters return $this->builder; } + + public function with_trashed($value) + { + + if($value == 'true'){ + + $this->builder->withTrashed(); + + } + + return $this->builder; + + } } diff --git a/config/ninja.php b/config/ninja.php index a6fc87778173..9c2761858c33 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -14,8 +14,8 @@ return [ 'require_https' => env('REQUIRE_HTTPS', true), 'app_url' => rtrim(env('APP_URL', ''), '/'), 'app_domain' => env('APP_DOMAIN', 'invoicing.co'), - 'app_version' => '5.3.23', - 'app_tag' => '5.3.23', + 'app_version' => '5.3.24', + 'app_tag' => '5.3.24', 'minimum_client_version' => '5.0.16', 'terms_version' => '1.0.1', 'api_secret' => env('API_SECRET', ''),