mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Fixes for subscription refactor
This commit is contained in:
parent
83c636aa55
commit
3479c127fd
@ -30,15 +30,18 @@ class SubscriptionRepository extends BaseRepository
|
||||
public function save($data, Subscription $subscription): ?Subscription
|
||||
{
|
||||
$subscription->fill($data);
|
||||
|
||||
$subscription->price = $this->calculatePrice($subscription);
|
||||
|
||||
$calculated_prices = $this->calculatePrice($subscription);
|
||||
|
||||
$subscription->price = $calculated_prices['price'];
|
||||
$subscription->promo_price = $calculated_prices['promo_price'];
|
||||
|
||||
$subscription->save();
|
||||
|
||||
return $subscription;
|
||||
}
|
||||
|
||||
private function calculatePrices($subscription) :array
|
||||
private function calculatePrice($subscription) :array
|
||||
{
|
||||
|
||||
DB::beginTransaction();
|
||||
@ -61,10 +64,13 @@ class SubscriptionRepository extends BaseRepository
|
||||
]);
|
||||
|
||||
$invoice = InvoiceFactory::create($subscription->company_id, $subscription->user_id);
|
||||
$invoice->client_id = $client->id;
|
||||
|
||||
$invoice->save();
|
||||
|
||||
$invitation = InvoiceInvitation::factory()->create([
|
||||
'user_id' => $subscription->user_id,
|
||||
'company_id' => $subscription->company_id,
|
||||
'user_id' => $subscription->user_id,
|
||||
'company_id' => $subscription->company_id,
|
||||
'invoice_id' => $invoice->id,
|
||||
'client_contact_id' => $contact->id,
|
||||
]);
|
||||
@ -73,8 +79,8 @@ class SubscriptionRepository extends BaseRepository
|
||||
$invoice->setRelation('client', $client);
|
||||
$invoice->setRelation('company', $subscription->company);
|
||||
$invoice->load('client');
|
||||
|
||||
$invoice->line_items = $this->generateLineItems($subscription);
|
||||
|
||||
$data['price'] = $invoice->calc()->getTotal();
|
||||
|
||||
$invoice->discount = $subscription->promo_discount;
|
||||
@ -94,12 +100,12 @@ class SubscriptionRepository extends BaseRepository
|
||||
|
||||
foreach($subscription->service()->products() as $product)
|
||||
{
|
||||
$line_items[] = $this->makeLineItem($product);
|
||||
$line_items[] = (array)$this->makeLineItem($product);
|
||||
}
|
||||
|
||||
foreach($subscription->service()->recurring_products() as $product)
|
||||
{
|
||||
$line_items[] = $this->makeLineItem($product);
|
||||
$line_items[] = (array)$this->makeLineItem($product);
|
||||
}
|
||||
|
||||
$line_items = $this->cleanItems($line_items);
|
||||
|
@ -118,8 +118,6 @@ class SubscriptionService
|
||||
|
||||
if(!$invoice)
|
||||
throw new \Exception("Could not match an invoice for payment of billing subscription");
|
||||
|
||||
//todo - need to remove the promo code - if it exists
|
||||
|
||||
return InvoiceToRecurringInvoiceFactory::create($invoice);
|
||||
|
||||
|
@ -80,6 +80,7 @@ class SubscriptionApiTest extends TestCase
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/subscriptions', ['product_ids' => $product->id, 'allow_cancellation' => true]);
|
||||
|
||||
// nlog($response);
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user