diff --git a/adjustments.go b/adjustments.go index e94bb78..b927e5c 100644 --- a/adjustments.go +++ b/adjustments.go @@ -214,8 +214,6 @@ func (c *AdjustmentsClient) ListAdjustments(ctx context.Context, req *ListAdjust type CreateAdjustmentRequest struct { // Action: How this adjustment impacts the related transaction. Action AdjustmentAction `json:"action,omitempty"` - // Items: List of transaction items to adjust. - Items []AdjustmentItem `json:"items,omitempty"` // Reason: Why this adjustment was created. Appears in the Paddle dashboard. Retained for record-keeping purposes. Reason string `json:"reason,omitempty"` /* @@ -226,6 +224,10 @@ type CreateAdjustmentRequest struct { You can't create an adjustment for a transaction that has a refund that's pending approval. */ TransactionID string `json:"transaction_id,omitempty"` + // Type: Type of adjustment. Use `full` to adjust the grand total for the related transaction. Include an `items` array when creating a `partial` adjustment. If omitted, defaults to `partial`. + Type *AdjustmentType `json:"type,omitempty"` + // Items: List of transaction items to adjust. Required if `type` is not populated or set to `partial`. + Items []AdjustmentItem `json:"items,omitempty"` } // CreateAdjustment performs the POST operation on a Adjustments resource. diff --git a/pkg/paddlenotification/adjustments.go b/pkg/paddlenotification/adjustments.go index 663c025..2e3bd61 100644 --- a/pkg/paddlenotification/adjustments.go +++ b/pkg/paddlenotification/adjustments.go @@ -28,6 +28,14 @@ const ( AdjustmentActionCreditReverse AdjustmentAction = "credit_reverse" ) +// AdjustmentType: Type of adjustment. Use `full` to adjust the grand total for the related transaction. Include an `items` array when creating a `partial` adjustment. If omitted, defaults to `partial`.. +type AdjustmentType string + +const ( + AdjustmentTypeFull AdjustmentType = "full" + AdjustmentTypePartial AdjustmentType = "partial" +) + /* AdjustmentStatus: Status of this adjustment. Set automatically by Paddle. @@ -45,16 +53,16 @@ const ( ) /* -AdjustmentType: Type of adjustment for this transaction item. `tax` adjustments are automatically created by Paddle. +AdjustmentItemType: Type of adjustment for this transaction item. `tax` adjustments are automatically created by Paddle. Include `amount` when creating a `partial` adjustment.. */ -type AdjustmentType string +type AdjustmentItemType string const ( - AdjustmentTypeFull AdjustmentType = "full" - AdjustmentTypePartial AdjustmentType = "partial" - AdjustmentTypeTax AdjustmentType = "tax" - AdjustmentTypeProration AdjustmentType = "proration" + AdjustmentItemTypeFull AdjustmentItemType = "full" + AdjustmentItemTypePartial AdjustmentItemType = "partial" + AdjustmentItemTypeTax AdjustmentItemType = "tax" + AdjustmentItemTypeProration AdjustmentItemType = "proration" ) // AdjustmentItemTotals: Breakdown of the total for an adjustment item. @@ -77,8 +85,8 @@ type AdjustmentItem struct { Type: Type of adjustment for this transaction item. `tax` adjustments are automatically created by Paddle. Include `amount` when creating a `partial` adjustment. */ - Type AdjustmentType `json:"type,omitempty"` - // Amount: Amount adjusted for this transaction item. Required when adjustment type is `partial`. + Type AdjustmentItemType `json:"type,omitempty"` + // Amount: Amount adjusted for this transaction item. Required when item type is `partial`. Amount *string `json:"amount,omitempty"` // Proration: How proration was calculated for this adjustment item. Proration *Proration `json:"proration,omitempty"` @@ -151,6 +159,8 @@ type AdjustmentNotification struct { ID string `json:"id"` // Action: How this adjustment impacts the related transaction. Action AdjustmentAction `json:"action"` + // Type: Type of adjustment. Use `full` to adjust the grand total for the related transaction. Include an `items` array when creating a `partial` adjustment. If omitted, defaults to `partial`. + Type *AdjustmentType `json:"type"` // TransactionID: Paddle ID of the transaction that this adjustment is for, prefixed with `txn_`. TransactionID string `json:"transaction_id"` /* diff --git a/pkg/paddlenotification/shared.go b/pkg/paddlenotification/shared.go index ccea0cb..4189380 100644 --- a/pkg/paddlenotification/shared.go +++ b/pkg/paddlenotification/shared.go @@ -337,6 +337,7 @@ const ( CurrencyCodeTRY CurrencyCode = "TRY" CurrencyCodeTWD CurrencyCode = "TWD" CurrencyCodeUAH CurrencyCode = "UAH" + CurrencyCodeVND CurrencyCode = "VND" CurrencyCodeZAR CurrencyCode = "ZAR" ) diff --git a/pkg/paddlenotification/subscriptions.go b/pkg/paddlenotification/subscriptions.go index 5371938..f35aa43 100644 --- a/pkg/paddlenotification/subscriptions.go +++ b/pkg/paddlenotification/subscriptions.go @@ -80,8 +80,8 @@ const ( type SubscriptionDiscountTimePeriod struct { // ID: Unique Paddle ID for this discount, prefixed with `dsc_`. ID string `json:"id,omitempty"` - // StartsAt: RFC 3339 datetime string of when this discount was first applied. - StartsAt string `json:"starts_at,omitempty"` + // StartsAt: RFC 3339 datetime string of when this discount was first applied. `null` for canceled subscriptions where a discount was redeemed but never applied to a transaction. + StartsAt *string `json:"starts_at,omitempty"` // EndsAt: RFC 3339 datetime string of when this discount no longer applies. Where a discount has `maximum_recurring_intervals`, this is the date of the last billing period where this discount applies. `null` where a discount recurs forever. EndsAt *string `json:"ends_at,omitempty"` } diff --git a/shared.go b/shared.go index bebc304..3446bdd 100644 --- a/shared.go +++ b/shared.go @@ -287,6 +287,7 @@ const ( CurrencyCodeTRY CurrencyCode = "TRY" CurrencyCodeTWD CurrencyCode = "TWD" CurrencyCodeUAH CurrencyCode = "UAH" + CurrencyCodeVND CurrencyCode = "VND" CurrencyCodeZAR CurrencyCode = "ZAR" ) @@ -1018,6 +1019,14 @@ const ( AdjustmentActionCreditReverse AdjustmentAction = "credit_reverse" ) +// AdjustmentType: Type of adjustment. Use `full` to adjust the grand total for the related transaction. Include an `items` array when creating a `partial` adjustment. If omitted, defaults to `partial`.. +type AdjustmentType string + +const ( + AdjustmentTypeFull AdjustmentType = "full" + AdjustmentTypePartial AdjustmentType = "partial" +) + /* AdjustmentStatus: Status of this adjustment. Set automatically by Paddle. @@ -1035,16 +1044,16 @@ const ( ) /* -AdjustmentType: Type of adjustment for this transaction item. `tax` adjustments are automatically created by Paddle. +AdjustmentItemType: Type of adjustment for this transaction item. `tax` adjustments are automatically created by Paddle. Include `amount` when creating a `partial` adjustment.. */ -type AdjustmentType string +type AdjustmentItemType string const ( - AdjustmentTypeFull AdjustmentType = "full" - AdjustmentTypePartial AdjustmentType = "partial" - AdjustmentTypeTax AdjustmentType = "tax" - AdjustmentTypeProration AdjustmentType = "proration" + AdjustmentItemTypeFull AdjustmentItemType = "full" + AdjustmentItemTypePartial AdjustmentItemType = "partial" + AdjustmentItemTypeTax AdjustmentItemType = "tax" + AdjustmentItemTypeProration AdjustmentItemType = "proration" ) // AdjustmentItemTotals: Breakdown of the total for an adjustment item. @@ -1057,7 +1066,7 @@ type AdjustmentItemTotals struct { Total string `json:"total,omitempty"` } -// AdjustmentItem: List of items on this adjustment. +// AdjustmentItem: List of items on this adjustment. Required if `type` is not populated or set to `partial`. type AdjustmentItem struct { // ID: Unique Paddle ID for this adjustment item, prefixed with `adjitm_`. ID string `json:"id,omitempty"` @@ -1067,8 +1076,8 @@ type AdjustmentItem struct { Type: Type of adjustment for this transaction item. `tax` adjustments are automatically created by Paddle. Include `amount` when creating a `partial` adjustment. */ - Type AdjustmentType `json:"type,omitempty"` - // Amount: Amount adjusted for this transaction item. Required when adjustment type is `partial`. + Type AdjustmentItemType `json:"type,omitempty"` + // Amount: Amount adjusted for this transaction item. Required when item type is `partial`. Amount *string `json:"amount,omitempty"` // Proration: How proration was calculated for this adjustment item. Proration *Proration `json:"proration,omitempty"` @@ -1139,6 +1148,8 @@ type Adjustment struct { ID string `json:"id,omitempty"` // Action: How this adjustment impacts the related transaction. Action AdjustmentAction `json:"action,omitempty"` + // Type: Type of adjustment. Use `full` to adjust the grand total for the related transaction. Include an `items` array when creating a `partial` adjustment. If omitted, defaults to `partial`. + Type AdjustmentType `json:"type,omitempty"` // TransactionID: Paddle ID of the transaction that this adjustment is for, prefixed with `txn_`. TransactionID string `json:"transaction_id,omitempty"` /* @@ -1165,7 +1176,7 @@ type Adjustment struct { Credit adjustments don't require approval from Paddle, so they're created as `approved`. */ Status AdjustmentStatus `json:"status,omitempty"` - // Items: List of items on this adjustment. + // Items: List of items on this adjustment. Required if `type` is not populated or set to `partial`. Items []AdjustmentItem `json:"items,omitempty"` // Totals: Breakdown of the total for an adjustment. Totals AdjustmentTotals `json:"totals,omitempty"` diff --git a/subscriptions.go b/subscriptions.go index 0be8b11..e1ffa49 100644 --- a/subscriptions.go +++ b/subscriptions.go @@ -387,6 +387,13 @@ var ErrSubscriptionImmediateCharge24HourLimitExceeded = &paddleerr.Error{ Type: paddleerr.ErrorTypeRequestError, } +// ErrSubscriptionContinuingExistingBillingPeriodNotAllowed represents a `subscription_continuing_existing_billing_period_not_allowed` error. +// See https://developer.paddle.com/errors/subscriptions/subscription_continuing_existing_billing_period_not_allowed for more information. +var ErrSubscriptionContinuingExistingBillingPeriodNotAllowed = &paddleerr.Error{ + Code: "subscription_continuing_existing_billing_period_not_allowed", + Type: paddleerr.ErrorTypeRequestError, +} + // SubscriptionStatus: Status of this subscription. Set automatically by Paddle. Use the pause subscription or cancel subscription operations to change.. type SubscriptionStatus string @@ -402,8 +409,8 @@ const ( type SubscriptionDiscountTimePeriod struct { // ID: Unique Paddle ID for this discount, prefixed with `dsc_`. ID string `json:"id,omitempty"` - // StartsAt: RFC 3339 datetime string of when this discount was first applied. - StartsAt string `json:"starts_at,omitempty"` + // StartsAt: RFC 3339 datetime string of when this discount was first applied. `null` for canceled subscriptions where a discount was redeemed but never applied to a transaction. + StartsAt *string `json:"starts_at,omitempty"` // EndsAt: RFC 3339 datetime string of when this discount no longer applies. Where a discount has `maximum_recurring_intervals`, this is the date of the last billing period where this discount applies. `null` where a discount recurs forever. EndsAt *string `json:"ends_at,omitempty"` } @@ -507,8 +514,8 @@ type SubscriptionAdjustmentItem struct { Type: Type of adjustment for this transaction item. `tax` adjustments are automatically created by Paddle. Include `amount` when creating a `partial` adjustment. */ - Type AdjustmentType `json:"type,omitempty"` - // Amount: Amount adjusted for this transaction item. Required when adjustment type is `partial`. + Type AdjustmentItemType `json:"type,omitempty"` + // Amount: Amount adjusted for this transaction item. Required when item type is `partial`. Amount *string `json:"amount,omitempty"` // Proration: How proration was calculated for this adjustment item. Proration *Proration `json:"proration,omitempty"` @@ -655,6 +662,14 @@ const ( SubscriptionOnPaymentFailureApplyChange SubscriptionOnPaymentFailure = "apply_change" ) +// SubscriptionOnResume: How Paddle should set the billing period for the subscription when resuming. If omitted, defaults to `start_new_billing_period`.. +type SubscriptionOnResume string + +const ( + SubscriptionOnResumeContinueExistingBillingPeriod SubscriptionOnResume = "continue_existing_billing_period" + SubscriptionOnResumeStartNewBillingPeriod SubscriptionOnResume = "start_new_billing_period" +) + type ResumeOnASpecificDate struct { /* EffectiveFrom: When this scheduled change should take effect from. RFC 3339 datetime string of when the subscription should resume. @@ -662,6 +677,8 @@ type ResumeOnASpecificDate struct { Valid where subscriptions are `active` with a scheduled change to pause, or where they have the status of `paused`. */ EffectiveFrom string `json:"effective_from,omitempty"` + // OnResume: How Paddle should set the billing period for the subscription when resuming. If omitted, defaults to `start_new_billing_period`. + OnResume SubscriptionOnResume `json:"on_resume,omitempty"` } type ResumeImmediately struct { @@ -673,6 +690,8 @@ type ResumeImmediately struct { Defaults to `immediately` if omitted. */ EffectiveFrom *EffectiveFrom `json:"effective_from,omitempty"` + // OnResume: How Paddle should set the billing period for the subscription when resuming. If omitted, defaults to `start_new_billing_period`. + OnResume SubscriptionOnResume `json:"on_resume,omitempty"` } // UpdateSummaryResultAction: Whether the subscription change results in a prorated credit or a charge.. @@ -1036,6 +1055,8 @@ type PauseSubscriptionRequest struct { EffectiveFrom *EffectiveFrom `json:"effective_from,omitempty"` // ResumeAt: RFC 3339 datetime string of when the paused subscription should resume. Omit to pause indefinitely until resumed. ResumeAt *string `json:"resume_at,omitempty"` + // OnResume: How Paddle should set the billing period for the subscription when resuming. If omitted, defaults to `start_new_billing_period`. + OnResume *SubscriptionOnResume `json:"on_resume,omitempty"` } // PauseSubscription performs the POST operation on a Subscriptions resource. diff --git a/webhook_verifier.go b/webhook_verifier.go index dee08a2..75d7b4a 100644 --- a/webhook_verifier.go +++ b/webhook_verifier.go @@ -51,6 +51,10 @@ func (wv *WebhookVerifier) Verify(req *http.Request) (bool, error) { ts := matches[0][1] h1 := matches[0][2] + const maxBodySize = 2 << 20 // 2 MB + + req.Body = http.MaxBytesReader(nil, req.Body, maxBodySize) + body, err := io.ReadAll(req.Body) if err != nil { return false, err