forked from Nixius/authelia
Fix subscription status not showing Expiring for cancel_at_period_end subs
- Also check sub.CancelAt > 0 (handles explicit cancel_at date, not just period-end) - Fall back to item CurrentPeriodEnd for the display date since current_period_end moved off the top-level Subscription object in stripe-go v84 Made-with: Cursor
This commit is contained in:
parent
159a0b4455
commit
74a24ffe2a
|
|
@ -93,10 +93,15 @@ func (c *Client) GetCustomerSubscriptionStatus(customerID string) *SubscriptionS
|
|||
sub := iter.Subscription()
|
||||
log.Printf("stripe: customer=%s sub=%s cancel_at_period_end=%v cancel_at=%d",
|
||||
customerID, sub.ID, sub.CancelAtPeriodEnd, sub.CancelAt)
|
||||
if sub.CancelAtPeriodEnd {
|
||||
if sub.CancelAtPeriodEnd || sub.CancelAt > 0 {
|
||||
// Prefer explicit cancel_at; fall back to current_period_end from the first item
|
||||
endTs := sub.CancelAt
|
||||
if endTs == 0 && sub.Items != nil && len(sub.Items.Data) > 0 {
|
||||
endTs = sub.Items.Data[0].CurrentPeriodEnd
|
||||
}
|
||||
var cancelAt string
|
||||
if sub.CancelAt > 0 {
|
||||
cancelAt = time.Unix(sub.CancelAt, 0).Format("Jan 2, 2006")
|
||||
if endTs > 0 {
|
||||
cancelAt = time.Unix(endTs, 0).Format("Jan 2, 2006")
|
||||
}
|
||||
return &SubscriptionStatus{
|
||||
Label: "Expiring",
|
||||
|
|
|
|||
Loading…
Reference in New Issue