diff --git a/app/Livewire/BillingPortalPurchase.php b/app/Livewire/BillingPortalPurchase.php index 34afb10309..f50fc723f9 100644 --- a/app/Livewire/BillingPortalPurchase.php +++ b/app/Livewire/BillingPortalPurchase.php @@ -469,8 +469,12 @@ class BillingPortalPurchase extends Component $context = 'purchase'; - if (Ninja::isHosted() && $this->subscription->service()->recurring_products()->first()?->product_key == 'whitelabel') { + if (config('ninja.ninja_default_company_id') == $this->subscription->company_id && $this->subscription->service()->recurring_products()->first()?->product_key == 'whitelabel') { $context = 'whitelabel'; + } + + if (config('ninja.ninja_default_company_id') == $this->subscription->company_id && in_array($this->subscription->service()->products()->first()?->product_key,['peppol_500','peppol_1000','selfhost_peppol_500','selfhost_peppol_1000'])) { + $context = $this->subscription->service()->products()->first()?->product_key; } Cache::put($this->hash, [ diff --git a/app/Mail/Ninja/StripeConnectFailed.php b/app/Mail/Ninja/StripeConnectFailed.php index bee93bd114..1511d0f1c8 100644 --- a/app/Mail/Ninja/StripeConnectFailed.php +++ b/app/Mail/Ninja/StripeConnectFailed.php @@ -52,41 +52,15 @@ class StripeConnectFailed extends Mailable { return new Content( - view: 'email.admin.stripe_connect_failed', - text: 'email.admin.stripe_connect_failed_text', + view: 'email.einvoice.peppol_purchase_allocation_failed', + text: 'email.einvoice.peppol_purchase_allocation_failed_text', with: [ - 'text_body' => $this->textBody(), //@todo this is a bit hacky here. - 'body' => $this->htmlBody(), - 'title' => 'Connect your Stripe account', - 'settings' => $this->company->settings, - 'logo' => $this->company->present()->logo(), - 'signature' => '', - 'company' => $this->company, - 'greeting' => '', - 'links' => [], - 'url' => 'https://www.loom.com/share/a3dc3131cc924e14a34634d5d48065c8?sid=b1971aa2-9deb-4339-8ebd-53f9947ef633', - 'button' => "texts.view" + ] ); } - private function textBody() - { - return " - We note you are yet to connect your Stripe account to Invoice Ninja. Please log in to Invoice Ninja and connect your Stripe account.\n\n - Once logged in you can use the following resource to connect your Stripe account: \n\n - "; - } - - private function htmlBody() - { - return " - We note you are yet to connect your Stripe account to Invoice Ninja. Please log in to Invoice Ninja and connect your Stripe account.

- - Once logged in you can use the following resource to connect your Stripe account:

- - "; - } + /** * Get the attachments for the message. * diff --git a/app/Services/Subscription/SubscriptionService.php b/app/Services/Subscription/SubscriptionService.php index 5cac37bde5..d754ea4944 100644 --- a/app/Services/Subscription/SubscriptionService.php +++ b/app/Services/Subscription/SubscriptionService.php @@ -61,6 +61,13 @@ class SubscriptionService public const WHITE_LABEL = 4316; + private array $peppol_keys = [ + 'peppol_500', + 'peppol_1000', + 'selfhost_peppol_500', + 'selfhost_peppol_1000', + ]; + private float $credit_payments = 0; public function __construct(Subscription $subscription) @@ -86,6 +93,9 @@ class SubscriptionService return $this->handleWhiteLabelPurchase($payment_hash); } + if (in_array($payment_hash->data->billing_context->context, $this->peppol_keys)) { + return $this->handlePeppolPurchase($payment_hash); + } // if we have a recurring product - then generate a recurring invoice if (strlen($this->subscription->recurring_product_ids ?? '') >= 1) { @@ -168,6 +178,15 @@ class SubscriptionService return $response; } + private function handlePeppolPurchase(PaymentHash $payment_hash) + { + + if (class_exists(\Modules\Admin\Jobs\Account\PeppolPurchase::class)) { + (new \Modules\Admin\Jobs\Account\PeppolPurchase($payment_hash))->run(); + } + + } + private function handleWhiteLabelPurchase(PaymentHash $payment_hash): bool { //send license to the user. @@ -189,7 +208,6 @@ class SubscriptionService //update the invoice and attach to the recurring invoice!!!!! $invoice->recurring_id = $recurring_invoice->id; $invoice->is_proforma = false; - // $invoice->service()->deletePdf(); $invoice->save(); $contact = $invoice->client->contacts()->whereNotNull('email')->first(); @@ -1176,9 +1194,9 @@ class SubscriptionService $keys = $this->transformKeys(explode(",", $this->subscription->product_ids)); if (is_array($keys)) { - return Product::query()->whereIn('id', $keys)->get(); + return Product::query()->where('company_id', $this->subscription->company_id)->whereIn('id', $keys)->get(); } else { - return Product::query()->where('id', $keys)->get(); + return Product::query()->where('company_id', $this->subscription->company_id)->where('id', $keys)->get(); } } @@ -1196,9 +1214,9 @@ class SubscriptionService $keys = $this->transformKeys(explode(",", $this->subscription->recurring_product_ids)); if (is_array($keys)) { - return Product::query()->whereIn('id', $keys)->get(); + return Product::query()->where('company_id', $this->subscription->company_id)->whereIn('id', $keys)->get(); } else { - return Product::query()->where('id', $keys)->get(); + return Product::query()->where('company_id', $this->subscription->company_id)->where('id', $keys)->get(); } } @@ -1217,9 +1235,9 @@ class SubscriptionService $keys = $this->transformKeys(explode(",", $this->subscription->optional_product_ids)); if (is_array($keys)) { - return Product::query()->whereIn('id', $keys)->get(); + return Product::query()->where('company_id', $this->subscription->company_id)->whereIn('id', $keys)->get(); } else { - return Product::query()->where('id', $keys)->get(); + return Product::query()->where('company_id', $this->subscription->company_id)->where('id', $keys)->get(); } } @@ -1237,9 +1255,9 @@ class SubscriptionService $keys = $this->transformKeys(explode(",", $this->subscription->optional_recurring_product_ids)); if (is_array($keys)) { - return Product::query()->whereIn('id', $keys)->get(); + return Product::query()->where('company_id', $this->subscription->company_id)->whereIn('id', $keys)->get(); } else { - return Product::query()->where('id', $keys)->get(); + return Product::query()->where('company_id', $this->subscription->company_id)->where('id', $keys)->get(); } }