From 8c7aa563f4a6daac64803d4939b4008878bd6619 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 17 Mar 2023 13:55:46 +1100 Subject: [PATCH] Fixes for liap --- .../ClientPortal/PrePaymentController.php | 3 +- .../AppStoreRenewSubscription.php | 62 ------------------- .../PlayStoreRenewSubscription.php | 49 --------------- app/Models/Gateway.php | 62 +++++-------------- app/Services/ClientPortal/InstantPayment.php | 1 + app/Services/Payment/UpdateInvoicePayment.php | 8 ++- config/liap.php | 6 +- config/ninja.php | 1 + .../gateways/includes/save_card.blade.php | 4 ++ .../gateways/stripe/credit_card/pay.blade.php | 5 ++ 10 files changed, 36 insertions(+), 165 deletions(-) delete mode 100644 app/Listeners/Subscription/AppStoreRenewSubscription.php delete mode 100644 app/Listeners/Subscription/PlayStoreRenewSubscription.php diff --git a/app/Http/Controllers/ClientPortal/PrePaymentController.php b/app/Http/Controllers/ClientPortal/PrePaymentController.php index 8e3f377778..874be8a353 100644 --- a/app/Http/Controllers/ClientPortal/PrePaymentController.php +++ b/app/Http/Controllers/ClientPortal/PrePaymentController.php @@ -110,9 +110,8 @@ class PrePaymentController extends Controller 'pre_payment' => true, 'frequency_id' => $request->frequency_id, 'remaining_cycles' => $request->remaining_cycles, - 'is_recurring' => $request->is_recurring, + 'is_recurring' => $request->is_recurring == 'on' ? true : false, ]; - return $this->render('invoices.payment', $data); diff --git a/app/Listeners/Subscription/AppStoreRenewSubscription.php b/app/Listeners/Subscription/AppStoreRenewSubscription.php deleted file mode 100644 index 07e5c493f9..0000000000 --- a/app/Listeners/Subscription/AppStoreRenewSubscription.php +++ /dev/null @@ -1,62 +0,0 @@ -getSubscriptionId(); //$subscription_id - - nlog("inapp upgrade processing for = {$inapp_transaction_id}"); - - MultiDB::findAndSetDbByInappTransactionId($inapp_transaction_id); - - $account = Account::where('inapp_transaction_id', $inapp_transaction_id)->first(); - - if (!$account) { - $ninja_company = Company::on('db-ninja-01')->find(config('ninja.ninja_default_company_id')); - $ninja_company->notification(new RenewalFailureNotification("{$inapp_transaction_id}"))->ninja(); - return; - } - - if ($account->plan_term == 'month') { - $account->plan_expires = now()->addMonth(); - } elseif ($account->plan_term == 'year') { - $account->plan_expires = now()->addYear(); - } - - $account->save(); - } -} diff --git a/app/Listeners/Subscription/PlayStoreRenewSubscription.php b/app/Listeners/Subscription/PlayStoreRenewSubscription.php deleted file mode 100644 index 1a3bb1684f..0000000000 --- a/app/Listeners/Subscription/PlayStoreRenewSubscription.php +++ /dev/null @@ -1,49 +0,0 @@ -getServerNotification(); - nlog("google"); - nlog($notification); - $in_app_identifier = $event->getSubscriptionIdentifier(); - - $parts = explode("..", $in_app_identifier); - - MultiDB::findAndSetDbByInappTransactionId($parts[0]); - - $expirationTime = $event->getSubscription()->getExpiryTime(); - - $account = Account::where('inapp_transaction_id', 'like', $parts[0]."%")->first(); - - if ($account) { - $account->update(['plan_expires' => Carbon::parse($expirationTime)]); - } - - if (!$account) { - $ninja_company = Company::on('db-ninja-01')->find(config('ninja.ninja_default_company_id')); - $ninja_company->notification(new RenewalFailureNotification("{$in_app_identifier}"))->ninja(); - return; - } - } -} diff --git a/app/Models/Gateway.php b/app/Models/Gateway.php index 9c19e25202..aa1105b852 100644 --- a/app/Models/Gateway.php +++ b/app/Models/Gateway.php @@ -117,13 +117,10 @@ class Gateway extends StaticModel switch ($this->id) { case 1: return [GatewayType::CREDIT_CARD => ['refund' => true, 'token_billing' => true]]; //Authorize.net - break; case 3: return [GatewayType::CREDIT_CARD => ['refund' => false, 'token_billing' => true]]; //eWay - break; case 11: return [GatewayType::CREDIT_CARD => ['refund' => false, 'token_billing' => true]]; //Payfast - break; case 7: return [ GatewayType::CREDIT_CARD => ['refund' => false, 'token_billing' => true, 'webhooks' => [' ']], // Mollie @@ -136,31 +133,29 @@ class Gateway extends StaticModel return [ GatewayType::PAYPAL => ['refund' => false, 'token_billing' => false], ]; //Paypal - break; case 20: + case 56: return [ - GatewayType::CREDIT_CARD => ['refund' => true, 'token_billing' => true, 'webhooks' => ['payment_intent.succeeded']], - GatewayType::BANK_TRANSFER => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'customer.source.updated','payment_intent.processing']], - GatewayType::DIRECT_DEBIT => ['refund' => false, 'token_billing' => false, 'webhooks' => ['payment_intent.processing','payment_intent.succeeded','payment_intent.partially_funded']], + GatewayType::CREDIT_CARD => ['refund' => true, 'token_billing' => true, 'webhooks' => ['payment_intent.succeeded', 'payment_intent.payment_failed']], + GatewayType::BANK_TRANSFER => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'customer.source.updated','payment_intent.processing', 'payment_intent.payment_failed']], + GatewayType::DIRECT_DEBIT => ['refund' => false, 'token_billing' => false, 'webhooks' => ['payment_intent.processing','payment_intent.succeeded','payment_intent.partially_funded', 'payment_intent.payment_failed']], GatewayType::ALIPAY => ['refund' => false, 'token_billing' => false], GatewayType::APPLE_PAY => ['refund' => false, 'token_billing' => false], - GatewayType::BACS => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'payment_intent.processing', 'payment_intent.succeeded', 'mandate.updated']], - GatewayType::SOFORT => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'payment_intent.succeeded']], - GatewayType::KLARNA => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'payment_intent.succeeded']], - GatewayType::SEPA => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'payment_intent.succeeded']], - GatewayType::PRZELEWY24 => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'payment_intent.succeeded']], - GatewayType::GIROPAY => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'payment_intent.succeeded']], - GatewayType::EPS => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'payment_intent.succeeded']], - GatewayType::BANCONTACT => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'payment_intent.succeeded']], - GatewayType::BECS => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'payment_intent.succeeded']], - GatewayType::IDEAL => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'payment_intent.succeeded']], - GatewayType::ACSS => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'payment_intent.succeeded']], + GatewayType::BACS => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'payment_intent.processing', 'payment_intent.succeeded', 'mandate.updated', 'payment_intent.payment_failed']], + GatewayType::SOFORT => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'payment_intent.succeeded', 'payment_intent.payment_failed']], + GatewayType::KLARNA => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'payment_intent.succeeded', 'payment_intent.payment_failed']], + GatewayType::SEPA => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'payment_intent.succeeded', 'payment_intent.payment_failed']], + GatewayType::PRZELEWY24 => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'payment_intent.succeeded', 'payment_intent.payment_failed']], + GatewayType::GIROPAY => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'payment_intent.succeeded', 'payment_intent.payment_failed']], + GatewayType::EPS => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'payment_intent.succeeded', 'payment_intent.payment_failed']], + GatewayType::BANCONTACT => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'payment_intent.succeeded', 'payment_intent.payment_failed']], + GatewayType::BECS => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'payment_intent.succeeded', 'payment_intent.payment_failed']], + GatewayType::IDEAL => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'payment_intent.succeeded', 'payment_intent.payment_failed']], + GatewayType::ACSS => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'payment_intent.succeeded', 'payment_intent.payment_failed']], GatewayType::FPX => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded']], ]; - break; case 39: return [GatewayType::CREDIT_CARD => ['refund' => true, 'token_billing' => true, 'webhooks' => [' ']]]; //Checkout - break; case 46: return [GatewayType::CREDIT_CARD => ['refund' => true, 'token_billing' => true]]; //Paytrace case 49: @@ -168,40 +163,16 @@ class Gateway extends StaticModel GatewayType::CREDIT_CARD => ['refund' => true, 'token_billing' => true], GatewayType::BANK_TRANSFER => ['refund' => true, 'token_billing' => true, 'webhooks' => [' ']], ]; //WePay - break; case 50: return [ GatewayType::CREDIT_CARD => ['refund' => true, 'token_billing' => true], //Braintree GatewayType::PAYPAL => ['refund' => true, 'token_billing' => true], GatewayType::BANK_TRANSFER => ['refund' => true, 'token_billing' => true, 'webhooks' => [' ']], ]; - break; - case 56: //Stripe - return [ - GatewayType::CREDIT_CARD => ['refund' => true, 'token_billing' => true, 'webhooks' => ['payment_intent.succeeded']], - GatewayType::BANK_TRANSFER => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'customer.source.updated','payment_intent.processing']], - GatewayType::DIRECT_DEBIT => ['refund' => false, 'token_billing' => false, 'webhooks' => ['payment_intent.processing','payment_intent.succeeded','payment_intent.partially_funded']], - GatewayType::ALIPAY => ['refund' => false, 'token_billing' => false], - GatewayType::APPLE_PAY => ['refund' => false, 'token_billing' => false], - GatewayType::SOFORT => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'payment_intent.succeeded']], - GatewayType::KLARNA => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'payment_intent.succeeded']], - GatewayType::SEPA => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'payment_intent.succeeded']], - GatewayType::PRZELEWY24 => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'payment_intent.succeeded']], - GatewayType::GIROPAY => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'payment_intent.succeeded']], - GatewayType::EPS => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'payment_intent.succeeded']], - GatewayType::BANCONTACT => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'payment_intent.succeeded']], - GatewayType::BECS => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'payment_intent.succeeded']], - GatewayType::BACS => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'payment_intent.processing', 'payment_intent.succeeded', 'mandate.updated']], - GatewayType::IDEAL => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'payment_intent.succeeded']], - GatewayType::ACSS => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'payment_intent.succeeded']], - GatewayType::FPX => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded']], - ]; - break; case 57: return [ GatewayType::CREDIT_CARD => ['refund' => false, 'token_billing' => true], //Square ]; - break; case 52: return [ GatewayType::BANK_TRANSFER => ['refund' => false, 'token_billing' => true, 'webhooks' => [' ']], // GoCardless @@ -214,16 +185,13 @@ class Gateway extends StaticModel return [ GatewayType::HOSTED_PAGE => ['refund' => false, 'token_billing' => false, 'webhooks' => [' ']], // Razorpay ]; - break; case 59: return [ GatewayType::CREDIT_CARD => ['refund' => true, 'token_billing' => true], // Forte GatewayType::BANK_TRANSFER => ['refund' => true, 'token_billing' => true, 'webhooks' => [' ']], ]; - break; default: return []; - break; } } } diff --git a/app/Services/ClientPortal/InstantPayment.php b/app/Services/ClientPortal/InstantPayment.php index 3cdc656e15..b8cc2b6cba 100644 --- a/app/Services/ClientPortal/InstantPayment.php +++ b/app/Services/ClientPortal/InstantPayment.php @@ -266,6 +266,7 @@ class InstantPayment 'payment_method_id' => $payment_method_id, 'amount_with_fee' => $invoice_totals + $fee_totals, 'client' => $client, + 'pre_payment' => $this->request->pre_payment, ]; if ($is_credit_payment || $totals <= 0) { diff --git a/app/Services/Payment/UpdateInvoicePayment.php b/app/Services/Payment/UpdateInvoicePayment.php index 7f6b0372e8..295496a78b 100644 --- a/app/Services/Payment/UpdateInvoicePayment.php +++ b/app/Services/Payment/UpdateInvoicePayment.php @@ -100,7 +100,7 @@ class UpdateInvoicePayment $recurring_invoice = RecurringInvoiceFactory::create($invoice->company_id, $invoice->user_id); $recurring_invoice->client_id = $invoice->client_id; $recurring_invoice->line_items = $invoice->line_items; - $recurring_invoice->frequency_id = $this->payment_hash->data->is_recurring ?: RecurringInvoice::FREQUENCY_MONTHLY; + $recurring_invoice->frequency_id = $this->payment_hash->data->frequency_id ?: RecurringInvoice::FREQUENCY_MONTHLY; $recurring_invoice->date = now(); $recurring_invoice->remaining_cycles = $this->payment_hash->data->remaining_cycles; $recurring_invoice->auto_bill = 'always'; @@ -108,7 +108,11 @@ class UpdateInvoicePayment $recurring_invoice->due_date_days = 'on_receipt'; $recurring_invoice->next_send_date = now()->format('Y-m-d'); $recurring_invoice->next_send_date_client = now()->format('Y-m-d'); - + $recurring_invoice->amount = $invoice->amount; + $recurring_invoice->balance = $invoice->amount; + $recurring_invoice->status_id = RecurringInvoice::STATUS_ACTIVE; + $recurring_invoice->is_proforma = true; + $recurring_invoice->saveQuietly(); $recurring_invoice->next_send_date = $recurring_invoice->nextSendDate(); $recurring_invoice->next_send_date_client = $recurring_invoice->nextSendDateClient(); diff --git a/config/liap.php b/config/liap.php index f140554cf6..cbc569b294 100644 --- a/config/liap.php +++ b/config/liap.php @@ -2,7 +2,6 @@ use Imdhemy\Purchases\Events\AppStore\DidRenew; use App\Listeners\Subscription\AppStoreRenewSubscription; -use App\Listeners\Subscription\PlayStoreRenewSubscription; use Imdhemy\Purchases\Events\GooglePlay\SubscriptionRenewed; return [ @@ -97,8 +96,9 @@ return [ /* \Imdhemy\Purchases\Events\GooglePlay\SubscriptionRecovered::class => [ \App\Listeners\GooglePlay\SubscriptionRecovered::class, ],*/ - SubscriptionRenewed::class => [PlayStoreRenewSubscription::class], - DidRenew::class => [AppStoreRenewSubscription::class], + + DidRenew::class => class_exists(\Modules\Admin\Listeners\Subscription\AppleAutoRenew::class) ? [\Modules\Admin\Listeners\Subscription\AppleAutoRenew::class] : [], + SubscriptionRenewed::class => class_exists(\Modules\Admin\Listeners\Subscription\GoogleAutoRenew::class) ? [\Modules\Admin\Listeners\Subscription\GoogleAutoRenew::class] : [], ], diff --git a/config/ninja.php b/config/ninja.php index e847e0c1d3..0006bbeaa1 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -213,4 +213,5 @@ return [ 'config_name' => env("YODLEE_CONFIG_NAME", false), ], 'licenses' => env('LICENSES',false), + 'google_application_credentials' => env("GOOGLE_APPLICATION_CREDENTIALS", false), ]; diff --git a/resources/views/portal/ninja2020/gateways/includes/save_card.blade.php b/resources/views/portal/ninja2020/gateways/includes/save_card.blade.php index 7a4ea8b41a..ce4967258a 100644 --- a/resources/views/portal/ninja2020/gateways/includes/save_card.blade.php +++ b/resources/views/portal/ninja2020/gateways/includes/save_card.blade.php @@ -21,6 +21,10 @@ $checked_off = ''; } + if (isset($pre_payment) && $pre_payment == '1') { + $token_billing_string = 'true'; + } + @endphp @if($token_billing) diff --git a/resources/views/portal/ninja2020/gateways/stripe/credit_card/pay.blade.php b/resources/views/portal/ninja2020/gateways/stripe/credit_card/pay.blade.php index 295a532708..d4d81ef11d 100644 --- a/resources/views/portal/ninja2020/gateways/stripe/credit_card/pay.blade.php +++ b/resources/views/portal/ninja2020/gateways/stripe/credit_card/pay.blade.php @@ -7,6 +7,11 @@ if($gateway_instance->token_billing == 'off' || $gateway_instance->token_billing == 'optin'){ $token_billing_string = 'false'; } + + if (isset($pre_payment) && $pre_payment == '1') { + $token_billing_string = 'true'; + } + @endphp