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

Fixes for subscriptions

This commit is contained in:
David Bomba 2023-04-29 16:04:42 +10:00
parent ef0fd30767
commit 06e2bcbf83
10 changed files with 45 additions and 123 deletions

View File

@ -14,8 +14,9 @@ namespace App\DataMapper\Tax;
use App\Models\Client; use App\Models\Client;
use App\Models\Invoice; use App\Models\Invoice;
use App\Models\Product; use App\Models\Product;
use App\DataMapper\Tax\ZipTax\Response; use App\DataMapper\Tax\TaxData;
use App\DataProviders\USStates; use App\DataProviders\USStates;
use App\DataMapper\Tax\ZipTax\Response;
class BaseRule implements RuleInterface class BaseRule implements RuleInterface
{ {
@ -148,7 +149,9 @@ class BaseRule implements RuleInterface
{ {
if(!array_key_exists($this->client->country->iso_3166_2, $this->region_codes)) { if(!array_key_exists($this->client->country->iso_3166_2, $this->region_codes)) {
throw new \Exception('Automatic tax calculations not supported for this country'); $this->client->country_id = $this->invoice->company->settings->country_id;
$this->client->saveQuietly();
nlog('Automatic tax calculations not supported for this country - defaulting to company country');
} }
$this->client_region = $this->region_codes[$this->client->country->iso_3166_2]; $this->client_region = $this->region_codes[$this->client->country->iso_3166_2];
@ -157,14 +160,17 @@ class BaseRule implements RuleInterface
return $this; return $this;
//determine if we are taxing locally or if we are taxing globally //determine if we are taxing locally or if we are taxing globally
$this->invoice->tax_data = $this->invoice->client->tax_data ?: new Response([]); $tax_data = $this->invoice->client->tax_data ?? new Response([]);
if(strlen($this->invoice->tax_data?->originDestination) == 0 && $this->client->company->tax_data->seller_subregion != $this->client_subregion) { if(strlen($this->invoice->tax_data?->originDestination) == 0 && $this->client->company->tax_data->seller_subregion != $this->client_subregion) {
$tax_data = $this->invoice->tax_data;
$tax_data->originDestination = "D"; $tax_data->originDestination = "D";
$tax_data->geoState = $this->client_subregion; $tax_data->geoState = $this->client_subregion;
$this->invoice->tax_data = $tax_data;
$this->invoice->saveQuietly(); if($this->invoice instanceof Invoice) {
$this->invoice->tax_data = $tax_data;
$this->invoice->saveQuietly();
}
} }
return $this; return $this;

View File

@ -100,7 +100,7 @@ class Response
public string $originDestination = ""; // defines if the client origin is the locale where the tax is remitted to public string $originDestination = ""; // defines if the client origin is the locale where the tax is remitted to
public function __construct($data) public function __construct($data = null)
{ {
if($data) { if($data) {

View File

@ -148,6 +148,8 @@ class InvoiceItemSum
// if (in_array($this->client->country->iso_3166_2, $this->tax_jurisdictions)) { //only calculate for supported tax jurisdictions // if (in_array($this->client->country->iso_3166_2, $this->tax_jurisdictions)) { //only calculate for supported tax jurisdictions
if (in_array($this->client->company->country()->iso_3166_2, $this->tax_jurisdictions)) { //only calculate for supported tax jurisdictions if (in_array($this->client->company->country()->iso_3166_2, $this->tax_jurisdictions)) { //only calculate for supported tax jurisdictions
nlog($this->client->company->country()->iso_3166_2);
$class = "App\DataMapper\Tax\\".$this->client->company->country()->iso_3166_2."\\Rule"; $class = "App\DataMapper\Tax\\".$this->client->company->country()->iso_3166_2."\\Rule";
$this->rule = new $class(); $this->rule = new $class();

View File

@ -62,84 +62,6 @@ class AccountController extends BaseController
* @param CreateAccountRequest $request * @param CreateAccountRequest $request
* @return Response * @return Response
* *
* @OA\Post(
* path="/api/v1/signup",
* operationId="postSignup",
* tags={"signup"},
* summary="Attempts a new account signup",
* description="Attempts a new account signup and returns a CompanyUser object on success",
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
* @OA\Parameter(
* name="token_name",
* in="query",
* description="A custom name for the user company token",
* example="Daves iOS Device",
* required=true,
* @OA\Schema(
* type="string",
* format="string",
* ),
* ),
* @OA\RequestBody(
* description="Signup credentials",
* required=true,
* @OA\MediaType(
* mediaType="application/json",
* @OA\Schema(
* type="object",
* @OA\Property(
* property="email",
* description="The user email address",
* type="string",
* ),
* @OA\Property(
* property="first_name",
* description="The signup users first name",
* type="string",
* ),
* @OA\Property(
* property="last_name",
* description="The signup users last name",
* type="string",
* ),
* @OA\Property(
* property="terms_of_service",
* description="The user accepted the terms of service",
* type="boolean",
* ),
* @OA\Property(
* property="privacy_policy",
* description="The user accepted the privacy policy",
* type="boolean",
* ),
* @OA\Property(
* property="password",
* example="1234567",
* description="The user password must meet minimum criteria ~ >6 characters",
* type="string"
* )
* )
* )
* ),
* @OA\Response(
* response=200,
* description="The Company User response",
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
* @OA\JsonContent(ref="#/components/schemas/CompanyUser"),
* ),
* @OA\Response(
* response=422,
* description="Validation error",
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
* ),
* @OA\Response(
* response="default",
* description="Unexpected Error",
* @OA\JsonContent(ref="#/components/schemas/Error"),
* ),
* )
*/ */
public function store(CreateAccountRequest $request) public function store(CreateAccountRequest $request)
{ {

View File

@ -405,8 +405,6 @@ class BillingPortalPurchase extends Component
$context = 'whitelabel'; $context = 'whitelabel';
} }
$utm = isset($this->request_data['utm']) ? $this->request_data['utm'] : null;
Cache::put($this->hash, [ Cache::put($this->hash, [
'subscription_id' => $this->subscription->hashed_id, 'subscription_id' => $this->subscription->hashed_id,
'email' => $this->email ?? $this->contact->email, 'email' => $this->email ?? $this->contact->email,
@ -414,7 +412,6 @@ class BillingPortalPurchase extends Component
'invoice_id' => $this->invoice->hashed_id, 'invoice_id' => $this->invoice->hashed_id,
'context' => $context, 'context' => $context,
'campaign' => $this->campaign, 'campaign' => $this->campaign,
'utm' => $utm,
], now()->addMinutes(60)); ], now()->addMinutes(60));
$this->emit('beforePaymentEventsCompleted'); $this->emit('beforePaymentEventsCompleted');
@ -447,15 +444,13 @@ class BillingPortalPurchase extends Component
return; return;
} }
$utm = isset($this->request_data['utm']) ? $this->request_data['utm'] : null;
return $this->subscription->service()->handleNoPaymentRequired([ return $this->subscription->service()->handleNoPaymentRequired([
'email' => $this->email ?? $this->contact->email, 'email' => $this->email ?? $this->contact->email,
'quantity' => $this->quantity, 'quantity' => $this->quantity,
'contact_id' => $this->contact->id, 'contact_id' => $this->contact->id,
'client_id' => $this->contact->client->id, 'client_id' => $this->contact->client->id,
'coupon' => $this->coupon, 'coupon' => $this->coupon,
'utm' => $utm 'campaign' => $this->campaign,
]); ]);
} }

View File

@ -529,8 +529,6 @@ class BillingPortalPurchasev2 extends Component
->adjustInventory() ->adjustInventory()
->save(); ->save();
$utm = isset($this->request_data['utm']) ? $this->request_data['utm'] : null;
Cache::put($this->hash, [ Cache::put($this->hash, [
'subscription_id' => $this->subscription->hashed_id, 'subscription_id' => $this->subscription->hashed_id,
'email' => $this->email ?? $this->contact->email, 'email' => $this->email ?? $this->contact->email,
@ -539,7 +537,6 @@ class BillingPortalPurchasev2 extends Component
'context' => 'purchase', 'context' => 'purchase',
'campaign' => $this->campaign, 'campaign' => $this->campaign,
'bundle' => $this->bundle, 'bundle' => $this->bundle,
'utm' => $utm,
], now()->addMinutes(60)); ], now()->addMinutes(60));
$this->emit('beforePaymentEventsCompleted'); $this->emit('beforePaymentEventsCompleted');

View File

@ -47,13 +47,13 @@ class CreateAccount
public function handle() public function handle()
{ {
if (config('ninja.environment') == 'selfhost' && Account::count() == 0) { // if (config('ninja.environment') == 'selfhost' && Account::count() == 0) {
return $this->create(); // return $this->create();
} elseif (config('ninja.environment') == 'selfhost' && Account::count() > 1) { // } elseif (config('ninja.environment') == 'selfhost' && Account::count() > 1) {
return response()->json(['message' => Ninja::selfHostedMessage()], 400); // return response()->json(['message' => Ninja::selfHostedMessage()], 400);
} elseif (! Ninja::boot()) { // } elseif (! Ninja::boot()) {
return response()->json(['message' => Ninja::parse()], 401); // return response()->json(['message' => Ninja::parse()], 401);
} // }
return $this->create(); return $this->create();
} }

View File

@ -11,24 +11,24 @@
namespace App\Models; namespace App\Models;
use App\Events\Invoice\InvoiceReminderWasEmailed;
use App\Events\Invoice\InvoiceWasEmailed;
use App\Helpers\Invoice\InvoiceSum;
use App\Helpers\Invoice\InvoiceSumInclusive;
use App\Jobs\Entity\CreateEntityPdf;
use App\Models\Presenters\InvoicePresenter;
use App\Services\Invoice\InvoiceService;
use App\Services\Ledger\LedgerService;
use App\Utils\Ninja; use App\Utils\Ninja;
use App\Utils\Traits\Invoice\ActionsInvoice; use Illuminate\Support\Carbon;
use App\Utils\Traits\MakesDates; use App\Utils\Traits\MakesDates;
use App\Utils\Traits\MakesInvoiceValues; use App\Helpers\Invoice\InvoiceSum;
use App\Jobs\Entity\CreateEntityPdf;
use App\Utils\Traits\MakesReminders; use App\Utils\Traits\MakesReminders;
use App\Utils\Traits\NumberFormatter; use App\Utils\Traits\NumberFormatter;
use Illuminate\Database\Eloquent\SoftDeletes; use App\Services\Ledger\LedgerService;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
use App\Services\Invoice\InvoiceService;
use App\Utils\Traits\MakesInvoiceValues;
use App\Events\Invoice\InvoiceWasEmailed;
use Laracasts\Presenter\PresentableTrait; use Laracasts\Presenter\PresentableTrait;
use App\Models\Presenters\InvoicePresenter;
use App\Helpers\Invoice\InvoiceSumInclusive;
use App\Utils\Traits\Invoice\ActionsInvoice;
use Illuminate\Database\Eloquent\SoftDeletes;
use App\Events\Invoice\InvoiceReminderWasEmailed;
/** /**
* App\Models\Invoice * App\Models\Invoice

View File

@ -121,8 +121,8 @@ class SubscriptionService
'account_key' => $recurring_invoice->client->custom_value2, 'account_key' => $recurring_invoice->client->custom_value2,
]; ];
if (!property_exists($payment_hash->data->billing_context, 'utm') && $payment_hash->data->billing_context->utm) { if (property_exists($payment_hash->data->billing_context, 'campaign')) {
$context['utm'] = $payment_hash->data->billing_context->utm; $context['campaign'] = $payment_hash->data->billing_context->campaign;
} }
$response = $this->triggerWebhook($context); $response = $this->triggerWebhook($context);

View File

@ -22,12 +22,12 @@ class ZeroCostProduct extends AbstractService
private $data; private $data;
/** /**
$data = [ * $data = [
'email' => $this->email ?? $this->contact->email, * 'email' => $this->email ?? $this->contact->email,
'quantity' => $this->quantity, * 'quantity' => $this->quantity,
'contact_id' => $this->contact->id, * 'contact_id' => $this->contact->id,
'client_id' => $this->contact->client->id, * 'client_id' => $this->contact->client->id,
]; * ];
*/ */
public function __construct(Subscription $subscription, array $data) public function __construct(Subscription $subscription, array $data)
{ {
@ -79,8 +79,8 @@ class ZeroCostProduct extends AbstractService
'redirect_url' => "/client/recurring_invoices/{$recurring_invoice->hashed_id}", 'redirect_url' => "/client/recurring_invoices/{$recurring_invoice->hashed_id}",
]; ];
if(isset($this->data['utm'])) if(isset($this->data['campaign']))
$context['utm'] = $this->data['utm']; $context['campaign'] = $this->data['campaign'];
return $context; return $context;
} }