From 946ab58f135ac69fa8cb4fb9a1a7711c73069312 Mon Sep 17 00:00:00 2001 From: = Date: Wed, 24 Mar 2021 10:43:21 +1100 Subject: [PATCH] Fixes for subscriptions --- .../BillingSubscriptionService.php | 4 +-- .../BillingSubscriptionTransformer.php | 4 ++- ...ble_constraint_to_recurring_invoice_id.php | 29 +++++++++++++++++++ 3 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 database/migrations/2021_03_23_233844_add_nullable_constraint_to_recurring_invoice_id.php diff --git a/app/Services/BillingSubscription/BillingSubscriptionService.php b/app/Services/BillingSubscription/BillingSubscriptionService.php index 8b6591219b73..acb39acf4635 100644 --- a/app/Services/BillingSubscription/BillingSubscriptionService.php +++ b/app/Services/BillingSubscription/BillingSubscriptionService.php @@ -46,7 +46,7 @@ class BillingSubscriptionService 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"); } @@ -79,7 +79,7 @@ class BillingSubscriptionService $cs->subscription_id = $this->billing_subscription->id; $cs->company_id = $this->billing_subscription->company_id; $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->client_id = $contact->client->id; $cs->save(); diff --git a/app/Transformers/BillingSubscriptionTransformer.php b/app/Transformers/BillingSubscriptionTransformer.php index 3dc50cd78235..919889dd96a6 100644 --- a/app/Transformers/BillingSubscriptionTransformer.php +++ b/app/Transformers/BillingSubscriptionTransformer.php @@ -34,6 +34,8 @@ class BillingSubscriptionTransformer extends EntityTransformer public function transform(BillingSubscription $billing_subscription): array { + $std = new stdClass; + return [ 'id' => $this->encodePrimaryKey($billing_subscription->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, 'plan_map' => (string)$billing_subscription->plan_map, '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), 'is_deleted' => (bool)$billing_subscription->is_deleted, 'created_at' => (int)$billing_subscription->created_at, diff --git a/database/migrations/2021_03_23_233844_add_nullable_constraint_to_recurring_invoice_id.php b/database/migrations/2021_03_23_233844_add_nullable_constraint_to_recurring_invoice_id.php new file mode 100644 index 000000000000..f1224c7cdb1a --- /dev/null +++ b/database/migrations/2021_03_23_233844_add_nullable_constraint_to_recurring_invoice_id.php @@ -0,0 +1,29 @@ +unsignedInteger('recurring_invoice_id')->nullable()->change(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + } +}