Fixes for subscriptions

This commit is contained in:
= 2021-03-24 10:43:21 +11:00
parent 90540d6403
commit 946ab58f13
3 changed files with 34 additions and 3 deletions

View File

@ -46,7 +46,7 @@ class BillingSubscriptionService
public function completePurchase(PaymentHash $payment_hash) public function completePurchase(PaymentHash $payment_hash)
{ {
if (!property_exists($payment_hash, 'billing_context')) { if (!property_exists($payment_hash->data, 'billing_context')) {
throw new \Exception("Illegal entrypoint into method, payload must contain billing context"); throw new \Exception("Illegal entrypoint into method, payload must contain billing context");
} }
@ -79,7 +79,7 @@ class BillingSubscriptionService
$cs->subscription_id = $this->billing_subscription->id; $cs->subscription_id = $this->billing_subscription->id;
$cs->company_id = $this->billing_subscription->company_id; $cs->company_id = $this->billing_subscription->company_id;
$cs->trial_started = time(); $cs->trial_started = time();
$cs->trial_duration = time() + $this->billing_subscription->trial_duration; $cs->trial_ends = time() + $this->billing_subscription->trial_duration;
$cs->quantity = $data['quantity']; $cs->quantity = $data['quantity'];
$cs->client_id = $contact->client->id; $cs->client_id = $contact->client->id;
$cs->save(); $cs->save();

View File

@ -34,6 +34,8 @@ class BillingSubscriptionTransformer extends EntityTransformer
public function transform(BillingSubscription $billing_subscription): array public function transform(BillingSubscription $billing_subscription): array
{ {
$std = new stdClass;
return [ return [
'id' => $this->encodePrimaryKey($billing_subscription->id), 'id' => $this->encodePrimaryKey($billing_subscription->id),
'user_id' => $this->encodePrimaryKey($billing_subscription->user_id), 'user_id' => $this->encodePrimaryKey($billing_subscription->user_id),
@ -56,7 +58,7 @@ class BillingSubscriptionTransformer extends EntityTransformer
'allow_plan_changes' => (bool)$billing_subscription->allow_plan_changes, 'allow_plan_changes' => (bool)$billing_subscription->allow_plan_changes,
'plan_map' => (string)$billing_subscription->plan_map, 'plan_map' => (string)$billing_subscription->plan_map,
'refund_period' => (int)$billing_subscription->refund_period, 'refund_period' => (int)$billing_subscription->refund_period,
'webhook_configuration' => (string)$billing_subscription->webhook_configuration, 'webhook_configuration' => $billing_subscription->webhook_configuration ?: $std,
'purchase_page' => (string)route('client.subscription.purchase', $billing_subscription->hashed_id), 'purchase_page' => (string)route('client.subscription.purchase', $billing_subscription->hashed_id),
'is_deleted' => (bool)$billing_subscription->is_deleted, 'is_deleted' => (bool)$billing_subscription->is_deleted,
'created_at' => (int)$billing_subscription->created_at, 'created_at' => (int)$billing_subscription->created_at,

View File

@ -0,0 +1,29 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddNullableConstraintToRecurringInvoiceId extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('client_subscriptions', function (Blueprint $table) {
$table->unsignedInteger('recurring_invoice_id')->nullable()->change();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
}
}