Skip to content

Commit a3bbf3f

Browse files
kitallisclaude
andcommitted
Fix subscription.payment.reminder parsing: next/end fields are numbers
Fastspring sends `next` and `end` as timestamps (numbers), not strings. Use `*Display` fields for formatted dates and add nextChargeTotalDisplay to show upcoming charge amount in payment reminders. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent d341988 commit a3bbf3f

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

main.go

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,20 @@ type Item struct {
5555
}
5656

5757
type SubscriptionData struct {
58-
ID string `json:"id"`
59-
Subscription string `json:"subscription"`
60-
Product string `json:"product"`
61-
Currency string `json:"currency"`
62-
Total any `json:"total"`
63-
TotalDisplay string `json:"totalDisplay"`
64-
Customer Customer `json:"customer"`
65-
State string `json:"state"`
66-
NextDate string `json:"next"`
67-
EndDate string `json:"end"`
58+
ID string `json:"id"`
59+
Subscription string `json:"subscription"`
60+
Product string `json:"product"`
61+
Display string `json:"display"`
62+
Currency string `json:"currency"`
63+
Total any `json:"total"`
64+
TotalDisplay string `json:"totalDisplay"`
65+
Customer Customer `json:"customer"`
66+
State string `json:"state"`
67+
Next any `json:"next"`
68+
NextDisplay string `json:"nextDisplay"`
69+
NextChargeTotalDisplay string `json:"nextChargeTotalDisplay"`
70+
End any `json:"end"`
71+
EndDisplay string `json:"endDisplay"`
6872
}
6973

7074
type SubscriptionChargeData struct {
@@ -469,21 +473,29 @@ func formatOrderMessage(data OrderData, live bool, title string, severity string
469473
func formatSubscriptionMessage(data SubscriptionData, live bool, title string, severity string) SlackMessage {
470474
emoji := severityEmoji(severity)
471475

476+
productDisplay := data.Display
477+
if productDisplay == "" {
478+
productDisplay = data.Product
479+
}
480+
472481
text := fmt.Sprintf(":%s: %s\n\nCustomer: %s %s (%s)\nSubscription: %s\nProduct: %s",
473482
emoji,
474483
title,
475484
data.Customer.First,
476485
data.Customer.Last,
477486
data.Customer.Email,
478487
data.Subscription,
479-
data.Product,
488+
productDisplay,
480489
)
481490

482-
if data.NextDate != "" {
483-
text += fmt.Sprintf("\nNext billing: %s", data.NextDate)
491+
if data.NextDisplay != "" {
492+
text += fmt.Sprintf("\nNext billing: %s", data.NextDisplay)
493+
if data.NextChargeTotalDisplay != "" {
494+
text += fmt.Sprintf(" (%s)", data.NextChargeTotalDisplay)
495+
}
484496
}
485-
if data.EndDate != "" {
486-
text += fmt.Sprintf("\nEnds: %s", data.EndDate)
497+
if data.EndDisplay != "" {
498+
text += fmt.Sprintf("\nEnds: %s", data.EndDisplay)
487499
}
488500

489501
return SlackMessage{Text: text}

0 commit comments

Comments
 (0)