1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +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\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;

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 function __construct($data)
public function __construct($data = null)
{
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->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();

View File

@ -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)
{

View File

@ -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,
]);
}

View File

@ -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');

View File

@ -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();
}

View File

@ -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

View File

@ -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);

View File

@ -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;
}