Skip to content

Commit

Permalink
subscription prices to be a regular column
Browse files Browse the repository at this point in the history
  • Loading branch information
i-just committed Apr 26, 2024
1 parent 7ae35e0 commit ab06cdf
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
5 changes: 1 addition & 4 deletions src/migrations/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public function createTables(): void
'dateCreated' => $this->dateTime()->notNull(),
'dateUpdated' => $this->dateTime()->notNull(),
'uid' => $this->string(),
'prices' => $this->text()->defaultValue(null),
]);

$this->archiveTableIfExists(Table::PAYMENTMETHODDATA);
Expand Down Expand Up @@ -194,10 +195,6 @@ private function createGeneratedColumns(): void
$this->execute("ALTER TABLE " . Table::SUBSCRIPTIONDATA . " ADD COLUMN " .
$db->quoteColumnName('trialEnd') . " VARCHAR(255) GENERATED ALWAYS AS (" .
$qb->jsonExtract('data', ['trial_end']) . ") STORED;");
// prices
$this->execute("ALTER TABLE " . Table::SUBSCRIPTIONDATA . " ADD COLUMN " .
$db->quoteColumnName('prices') . " VARCHAR(255) GENERATED ALWAYS AS (" .
$qb->jsonExtract('data', ['items', 'data[*]', 'price', 'id']) . ") STORED;");

// invoice data
// created
Expand Down
1 change: 1 addition & 0 deletions src/services/Subscriptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public function createOrUpdateSubscription(StripeSubscription $subscription): bo
'title' => $subscription->description ?? $subscription->id,
'stripeStatus' => $subscription->status,
'data' => Json::decode($subscription->toJSON()),
'prices' => array_map(fn($item) => $item['price']['id'], $subscription->items->data),
];

// Set attributes on the element to emulate it having been loaded with JOINed data:
Expand Down

0 comments on commit ab06cdf

Please sign in to comment.