diff --git a/app/DataMapper/Tax/BaseRule.php b/app/DataMapper/Tax/BaseRule.php index 06ca9b9f5d23..714fd3c3c317 100644 --- a/app/DataMapper/Tax/BaseRule.php +++ b/app/DataMapper/Tax/BaseRule.php @@ -14,8 +14,9 @@ namespace App\DataMapper\Tax; use App\Models\Client; use App\Models\Invoice; use App\Models\Product; -use App\DataMapper\Tax\ZipTax\Response; +use App\DataMapper\Tax\TaxData; use App\DataProviders\USStates; +use App\DataMapper\Tax\ZipTax\Response; 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)) { - 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]; @@ -157,14 +160,17 @@ class BaseRule implements RuleInterface return $this; //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) { - $tax_data = $this->invoice->tax_data; $tax_data->originDestination = "D"; $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; diff --git a/app/DataMapper/Tax/ZipTax/Response.php b/app/DataMapper/Tax/ZipTax/Response.php index 255c5f6ec8b4..2a7e9d347337 100644 --- a/app/DataMapper/Tax/ZipTax/Response.php +++ b/app/DataMapper/Tax/ZipTax/Response.php @@ -100,7 +100,7 @@ class Response 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) { diff --git a/app/Helpers/Invoice/InvoiceItemSum.php b/app/Helpers/Invoice/InvoiceItemSum.php index eccd827a9aa6..dd2d9b2e434e 100644 --- a/app/Helpers/Invoice/InvoiceItemSum.php +++ b/app/Helpers/Invoice/InvoiceItemSum.php @@ -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->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"; $this->rule = new $class(); diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index 2c6cc2ef8b3d..74b4dcd0c4d5 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -62,84 +62,6 @@ class AccountController extends BaseController * @param CreateAccountRequest $request * @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) { diff --git a/app/Http/Livewire/BillingPortalPurchase.php b/app/Http/Livewire/BillingPortalPurchase.php index 02f4158c8379..d38dbf9965d3 100644 --- a/app/Http/Livewire/BillingPortalPurchase.php +++ b/app/Http/Livewire/BillingPortalPurchase.php @@ -405,8 +405,6 @@ class BillingPortalPurchase extends Component $context = 'whitelabel'; } - $utm = isset($this->request_data['utm']) ? $this->request_data['utm'] : null; - Cache::put($this->hash, [ 'subscription_id' => $this->subscription->hashed_id, 'email' => $this->email ?? $this->contact->email, @@ -414,7 +412,6 @@ class BillingPortalPurchase extends Component 'invoice_id' => $this->invoice->hashed_id, 'context' => $context, 'campaign' => $this->campaign, - 'utm' => $utm, ], now()->addMinutes(60)); $this->emit('beforePaymentEventsCompleted'); @@ -447,15 +444,13 @@ class BillingPortalPurchase extends Component return; } - $utm = isset($this->request_data['utm']) ? $this->request_data['utm'] : null; - return $this->subscription->service()->handleNoPaymentRequired([ 'email' => $this->email ?? $this->contact->email, 'quantity' => $this->quantity, 'contact_id' => $this->contact->id, 'client_id' => $this->contact->client->id, 'coupon' => $this->coupon, - 'utm' => $utm + 'campaign' => $this->campaign, ]); } diff --git a/app/Http/Livewire/BillingPortalPurchasev2.php b/app/Http/Livewire/BillingPortalPurchasev2.php index 3ca864981e84..aaf9bf65cbfe 100644 --- a/app/Http/Livewire/BillingPortalPurchasev2.php +++ b/app/Http/Livewire/BillingPortalPurchasev2.php @@ -529,8 +529,6 @@ class BillingPortalPurchasev2 extends Component ->adjustInventory() ->save(); - $utm = isset($this->request_data['utm']) ? $this->request_data['utm'] : null; - Cache::put($this->hash, [ 'subscription_id' => $this->subscription->hashed_id, 'email' => $this->email ?? $this->contact->email, @@ -539,7 +537,6 @@ class BillingPortalPurchasev2 extends Component 'context' => 'purchase', 'campaign' => $this->campaign, 'bundle' => $this->bundle, - 'utm' => $utm, ], now()->addMinutes(60)); $this->emit('beforePaymentEventsCompleted'); diff --git a/app/Jobs/Account/CreateAccount.php b/app/Jobs/Account/CreateAccount.php index daf79f32811e..0444cf7310c3 100644 --- a/app/Jobs/Account/CreateAccount.php +++ b/app/Jobs/Account/CreateAccount.php @@ -47,13 +47,13 @@ class CreateAccount public function handle() { - if (config('ninja.environment') == 'selfhost' && Account::count() == 0) { - return $this->create(); - } elseif (config('ninja.environment') == 'selfhost' && Account::count() > 1) { - return response()->json(['message' => Ninja::selfHostedMessage()], 400); - } elseif (! Ninja::boot()) { - return response()->json(['message' => Ninja::parse()], 401); - } + // if (config('ninja.environment') == 'selfhost' && Account::count() == 0) { + // return $this->create(); + // } elseif (config('ninja.environment') == 'selfhost' && Account::count() > 1) { + // return response()->json(['message' => Ninja::selfHostedMessage()], 400); + // } elseif (! Ninja::boot()) { + // return response()->json(['message' => Ninja::parse()], 401); + // } return $this->create(); } diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index a6bd4638e8cb..a2af497142a0 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -11,24 +11,24 @@ 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\Traits\Invoice\ActionsInvoice; +use Illuminate\Support\Carbon; 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\NumberFormatter; -use Illuminate\Database\Eloquent\SoftDeletes; -use Illuminate\Support\Carbon; +use App\Services\Ledger\LedgerService; 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 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 diff --git a/app/Services/Subscription/SubscriptionService.php b/app/Services/Subscription/SubscriptionService.php index 50fca10a4daa..955e567f62f1 100644 --- a/app/Services/Subscription/SubscriptionService.php +++ b/app/Services/Subscription/SubscriptionService.php @@ -121,8 +121,8 @@ class SubscriptionService 'account_key' => $recurring_invoice->client->custom_value2, ]; - if (!property_exists($payment_hash->data->billing_context, 'utm') && $payment_hash->data->billing_context->utm) { - $context['utm'] = $payment_hash->data->billing_context->utm; + if (property_exists($payment_hash->data->billing_context, 'campaign')) { + $context['campaign'] = $payment_hash->data->billing_context->campaign; } $response = $this->triggerWebhook($context); diff --git a/app/Services/Subscription/ZeroCostProduct.php b/app/Services/Subscription/ZeroCostProduct.php index 9dfe2f3182de..b73cc146cf93 100644 --- a/app/Services/Subscription/ZeroCostProduct.php +++ b/app/Services/Subscription/ZeroCostProduct.php @@ -22,12 +22,12 @@ class ZeroCostProduct extends AbstractService private $data; /** - $data = [ - 'email' => $this->email ?? $this->contact->email, - 'quantity' => $this->quantity, - 'contact_id' => $this->contact->id, - 'client_id' => $this->contact->client->id, - ]; + * $data = [ + * 'email' => $this->email ?? $this->contact->email, + * 'quantity' => $this->quantity, + * 'contact_id' => $this->contact->id, + * 'client_id' => $this->contact->client->id, + * ]; */ public function __construct(Subscription $subscription, array $data) { @@ -79,8 +79,8 @@ class ZeroCostProduct extends AbstractService 'redirect_url' => "/client/recurring_invoices/{$recurring_invoice->hashed_id}", ]; - if(isset($this->data['utm'])) - $context['utm'] = $this->data['utm']; + if(isset($this->data['campaign'])) + $context['campaign'] = $this->data['campaign']; return $context; }