diff --git a/CHANGELOG.md b/CHANGELOG.md index 23563687..ba895e15 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +### v3.40.0-beta.1 (2025-11-18) +*** + +### New Enhancement: +* Added a webhook parser to automatically convert event JSON payloads into Chargebee objects. + ### v3.39.0 ( 2025-10-28) * * * diff --git a/README.md b/README.md index 4f2a869c..12169295 100644 --- a/README.md +++ b/README.md @@ -253,8 +253,109 @@ func main() { ``` `IsIdempotencyReplayed()` method can be accessed to differentiate between original and replayed requests. +### Handle webhooks +Use the `webhook` package to parse and route webhook payloads from Chargebee. +High-level: route events with callbacks using `WebhookHandler`: + +```go +package main + +import ( + "log" + "net/http" + + "github.com/chargebee/chargebee-go/v3/webhook" +) + +func main() { + handler := &webhook.WebhookHandler{ + // Optional: protect endpoint (e.g., Basic Auth) + RequestValidator: webhook.BasicAuthValidator(func(user, pass string) bool { + return user == "admin" && pass == "secret" + }), + OnError: webhook.BasicAuthErrorHandler, // Optional: standard auth error responses + + // Register only the events you care about + OnSubscriptionCreated: func(e webhook.SubscriptionCreatedEvent) error { + log.Printf("Subscription created event %s", e.Id) + return nil + }, + OnPaymentSucceeded: func(e webhook.PaymentSucceededEvent) error { + log.Printf("Payment succeeded for customer: %v", e.Content.Customer) + return nil + }, + } + + http.Handle("/chargebee/webhooks", handler.HTTPHandler()) + log.Fatal(http.ListenAndServe(":8080", nil)) +} +``` + +Low-level: parse just the event type and unmarshal yourself: + +```go +package main + +import ( + "encoding/json" + "io" + "net/http" + + "github.com/chargebee/chargebee-go/v3/enum" + "github.com/chargebee/chargebee-go/v3/webhook" +) + +func cbWebhook(w http.ResponseWriter, r *http.Request) { + defer r.Body.Close() + body, err := io.ReadAll(r.Body) + if err != nil { + http.Error(w, err.Error(), http.StatusBadRequest) + return + } + + evtType, err := webhook.ParseEventType(body) // validates api_version too + if err != nil { + http.Error(w, err.Error(), http.StatusBadRequest) + return + } + + switch evtType { + case enum.EventTypeSubscriptionCreated: + var e webhook.SubscriptionCreatedEvent + if err := json.Unmarshal(body, &e); err != nil { + http.Error(w, err.Error(), http.StatusBadRequest) + return + } + // handle e + default: + // ignore or log + } + w.WriteHeader(http.StatusOK) +} +``` + +#### Unhandled events + +By default, if an incoming webhook’s event type is unknown or you have not registered a corresponding handler on `WebhookHandler`, the SDK treats it as an error. When using `HTTPHandler()`, this results in a 500 response unless you provide a custom `OnError` handler. + +If you prefer to acknowledge unknown/unregistered events (return 200) and just log them, set `OnUnhandledEvent` to a function that returns `nil`: + +```go +import ( + "log" + "github.com/chargebee/chargebee-go/v3/enum" + "github.com/chargebee/chargebee-go/v3/webhook" +) + +handler := &webhook.WebhookHandler{ + OnUnhandledEvent: func(t enum.EventType, body []byte) error { + log.Printf("Ignoring unhandled event: %s", t) + return nil // swallow as OK + }, +} +``` ## Use the test suite *** diff --git a/enum/event_type.go b/enum/event_type.go index 7aae1854..cb2baf06 100644 --- a/enum/event_type.go +++ b/enum/event_type.go @@ -3,219 +3,228 @@ package enum type EventType string const ( + EventTypeAddUsagesReminder EventType = "add_usages_reminder" + EventTypeAddonCreated EventType = "addon_created" + EventTypeAddonDeleted EventType = "addon_deleted" + EventTypeAddonUpdated EventType = "addon_updated" + EventTypeAttachedItemCreated EventType = "attached_item_created" + EventTypeAttachedItemDeleted EventType = "attached_item_deleted" + EventTypeAttachedItemUpdated EventType = "attached_item_updated" + EventTypeAuthorizationSucceeded EventType = "authorization_succeeded" + EventTypeAuthorizationVoided EventType = "authorization_voided" + EventTypeBusinessEntityCreated EventType = "business_entity_created" + EventTypeBusinessEntityDeleted EventType = "business_entity_deleted" + EventTypeBusinessEntityUpdated EventType = "business_entity_updated" + EventTypeCardAdded EventType = "card_added" + EventTypeCardDeleted EventType = "card_deleted" + EventTypeCardExpired EventType = "card_expired" + EventTypeCardExpiryReminder EventType = "card_expiry_reminder" + EventTypeCardUpdated EventType = "card_updated" + EventTypeContractTermCancelled EventType = "contract_term_cancelled" + EventTypeContractTermCompleted EventType = "contract_term_completed" + EventTypeContractTermCreated EventType = "contract_term_created" + EventTypeContractTermRenewed EventType = "contract_term_renewed" + EventTypeContractTermTerminated EventType = "contract_term_terminated" + EventTypeCouponCodesAdded EventType = "coupon_codes_added" + EventTypeCouponCodesDeleted EventType = "coupon_codes_deleted" + EventTypeCouponCodesUpdated EventType = "coupon_codes_updated" EventTypeCouponCreated EventType = "coupon_created" - EventTypeCouponUpdated EventType = "coupon_updated" EventTypeCouponDeleted EventType = "coupon_deleted" EventTypeCouponSetCreated EventType = "coupon_set_created" - EventTypeCouponSetUpdated EventType = "coupon_set_updated" EventTypeCouponSetDeleted EventType = "coupon_set_deleted" - EventTypeCouponCodesAdded EventType = "coupon_codes_added" - EventTypeCouponCodesDeleted EventType = "coupon_codes_deleted" - EventTypeCouponCodesUpdated EventType = "coupon_codes_updated" - EventTypeCustomerCreated EventType = "customer_created" - EventTypeCustomerChanged EventType = "customer_changed" - EventTypeCustomerDeleted EventType = "customer_deleted" - EventTypeCustomerMovedOut EventType = "customer_moved_out" - EventTypeCustomerMovedIn EventType = "customer_moved_in" - EventTypePromotionalCreditsAdded EventType = "promotional_credits_added" - EventTypePromotionalCreditsDeducted EventType = "promotional_credits_deducted" - EventTypeSubscriptionCreated EventType = "subscription_created" - EventTypeSubscriptionCreatedWithBackdating EventType = "subscription_created_with_backdating" - EventTypeSubscriptionStarted EventType = "subscription_started" - EventTypeSubscriptionTrialEndReminder EventType = "subscription_trial_end_reminder" - EventTypeSubscriptionActivated EventType = "subscription_activated" - EventTypeSubscriptionActivatedWithBackdating EventType = "subscription_activated_with_backdating" - EventTypeSubscriptionChanged EventType = "subscription_changed" - EventTypeSubscriptionTrialExtended EventType = "subscription_trial_extended" - EventTypeMrrUpdated EventType = "mrr_updated" - EventTypeSubscriptionChangedWithBackdating EventType = "subscription_changed_with_backdating" - EventTypeSubscriptionCancellationScheduled EventType = "subscription_cancellation_scheduled" - EventTypeSubscriptionCancellationReminder EventType = "subscription_cancellation_reminder" - EventTypeSubscriptionCancelled EventType = "subscription_cancelled" - EventTypeSubscriptionCanceledWithBackdating EventType = "subscription_canceled_with_backdating" - EventTypeSubscriptionReactivated EventType = "subscription_reactivated" - EventTypeSubscriptionReactivatedWithBackdating EventType = "subscription_reactivated_with_backdating" - EventTypeSubscriptionRenewed EventType = "subscription_renewed" - EventTypeSubscriptionItemsRenewed EventType = "subscription_items_renewed" - EventTypeSubscriptionScheduledCancellationRemoved EventType = "subscription_scheduled_cancellation_removed" - EventTypeSubscriptionChangesScheduled EventType = "subscription_changes_scheduled" - EventTypeSubscriptionScheduledChangesRemoved EventType = "subscription_scheduled_changes_removed" - EventTypeSubscriptionShippingAddressUpdated EventType = "subscription_shipping_address_updated" - EventTypeSubscriptionDeleted EventType = "subscription_deleted" - EventTypeSubscriptionPaused EventType = "subscription_paused" - EventTypeSubscriptionPauseScheduled EventType = "subscription_pause_scheduled" - EventTypeSubscriptionScheduledPauseRemoved EventType = "subscription_scheduled_pause_removed" - EventTypeSubscriptionResumed EventType = "subscription_resumed" - EventTypeSubscriptionResumptionScheduled EventType = "subscription_resumption_scheduled" - EventTypeSubscriptionScheduledResumptionRemoved EventType = "subscription_scheduled_resumption_removed" - EventTypeSubscriptionAdvanceInvoiceScheduleAdded EventType = "subscription_advance_invoice_schedule_added" - EventTypeSubscriptionAdvanceInvoiceScheduleUpdated EventType = "subscription_advance_invoice_schedule_updated" - EventTypeSubscriptionAdvanceInvoiceScheduleRemoved EventType = "subscription_advance_invoice_schedule_removed" - EventTypePendingInvoiceCreated EventType = "pending_invoice_created" - EventTypePendingInvoiceUpdated EventType = "pending_invoice_updated" - EventTypeInvoiceGenerated EventType = "invoice_generated" - EventTypeInvoiceGeneratedWithBackdating EventType = "invoice_generated_with_backdating" - EventTypeInvoiceUpdated EventType = "invoice_updated" - EventTypeInvoiceDeleted EventType = "invoice_deleted" + EventTypeCouponSetUpdated EventType = "coupon_set_updated" + EventTypeCouponUpdated EventType = "coupon_updated" EventTypeCreditNoteCreated EventType = "credit_note_created" EventTypeCreditNoteCreatedWithBackdating EventType = "credit_note_created_with_backdating" - EventTypeCreditNoteUpdated EventType = "credit_note_updated" EventTypeCreditNoteDeleted EventType = "credit_note_deleted" - EventTypePaymentSchedulesCreated EventType = "payment_schedules_created" - EventTypePaymentSchedulesUpdated EventType = "payment_schedules_updated" - EventTypePaymentScheduleSchemeCreated EventType = "payment_schedule_scheme_created" - EventTypePaymentScheduleSchemeDeleted EventType = "payment_schedule_scheme_deleted" - EventTypeSubscriptionRenewalReminder EventType = "subscription_renewal_reminder" - EventTypeAddUsagesReminder EventType = "add_usages_reminder" - EventTypeTransactionCreated EventType = "transaction_created" - EventTypeTransactionUpdated EventType = "transaction_updated" - EventTypeTransactionDeleted EventType = "transaction_deleted" - EventTypePaymentSucceeded EventType = "payment_succeeded" - EventTypePaymentFailed EventType = "payment_failed" + EventTypeCreditNoteUpdated EventType = "credit_note_updated" + EventTypeCustomerBusinessEntityChanged EventType = "customer_business_entity_changed" + EventTypeCustomerChanged EventType = "customer_changed" + EventTypeCustomerCreated EventType = "customer_created" + EventTypeCustomerDeleted EventType = "customer_deleted" + EventTypeCustomerEntitlementsUpdated EventType = "customer_entitlements_updated" + EventTypeCustomerMovedIn EventType = "customer_moved_in" + EventTypeCustomerMovedOut EventType = "customer_moved_out" + EventTypeDifferentialPriceCreated EventType = "differential_price_created" + EventTypeDifferentialPriceDeleted EventType = "differential_price_deleted" + EventTypeDifferentialPriceUpdated EventType = "differential_price_updated" EventTypeDunningUpdated EventType = "dunning_updated" - EventTypePaymentRefunded EventType = "payment_refunded" - EventTypePaymentInitiated EventType = "payment_initiated" - EventTypeRefundInitiated EventType = "refund_initiated" - EventTypeAuthorizationSucceeded EventType = "authorization_succeeded" - EventTypeAuthorizationVoided EventType = "authorization_voided" - EventTypeCardAdded EventType = "card_added" - EventTypeCardUpdated EventType = "card_updated" - EventTypeCardExpiryReminder EventType = "card_expiry_reminder" - EventTypeCardExpired EventType = "card_expired" - EventTypeCardDeleted EventType = "card_deleted" - EventTypePaymentSourceAdded EventType = "payment_source_added" - EventTypePaymentSourceUpdated EventType = "payment_source_updated" - EventTypePaymentSourceDeleted EventType = "payment_source_deleted" - EventTypePaymentSourceExpiring EventType = "payment_source_expiring" - EventTypePaymentSourceExpired EventType = "payment_source_expired" - EventTypePaymentSourceLocallyDeleted EventType = "payment_source_locally_deleted" - EventTypeVirtualBankAccountAdded EventType = "virtual_bank_account_added" - EventTypeVirtualBankAccountUpdated EventType = "virtual_bank_account_updated" - EventTypeVirtualBankAccountDeleted EventType = "virtual_bank_account_deleted" - EventTypeTokenCreated EventType = "token_created" - EventTypeTokenConsumed EventType = "token_consumed" - EventTypeTokenExpired EventType = "token_expired" - EventTypeUnbilledChargesCreated EventType = "unbilled_charges_created" - EventTypeUnbilledChargesVoided EventType = "unbilled_charges_voided" - EventTypeUnbilledChargesDeleted EventType = "unbilled_charges_deleted" - EventTypeUnbilledChargesInvoiced EventType = "unbilled_charges_invoiced" - EventTypeOrderCreated EventType = "order_created" - EventTypeOrderUpdated EventType = "order_updated" - EventTypeOrderCancelled EventType = "order_cancelled" - EventTypeOrderDelivered EventType = "order_delivered" - EventTypeOrderReturned EventType = "order_returned" - EventTypeOrderReadyToProcess EventType = "order_ready_to_process" - EventTypeOrderReadyToShip EventType = "order_ready_to_ship" - EventTypeOrderDeleted EventType = "order_deleted" - EventTypeOrderResent EventType = "order_resent" - EventTypeQuoteCreated EventType = "quote_created" - EventTypeQuoteUpdated EventType = "quote_updated" - EventTypeQuoteDeleted EventType = "quote_deleted" - EventTypeTaxWithheldRecorded EventType = "tax_withheld_recorded" - EventTypeTaxWithheldDeleted EventType = "tax_withheld_deleted" - EventTypeTaxWithheldRefunded EventType = "tax_withheld_refunded" - EventTypeGiftScheduled EventType = "gift_scheduled" - EventTypeGiftUnclaimed EventType = "gift_unclaimed" + EventTypeEntitlementOverridesAutoRemoved EventType = "entitlement_overrides_auto_removed" + EventTypeEntitlementOverridesRemoved EventType = "entitlement_overrides_removed" + EventTypeEntitlementOverridesUpdated EventType = "entitlement_overrides_updated" + EventTypeFeatureActivated EventType = "feature_activated" + EventTypeFeatureArchived EventType = "feature_archived" + EventTypeFeatureCreated EventType = "feature_created" + EventTypeFeatureDeleted EventType = "feature_deleted" + EventTypeFeatureReactivated EventType = "feature_reactivated" + EventTypeFeatureUpdated EventType = "feature_updated" + EventTypeGiftCancelled EventType = "gift_cancelled" EventTypeGiftClaimed EventType = "gift_claimed" EventTypeGiftExpired EventType = "gift_expired" - EventTypeGiftCancelled EventType = "gift_cancelled" + EventTypeGiftScheduled EventType = "gift_scheduled" + EventTypeGiftUnclaimed EventType = "gift_unclaimed" EventTypeGiftUpdated EventType = "gift_updated" EventTypeHierarchyCreated EventType = "hierarchy_created" EventTypeHierarchyDeleted EventType = "hierarchy_deleted" - EventTypePaymentIntentCreated EventType = "payment_intent_created" - EventTypePaymentIntentUpdated EventType = "payment_intent_updated" - EventTypeContractTermCreated EventType = "contract_term_created" - EventTypeContractTermRenewed EventType = "contract_term_renewed" - EventTypeContractTermTerminated EventType = "contract_term_terminated" - EventTypeContractTermCompleted EventType = "contract_term_completed" - EventTypeContractTermCancelled EventType = "contract_term_cancelled" - EventTypeItemFamilyCreated EventType = "item_family_created" - EventTypeItemFamilyUpdated EventType = "item_family_updated" - EventTypeItemFamilyDeleted EventType = "item_family_deleted" + EventTypeInvoiceDeleted EventType = "invoice_deleted" + EventTypeInvoiceGenerated EventType = "invoice_generated" + EventTypeInvoiceGeneratedWithBackdating EventType = "invoice_generated_with_backdating" + EventTypeInvoiceUpdated EventType = "invoice_updated" EventTypeItemCreated EventType = "item_created" - EventTypeItemUpdated EventType = "item_updated" EventTypeItemDeleted EventType = "item_deleted" + EventTypeItemEntitlementsRemoved EventType = "item_entitlements_removed" + EventTypeItemEntitlementsUpdated EventType = "item_entitlements_updated" + EventTypeItemFamilyCreated EventType = "item_family_created" + EventTypeItemFamilyDeleted EventType = "item_family_deleted" + EventTypeItemFamilyUpdated EventType = "item_family_updated" EventTypeItemPriceCreated EventType = "item_price_created" - EventTypeItemPriceUpdated EventType = "item_price_updated" EventTypeItemPriceDeleted EventType = "item_price_deleted" - EventTypeAttachedItemCreated EventType = "attached_item_created" - EventTypeAttachedItemUpdated EventType = "attached_item_updated" - EventTypeAttachedItemDeleted EventType = "attached_item_deleted" - EventTypeDifferentialPriceCreated EventType = "differential_price_created" - EventTypeDifferentialPriceUpdated EventType = "differential_price_updated" - EventTypeDifferentialPriceDeleted EventType = "differential_price_deleted" - EventTypeFeatureCreated EventType = "feature_created" - EventTypeFeatureUpdated EventType = "feature_updated" - EventTypeFeatureDeleted EventType = "feature_deleted" - EventTypeFeatureActivated EventType = "feature_activated" - EventTypeFeatureReactivated EventType = "feature_reactivated" - EventTypeFeatureArchived EventType = "feature_archived" - EventTypeItemEntitlementsUpdated EventType = "item_entitlements_updated" - EventTypeEntitlementOverridesUpdated EventType = "entitlement_overrides_updated" - EventTypeEntitlementOverridesRemoved EventType = "entitlement_overrides_removed" - EventTypeItemEntitlementsRemoved EventType = "item_entitlements_removed" - EventTypeEntitlementOverridesAutoRemoved EventType = "entitlement_overrides_auto_removed" - EventTypeSubscriptionEntitlementsCreated EventType = "subscription_entitlements_created" - EventTypeSubscriptionEntitlementsUpdated EventType = "subscription_entitlements_updated" - EventTypeBusinessEntityCreated EventType = "business_entity_created" - EventTypeBusinessEntityUpdated EventType = "business_entity_updated" - EventTypeBusinessEntityDeleted EventType = "business_entity_deleted" - EventTypeCustomerBusinessEntityChanged EventType = "customer_business_entity_changed" - EventTypeSubscriptionBusinessEntityChanged EventType = "subscription_business_entity_changed" - EventTypePurchaseCreated EventType = "purchase_created" - EventTypeVoucherCreated EventType = "voucher_created" - EventTypeVoucherExpired EventType = "voucher_expired" - EventTypeVoucherCreateFailed EventType = "voucher_create_failed" - EventTypeItemPriceEntitlementsUpdated EventType = "item_price_entitlements_updated" EventTypeItemPriceEntitlementsRemoved EventType = "item_price_entitlements_removed" - EventTypeSubscriptionRampCreated EventType = "subscription_ramp_created" - EventTypeSubscriptionRampDeleted EventType = "subscription_ramp_deleted" - EventTypeSubscriptionRampApplied EventType = "subscription_ramp_applied" - EventTypeSubscriptionRampDrafted EventType = "subscription_ramp_drafted" - EventTypeSubscriptionRampUpdated EventType = "subscription_ramp_updated" - EventTypePriceVariantCreated EventType = "price_variant_created" - EventTypePriceVariantUpdated EventType = "price_variant_updated" - EventTypePriceVariantDeleted EventType = "price_variant_deleted" - EventTypeCustomerEntitlementsUpdated EventType = "customer_entitlements_updated" - EventTypeSubscriptionMovedIn EventType = "subscription_moved_in" - EventTypeSubscriptionMovedOut EventType = "subscription_moved_out" - EventTypeSubscriptionMovementFailed EventType = "subscription_movement_failed" + EventTypeItemPriceEntitlementsUpdated EventType = "item_price_entitlements_updated" + EventTypeItemPriceUpdated EventType = "item_price_updated" + EventTypeItemUpdated EventType = "item_updated" + EventTypeMrrUpdated EventType = "mrr_updated" + EventTypeNetdPaymentDueReminder EventType = "netd_payment_due_reminder" + EventTypeOmnichannelOneTimeOrderCreated EventType = "omnichannel_one_time_order_created" + EventTypeOmnichannelOneTimeOrderItemCancelled EventType = "omnichannel_one_time_order_item_cancelled" EventTypeOmnichannelSubscriptionCreated EventType = "omnichannel_subscription_created" - EventTypeOmnichannelSubscriptionItemRenewed EventType = "omnichannel_subscription_item_renewed" - EventTypeOmnichannelSubscriptionItemDowngraded EventType = "omnichannel_subscription_item_downgraded" - EventTypeOmnichannelSubscriptionItemExpired EventType = "omnichannel_subscription_item_expired" + EventTypeOmnichannelSubscriptionImported EventType = "omnichannel_subscription_imported" EventTypeOmnichannelSubscriptionItemCancellationScheduled EventType = "omnichannel_subscription_item_cancellation_scheduled" - EventTypeOmnichannelSubscriptionItemScheduledCancellationRemoved EventType = "omnichannel_subscription_item_scheduled_cancellation_removed" - EventTypeOmnichannelSubscriptionItemResubscribed EventType = "omnichannel_subscription_item_resubscribed" - EventTypeOmnichannelSubscriptionItemUpgraded EventType = "omnichannel_subscription_item_upgraded" EventTypeOmnichannelSubscriptionItemCancelled EventType = "omnichannel_subscription_item_cancelled" - EventTypeOmnichannelSubscriptionImported EventType = "omnichannel_subscription_imported" - EventTypeOmnichannelSubscriptionItemGracePeriodStarted EventType = "omnichannel_subscription_item_grace_period_started" - EventTypeOmnichannelSubscriptionItemGracePeriodExpired EventType = "omnichannel_subscription_item_grace_period_expired" - EventTypeOmnichannelSubscriptionItemDunningStarted EventType = "omnichannel_subscription_item_dunning_started" - EventTypeOmnichannelSubscriptionItemDunningExpired EventType = "omnichannel_subscription_item_dunning_expired" - EventTypeRuleCreated EventType = "rule_created" - EventTypeRuleUpdated EventType = "rule_updated" - EventTypeRuleDeleted EventType = "rule_deleted" - EventTypeRecordPurchaseFailed EventType = "record_purchase_failed" EventTypeOmnichannelSubscriptionItemChangeScheduled EventType = "omnichannel_subscription_item_change_scheduled" - EventTypeOmnichannelSubscriptionItemScheduledChangeRemoved EventType = "omnichannel_subscription_item_scheduled_change_removed" - EventTypeOmnichannelSubscriptionItemReactivated EventType = "omnichannel_subscription_item_reactivated" - EventTypeSalesOrderCreated EventType = "sales_order_created" - EventTypeSalesOrderUpdated EventType = "sales_order_updated" EventTypeOmnichannelSubscriptionItemChanged EventType = "omnichannel_subscription_item_changed" + EventTypeOmnichannelSubscriptionItemDowngradeScheduled EventType = "omnichannel_subscription_item_downgrade_scheduled" + EventTypeOmnichannelSubscriptionItemDowngraded EventType = "omnichannel_subscription_item_downgraded" + EventTypeOmnichannelSubscriptionItemDunningExpired EventType = "omnichannel_subscription_item_dunning_expired" + EventTypeOmnichannelSubscriptionItemDunningStarted EventType = "omnichannel_subscription_item_dunning_started" + EventTypeOmnichannelSubscriptionItemExpired EventType = "omnichannel_subscription_item_expired" + EventTypeOmnichannelSubscriptionItemGracePeriodExpired EventType = "omnichannel_subscription_item_grace_period_expired" + EventTypeOmnichannelSubscriptionItemGracePeriodStarted EventType = "omnichannel_subscription_item_grace_period_started" + EventTypeOmnichannelSubscriptionItemPauseScheduled EventType = "omnichannel_subscription_item_pause_scheduled" EventTypeOmnichannelSubscriptionItemPaused EventType = "omnichannel_subscription_item_paused" + EventTypeOmnichannelSubscriptionItemReactivated EventType = "omnichannel_subscription_item_reactivated" + EventTypeOmnichannelSubscriptionItemRenewed EventType = "omnichannel_subscription_item_renewed" + EventTypeOmnichannelSubscriptionItemResubscribed EventType = "omnichannel_subscription_item_resubscribed" EventTypeOmnichannelSubscriptionItemResumed EventType = "omnichannel_subscription_item_resumed" - EventTypeOmnichannelOneTimeOrderCreated EventType = "omnichannel_one_time_order_created" - EventTypeOmnichannelOneTimeOrderItemCancelled EventType = "omnichannel_one_time_order_item_cancelled" - EventTypeUsageFileIngested EventType = "usage_file_ingested" - EventTypeOmnichannelSubscriptionItemPauseScheduled EventType = "omnichannel_subscription_item_pause_scheduled" + EventTypeOmnichannelSubscriptionItemScheduledCancellationRemoved EventType = "omnichannel_subscription_item_scheduled_cancellation_removed" + EventTypeOmnichannelSubscriptionItemScheduledChangeRemoved EventType = "omnichannel_subscription_item_scheduled_change_removed" + EventTypeOmnichannelSubscriptionItemScheduledDowngradeRemoved EventType = "omnichannel_subscription_item_scheduled_downgrade_removed" + EventTypeOmnichannelSubscriptionItemUpgraded EventType = "omnichannel_subscription_item_upgraded" EventTypeOmnichannelSubscriptionMovedIn EventType = "omnichannel_subscription_moved_in" EventTypeOmnichannelTransactionCreated EventType = "omnichannel_transaction_created" + EventTypeOrderCancelled EventType = "order_cancelled" + EventTypeOrderCreated EventType = "order_created" + EventTypeOrderDeleted EventType = "order_deleted" + EventTypeOrderDelivered EventType = "order_delivered" + EventTypeOrderReadyToProcess EventType = "order_ready_to_process" + EventTypeOrderReadyToShip EventType = "order_ready_to_ship" + EventTypeOrderResent EventType = "order_resent" + EventTypeOrderReturned EventType = "order_returned" + EventTypeOrderUpdated EventType = "order_updated" + EventTypePaymentFailed EventType = "payment_failed" + EventTypePaymentInitiated EventType = "payment_initiated" + EventTypePaymentIntentCreated EventType = "payment_intent_created" + EventTypePaymentIntentUpdated EventType = "payment_intent_updated" + EventTypePaymentRefunded EventType = "payment_refunded" + EventTypePaymentScheduleSchemeCreated EventType = "payment_schedule_scheme_created" + EventTypePaymentScheduleSchemeDeleted EventType = "payment_schedule_scheme_deleted" + EventTypePaymentSchedulesCreated EventType = "payment_schedules_created" + EventTypePaymentSchedulesUpdated EventType = "payment_schedules_updated" + EventTypePaymentSourceAdded EventType = "payment_source_added" + EventTypePaymentSourceDeleted EventType = "payment_source_deleted" + EventTypePaymentSourceExpired EventType = "payment_source_expired" + EventTypePaymentSourceExpiring EventType = "payment_source_expiring" + EventTypePaymentSourceLocallyDeleted EventType = "payment_source_locally_deleted" + EventTypePaymentSourceUpdated EventType = "payment_source_updated" + EventTypePaymentSucceeded EventType = "payment_succeeded" + EventTypePendingInvoiceCreated EventType = "pending_invoice_created" + EventTypePendingInvoiceUpdated EventType = "pending_invoice_updated" EventTypePlanCreated EventType = "plan_created" - EventTypePlanUpdated EventType = "plan_updated" EventTypePlanDeleted EventType = "plan_deleted" - EventTypeAddonCreated EventType = "addon_created" - EventTypeAddonUpdated EventType = "addon_updated" - EventTypeAddonDeleted EventType = "addon_deleted" + EventTypePlanUpdated EventType = "plan_updated" + EventTypePriceVariantCreated EventType = "price_variant_created" + EventTypePriceVariantDeleted EventType = "price_variant_deleted" + EventTypePriceVariantUpdated EventType = "price_variant_updated" + EventTypeProductCreated EventType = "product_created" + EventTypeProductDeleted EventType = "product_deleted" + EventTypeProductUpdated EventType = "product_updated" + EventTypePromotionalCreditsAdded EventType = "promotional_credits_added" + EventTypePromotionalCreditsDeducted EventType = "promotional_credits_deducted" + EventTypePurchaseCreated EventType = "purchase_created" + EventTypeQuoteCreated EventType = "quote_created" + EventTypeQuoteDeleted EventType = "quote_deleted" + EventTypeQuoteUpdated EventType = "quote_updated" + EventTypeRecordPurchaseFailed EventType = "record_purchase_failed" + EventTypeRefundInitiated EventType = "refund_initiated" + EventTypeRuleCreated EventType = "rule_created" + EventTypeRuleDeleted EventType = "rule_deleted" + EventTypeRuleUpdated EventType = "rule_updated" + EventTypeSalesOrderCreated EventType = "sales_order_created" + EventTypeSalesOrderUpdated EventType = "sales_order_updated" + EventTypeSubscriptionActivated EventType = "subscription_activated" + EventTypeSubscriptionActivatedWithBackdating EventType = "subscription_activated_with_backdating" + EventTypeSubscriptionAdvanceInvoiceScheduleAdded EventType = "subscription_advance_invoice_schedule_added" + EventTypeSubscriptionAdvanceInvoiceScheduleRemoved EventType = "subscription_advance_invoice_schedule_removed" + EventTypeSubscriptionAdvanceInvoiceScheduleUpdated EventType = "subscription_advance_invoice_schedule_updated" + EventTypeSubscriptionBusinessEntityChanged EventType = "subscription_business_entity_changed" + EventTypeSubscriptionCanceledWithBackdating EventType = "subscription_canceled_with_backdating" + EventTypeSubscriptionCancellationReminder EventType = "subscription_cancellation_reminder" + EventTypeSubscriptionCancellationScheduled EventType = "subscription_cancellation_scheduled" + EventTypeSubscriptionCancelled EventType = "subscription_cancelled" + EventTypeSubscriptionChanged EventType = "subscription_changed" + EventTypeSubscriptionChangedWithBackdating EventType = "subscription_changed_with_backdating" + EventTypeSubscriptionChangesScheduled EventType = "subscription_changes_scheduled" + EventTypeSubscriptionCreated EventType = "subscription_created" + EventTypeSubscriptionCreatedWithBackdating EventType = "subscription_created_with_backdating" + EventTypeSubscriptionDeleted EventType = "subscription_deleted" + EventTypeSubscriptionEntitlementsCreated EventType = "subscription_entitlements_created" + EventTypeSubscriptionEntitlementsUpdated EventType = "subscription_entitlements_updated" + EventTypeSubscriptionItemsRenewed EventType = "subscription_items_renewed" + EventTypeSubscriptionMovedIn EventType = "subscription_moved_in" + EventTypeSubscriptionMovedOut EventType = "subscription_moved_out" + EventTypeSubscriptionMovementFailed EventType = "subscription_movement_failed" + EventTypeSubscriptionPauseScheduled EventType = "subscription_pause_scheduled" + EventTypeSubscriptionPaused EventType = "subscription_paused" + EventTypeSubscriptionRampApplied EventType = "subscription_ramp_applied" + EventTypeSubscriptionRampCreated EventType = "subscription_ramp_created" + EventTypeSubscriptionRampDeleted EventType = "subscription_ramp_deleted" + EventTypeSubscriptionRampDrafted EventType = "subscription_ramp_drafted" + EventTypeSubscriptionRampUpdated EventType = "subscription_ramp_updated" + EventTypeSubscriptionReactivated EventType = "subscription_reactivated" + EventTypeSubscriptionReactivatedWithBackdating EventType = "subscription_reactivated_with_backdating" + EventTypeSubscriptionRenewalReminder EventType = "subscription_renewal_reminder" + EventTypeSubscriptionRenewed EventType = "subscription_renewed" + EventTypeSubscriptionResumed EventType = "subscription_resumed" + EventTypeSubscriptionResumptionScheduled EventType = "subscription_resumption_scheduled" + EventTypeSubscriptionScheduledCancellationRemoved EventType = "subscription_scheduled_cancellation_removed" + EventTypeSubscriptionScheduledChangesRemoved EventType = "subscription_scheduled_changes_removed" + EventTypeSubscriptionScheduledPauseRemoved EventType = "subscription_scheduled_pause_removed" + EventTypeSubscriptionScheduledResumptionRemoved EventType = "subscription_scheduled_resumption_removed" + EventTypeSubscriptionShippingAddressUpdated EventType = "subscription_shipping_address_updated" + EventTypeSubscriptionStarted EventType = "subscription_started" + EventTypeSubscriptionTrialEndReminder EventType = "subscription_trial_end_reminder" + EventTypeSubscriptionTrialExtended EventType = "subscription_trial_extended" + EventTypeTaxWithheldDeleted EventType = "tax_withheld_deleted" + EventTypeTaxWithheldRecorded EventType = "tax_withheld_recorded" + EventTypeTaxWithheldRefunded EventType = "tax_withheld_refunded" + EventTypeTokenConsumed EventType = "token_consumed" + EventTypeTokenCreated EventType = "token_created" + EventTypeTokenExpired EventType = "token_expired" + EventTypeTransactionCreated EventType = "transaction_created" + EventTypeTransactionDeleted EventType = "transaction_deleted" + EventTypeTransactionUpdated EventType = "transaction_updated" + EventTypeUnbilledChargesCreated EventType = "unbilled_charges_created" + EventTypeUnbilledChargesDeleted EventType = "unbilled_charges_deleted" + EventTypeUnbilledChargesInvoiced EventType = "unbilled_charges_invoiced" + EventTypeUnbilledChargesVoided EventType = "unbilled_charges_voided" + EventTypeUsageFileIngested EventType = "usage_file_ingested" + EventTypeVariantCreated EventType = "variant_created" + EventTypeVariantDeleted EventType = "variant_deleted" + EventTypeVariantUpdated EventType = "variant_updated" + EventTypeVirtualBankAccountAdded EventType = "virtual_bank_account_added" + EventTypeVirtualBankAccountDeleted EventType = "virtual_bank_account_deleted" + EventTypeVirtualBankAccountUpdated EventType = "virtual_bank_account_updated" + EventTypeVoucherCreateFailed EventType = "voucher_create_failed" + EventTypeVoucherCreated EventType = "voucher_created" + EventTypeVoucherExpired EventType = "voucher_expired" ) diff --git a/go.sum b/go.sum index 2ec90f70..14c872b7 100644 --- a/go.sum +++ b/go.sum @@ -1,17 +1,12 @@ -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= -github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/tests/webhook_test.go b/tests/webhook_test.go new file mode 100644 index 00000000..1bf171ad --- /dev/null +++ b/tests/webhook_test.go @@ -0,0 +1,426 @@ +package tests + +import ( + "bytes" + "encoding/base64" + "errors" + "net/http" + "net/http/httptest" + "strconv" + "testing" + "time" + + "github.com/chargebee/chargebee-go/v3/enum" + "github.com/chargebee/chargebee-go/v3/webhook" + "github.com/stretchr/testify/assert" +) + +func makeEventBody(eventType string, content string) []byte { + if content == "" { + content = "{}" + } + now := time.Now().Unix() + body := []byte(`{ + "id":"evt_test_1", + "occurred_at":` + toIntString(now) + `, + "event_type":"` + eventType + `", + "api_version":"v2", + "content":` + content + ` + }`) + return body +} + +func toIntString(v int64) string { + return strconv.FormatInt(v, 10) +} + +func TestParseEventType_OK(t *testing.T) { + body := makeEventBody("pending_invoice_created", "{}") + evtType, err := webhook.ParseEventType(body) + assert.NoError(t, err) + assert.Equal(t, enum.EventTypePendingInvoiceCreated, evtType) +} + +func TestParseEventType_InvalidJSON(t *testing.T) { + body := []byte(`invalid json`) + _, err := webhook.ParseEventType(body) + assert.Error(t, err) +} + +func TestParseEventType_ApiVersionMismatch(t *testing.T) { + body := []byte(`{"event_type":"pending_invoice_created","api_version":"v1"}`) + _, err := webhook.ParseEventType(body) + assert.Error(t, err) + assert.Contains(t, err.Error(), "API version") +} + +func TestParseEventType_MissingEventType(t *testing.T) { + body := []byte(`{"api_version":"v2"}`) + evtType, err := webhook.ParseEventType(body) + assert.NoError(t, err) + assert.Equal(t, enum.EventType(""), evtType) +} + +func TestHTTPHandler_RoutesToCallback(t *testing.T) { + var called bool + h := &webhook.WebhookHandler{ + RequestValidator: func(r *http.Request) error { return nil }, + OnError: func(w http.ResponseWriter, r *http.Request, err error) { + t.Fatalf("unexpected error: %v", err) + }, + OnPendingInvoiceCreated: func(e webhook.PendingInvoiceCreatedEvent) error { + called = true + assert.NotEmpty(t, e.Id) + assert.NotEmpty(t, e.EventType) + assert.NotZero(t, e.OccurredAt) + assert.NotNil(t, e.Content) + return nil + }, + } + rec := httptest.NewRecorder() + req := httptest.NewRequest(http.MethodPost, "/cb", bytes.NewReader(makeEventBody("pending_invoice_created", "{}"))) + h.HTTPHandler().ServeHTTP(rec, req) + assert.Equal(t, http.StatusOK, rec.Code) + assert.True(t, called) +} + +func TestHTTPHandler_ValidatorError(t *testing.T) { + var onErrorCalled bool + h := &webhook.WebhookHandler{ + RequestValidator: func(r *http.Request) error { return errors.New("bad signature") }, + OnError: func(w http.ResponseWriter, r *http.Request, err error) { + onErrorCalled = true + http.Error(w, err.Error(), http.StatusInternalServerError) + }, + } + rec := httptest.NewRecorder() + req := httptest.NewRequest(http.MethodPost, "/cb", bytes.NewReader(makeEventBody("pending_invoice_created", "{}"))) + h.HTTPHandler().ServeHTTP(rec, req) + assert.Equal(t, http.StatusInternalServerError, rec.Code) + assert.True(t, onErrorCalled) +} + +func TestHTTPHandler_CallbackError(t *testing.T) { + var onErrorCalled bool + h := &webhook.WebhookHandler{ + RequestValidator: func(r *http.Request) error { return nil }, + OnError: func(w http.ResponseWriter, r *http.Request, err error) { + onErrorCalled = true + http.Error(w, err.Error(), http.StatusInternalServerError) + }, + OnPendingInvoiceCreated: func(e webhook.PendingInvoiceCreatedEvent) error { + return errors.New("user code failed") + }, + } + rec := httptest.NewRecorder() + req := httptest.NewRequest(http.MethodPost, "/cb", bytes.NewReader(makeEventBody("pending_invoice_created", "{}"))) + h.HTTPHandler().ServeHTTP(rec, req) + assert.Equal(t, http.StatusInternalServerError, rec.Code) + assert.True(t, onErrorCalled) +} + +func TestHTTPHandler_UnknownEvent_Error(t *testing.T) { + h := &webhook.WebhookHandler{ + RequestValidator: func(r *http.Request) error { return nil }, + // Use default error handler which writes 500 + } + rec := httptest.NewRecorder() + req := httptest.NewRequest(http.MethodPost, "/cb", bytes.NewReader(makeEventBody("non_existing_event", "{}"))) + h.HTTPHandler().ServeHTTP(rec, req) + assert.Equal(t, http.StatusInternalServerError, rec.Code) +} + +func TestHTTPHandler_NoHandlerRegistered_Error(t *testing.T) { + h := &webhook.WebhookHandler{ + RequestValidator: func(r *http.Request) error { return nil }, + // No OnPendingInvoiceCreated handler registered; expect 500 via default error handler + } + rec := httptest.NewRecorder() + req := httptest.NewRequest(http.MethodPost, "/cb", bytes.NewReader(makeEventBody("pending_invoice_created", "{}"))) + h.HTTPHandler().ServeHTTP(rec, req) + assert.Equal(t, http.StatusInternalServerError, rec.Code) +} + +func TestHTTPHandler_MultipleEventTypes(t *testing.T) { + var pendingInvoiceCalled, subscriptionCalled bool + h := &webhook.WebhookHandler{ + RequestValidator: func(r *http.Request) error { return nil }, + OnError: func(w http.ResponseWriter, r *http.Request, err error) { t.Fatalf("unexpected error: %v", err) }, + OnPendingInvoiceCreated: func(e webhook.PendingInvoiceCreatedEvent) error { + pendingInvoiceCalled = true + return nil + }, + OnSubscriptionCreated: func(e webhook.SubscriptionCreatedEvent) error { + subscriptionCalled = true + return nil + }, + } + + // Test pending_invoice_created + rec1 := httptest.NewRecorder() + req1 := httptest.NewRequest(http.MethodPost, "/cb", bytes.NewReader(makeEventBody("pending_invoice_created", "{}"))) + h.HTTPHandler().ServeHTTP(rec1, req1) + assert.Equal(t, http.StatusOK, rec1.Code) + assert.True(t, pendingInvoiceCalled) + assert.False(t, subscriptionCalled) + + // Test subscription_created + pendingInvoiceCalled = false + rec2 := httptest.NewRecorder() + req2 := httptest.NewRequest(http.MethodPost, "/cb", bytes.NewReader(makeEventBody("subscription_created", "{}"))) + h.HTTPHandler().ServeHTTP(rec2, req2) + assert.Equal(t, http.StatusOK, rec2.Code) + assert.False(t, pendingInvoiceCalled) + assert.True(t, subscriptionCalled) +} + +func TestHTTPHandler_InvalidJSONBody(t *testing.T) { + var onErrorCalled bool + h := &webhook.WebhookHandler{ + RequestValidator: func(r *http.Request) error { return nil }, + OnError: func(w http.ResponseWriter, r *http.Request, err error) { + onErrorCalled = true + http.Error(w, err.Error(), http.StatusInternalServerError) + }, + } + rec := httptest.NewRecorder() + req := httptest.NewRequest(http.MethodPost, "/cb", bytes.NewReader([]byte("invalid json"))) + h.HTTPHandler().ServeHTTP(rec, req) + assert.Equal(t, http.StatusInternalServerError, rec.Code) + assert.True(t, onErrorCalled) +} + +func TestHTTPHandler_CustomValidator(t *testing.T) { + var validatorCalled bool + h := &webhook.WebhookHandler{ + RequestValidator: func(r *http.Request) error { + validatorCalled = true + // Custom validation logic - e.g., check headers + if r.Header.Get("X-Custom-Header") != "expected-value" { + return errors.New("missing required header") + } + return nil + }, + OnError: func(w http.ResponseWriter, r *http.Request, err error) { + http.Error(w, err.Error(), http.StatusUnauthorized) + }, + OnPendingInvoiceCreated: func(e webhook.PendingInvoiceCreatedEvent) error { + return nil + }, + } + + // Test without required header + rec1 := httptest.NewRecorder() + req1 := httptest.NewRequest(http.MethodPost, "/cb", bytes.NewReader(makeEventBody("pending_invoice_created", "{}"))) + h.HTTPHandler().ServeHTTP(rec1, req1) + assert.Equal(t, http.StatusUnauthorized, rec1.Code) + assert.True(t, validatorCalled) + + // Test with required header + validatorCalled = false + rec2 := httptest.NewRecorder() + req2 := httptest.NewRequest(http.MethodPost, "/cb", bytes.NewReader(makeEventBody("pending_invoice_created", "{}"))) + req2.Header.Set("X-Custom-Header", "expected-value") + h.HTTPHandler().ServeHTTP(rec2, req2) + assert.Equal(t, http.StatusOK, rec2.Code) + assert.True(t, validatorCalled) +} + +// Helper function to create Basic Auth header value +func makeBasicAuth(username, password string) string { + credentials := username + ":" + password + encoded := base64.StdEncoding.EncodeToString([]byte(credentials)) + return "Basic " + encoded +} + +func TestBasicAuthValidator_ValidCredentials(t *testing.T) { + validator := webhook.BasicAuthValidator(func(username, password string) bool { + return username == "testuser" && password == "testpass" + }) + + req := httptest.NewRequest(http.MethodPost, "/webhook", nil) + req.Header.Set("Authorization", makeBasicAuth("testuser", "testpass")) + + err := validator(req) + assert.NoError(t, err) +} + +func TestBasicAuthValidator_InvalidCredentials(t *testing.T) { + validator := webhook.BasicAuthValidator(func(username, password string) bool { + return username == "testuser" && password == "testpass" + }) + + req := httptest.NewRequest(http.MethodPost, "/webhook", nil) + req.Header.Set("Authorization", makeBasicAuth("wronguser", "wrongpass")) + + err := validator(req) + assert.Error(t, err) + assert.Contains(t, err.Error(), "invalid credentials") +} + +func TestBasicAuthValidator_MissingAuthorizationHeader(t *testing.T) { + validator := webhook.BasicAuthValidator(func(username, password string) bool { + return true + }) + + req := httptest.NewRequest(http.MethodPost, "/webhook", nil) + // No Authorization header set + + err := validator(req) + assert.Error(t, err) + assert.Contains(t, err.Error(), "invalid basic authorization header") +} + +func TestBasicAuthValidator_InvalidScheme(t *testing.T) { + validator := webhook.BasicAuthValidator(func(username, password string) bool { + return true + }) + + req := httptest.NewRequest(http.MethodPost, "/webhook", nil) + req.Header.Set("Authorization", "Bearer token123") + + err := validator(req) + assert.Error(t, err) + assert.Contains(t, err.Error(), "invalid basic authorization header") +} + +func TestBasicAuthValidator_InvalidBase64Encoding(t *testing.T) { + validator := webhook.BasicAuthValidator(func(username, password string) bool { + return true + }) + + req := httptest.NewRequest(http.MethodPost, "/webhook", nil) + req.Header.Set("Authorization", "Basic invalid-base64!!!") + + err := validator(req) + assert.Error(t, err) + assert.Contains(t, err.Error(), "invalid basic authorization header") +} + +func TestBasicAuthValidator_InvalidCredentialsFormat(t *testing.T) { + validator := webhook.BasicAuthValidator(func(username, password string) bool { + return true + }) + + // Encode a string without colon separator + encoded := base64.StdEncoding.EncodeToString([]byte("nocolonseparator")) + req := httptest.NewRequest(http.MethodPost, "/webhook", nil) + req.Header.Set("Authorization", "Basic "+encoded) + + err := validator(req) + assert.Error(t, err) + assert.Contains(t, err.Error(), "invalid basic authorization header") +} + +func TestBasicAuthValidator_EmptyCredentialsAllowed(t *testing.T) { + // When validateCredentials always returns true (empty credentials allowed) + validator := webhook.BasicAuthValidator(func(username, password string) bool { + return true // Allow all credentials + }) + + req := httptest.NewRequest(http.MethodPost, "/webhook", nil) + req.Header.Set("Authorization", makeBasicAuth("anyuser", "anypass")) + + err := validator(req) + assert.NoError(t, err) +} + +func TestBasicAuthValidator_UsernameWithColon(t *testing.T) { + validator := webhook.BasicAuthValidator(func(username, password string) bool { + // When encoding "user:name:pass:word", SplitN creates username="user" and password="name:pass:word" + return username == "user" && password == "name:pass:word" + }) + + // Create auth header with colon in credentials + credentials := "user:name:pass:word" + encoded := base64.StdEncoding.EncodeToString([]byte(credentials)) + req := httptest.NewRequest(http.MethodPost, "/webhook", nil) + req.Header.Set("Authorization", "Basic "+encoded) + + err := validator(req) + assert.NoError(t, err) +} + +func TestBasicAuthErrorHandler_AuthError(t *testing.T) { + rec := httptest.NewRecorder() + req := httptest.NewRequest(http.MethodPost, "/webhook", nil) + + // Test with missing Authorization header error + err := errors.New("missing Authorization header") + webhook.BasicAuthErrorHandler(rec, req, err) + + assert.Equal(t, http.StatusUnauthorized, rec.Code) + assert.Equal(t, `Basic realm="Webhook"`, rec.Header().Get("WWW-Authenticate")) + assert.Contains(t, rec.Body.String(), "unauthorized") +} + +func TestBasicAuthErrorHandler_InvalidCredentialsError(t *testing.T) { + rec := httptest.NewRecorder() + req := httptest.NewRequest(http.MethodPost, "/webhook", nil) + + err := errors.New("invalid credentials") + webhook.BasicAuthErrorHandler(rec, req, err) + + assert.Equal(t, http.StatusUnauthorized, rec.Code) + assert.Equal(t, `Basic realm="Webhook"`, rec.Header().Get("WWW-Authenticate")) + assert.Contains(t, rec.Body.String(), "unauthorized") +} + +func TestBasicAuthErrorHandler_InvalidSchemeError(t *testing.T) { + rec := httptest.NewRecorder() + req := httptest.NewRequest(http.MethodPost, "/webhook", nil) + + err := errors.New("invalid authorization scheme, expected Basic") + webhook.BasicAuthErrorHandler(rec, req, err) + + assert.Equal(t, http.StatusUnauthorized, rec.Code) + assert.Equal(t, `Basic realm="Webhook"`, rec.Header().Get("WWW-Authenticate")) + assert.Contains(t, rec.Body.String(), "unauthorized") +} + +func TestBasicAuthErrorHandler_NonAuthError(t *testing.T) { + rec := httptest.NewRecorder() + req := httptest.NewRequest(http.MethodPost, "/webhook", nil) + + // Test with a non-auth error + err := errors.New("internal server error") + webhook.BasicAuthErrorHandler(rec, req, err) + + assert.Equal(t, http.StatusUnauthorized, rec.Code) + assert.Equal(t, `Basic realm="Webhook"`, rec.Header().Get("WWW-Authenticate")) + assert.Contains(t, rec.Body.String(), "unauthorized") +} + +func TestBasicAuthValidator_IntegrationWithWebhookHandler(t *testing.T) { + var callbackCalled bool + validator := webhook.BasicAuthValidator(func(username, password string) bool { + return username == "admin" && password == "secret" + }) + + h := &webhook.WebhookHandler{ + RequestValidator: validator, + OnError: webhook.BasicAuthErrorHandler, + OnPendingInvoiceCreated: func(e webhook.PendingInvoiceCreatedEvent) error { + callbackCalled = true + return nil + }, + } + + // Test with valid credentials + rec1 := httptest.NewRecorder() + req1 := httptest.NewRequest(http.MethodPost, "/webhook", bytes.NewReader(makeEventBody("pending_invoice_created", "{}"))) + req1.Header.Set("Authorization", makeBasicAuth("admin", "secret")) + h.HTTPHandler().ServeHTTP(rec1, req1) + assert.Equal(t, http.StatusOK, rec1.Code) + assert.True(t, callbackCalled) + + // Test with invalid credentials + callbackCalled = false + rec2 := httptest.NewRecorder() + req2 := httptest.NewRequest(http.MethodPost, "/webhook", bytes.NewReader(makeEventBody("pending_invoice_created", "{}"))) + req2.Header.Set("Authorization", makeBasicAuth("wrong", "wrong")) + h.HTTPHandler().ServeHTTP(rec2, req2) + assert.Equal(t, http.StatusUnauthorized, rec2.Code) + assert.Equal(t, `Basic realm="Webhook"`, rec2.Header().Get("WWW-Authenticate")) + assert.False(t, callbackCalled) +} diff --git a/version.go b/version.go index 7d2c6702..a9e2a5ae 100644 --- a/version.go +++ b/version.go @@ -1,3 +1,3 @@ package chargebee -const Version string = "3.39.0" +const Version string = "3.40.0-beta.1" diff --git a/webhook/auth.go b/webhook/auth.go new file mode 100644 index 00000000..72408adc --- /dev/null +++ b/webhook/auth.go @@ -0,0 +1,31 @@ +package webhook + +import ( + "errors" + "net/http" +) + +func BasicAuthValidator(validateCredentials func(username, password string) bool) func(*http.Request) error { + return func(r *http.Request) error { + username, password, ok := r.BasicAuth() + if !ok { + return errors.New("invalid basic authorization header") + } + + // Validate credentials using the provided function + if !validateCredentials(username, password) { + return errors.New("invalid credentials") + } + + return nil + } +} + +// BasicAuthErrorHandler creates an OnError handler that returns 401 Unauthorized for auth errors +func BasicAuthErrorHandler(w http.ResponseWriter, r *http.Request, err error) { + if err == nil { + return + } + w.Header().Set("WWW-Authenticate", `Basic realm="Webhook"`) + http.Error(w, "unauthorized", http.StatusUnauthorized) +} diff --git a/webhook/content.go b/webhook/content.go new file mode 100644 index 00000000..b764eba3 --- /dev/null +++ b/webhook/content.go @@ -0,0 +1,2905 @@ +package webhook + +import ( + "time" + + "github.com/chargebee/chargebee-go/v3/models/addon" + + "github.com/chargebee/chargebee-go/v3/models/advanceinvoiceschedule" + + "github.com/chargebee/chargebee-go/v3/models/attacheditem" + + "github.com/chargebee/chargebee-go/v3/models/attribute" + + "github.com/chargebee/chargebee-go/v3/models/businessentity" + + "github.com/chargebee/chargebee-go/v3/models/businessentitytransfer" + + "github.com/chargebee/chargebee-go/v3/models/card" + + "github.com/chargebee/chargebee-go/v3/models/contractterm" + + "github.com/chargebee/chargebee-go/v3/models/coupon" + + "github.com/chargebee/chargebee-go/v3/models/couponcode" + + "github.com/chargebee/chargebee-go/v3/models/couponset" + + "github.com/chargebee/chargebee-go/v3/models/creditnote" + + "github.com/chargebee/chargebee-go/v3/models/customer" + + "github.com/chargebee/chargebee-go/v3/models/differentialprice" + + "github.com/chargebee/chargebee-go/v3/models/feature" + + "github.com/chargebee/chargebee-go/v3/models/gift" + + "github.com/chargebee/chargebee-go/v3/models/impactedcustomer" + + "github.com/chargebee/chargebee-go/v3/models/impacteditem" + + "github.com/chargebee/chargebee-go/v3/models/impacteditemprice" + + "github.com/chargebee/chargebee-go/v3/models/impactedsubscription" + + "github.com/chargebee/chargebee-go/v3/models/invoice" + + "github.com/chargebee/chargebee-go/v3/models/item" + + "github.com/chargebee/chargebee-go/v3/models/itemfamily" + + "github.com/chargebee/chargebee-go/v3/models/itemprice" + + "github.com/chargebee/chargebee-go/v3/models/metadata" + + "github.com/chargebee/chargebee-go/v3/models/omnichannelonetimeorder" + + "github.com/chargebee/chargebee-go/v3/models/omnichannelonetimeorderitem" + + "github.com/chargebee/chargebee-go/v3/models/omnichannelsubscription" + + "github.com/chargebee/chargebee-go/v3/models/omnichannelsubscriptionitem" + + "github.com/chargebee/chargebee-go/v3/models/omnichannelsubscriptionitemscheduledchange" + + "github.com/chargebee/chargebee-go/v3/models/omnichanneltransaction" + + "github.com/chargebee/chargebee-go/v3/models/order" + + "github.com/chargebee/chargebee-go/v3/models/paymentintent" + + "github.com/chargebee/chargebee-go/v3/models/paymentschedule" + + "github.com/chargebee/chargebee-go/v3/models/paymentschedulescheme" + + "github.com/chargebee/chargebee-go/v3/models/paymentsource" + + "github.com/chargebee/chargebee-go/v3/models/paymentvoucher" + + "github.com/chargebee/chargebee-go/v3/models/plan" + + "github.com/chargebee/chargebee-go/v3/models/pricevariant" + + "github.com/chargebee/chargebee-go/v3/models/promotionalcredit" + + "github.com/chargebee/chargebee-go/v3/models/purchase" + + "github.com/chargebee/chargebee-go/v3/models/quote" + + "github.com/chargebee/chargebee-go/v3/models/ramp" + + "github.com/chargebee/chargebee-go/v3/models/recordedpurchase" + + "github.com/chargebee/chargebee-go/v3/models/rule" + + "github.com/chargebee/chargebee-go/v3/models/subscription" + + "github.com/chargebee/chargebee-go/v3/models/subscriptionentitlementscreateddetail" + + "github.com/chargebee/chargebee-go/v3/models/subscriptionentitlementsupdateddetail" + + "github.com/chargebee/chargebee-go/v3/models/taxwithheld" + + "github.com/chargebee/chargebee-go/v3/models/token" + + "github.com/chargebee/chargebee-go/v3/models/transaction" + + "github.com/chargebee/chargebee-go/v3/models/unbilledcharge" + + "github.com/chargebee/chargebee-go/v3/models/usagefile" + + "github.com/chargebee/chargebee-go/v3/models/virtualbankaccount" +) + +// Event content structures for each webhook type + +type SubscriptionPauseScheduledContent struct { + Subscription *subscription.Subscription `json:"subscription,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` + + Card *card.Card `json:"card,omitempty"` + + AdvanceInvoiceSchedule *advanceinvoiceschedule.AdvanceInvoiceSchedule `json:"advance_invoice_schedule,omitempty"` +} + +type CustomerBusinessEntityChangedContent struct { + BusinessEntityTransfer *businessentitytransfer.BusinessEntityTransfer `json:"business_entity_transfer,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` +} + +type SubscriptionAdvanceInvoiceScheduleAddedContent struct { + Subscription *subscription.Subscription `json:"subscription,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` + + AdvanceInvoiceSchedule *advanceinvoiceschedule.AdvanceInvoiceSchedule `json:"advance_invoice_schedule,omitempty"` +} + +type GiftExpiredContent struct { + Gift *gift.Gift `json:"gift,omitempty"` +} + +type TaxWithheldDeletedContent struct { + TaxWithheld *taxwithheld.TaxWithheld `json:"tax_withheld,omitempty"` + + Invoice *invoice.Invoice `json:"invoice,omitempty"` + + CreditNote *creditnote.CreditNote `json:"credit_note,omitempty"` +} + +type UnbilledChargesDeletedContent struct { + UnbilledCharge *unbilledcharge.UnbilledCharge `json:"unbilled_charge,omitempty"` +} + +type CouponUpdatedContent struct { + Coupon *coupon.Coupon `json:"coupon,omitempty"` +} + +type ProductUpdatedContent struct { +} + +type OmnichannelSubscriptionItemReactivatedContent struct { + OmnichannelSubscription *omnichannelsubscription.OmnichannelSubscription `json:"omnichannel_subscription,omitempty"` + + OmnichannelSubscriptionItem *omnichannelsubscriptionitem.OmnichannelSubscriptionItem `json:"omnichannel_subscription_item,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` +} + +type OmnichannelSubscriptionItemRenewedContent struct { + OmnichannelSubscriptionItem *omnichannelsubscriptionitem.OmnichannelSubscriptionItem `json:"omnichannel_subscription_item,omitempty"` + + OmnichannelSubscription *omnichannelsubscription.OmnichannelSubscription `json:"omnichannel_subscription,omitempty"` + + OmnichannelTransaction *omnichanneltransaction.OmnichannelTransaction `json:"omnichannel_transaction,omitempty"` + + OmnichannelSubscriptionItemScheduledChange *omnichannelsubscriptionitemscheduledchange.OmnichannelSubscriptionItemScheduledChange `json:"omnichannel_subscription_item_scheduled_change,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` +} + +type UnbilledChargesCreatedContent struct { + UnbilledCharge *unbilledcharge.UnbilledCharge `json:"unbilled_charge,omitempty"` +} + +type SubscriptionResumedContent struct { + Subscription *subscription.Subscription `json:"subscription,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` + + Card *card.Card `json:"card,omitempty"` + + Invoice *invoice.Invoice `json:"invoice,omitempty"` + + UnbilledCharge *unbilledcharge.UnbilledCharge `json:"unbilled_charge,omitempty"` +} + +type OmnichannelOneTimeOrderItemCancelledContent struct { + OmnichannelOneTimeOrder *omnichannelonetimeorder.OmnichannelOneTimeOrder `json:"omnichannel_one_time_order,omitempty"` + + OmnichannelOneTimeOrderItem *omnichannelonetimeorderitem.OmnichannelOneTimeOrderItem `json:"omnichannel_one_time_order_item,omitempty"` + + OmnichannelTransaction *omnichanneltransaction.OmnichannelTransaction `json:"omnichannel_transaction,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` +} + +type SubscriptionCancelledContent struct { + Subscription *subscription.Subscription `json:"subscription,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` + + Card *card.Card `json:"card,omitempty"` + + Invoice *invoice.Invoice `json:"invoice,omitempty"` + + CreditNote *creditnote.CreditNote `json:"credit_note,omitempty"` + + UnbilledCharge *unbilledcharge.UnbilledCharge `json:"unbilled_charge,omitempty"` +} + +type ItemEntitlementsRemovedContent struct { + Feature *feature.Feature `json:"feature,omitempty"` + + Metadata *metadata.Metadata `json:"metadata,omitempty"` + + ImpactedItem *impacteditem.ImpactedItem `json:"impacted_item,omitempty"` + + ImpactedSubscription *impactedsubscription.ImpactedSubscription `json:"impacted_subscription,omitempty"` +} + +type BusinessEntityCreatedContent struct { + BusinessEntity *businessentity.BusinessEntity `json:"business_entity,omitempty"` +} + +type CouponSetUpdatedContent struct { + Coupon *coupon.Coupon `json:"coupon,omitempty"` + + CouponSet *couponset.CouponSet `json:"coupon_set,omitempty"` +} + +type DifferentialPriceUpdatedContent struct { + DifferentialPrice *differentialprice.DifferentialPrice `json:"differential_price,omitempty"` +} + +type OmnichannelSubscriptionItemPausedContent struct { + OmnichannelSubscription *omnichannelsubscription.OmnichannelSubscription `json:"omnichannel_subscription,omitempty"` + + OmnichannelSubscriptionItem *omnichannelsubscriptionitem.OmnichannelSubscriptionItem `json:"omnichannel_subscription_item,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` +} + +type EntitlementOverridesRemovedContent struct { + ImpactedSubscription *impactedsubscription.ImpactedSubscription `json:"impacted_subscription,omitempty"` + + Metadata *metadata.Metadata `json:"metadata,omitempty"` +} + +type SubscriptionActivatedWithBackdatingContent struct { + Subscription *subscription.Subscription `json:"subscription,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` + + Card *card.Card `json:"card,omitempty"` + + Invoice *invoice.Invoice `json:"invoice,omitempty"` + + UnbilledCharge *unbilledcharge.UnbilledCharge `json:"unbilled_charge,omitempty"` +} + +type SubscriptionTrialEndReminderContent struct { + Subscription *subscription.Subscription `json:"subscription,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` + + Card *card.Card `json:"card,omitempty"` + + AdvanceInvoiceSchedule *advanceinvoiceschedule.AdvanceInvoiceSchedule `json:"advance_invoice_schedule,omitempty"` +} + +type SubscriptionShippingAddressUpdatedContent struct { + Subscription *subscription.Subscription `json:"subscription,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` + + Card *card.Card `json:"card,omitempty"` + + AdvanceInvoiceSchedule *advanceinvoiceschedule.AdvanceInvoiceSchedule `json:"advance_invoice_schedule,omitempty"` +} + +type VoucherCreateFailedContent struct { + PaymentVoucher *paymentvoucher.PaymentVoucher `json:"payment_voucher,omitempty"` +} + +type GiftClaimedContent struct { + Gift *gift.Gift `json:"gift,omitempty"` +} + +type CustomerDeletedContent struct { + Customer *customer.Customer `json:"customer,omitempty"` + + Card *card.Card `json:"card,omitempty"` + + Subscription *subscription.Subscription `json:"subscription,omitempty"` +} + +type RefundInitiatedContent struct { + Transaction *transaction.Transaction `json:"transaction,omitempty"` + + Invoice *invoice.Invoice `json:"invoice,omitempty"` + + CreditNote *creditnote.CreditNote `json:"credit_note,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` + + Subscription *subscription.Subscription `json:"subscription,omitempty"` + + Card *card.Card `json:"card,omitempty"` +} + +type InvoiceGeneratedWithBackdatingContent struct { + Invoice *invoice.Invoice `json:"invoice,omitempty"` +} + +type OmnichannelTransactionCreatedContent struct { + OmnichannelTransaction *omnichanneltransaction.OmnichannelTransaction `json:"omnichannel_transaction,omitempty"` +} + +type AddUsagesReminderContent struct { + Subscription *subscription.Subscription `json:"subscription,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` +} + +type VoucherCreatedContent struct { + PaymentVoucher *paymentvoucher.PaymentVoucher `json:"payment_voucher,omitempty"` +} + +type RuleUpdatedContent struct { + Rule *rule.Rule `json:"rule,omitempty"` +} + +type PaymentSchedulesCreatedContent struct { + PaymentSchedule *paymentschedule.PaymentSchedule `json:"payment_schedule,omitempty"` +} + +type FeatureActivatedContent struct { + Feature *feature.Feature `json:"feature,omitempty"` + + Metadata *metadata.Metadata `json:"metadata,omitempty"` + + ImpactedItem *impacteditem.ImpactedItem `json:"impacted_item,omitempty"` + + ImpactedSubscription *impactedsubscription.ImpactedSubscription `json:"impacted_subscription,omitempty"` +} + +type PaymentSourceLocallyDeletedContent struct { + Customer *customer.Customer `json:"customer,omitempty"` + + PaymentSource *paymentsource.PaymentSource `json:"payment_source,omitempty"` +} + +type InvoiceGeneratedContent struct { + Invoice *invoice.Invoice `json:"invoice,omitempty"` +} + +type VoucherExpiredContent struct { + PaymentVoucher *paymentvoucher.PaymentVoucher `json:"payment_voucher,omitempty"` +} + +type AuthorizationSucceededContent struct { + Transaction *transaction.Transaction `json:"transaction,omitempty"` +} + +type GiftScheduledContent struct { + Gift *gift.Gift `json:"gift,omitempty"` +} + +type SubscriptionChangesScheduledContent struct { + Subscription *subscription.Subscription `json:"subscription,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` + + Card *card.Card `json:"card,omitempty"` + + AdvanceInvoiceSchedule *advanceinvoiceschedule.AdvanceInvoiceSchedule `json:"advance_invoice_schedule,omitempty"` +} + +type SubscriptionChangedWithBackdatingContent struct { + Subscription *subscription.Subscription `json:"subscription,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` + + Card *card.Card `json:"card,omitempty"` + + Invoice *invoice.Invoice `json:"invoice,omitempty"` + + CreditNote *creditnote.CreditNote `json:"credit_note,omitempty"` + + UnbilledCharge *unbilledcharge.UnbilledCharge `json:"unbilled_charge,omitempty"` +} + +type VariantCreatedContent struct { +} + +type OmnichannelSubscriptionItemChangedContent struct { + OmnichannelSubscriptionItem *omnichannelsubscriptionitem.OmnichannelSubscriptionItem `json:"omnichannel_subscription_item,omitempty"` + + OmnichannelSubscription *omnichannelsubscription.OmnichannelSubscription `json:"omnichannel_subscription,omitempty"` + + OmnichannelTransaction *omnichanneltransaction.OmnichannelTransaction `json:"omnichannel_transaction,omitempty"` + + OmnichannelSubscriptionItemScheduledChange *omnichannelsubscriptionitemscheduledchange.OmnichannelSubscriptionItemScheduledChange `json:"omnichannel_subscription_item_scheduled_change,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` +} + +type GiftUnclaimedContent struct { + Gift *gift.Gift `json:"gift,omitempty"` +} + +type VirtualBankAccountAddedContent struct { + Customer *customer.Customer `json:"customer,omitempty"` + + VirtualBankAccount *virtualbankaccount.VirtualBankAccount `json:"virtual_bank_account,omitempty"` +} + +type PaymentIntentCreatedContent struct { + PaymentIntent *paymentintent.PaymentIntent `json:"payment_intent,omitempty"` +} + +type CreditNoteCreatedWithBackdatingContent struct { + CreditNote *creditnote.CreditNote `json:"credit_note,omitempty"` +} + +type ContractTermTerminatedContent struct { + ContractTerm *contractterm.ContractTerm `json:"contract_term,omitempty"` +} + +type ItemFamilyUpdatedContent struct { + ItemFamily *itemfamily.ItemFamily `json:"item_family,omitempty"` +} + +type OrderCreatedContent struct { + Order *order.Order `json:"order,omitempty"` +} + +type PriceVariantDeletedContent struct { + PriceVariant *pricevariant.PriceVariant `json:"price_variant,omitempty"` + + Attribute *attribute.Attribute `json:"attribute,omitempty"` +} + +type SubscriptionMovementFailedContent struct { + Subscription *subscription.Subscription `json:"subscription,omitempty"` +} + +type CustomerMovedInContent struct { + Customer *customer.Customer `json:"customer,omitempty"` + + Card *card.Card `json:"card,omitempty"` +} + +type SubscriptionAdvanceInvoiceScheduleUpdatedContent struct { + Subscription *subscription.Subscription `json:"subscription,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` + + AdvanceInvoiceSchedule *advanceinvoiceschedule.AdvanceInvoiceSchedule `json:"advance_invoice_schedule,omitempty"` +} + +type ItemDeletedContent struct { + Item *item.Item `json:"item,omitempty"` +} + +type SubscriptionRampDraftedContent struct { + Ramp *ramp.Ramp `json:"ramp,omitempty"` +} + +type DunningUpdatedContent struct { + Invoice *invoice.Invoice `json:"invoice,omitempty"` +} + +type ItemEntitlementsUpdatedContent struct { + Feature *feature.Feature `json:"feature,omitempty"` + + Metadata *metadata.Metadata `json:"metadata,omitempty"` + + ImpactedItem *impacteditem.ImpactedItem `json:"impacted_item,omitempty"` + + ImpactedSubscription *impactedsubscription.ImpactedSubscription `json:"impacted_subscription,omitempty"` +} + +type TokenConsumedContent struct { + Token *token.Token `json:"token,omitempty"` +} + +type HierarchyDeletedContent struct { + Customer *customer.Customer `json:"customer,omitempty"` +} + +type SubscriptionCancellationScheduledContent struct { + Subscription *subscription.Subscription `json:"subscription,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` + + Card *card.Card `json:"card,omitempty"` + + AdvanceInvoiceSchedule *advanceinvoiceschedule.AdvanceInvoiceSchedule `json:"advance_invoice_schedule,omitempty"` +} + +type SubscriptionRenewedContent struct { + Subscription *subscription.Subscription `json:"subscription,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` + + Card *card.Card `json:"card,omitempty"` + + Invoice *invoice.Invoice `json:"invoice,omitempty"` + + UnbilledCharge *unbilledcharge.UnbilledCharge `json:"unbilled_charge,omitempty"` +} + +type FeatureUpdatedContent struct { + Feature *feature.Feature `json:"feature,omitempty"` + + Metadata *metadata.Metadata `json:"metadata,omitempty"` +} + +type FeatureDeletedContent struct { + Feature *feature.Feature `json:"feature,omitempty"` + + Metadata *metadata.Metadata `json:"metadata,omitempty"` + + ImpactedItem *impacteditem.ImpactedItem `json:"impacted_item,omitempty"` + + ImpactedSubscription *impactedsubscription.ImpactedSubscription `json:"impacted_subscription,omitempty"` +} + +type ItemFamilyCreatedContent struct { + ItemFamily *itemfamily.ItemFamily `json:"item_family,omitempty"` +} + +type OmnichannelSubscriptionItemScheduledChangeRemovedContent struct { + OmnichannelSubscriptionItem *omnichannelsubscriptionitem.OmnichannelSubscriptionItem `json:"omnichannel_subscription_item,omitempty"` + + OmnichannelSubscriptionItemScheduledChange *omnichannelsubscriptionitemscheduledchange.OmnichannelSubscriptionItemScheduledChange `json:"omnichannel_subscription_item_scheduled_change,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` +} + +type OmnichannelSubscriptionItemResumedContent struct { + OmnichannelSubscription *omnichannelsubscription.OmnichannelSubscription `json:"omnichannel_subscription,omitempty"` + + OmnichannelSubscriptionItem *omnichannelsubscriptionitem.OmnichannelSubscriptionItem `json:"omnichannel_subscription_item,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` +} + +type PurchaseCreatedContent struct { + Purchase *purchase.Purchase `json:"purchase,omitempty"` +} + +type EntitlementOverridesUpdatedContent struct { + ImpactedSubscription *impactedsubscription.ImpactedSubscription `json:"impacted_subscription,omitempty"` + + Metadata *metadata.Metadata `json:"metadata,omitempty"` +} + +type ItemFamilyDeletedContent struct { + ItemFamily *itemfamily.ItemFamily `json:"item_family,omitempty"` +} + +type SubscriptionResumptionScheduledContent struct { + Subscription *subscription.Subscription `json:"subscription,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` + + Card *card.Card `json:"card,omitempty"` + + AdvanceInvoiceSchedule *advanceinvoiceschedule.AdvanceInvoiceSchedule `json:"advance_invoice_schedule,omitempty"` +} + +type FeatureReactivatedContent struct { + Feature *feature.Feature `json:"feature,omitempty"` + + Metadata *metadata.Metadata `json:"metadata,omitempty"` +} + +type CouponCodesDeletedContent struct { + Coupon *coupon.Coupon `json:"coupon,omitempty"` + + CouponSet *couponset.CouponSet `json:"coupon_set,omitempty"` + + CouponCode *couponcode.CouponCode `json:"coupon_code,omitempty"` +} + +type CardExpiredContent struct { + Customer *customer.Customer `json:"customer,omitempty"` + + Card *card.Card `json:"card,omitempty"` +} + +type CreditNoteUpdatedContent struct { + CreditNote *creditnote.CreditNote `json:"credit_note,omitempty"` +} + +type OmnichannelSubscriptionItemDowngradedContent struct { + OmnichannelSubscriptionItem *omnichannelsubscriptionitem.OmnichannelSubscriptionItem `json:"omnichannel_subscription_item,omitempty"` + + OmnichannelSubscription *omnichannelsubscription.OmnichannelSubscription `json:"omnichannel_subscription,omitempty"` + + OmnichannelTransaction *omnichanneltransaction.OmnichannelTransaction `json:"omnichannel_transaction,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` +} + +type PriceVariantUpdatedContent struct { + PriceVariant *pricevariant.PriceVariant `json:"price_variant,omitempty"` + + Attribute *attribute.Attribute `json:"attribute,omitempty"` +} + +type PromotionalCreditsDeductedContent struct { + Customer *customer.Customer `json:"customer,omitempty"` + + PromotionalCredit *promotionalcredit.PromotionalCredit `json:"promotional_credit,omitempty"` +} + +type SubscriptionRampAppliedContent struct { + Ramp *ramp.Ramp `json:"ramp,omitempty"` +} + +type SubscriptionPausedContent struct { + Subscription *subscription.Subscription `json:"subscription,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` + + Card *card.Card `json:"card,omitempty"` + + Invoice *invoice.Invoice `json:"invoice,omitempty"` + + CreditNote *creditnote.CreditNote `json:"credit_note,omitempty"` + + UnbilledCharge *unbilledcharge.UnbilledCharge `json:"unbilled_charge,omitempty"` +} + +type OrderReadyToProcessContent struct { + Order *order.Order `json:"order,omitempty"` +} + +type FeatureCreatedContent struct { + Feature *feature.Feature `json:"feature,omitempty"` + + Metadata *metadata.Metadata `json:"metadata,omitempty"` + + ImpactedItem *impacteditem.ImpactedItem `json:"impacted_item,omitempty"` + + ImpactedSubscription *impactedsubscription.ImpactedSubscription `json:"impacted_subscription,omitempty"` +} + +type TransactionDeletedContent struct { + Transaction *transaction.Transaction `json:"transaction,omitempty"` +} + +type CreditNoteCreatedContent struct { + CreditNote *creditnote.CreditNote `json:"credit_note,omitempty"` +} + +type OmnichannelSubscriptionItemResubscribedContent struct { + OmnichannelSubscriptionItem *omnichannelsubscriptionitem.OmnichannelSubscriptionItem `json:"omnichannel_subscription_item,omitempty"` + + OmnichannelSubscription *omnichannelsubscription.OmnichannelSubscription `json:"omnichannel_subscription,omitempty"` + + OmnichannelTransaction *omnichanneltransaction.OmnichannelTransaction `json:"omnichannel_transaction,omitempty"` + + OmnichannelSubscriptionItemScheduledChange *omnichannelsubscriptionitemscheduledchange.OmnichannelSubscriptionItemScheduledChange `json:"omnichannel_subscription_item_scheduled_change,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` +} + +type RecordPurchaseFailedContent struct { + RecordedPurchase *recordedpurchase.RecordedPurchase `json:"recorded_purchase,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` +} + +type ItemCreatedContent struct { + Item *item.Item `json:"item,omitempty"` +} + +type TransactionUpdatedContent struct { + Transaction *transaction.Transaction `json:"transaction,omitempty"` +} + +type VariantDeletedContent struct { +} + +type MrrUpdatedContent struct { + Subscription *subscription.Subscription `json:"subscription,omitempty"` +} + +type UnbilledChargesInvoicedContent struct { + UnbilledCharge *unbilledcharge.UnbilledCharge `json:"unbilled_charge,omitempty"` + + Invoice *invoice.Invoice `json:"invoice,omitempty"` +} + +type ItemPriceUpdatedContent struct { + ItemPrice *itemprice.ItemPrice `json:"item_price,omitempty"` +} + +type CouponCodesUpdatedContent struct { + Coupon *coupon.Coupon `json:"coupon,omitempty"` + + CouponSet *couponset.CouponSet `json:"coupon_set,omitempty"` +} + +type VirtualBankAccountUpdatedContent struct { + Customer *customer.Customer `json:"customer,omitempty"` + + VirtualBankAccount *virtualbankaccount.VirtualBankAccount `json:"virtual_bank_account,omitempty"` +} + +type ContractTermCreatedContent struct { + ContractTerm *contractterm.ContractTerm `json:"contract_term,omitempty"` +} + +type SubscriptionChangedContent struct { + Subscription *subscription.Subscription `json:"subscription,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` + + Card *card.Card `json:"card,omitempty"` + + Invoice *invoice.Invoice `json:"invoice,omitempty"` + + CreditNote *creditnote.CreditNote `json:"credit_note,omitempty"` + + UnbilledCharge *unbilledcharge.UnbilledCharge `json:"unbilled_charge,omitempty"` +} + +type PaymentFailedContent struct { + Transaction *transaction.Transaction `json:"transaction,omitempty"` + + Invoice *invoice.Invoice `json:"invoice,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` + + Subscription *subscription.Subscription `json:"subscription,omitempty"` + + Card *card.Card `json:"card,omitempty"` +} + +type CreditNoteDeletedContent struct { + CreditNote *creditnote.CreditNote `json:"credit_note,omitempty"` +} + +type TaxWithheldRefundedContent struct { + TaxWithheld *taxwithheld.TaxWithheld `json:"tax_withheld,omitempty"` + + Invoice *invoice.Invoice `json:"invoice,omitempty"` + + CreditNote *creditnote.CreditNote `json:"credit_note,omitempty"` +} + +type ContractTermCompletedContent struct { + ContractTerm *contractterm.ContractTerm `json:"contract_term,omitempty"` +} + +type PaymentSchedulesUpdatedContent struct { + PaymentSchedule *paymentschedule.PaymentSchedule `json:"payment_schedule,omitempty"` +} + +type OmnichannelSubscriptionItemExpiredContent struct { + OmnichannelSubscription *omnichannelsubscription.OmnichannelSubscription `json:"omnichannel_subscription,omitempty"` + + OmnichannelSubscriptionItem *omnichannelsubscriptionitem.OmnichannelSubscriptionItem `json:"omnichannel_subscription_item,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` +} + +type CardUpdatedContent struct { + Customer *customer.Customer `json:"customer,omitempty"` + + Card *card.Card `json:"card,omitempty"` +} + +type CustomerCreatedContent struct { + Customer *customer.Customer `json:"customer,omitempty"` + + Card *card.Card `json:"card,omitempty"` +} + +type SubscriptionRenewalReminderContent struct { + Subscription *subscription.Subscription `json:"subscription,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` + + Card *card.Card `json:"card,omitempty"` + + AdvanceInvoiceSchedule *advanceinvoiceschedule.AdvanceInvoiceSchedule `json:"advance_invoice_schedule,omitempty"` +} + +type NetdPaymentDueReminderContent struct { + Invoice *invoice.Invoice `json:"invoice,omitempty"` +} + +type OrderDeliveredContent struct { + Order *order.Order `json:"order,omitempty"` +} + +type OmnichannelSubscriptionItemCancellationScheduledContent struct { + OmnichannelSubscription *omnichannelsubscription.OmnichannelSubscription `json:"omnichannel_subscription,omitempty"` + + OmnichannelSubscriptionItem *omnichannelsubscriptionitem.OmnichannelSubscriptionItem `json:"omnichannel_subscription_item,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` +} + +type OmnichannelSubscriptionItemGracePeriodExpiredContent struct { + OmnichannelSubscription *omnichannelsubscription.OmnichannelSubscription `json:"omnichannel_subscription,omitempty"` + + OmnichannelSubscriptionItem *omnichannelsubscriptionitem.OmnichannelSubscriptionItem `json:"omnichannel_subscription_item,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` +} + +type CouponCodesAddedContent struct { + Coupon *coupon.Coupon `json:"coupon,omitempty"` + + CouponSet *couponset.CouponSet `json:"coupon_set,omitempty"` +} + +type GiftCancelledContent struct { + Gift *gift.Gift `json:"gift,omitempty"` +} + +type OrderCancelledContent struct { + Order *order.Order `json:"order,omitempty"` +} + +type CouponDeletedContent struct { + Coupon *coupon.Coupon `json:"coupon,omitempty"` +} + +type SubscriptionScheduledChangesRemovedContent struct { + Subscription *subscription.Subscription `json:"subscription,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` + + Card *card.Card `json:"card,omitempty"` + + AdvanceInvoiceSchedule *advanceinvoiceschedule.AdvanceInvoiceSchedule `json:"advance_invoice_schedule,omitempty"` +} + +type PendingInvoiceCreatedContent struct { + Invoice *invoice.Invoice `json:"invoice,omitempty"` +} + +type ProductDeletedContent struct { +} + +type EntitlementOverridesAutoRemovedContent struct { + Feature *feature.Feature `json:"feature,omitempty"` + + Metadata *metadata.Metadata `json:"metadata,omitempty"` + + ImpactedItem *impacteditem.ImpactedItem `json:"impacted_item,omitempty"` + + ImpactedSubscription *impactedsubscription.ImpactedSubscription `json:"impacted_subscription,omitempty"` +} + +type OmnichannelSubscriptionItemUpgradedContent struct { + OmnichannelSubscriptionItem *omnichannelsubscriptionitem.OmnichannelSubscriptionItem `json:"omnichannel_subscription_item,omitempty"` + + OmnichannelSubscription *omnichannelsubscription.OmnichannelSubscription `json:"omnichannel_subscription,omitempty"` + + OmnichannelTransaction *omnichanneltransaction.OmnichannelTransaction `json:"omnichannel_transaction,omitempty"` + + OmnichannelSubscriptionItemScheduledChange *omnichannelsubscriptionitemscheduledchange.OmnichannelSubscriptionItemScheduledChange `json:"omnichannel_subscription_item_scheduled_change,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` +} + +type SubscriptionBusinessEntityChangedContent struct { + BusinessEntityTransfer *businessentitytransfer.BusinessEntityTransfer `json:"business_entity_transfer,omitempty"` + + Subscription *subscription.Subscription `json:"subscription,omitempty"` +} + +type OmnichannelOneTimeOrderCreatedContent struct { + OmnichannelOneTimeOrder *omnichannelonetimeorder.OmnichannelOneTimeOrder `json:"omnichannel_one_time_order,omitempty"` + + OmnichannelOneTimeOrderItem *omnichannelonetimeorderitem.OmnichannelOneTimeOrderItem `json:"omnichannel_one_time_order_item,omitempty"` + + OmnichannelTransaction *omnichanneltransaction.OmnichannelTransaction `json:"omnichannel_transaction,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` +} + +type PaymentSourceDeletedContent struct { + Customer *customer.Customer `json:"customer,omitempty"` + + PaymentSource *paymentsource.PaymentSource `json:"payment_source,omitempty"` +} + +type OmnichannelSubscriptionItemCancelledContent struct { + OmnichannelSubscription *omnichannelsubscription.OmnichannelSubscription `json:"omnichannel_subscription,omitempty"` + + OmnichannelSubscriptionItem *omnichannelsubscriptionitem.OmnichannelSubscriptionItem `json:"omnichannel_subscription_item,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` +} + +type QuoteDeletedContent struct { + Quote *quote.Quote `json:"quote,omitempty"` +} + +type InvoiceUpdatedContent struct { + Invoice *invoice.Invoice `json:"invoice,omitempty"` +} + +type SubscriptionAdvanceInvoiceScheduleRemovedContent struct { + Subscription *subscription.Subscription `json:"subscription,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` + + AdvanceInvoiceSchedule *advanceinvoiceschedule.AdvanceInvoiceSchedule `json:"advance_invoice_schedule,omitempty"` +} + +type CardDeletedContent struct { + Customer *customer.Customer `json:"customer,omitempty"` + + Card *card.Card `json:"card,omitempty"` +} + +type OrderReadyToShipContent struct { + Order *order.Order `json:"order,omitempty"` +} + +type VariantUpdatedContent struct { +} + +type SubscriptionMovedOutContent struct { + Subscription *subscription.Subscription `json:"subscription,omitempty"` +} + +type PaymentScheduleSchemeCreatedContent struct { + PaymentScheduleScheme *paymentschedulescheme.PaymentScheduleScheme `json:"payment_schedule_scheme,omitempty"` +} + +type BusinessEntityUpdatedContent struct { + BusinessEntity *businessentity.BusinessEntity `json:"business_entity,omitempty"` +} + +type SubscriptionScheduledResumptionRemovedContent struct { + Subscription *subscription.Subscription `json:"subscription,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` + + Card *card.Card `json:"card,omitempty"` + + AdvanceInvoiceSchedule *advanceinvoiceschedule.AdvanceInvoiceSchedule `json:"advance_invoice_schedule,omitempty"` +} + +type PaymentInitiatedContent struct { + Transaction *transaction.Transaction `json:"transaction,omitempty"` + + Invoice *invoice.Invoice `json:"invoice,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` + + Subscription *subscription.Subscription `json:"subscription,omitempty"` + + Card *card.Card `json:"card,omitempty"` +} + +type FeatureArchivedContent struct { + Feature *feature.Feature `json:"feature,omitempty"` + + Metadata *metadata.Metadata `json:"metadata,omitempty"` +} + +type SubscriptionReactivatedWithBackdatingContent struct { + Subscription *subscription.Subscription `json:"subscription,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` + + Card *card.Card `json:"card,omitempty"` + + Invoice *invoice.Invoice `json:"invoice,omitempty"` + + UnbilledCharge *unbilledcharge.UnbilledCharge `json:"unbilled_charge,omitempty"` +} + +type OmnichannelSubscriptionImportedContent struct { + OmnichannelSubscriptionItem *omnichannelsubscriptionitem.OmnichannelSubscriptionItem `json:"omnichannel_subscription_item,omitempty"` + + OmnichannelSubscription *omnichannelsubscription.OmnichannelSubscription `json:"omnichannel_subscription,omitempty"` + + OmnichannelTransaction *omnichanneltransaction.OmnichannelTransaction `json:"omnichannel_transaction,omitempty"` + + OmnichannelSubscriptionItemScheduledChange *omnichannelsubscriptionitemscheduledchange.OmnichannelSubscriptionItemScheduledChange `json:"omnichannel_subscription_item_scheduled_change,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` +} + +type TokenExpiredContent struct { + Token *token.Token `json:"token,omitempty"` +} + +type CardAddedContent struct { + Customer *customer.Customer `json:"customer,omitempty"` + + Card *card.Card `json:"card,omitempty"` +} + +type CouponCreatedContent struct { + Coupon *coupon.Coupon `json:"coupon,omitempty"` +} + +type RuleDeletedContent struct { + Rule *rule.Rule `json:"rule,omitempty"` +} + +type ItemPriceEntitlementsUpdatedContent struct { + Feature *feature.Feature `json:"feature,omitempty"` + + Metadata *metadata.Metadata `json:"metadata,omitempty"` + + ImpactedItemPrice *impacteditemprice.ImpactedItemPrice `json:"impacted_item_price,omitempty"` + + ImpactedSubscription *impactedsubscription.ImpactedSubscription `json:"impacted_subscription,omitempty"` +} + +type ItemPriceDeletedContent struct { + ItemPrice *itemprice.ItemPrice `json:"item_price,omitempty"` +} + +type VirtualBankAccountDeletedContent struct { + Customer *customer.Customer `json:"customer,omitempty"` + + VirtualBankAccount *virtualbankaccount.VirtualBankAccount `json:"virtual_bank_account,omitempty"` +} + +type PaymentScheduleSchemeDeletedContent struct { + PaymentScheduleScheme *paymentschedulescheme.PaymentScheduleScheme `json:"payment_schedule_scheme,omitempty"` +} + +type SubscriptionCreatedContent struct { + Subscription *subscription.Subscription `json:"subscription,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` + + Card *card.Card `json:"card,omitempty"` + + Invoice *invoice.Invoice `json:"invoice,omitempty"` + + UnbilledCharge *unbilledcharge.UnbilledCharge `json:"unbilled_charge,omitempty"` +} + +type SubscriptionEntitlementsCreatedContent struct { + SubscriptionEntitlementsCreatedDetail *subscriptionentitlementscreateddetail.SubscriptionEntitlementsCreatedDetail `json:"subscription_entitlements_created_detail,omitempty"` +} + +type OrderReturnedContent struct { + Order *order.Order `json:"order,omitempty"` +} + +type SubscriptionDeletedContent struct { + Subscription *subscription.Subscription `json:"subscription,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` + + Card *card.Card `json:"card,omitempty"` + + AdvanceInvoiceSchedule *advanceinvoiceschedule.AdvanceInvoiceSchedule `json:"advance_invoice_schedule,omitempty"` +} + +type PaymentSourceAddedContent struct { + Customer *customer.Customer `json:"customer,omitempty"` + + PaymentSource *paymentsource.PaymentSource `json:"payment_source,omitempty"` +} + +type SubscriptionMovedInContent struct { + Subscription *subscription.Subscription `json:"subscription,omitempty"` +} + +type ItemPriceCreatedContent struct { + ItemPrice *itemprice.ItemPrice `json:"item_price,omitempty"` +} + +type SubscriptionScheduledCancellationRemovedContent struct { + Subscription *subscription.Subscription `json:"subscription,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` + + Card *card.Card `json:"card,omitempty"` + + AdvanceInvoiceSchedule *advanceinvoiceschedule.AdvanceInvoiceSchedule `json:"advance_invoice_schedule,omitempty"` +} + +type PaymentRefundedContent struct { + Transaction *transaction.Transaction `json:"transaction,omitempty"` + + Invoice *invoice.Invoice `json:"invoice,omitempty"` + + CreditNote *creditnote.CreditNote `json:"credit_note,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` + + Subscription *subscription.Subscription `json:"subscription,omitempty"` + + Card *card.Card `json:"card,omitempty"` +} + +type UsageFileIngestedContent struct { + UsageFile *usagefile.UsageFile `json:"usage_file,omitempty"` +} + +type ProductCreatedContent struct { +} + +type OmnichannelSubscriptionMovedInContent struct { + OmnichannelSubscription *omnichannelsubscription.OmnichannelSubscription `json:"omnichannel_subscription,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` +} + +type DifferentialPriceCreatedContent struct { + DifferentialPrice *differentialprice.DifferentialPrice `json:"differential_price,omitempty"` +} + +type TransactionCreatedContent struct { + Transaction *transaction.Transaction `json:"transaction,omitempty"` +} + +type OmnichannelSubscriptionItemDowngradeScheduledContent struct { + OmnichannelSubscription *omnichannelsubscription.OmnichannelSubscription `json:"omnichannel_subscription,omitempty"` + + OmnichannelSubscriptionItem *omnichannelsubscriptionitem.OmnichannelSubscriptionItem `json:"omnichannel_subscription_item,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` +} + +type PaymentSucceededContent struct { + Transaction *transaction.Transaction `json:"transaction,omitempty"` + + Invoice *invoice.Invoice `json:"invoice,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` + + Subscription *subscription.Subscription `json:"subscription,omitempty"` + + Card *card.Card `json:"card,omitempty"` +} + +type SubscriptionCanceledWithBackdatingContent struct { + Subscription *subscription.Subscription `json:"subscription,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` + + Card *card.Card `json:"card,omitempty"` + + Invoice *invoice.Invoice `json:"invoice,omitempty"` + + CreditNote *creditnote.CreditNote `json:"credit_note,omitempty"` + + UnbilledCharge *unbilledcharge.UnbilledCharge `json:"unbilled_charge,omitempty"` +} + +type UnbilledChargesVoidedContent struct { + UnbilledCharge *unbilledcharge.UnbilledCharge `json:"unbilled_charge,omitempty"` +} + +type QuoteCreatedContent struct { + Quote *quote.Quote `json:"quote,omitempty"` +} + +type CouponSetDeletedContent struct { + Coupon *coupon.Coupon `json:"coupon,omitempty"` + + CouponSet *couponset.CouponSet `json:"coupon_set,omitempty"` +} + +type AttachedItemCreatedContent struct { + AttachedItem *attacheditem.AttachedItem `json:"attached_item,omitempty"` +} + +type SalesOrderCreatedContent struct { +} + +type CustomerChangedContent struct { + Customer *customer.Customer `json:"customer,omitempty"` + + Card *card.Card `json:"card,omitempty"` +} + +type SubscriptionStartedContent struct { + Subscription *subscription.Subscription `json:"subscription,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` + + Card *card.Card `json:"card,omitempty"` + + Invoice *invoice.Invoice `json:"invoice,omitempty"` +} + +type SubscriptionActivatedContent struct { + Subscription *subscription.Subscription `json:"subscription,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` + + Card *card.Card `json:"card,omitempty"` + + Invoice *invoice.Invoice `json:"invoice,omitempty"` +} + +type PaymentSourceExpiringContent struct { + Customer *customer.Customer `json:"customer,omitempty"` + + PaymentSource *paymentsource.PaymentSource `json:"payment_source,omitempty"` +} + +type SubscriptionReactivatedContent struct { + Subscription *subscription.Subscription `json:"subscription,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` + + Card *card.Card `json:"card,omitempty"` + + Invoice *invoice.Invoice `json:"invoice,omitempty"` + + UnbilledCharge *unbilledcharge.UnbilledCharge `json:"unbilled_charge,omitempty"` +} + +type OrderUpdatedContent struct { + Order *order.Order `json:"order,omitempty"` +} + +type SubscriptionScheduledPauseRemovedContent struct { + Subscription *subscription.Subscription `json:"subscription,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` + + Card *card.Card `json:"card,omitempty"` + + AdvanceInvoiceSchedule *advanceinvoiceschedule.AdvanceInvoiceSchedule `json:"advance_invoice_schedule,omitempty"` +} + +type SubscriptionCancellationReminderContent struct { + Subscription *subscription.Subscription `json:"subscription,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` + + Card *card.Card `json:"card,omitempty"` + + AdvanceInvoiceSchedule *advanceinvoiceschedule.AdvanceInvoiceSchedule `json:"advance_invoice_schedule,omitempty"` +} + +type SubscriptionCreatedWithBackdatingContent struct { + Subscription *subscription.Subscription `json:"subscription,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` + + Card *card.Card `json:"card,omitempty"` + + Invoice *invoice.Invoice `json:"invoice,omitempty"` + + UnbilledCharge *unbilledcharge.UnbilledCharge `json:"unbilled_charge,omitempty"` +} + +type SubscriptionRampCreatedContent struct { + Ramp *ramp.Ramp `json:"ramp,omitempty"` +} + +type OrderDeletedContent struct { + Order *order.Order `json:"order,omitempty"` +} + +type OmnichannelSubscriptionItemPauseScheduledContent struct { + OmnichannelSubscriptionItem *omnichannelsubscriptionitem.OmnichannelSubscriptionItem `json:"omnichannel_subscription_item,omitempty"` + + OmnichannelSubscriptionItemScheduledChange *omnichannelsubscriptionitemscheduledchange.OmnichannelSubscriptionItemScheduledChange `json:"omnichannel_subscription_item_scheduled_change,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` +} + +type GiftUpdatedContent struct { + Gift *gift.Gift `json:"gift,omitempty"` +} + +type SubscriptionTrialExtendedContent struct { + Subscription *subscription.Subscription `json:"subscription,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` + + Card *card.Card `json:"card,omitempty"` + + AdvanceInvoiceSchedule *advanceinvoiceschedule.AdvanceInvoiceSchedule `json:"advance_invoice_schedule,omitempty"` +} + +type OmnichannelSubscriptionItemGracePeriodStartedContent struct { + OmnichannelSubscription *omnichannelsubscription.OmnichannelSubscription `json:"omnichannel_subscription,omitempty"` + + OmnichannelSubscriptionItem *omnichannelsubscriptionitem.OmnichannelSubscriptionItem `json:"omnichannel_subscription_item,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` +} + +type CardExpiryReminderContent struct { + Customer *customer.Customer `json:"customer,omitempty"` + + Card *card.Card `json:"card,omitempty"` +} + +type TokenCreatedContent struct { + Token *token.Token `json:"token,omitempty"` +} + +type PromotionalCreditsAddedContent struct { + Customer *customer.Customer `json:"customer,omitempty"` + + PromotionalCredit *promotionalcredit.PromotionalCredit `json:"promotional_credit,omitempty"` +} + +type SubscriptionRampUpdatedContent struct { + Ramp *ramp.Ramp `json:"ramp,omitempty"` +} + +type CustomerEntitlementsUpdatedContent struct { + ImpactedCustomer *impactedcustomer.ImpactedCustomer `json:"impacted_customer,omitempty"` +} + +type PaymentSourceExpiredContent struct { + Customer *customer.Customer `json:"customer,omitempty"` + + PaymentSource *paymentsource.PaymentSource `json:"payment_source,omitempty"` +} + +type CustomerMovedOutContent struct { + Customer *customer.Customer `json:"customer,omitempty"` + + Card *card.Card `json:"card,omitempty"` +} + +type SubscriptionEntitlementsUpdatedContent struct { + SubscriptionEntitlementsUpdatedDetail *subscriptionentitlementsupdateddetail.SubscriptionEntitlementsUpdatedDetail `json:"subscription_entitlements_updated_detail,omitempty"` +} + +type OmnichannelSubscriptionItemDunningExpiredContent struct { + OmnichannelSubscription *omnichannelsubscription.OmnichannelSubscription `json:"omnichannel_subscription,omitempty"` + + OmnichannelSubscriptionItem *omnichannelsubscriptionitem.OmnichannelSubscriptionItem `json:"omnichannel_subscription_item,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` +} + +type HierarchyCreatedContent struct { + Customer *customer.Customer `json:"customer,omitempty"` +} + +type AttachedItemDeletedContent struct { + AttachedItem *attacheditem.AttachedItem `json:"attached_item,omitempty"` +} + +type OmnichannelSubscriptionItemScheduledCancellationRemovedContent struct { + OmnichannelSubscription *omnichannelsubscription.OmnichannelSubscription `json:"omnichannel_subscription,omitempty"` + + OmnichannelSubscriptionItem *omnichannelsubscriptionitem.OmnichannelSubscriptionItem `json:"omnichannel_subscription_item,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` +} + +type ItemUpdatedContent struct { + Item *item.Item `json:"item,omitempty"` +} + +type CouponSetCreatedContent struct { + Coupon *coupon.Coupon `json:"coupon,omitempty"` + + CouponSet *couponset.CouponSet `json:"coupon_set,omitempty"` +} + +type PaymentIntentUpdatedContent struct { + PaymentIntent *paymentintent.PaymentIntent `json:"payment_intent,omitempty"` +} + +type OrderResentContent struct { + Order *order.Order `json:"order,omitempty"` +} + +type OmnichannelSubscriptionItemScheduledDowngradeRemovedContent struct { + OmnichannelSubscription *omnichannelsubscription.OmnichannelSubscription `json:"omnichannel_subscription,omitempty"` + + OmnichannelSubscriptionItem *omnichannelsubscriptionitem.OmnichannelSubscriptionItem `json:"omnichannel_subscription_item,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` +} + +type OmnichannelSubscriptionCreatedContent struct { + OmnichannelSubscriptionItem *omnichannelsubscriptionitem.OmnichannelSubscriptionItem `json:"omnichannel_subscription_item,omitempty"` + + OmnichannelSubscription *omnichannelsubscription.OmnichannelSubscription `json:"omnichannel_subscription,omitempty"` + + OmnichannelTransaction *omnichanneltransaction.OmnichannelTransaction `json:"omnichannel_transaction,omitempty"` + + OmnichannelSubscriptionItemScheduledChange *omnichannelsubscriptionitemscheduledchange.OmnichannelSubscriptionItemScheduledChange `json:"omnichannel_subscription_item_scheduled_change,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` +} + +type TaxWithheldRecordedContent struct { + TaxWithheld *taxwithheld.TaxWithheld `json:"tax_withheld,omitempty"` + + Invoice *invoice.Invoice `json:"invoice,omitempty"` + + CreditNote *creditnote.CreditNote `json:"credit_note,omitempty"` +} + +type PriceVariantCreatedContent struct { + PriceVariant *pricevariant.PriceVariant `json:"price_variant,omitempty"` + + Attribute *attribute.Attribute `json:"attribute,omitempty"` +} + +type DifferentialPriceDeletedContent struct { + DifferentialPrice *differentialprice.DifferentialPrice `json:"differential_price,omitempty"` +} + +type SubscriptionItemsRenewedContent struct { + Subscription *subscription.Subscription `json:"subscription,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` + + Card *card.Card `json:"card,omitempty"` + + Invoice *invoice.Invoice `json:"invoice,omitempty"` + + CreditNote *creditnote.CreditNote `json:"credit_note,omitempty"` + + UnbilledCharge *unbilledcharge.UnbilledCharge `json:"unbilled_charge,omitempty"` +} + +type RuleCreatedContent struct { + Rule *rule.Rule `json:"rule,omitempty"` +} + +type ContractTermCancelledContent struct { + ContractTerm *contractterm.ContractTerm `json:"contract_term,omitempty"` +} + +type ContractTermRenewedContent struct { + ContractTerm *contractterm.ContractTerm `json:"contract_term,omitempty"` +} + +type InvoiceDeletedContent struct { + Invoice *invoice.Invoice `json:"invoice,omitempty"` +} + +type ItemPriceEntitlementsRemovedContent struct { + Feature *feature.Feature `json:"feature,omitempty"` + + Metadata *metadata.Metadata `json:"metadata,omitempty"` + + ImpactedItemPrice *impacteditemprice.ImpactedItemPrice `json:"impacted_item_price,omitempty"` + + ImpactedSubscription *impactedsubscription.ImpactedSubscription `json:"impacted_subscription,omitempty"` +} + +type SalesOrderUpdatedContent struct { +} + +type OmnichannelSubscriptionItemDunningStartedContent struct { + OmnichannelSubscription *omnichannelsubscription.OmnichannelSubscription `json:"omnichannel_subscription,omitempty"` + + OmnichannelSubscriptionItem *omnichannelsubscriptionitem.OmnichannelSubscriptionItem `json:"omnichannel_subscription_item,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` +} + +type OmnichannelSubscriptionItemChangeScheduledContent struct { + OmnichannelSubscriptionItem *omnichannelsubscriptionitem.OmnichannelSubscriptionItem `json:"omnichannel_subscription_item,omitempty"` + + OmnichannelSubscriptionItemScheduledChange *omnichannelsubscriptionitemscheduledchange.OmnichannelSubscriptionItemScheduledChange `json:"omnichannel_subscription_item_scheduled_change,omitempty"` + + Customer *customer.Customer `json:"customer,omitempty"` +} + +type PendingInvoiceUpdatedContent struct { + Invoice *invoice.Invoice `json:"invoice,omitempty"` +} + +type QuoteUpdatedContent struct { + Quote *quote.Quote `json:"quote,omitempty"` +} + +type AttachedItemUpdatedContent struct { + AttachedItem *attacheditem.AttachedItem `json:"attached_item,omitempty"` +} + +type PaymentSourceUpdatedContent struct { + Customer *customer.Customer `json:"customer,omitempty"` + + PaymentSource *paymentsource.PaymentSource `json:"payment_source,omitempty"` +} + +type BusinessEntityDeletedContent struct { + BusinessEntity *businessentity.BusinessEntity `json:"business_entity,omitempty"` +} + +type AuthorizationVoidedContent struct { + Transaction *transaction.Transaction `json:"transaction,omitempty"` +} + +type SubscriptionRampDeletedContent struct { + Ramp *ramp.Ramp `json:"ramp,omitempty"` +} + +type PlanDeletedContent struct { + Plan *plan.Plan `json:"plan,omitempty"` +} + +type AddonDeletedContent struct { + Addon *addon.Addon `json:"addon,omitempty"` +} + +type AddonUpdatedContent struct { + Addon *addon.Addon `json:"addon,omitempty"` +} + +type AddonCreatedContent struct { + Addon *addon.Addon `json:"addon,omitempty"` +} + +type PlanCreatedContent struct { + Plan *plan.Plan `json:"plan,omitempty"` +} + +type PlanUpdatedContent struct { + Plan *plan.Plan `json:"plan,omitempty"` +} + +type BaseEvent struct { + Id string `json:"id"` + OccurredAt int64 `json:"occurred_at"` + Source string `json:"source"` + Object string `json:"object"` + ApiVersion string `json:"api_version"` + EventType string `json:"event_type"` + WebhookStatus string `json:"webhook_status"` +} + +func (e *BaseEvent) GetOccurredAtTime() time.Time { + return time.Unix(e.OccurredAt, 0) +} + +// SubscriptionPauseScheduledEvent represents a subscription_pause_scheduled webhook event +type SubscriptionPauseScheduledEvent struct { + BaseEvent + Content *SubscriptionPauseScheduledContent `json:"content"` +} + +// CustomerBusinessEntityChangedEvent represents a customer_business_entity_changed webhook event +type CustomerBusinessEntityChangedEvent struct { + BaseEvent + Content *CustomerBusinessEntityChangedContent `json:"content"` +} + +// SubscriptionAdvanceInvoiceScheduleAddedEvent represents a subscription_advance_invoice_schedule_added webhook event +type SubscriptionAdvanceInvoiceScheduleAddedEvent struct { + BaseEvent + Content *SubscriptionAdvanceInvoiceScheduleAddedContent `json:"content"` +} + +// GiftExpiredEvent represents a gift_expired webhook event +type GiftExpiredEvent struct { + BaseEvent + Content *GiftExpiredContent `json:"content"` +} + +// TaxWithheldDeletedEvent represents a tax_withheld_deleted webhook event +type TaxWithheldDeletedEvent struct { + BaseEvent + Content *TaxWithheldDeletedContent `json:"content"` +} + +// UnbilledChargesDeletedEvent represents a unbilled_charges_deleted webhook event +type UnbilledChargesDeletedEvent struct { + BaseEvent + Content *UnbilledChargesDeletedContent `json:"content"` +} + +// CouponUpdatedEvent represents a coupon_updated webhook event +type CouponUpdatedEvent struct { + BaseEvent + Content *CouponUpdatedContent `json:"content"` +} + +// ProductUpdatedEvent represents a product_updated webhook event +type ProductUpdatedEvent struct { + BaseEvent + Content *ProductUpdatedContent `json:"content"` +} + +// OmnichannelSubscriptionItemReactivatedEvent represents a omnichannel_subscription_item_reactivated webhook event +type OmnichannelSubscriptionItemReactivatedEvent struct { + BaseEvent + Content *OmnichannelSubscriptionItemReactivatedContent `json:"content"` +} + +// OmnichannelSubscriptionItemRenewedEvent represents a omnichannel_subscription_item_renewed webhook event +type OmnichannelSubscriptionItemRenewedEvent struct { + BaseEvent + Content *OmnichannelSubscriptionItemRenewedContent `json:"content"` +} + +// UnbilledChargesCreatedEvent represents a unbilled_charges_created webhook event +type UnbilledChargesCreatedEvent struct { + BaseEvent + Content *UnbilledChargesCreatedContent `json:"content"` +} + +// SubscriptionResumedEvent represents a subscription_resumed webhook event +type SubscriptionResumedEvent struct { + BaseEvent + Content *SubscriptionResumedContent `json:"content"` +} + +// OmnichannelOneTimeOrderItemCancelledEvent represents a omnichannel_one_time_order_item_cancelled webhook event +type OmnichannelOneTimeOrderItemCancelledEvent struct { + BaseEvent + Content *OmnichannelOneTimeOrderItemCancelledContent `json:"content"` +} + +// SubscriptionCancelledEvent represents a subscription_cancelled webhook event +type SubscriptionCancelledEvent struct { + BaseEvent + Content *SubscriptionCancelledContent `json:"content"` +} + +// ItemEntitlementsRemovedEvent represents a item_entitlements_removed webhook event +type ItemEntitlementsRemovedEvent struct { + BaseEvent + Content *ItemEntitlementsRemovedContent `json:"content"` +} + +// BusinessEntityCreatedEvent represents a business_entity_created webhook event +type BusinessEntityCreatedEvent struct { + BaseEvent + Content *BusinessEntityCreatedContent `json:"content"` +} + +// CouponSetUpdatedEvent represents a coupon_set_updated webhook event +type CouponSetUpdatedEvent struct { + BaseEvent + Content *CouponSetUpdatedContent `json:"content"` +} + +// DifferentialPriceUpdatedEvent represents a differential_price_updated webhook event +type DifferentialPriceUpdatedEvent struct { + BaseEvent + Content *DifferentialPriceUpdatedContent `json:"content"` +} + +// OmnichannelSubscriptionItemPausedEvent represents a omnichannel_subscription_item_paused webhook event +type OmnichannelSubscriptionItemPausedEvent struct { + BaseEvent + Content *OmnichannelSubscriptionItemPausedContent `json:"content"` +} + +// EntitlementOverridesRemovedEvent represents a entitlement_overrides_removed webhook event +type EntitlementOverridesRemovedEvent struct { + BaseEvent + Content *EntitlementOverridesRemovedContent `json:"content"` +} + +// SubscriptionActivatedWithBackdatingEvent represents a subscription_activated_with_backdating webhook event +type SubscriptionActivatedWithBackdatingEvent struct { + BaseEvent + Content *SubscriptionActivatedWithBackdatingContent `json:"content"` +} + +// SubscriptionTrialEndReminderEvent represents a subscription_trial_end_reminder webhook event +type SubscriptionTrialEndReminderEvent struct { + BaseEvent + Content *SubscriptionTrialEndReminderContent `json:"content"` +} + +// SubscriptionShippingAddressUpdatedEvent represents a subscription_shipping_address_updated webhook event +type SubscriptionShippingAddressUpdatedEvent struct { + BaseEvent + Content *SubscriptionShippingAddressUpdatedContent `json:"content"` +} + +// VoucherCreateFailedEvent represents a voucher_create_failed webhook event +type VoucherCreateFailedEvent struct { + BaseEvent + Content *VoucherCreateFailedContent `json:"content"` +} + +// GiftClaimedEvent represents a gift_claimed webhook event +type GiftClaimedEvent struct { + BaseEvent + Content *GiftClaimedContent `json:"content"` +} + +// CustomerDeletedEvent represents a customer_deleted webhook event +type CustomerDeletedEvent struct { + BaseEvent + Content *CustomerDeletedContent `json:"content"` +} + +// RefundInitiatedEvent represents a refund_initiated webhook event +type RefundInitiatedEvent struct { + BaseEvent + Content *RefundInitiatedContent `json:"content"` +} + +// InvoiceGeneratedWithBackdatingEvent represents a invoice_generated_with_backdating webhook event +type InvoiceGeneratedWithBackdatingEvent struct { + BaseEvent + Content *InvoiceGeneratedWithBackdatingContent `json:"content"` +} + +// OmnichannelTransactionCreatedEvent represents a omnichannel_transaction_created webhook event +type OmnichannelTransactionCreatedEvent struct { + BaseEvent + Content *OmnichannelTransactionCreatedContent `json:"content"` +} + +// AddUsagesReminderEvent represents a add_usages_reminder webhook event +type AddUsagesReminderEvent struct { + BaseEvent + Content *AddUsagesReminderContent `json:"content"` +} + +// VoucherCreatedEvent represents a voucher_created webhook event +type VoucherCreatedEvent struct { + BaseEvent + Content *VoucherCreatedContent `json:"content"` +} + +// RuleUpdatedEvent represents a rule_updated webhook event +type RuleUpdatedEvent struct { + BaseEvent + Content *RuleUpdatedContent `json:"content"` +} + +// PaymentSchedulesCreatedEvent represents a payment_schedules_created webhook event +type PaymentSchedulesCreatedEvent struct { + BaseEvent + Content *PaymentSchedulesCreatedContent `json:"content"` +} + +// FeatureActivatedEvent represents a feature_activated webhook event +type FeatureActivatedEvent struct { + BaseEvent + Content *FeatureActivatedContent `json:"content"` +} + +// PaymentSourceLocallyDeletedEvent represents a payment_source_locally_deleted webhook event +type PaymentSourceLocallyDeletedEvent struct { + BaseEvent + Content *PaymentSourceLocallyDeletedContent `json:"content"` +} + +// InvoiceGeneratedEvent represents a invoice_generated webhook event +type InvoiceGeneratedEvent struct { + BaseEvent + Content *InvoiceGeneratedContent `json:"content"` +} + +// VoucherExpiredEvent represents a voucher_expired webhook event +type VoucherExpiredEvent struct { + BaseEvent + Content *VoucherExpiredContent `json:"content"` +} + +// AuthorizationSucceededEvent represents a authorization_succeeded webhook event +type AuthorizationSucceededEvent struct { + BaseEvent + Content *AuthorizationSucceededContent `json:"content"` +} + +// GiftScheduledEvent represents a gift_scheduled webhook event +type GiftScheduledEvent struct { + BaseEvent + Content *GiftScheduledContent `json:"content"` +} + +// SubscriptionChangesScheduledEvent represents a subscription_changes_scheduled webhook event +type SubscriptionChangesScheduledEvent struct { + BaseEvent + Content *SubscriptionChangesScheduledContent `json:"content"` +} + +// SubscriptionChangedWithBackdatingEvent represents a subscription_changed_with_backdating webhook event +type SubscriptionChangedWithBackdatingEvent struct { + BaseEvent + Content *SubscriptionChangedWithBackdatingContent `json:"content"` +} + +// VariantCreatedEvent represents a variant_created webhook event +type VariantCreatedEvent struct { + BaseEvent + Content *VariantCreatedContent `json:"content"` +} + +// OmnichannelSubscriptionItemChangedEvent represents a omnichannel_subscription_item_changed webhook event +type OmnichannelSubscriptionItemChangedEvent struct { + BaseEvent + Content *OmnichannelSubscriptionItemChangedContent `json:"content"` +} + +// GiftUnclaimedEvent represents a gift_unclaimed webhook event +type GiftUnclaimedEvent struct { + BaseEvent + Content *GiftUnclaimedContent `json:"content"` +} + +// VirtualBankAccountAddedEvent represents a virtual_bank_account_added webhook event +type VirtualBankAccountAddedEvent struct { + BaseEvent + Content *VirtualBankAccountAddedContent `json:"content"` +} + +// PaymentIntentCreatedEvent represents a payment_intent_created webhook event +type PaymentIntentCreatedEvent struct { + BaseEvent + Content *PaymentIntentCreatedContent `json:"content"` +} + +// CreditNoteCreatedWithBackdatingEvent represents a credit_note_created_with_backdating webhook event +type CreditNoteCreatedWithBackdatingEvent struct { + BaseEvent + Content *CreditNoteCreatedWithBackdatingContent `json:"content"` +} + +// ContractTermTerminatedEvent represents a contract_term_terminated webhook event +type ContractTermTerminatedEvent struct { + BaseEvent + Content *ContractTermTerminatedContent `json:"content"` +} + +// ItemFamilyUpdatedEvent represents a item_family_updated webhook event +type ItemFamilyUpdatedEvent struct { + BaseEvent + Content *ItemFamilyUpdatedContent `json:"content"` +} + +// OrderCreatedEvent represents a order_created webhook event +type OrderCreatedEvent struct { + BaseEvent + Content *OrderCreatedContent `json:"content"` +} + +// PriceVariantDeletedEvent represents a price_variant_deleted webhook event +type PriceVariantDeletedEvent struct { + BaseEvent + Content *PriceVariantDeletedContent `json:"content"` +} + +// SubscriptionMovementFailedEvent represents a subscription_movement_failed webhook event +type SubscriptionMovementFailedEvent struct { + BaseEvent + Content *SubscriptionMovementFailedContent `json:"content"` +} + +// CustomerMovedInEvent represents a customer_moved_in webhook event +type CustomerMovedInEvent struct { + BaseEvent + Content *CustomerMovedInContent `json:"content"` +} + +// SubscriptionAdvanceInvoiceScheduleUpdatedEvent represents a subscription_advance_invoice_schedule_updated webhook event +type SubscriptionAdvanceInvoiceScheduleUpdatedEvent struct { + BaseEvent + Content *SubscriptionAdvanceInvoiceScheduleUpdatedContent `json:"content"` +} + +// ItemDeletedEvent represents a item_deleted webhook event +type ItemDeletedEvent struct { + BaseEvent + Content *ItemDeletedContent `json:"content"` +} + +// SubscriptionRampDraftedEvent represents a subscription_ramp_drafted webhook event +type SubscriptionRampDraftedEvent struct { + BaseEvent + Content *SubscriptionRampDraftedContent `json:"content"` +} + +// DunningUpdatedEvent represents a dunning_updated webhook event +type DunningUpdatedEvent struct { + BaseEvent + Content *DunningUpdatedContent `json:"content"` +} + +// ItemEntitlementsUpdatedEvent represents a item_entitlements_updated webhook event +type ItemEntitlementsUpdatedEvent struct { + BaseEvent + Content *ItemEntitlementsUpdatedContent `json:"content"` +} + +// TokenConsumedEvent represents a token_consumed webhook event +type TokenConsumedEvent struct { + BaseEvent + Content *TokenConsumedContent `json:"content"` +} + +// HierarchyDeletedEvent represents a hierarchy_deleted webhook event +type HierarchyDeletedEvent struct { + BaseEvent + Content *HierarchyDeletedContent `json:"content"` +} + +// SubscriptionCancellationScheduledEvent represents a subscription_cancellation_scheduled webhook event +type SubscriptionCancellationScheduledEvent struct { + BaseEvent + Content *SubscriptionCancellationScheduledContent `json:"content"` +} + +// SubscriptionRenewedEvent represents a subscription_renewed webhook event +type SubscriptionRenewedEvent struct { + BaseEvent + Content *SubscriptionRenewedContent `json:"content"` +} + +// FeatureUpdatedEvent represents a feature_updated webhook event +type FeatureUpdatedEvent struct { + BaseEvent + Content *FeatureUpdatedContent `json:"content"` +} + +// FeatureDeletedEvent represents a feature_deleted webhook event +type FeatureDeletedEvent struct { + BaseEvent + Content *FeatureDeletedContent `json:"content"` +} + +// ItemFamilyCreatedEvent represents a item_family_created webhook event +type ItemFamilyCreatedEvent struct { + BaseEvent + Content *ItemFamilyCreatedContent `json:"content"` +} + +// OmnichannelSubscriptionItemScheduledChangeRemovedEvent represents a omnichannel_subscription_item_scheduled_change_removed webhook event +type OmnichannelSubscriptionItemScheduledChangeRemovedEvent struct { + BaseEvent + Content *OmnichannelSubscriptionItemScheduledChangeRemovedContent `json:"content"` +} + +// OmnichannelSubscriptionItemResumedEvent represents a omnichannel_subscription_item_resumed webhook event +type OmnichannelSubscriptionItemResumedEvent struct { + BaseEvent + Content *OmnichannelSubscriptionItemResumedContent `json:"content"` +} + +// PurchaseCreatedEvent represents a purchase_created webhook event +type PurchaseCreatedEvent struct { + BaseEvent + Content *PurchaseCreatedContent `json:"content"` +} + +// EntitlementOverridesUpdatedEvent represents a entitlement_overrides_updated webhook event +type EntitlementOverridesUpdatedEvent struct { + BaseEvent + Content *EntitlementOverridesUpdatedContent `json:"content"` +} + +// ItemFamilyDeletedEvent represents a item_family_deleted webhook event +type ItemFamilyDeletedEvent struct { + BaseEvent + Content *ItemFamilyDeletedContent `json:"content"` +} + +// SubscriptionResumptionScheduledEvent represents a subscription_resumption_scheduled webhook event +type SubscriptionResumptionScheduledEvent struct { + BaseEvent + Content *SubscriptionResumptionScheduledContent `json:"content"` +} + +// FeatureReactivatedEvent represents a feature_reactivated webhook event +type FeatureReactivatedEvent struct { + BaseEvent + Content *FeatureReactivatedContent `json:"content"` +} + +// CouponCodesDeletedEvent represents a coupon_codes_deleted webhook event +type CouponCodesDeletedEvent struct { + BaseEvent + Content *CouponCodesDeletedContent `json:"content"` +} + +// CardExpiredEvent represents a card_expired webhook event +type CardExpiredEvent struct { + BaseEvent + Content *CardExpiredContent `json:"content"` +} + +// CreditNoteUpdatedEvent represents a credit_note_updated webhook event +type CreditNoteUpdatedEvent struct { + BaseEvent + Content *CreditNoteUpdatedContent `json:"content"` +} + +// OmnichannelSubscriptionItemDowngradedEvent represents a omnichannel_subscription_item_downgraded webhook event +type OmnichannelSubscriptionItemDowngradedEvent struct { + BaseEvent + Content *OmnichannelSubscriptionItemDowngradedContent `json:"content"` +} + +// PriceVariantUpdatedEvent represents a price_variant_updated webhook event +type PriceVariantUpdatedEvent struct { + BaseEvent + Content *PriceVariantUpdatedContent `json:"content"` +} + +// PromotionalCreditsDeductedEvent represents a promotional_credits_deducted webhook event +type PromotionalCreditsDeductedEvent struct { + BaseEvent + Content *PromotionalCreditsDeductedContent `json:"content"` +} + +// SubscriptionRampAppliedEvent represents a subscription_ramp_applied webhook event +type SubscriptionRampAppliedEvent struct { + BaseEvent + Content *SubscriptionRampAppliedContent `json:"content"` +} + +// SubscriptionPausedEvent represents a subscription_paused webhook event +type SubscriptionPausedEvent struct { + BaseEvent + Content *SubscriptionPausedContent `json:"content"` +} + +// OrderReadyToProcessEvent represents a order_ready_to_process webhook event +type OrderReadyToProcessEvent struct { + BaseEvent + Content *OrderReadyToProcessContent `json:"content"` +} + +// FeatureCreatedEvent represents a feature_created webhook event +type FeatureCreatedEvent struct { + BaseEvent + Content *FeatureCreatedContent `json:"content"` +} + +// TransactionDeletedEvent represents a transaction_deleted webhook event +type TransactionDeletedEvent struct { + BaseEvent + Content *TransactionDeletedContent `json:"content"` +} + +// CreditNoteCreatedEvent represents a credit_note_created webhook event +type CreditNoteCreatedEvent struct { + BaseEvent + Content *CreditNoteCreatedContent `json:"content"` +} + +// OmnichannelSubscriptionItemResubscribedEvent represents a omnichannel_subscription_item_resubscribed webhook event +type OmnichannelSubscriptionItemResubscribedEvent struct { + BaseEvent + Content *OmnichannelSubscriptionItemResubscribedContent `json:"content"` +} + +// RecordPurchaseFailedEvent represents a record_purchase_failed webhook event +type RecordPurchaseFailedEvent struct { + BaseEvent + Content *RecordPurchaseFailedContent `json:"content"` +} + +// ItemCreatedEvent represents a item_created webhook event +type ItemCreatedEvent struct { + BaseEvent + Content *ItemCreatedContent `json:"content"` +} + +// TransactionUpdatedEvent represents a transaction_updated webhook event +type TransactionUpdatedEvent struct { + BaseEvent + Content *TransactionUpdatedContent `json:"content"` +} + +// VariantDeletedEvent represents a variant_deleted webhook event +type VariantDeletedEvent struct { + BaseEvent + Content *VariantDeletedContent `json:"content"` +} + +// MrrUpdatedEvent represents a mrr_updated webhook event +type MrrUpdatedEvent struct { + BaseEvent + Content *MrrUpdatedContent `json:"content"` +} + +// UnbilledChargesInvoicedEvent represents a unbilled_charges_invoiced webhook event +type UnbilledChargesInvoicedEvent struct { + BaseEvent + Content *UnbilledChargesInvoicedContent `json:"content"` +} + +// ItemPriceUpdatedEvent represents a item_price_updated webhook event +type ItemPriceUpdatedEvent struct { + BaseEvent + Content *ItemPriceUpdatedContent `json:"content"` +} + +// CouponCodesUpdatedEvent represents a coupon_codes_updated webhook event +type CouponCodesUpdatedEvent struct { + BaseEvent + Content *CouponCodesUpdatedContent `json:"content"` +} + +// VirtualBankAccountUpdatedEvent represents a virtual_bank_account_updated webhook event +type VirtualBankAccountUpdatedEvent struct { + BaseEvent + Content *VirtualBankAccountUpdatedContent `json:"content"` +} + +// ContractTermCreatedEvent represents a contract_term_created webhook event +type ContractTermCreatedEvent struct { + BaseEvent + Content *ContractTermCreatedContent `json:"content"` +} + +// SubscriptionChangedEvent represents a subscription_changed webhook event +type SubscriptionChangedEvent struct { + BaseEvent + Content *SubscriptionChangedContent `json:"content"` +} + +// PaymentFailedEvent represents a payment_failed webhook event +type PaymentFailedEvent struct { + BaseEvent + Content *PaymentFailedContent `json:"content"` +} + +// CreditNoteDeletedEvent represents a credit_note_deleted webhook event +type CreditNoteDeletedEvent struct { + BaseEvent + Content *CreditNoteDeletedContent `json:"content"` +} + +// TaxWithheldRefundedEvent represents a tax_withheld_refunded webhook event +type TaxWithheldRefundedEvent struct { + BaseEvent + Content *TaxWithheldRefundedContent `json:"content"` +} + +// ContractTermCompletedEvent represents a contract_term_completed webhook event +type ContractTermCompletedEvent struct { + BaseEvent + Content *ContractTermCompletedContent `json:"content"` +} + +// PaymentSchedulesUpdatedEvent represents a payment_schedules_updated webhook event +type PaymentSchedulesUpdatedEvent struct { + BaseEvent + Content *PaymentSchedulesUpdatedContent `json:"content"` +} + +// OmnichannelSubscriptionItemExpiredEvent represents a omnichannel_subscription_item_expired webhook event +type OmnichannelSubscriptionItemExpiredEvent struct { + BaseEvent + Content *OmnichannelSubscriptionItemExpiredContent `json:"content"` +} + +// CardUpdatedEvent represents a card_updated webhook event +type CardUpdatedEvent struct { + BaseEvent + Content *CardUpdatedContent `json:"content"` +} + +// CustomerCreatedEvent represents a customer_created webhook event +type CustomerCreatedEvent struct { + BaseEvent + Content *CustomerCreatedContent `json:"content"` +} + +// SubscriptionRenewalReminderEvent represents a subscription_renewal_reminder webhook event +type SubscriptionRenewalReminderEvent struct { + BaseEvent + Content *SubscriptionRenewalReminderContent `json:"content"` +} + +// NetdPaymentDueReminderEvent represents a netd_payment_due_reminder webhook event +type NetdPaymentDueReminderEvent struct { + BaseEvent + Content *NetdPaymentDueReminderContent `json:"content"` +} + +// OrderDeliveredEvent represents a order_delivered webhook event +type OrderDeliveredEvent struct { + BaseEvent + Content *OrderDeliveredContent `json:"content"` +} + +// OmnichannelSubscriptionItemCancellationScheduledEvent represents a omnichannel_subscription_item_cancellation_scheduled webhook event +type OmnichannelSubscriptionItemCancellationScheduledEvent struct { + BaseEvent + Content *OmnichannelSubscriptionItemCancellationScheduledContent `json:"content"` +} + +// OmnichannelSubscriptionItemGracePeriodExpiredEvent represents a omnichannel_subscription_item_grace_period_expired webhook event +type OmnichannelSubscriptionItemGracePeriodExpiredEvent struct { + BaseEvent + Content *OmnichannelSubscriptionItemGracePeriodExpiredContent `json:"content"` +} + +// CouponCodesAddedEvent represents a coupon_codes_added webhook event +type CouponCodesAddedEvent struct { + BaseEvent + Content *CouponCodesAddedContent `json:"content"` +} + +// GiftCancelledEvent represents a gift_cancelled webhook event +type GiftCancelledEvent struct { + BaseEvent + Content *GiftCancelledContent `json:"content"` +} + +// OrderCancelledEvent represents a order_cancelled webhook event +type OrderCancelledEvent struct { + BaseEvent + Content *OrderCancelledContent `json:"content"` +} + +// CouponDeletedEvent represents a coupon_deleted webhook event +type CouponDeletedEvent struct { + BaseEvent + Content *CouponDeletedContent `json:"content"` +} + +// SubscriptionScheduledChangesRemovedEvent represents a subscription_scheduled_changes_removed webhook event +type SubscriptionScheduledChangesRemovedEvent struct { + BaseEvent + Content *SubscriptionScheduledChangesRemovedContent `json:"content"` +} + +// PendingInvoiceCreatedEvent represents a pending_invoice_created webhook event +type PendingInvoiceCreatedEvent struct { + BaseEvent + Content *PendingInvoiceCreatedContent `json:"content"` +} + +// ProductDeletedEvent represents a product_deleted webhook event +type ProductDeletedEvent struct { + BaseEvent + Content *ProductDeletedContent `json:"content"` +} + +// EntitlementOverridesAutoRemovedEvent represents a entitlement_overrides_auto_removed webhook event +type EntitlementOverridesAutoRemovedEvent struct { + BaseEvent + Content *EntitlementOverridesAutoRemovedContent `json:"content"` +} + +// OmnichannelSubscriptionItemUpgradedEvent represents a omnichannel_subscription_item_upgraded webhook event +type OmnichannelSubscriptionItemUpgradedEvent struct { + BaseEvent + Content *OmnichannelSubscriptionItemUpgradedContent `json:"content"` +} + +// SubscriptionBusinessEntityChangedEvent represents a subscription_business_entity_changed webhook event +type SubscriptionBusinessEntityChangedEvent struct { + BaseEvent + Content *SubscriptionBusinessEntityChangedContent `json:"content"` +} + +// OmnichannelOneTimeOrderCreatedEvent represents a omnichannel_one_time_order_created webhook event +type OmnichannelOneTimeOrderCreatedEvent struct { + BaseEvent + Content *OmnichannelOneTimeOrderCreatedContent `json:"content"` +} + +// PaymentSourceDeletedEvent represents a payment_source_deleted webhook event +type PaymentSourceDeletedEvent struct { + BaseEvent + Content *PaymentSourceDeletedContent `json:"content"` +} + +// OmnichannelSubscriptionItemCancelledEvent represents a omnichannel_subscription_item_cancelled webhook event +type OmnichannelSubscriptionItemCancelledEvent struct { + BaseEvent + Content *OmnichannelSubscriptionItemCancelledContent `json:"content"` +} + +// QuoteDeletedEvent represents a quote_deleted webhook event +type QuoteDeletedEvent struct { + BaseEvent + Content *QuoteDeletedContent `json:"content"` +} + +// InvoiceUpdatedEvent represents a invoice_updated webhook event +type InvoiceUpdatedEvent struct { + BaseEvent + Content *InvoiceUpdatedContent `json:"content"` +} + +// SubscriptionAdvanceInvoiceScheduleRemovedEvent represents a subscription_advance_invoice_schedule_removed webhook event +type SubscriptionAdvanceInvoiceScheduleRemovedEvent struct { + BaseEvent + Content *SubscriptionAdvanceInvoiceScheduleRemovedContent `json:"content"` +} + +// CardDeletedEvent represents a card_deleted webhook event +type CardDeletedEvent struct { + BaseEvent + Content *CardDeletedContent `json:"content"` +} + +// OrderReadyToShipEvent represents a order_ready_to_ship webhook event +type OrderReadyToShipEvent struct { + BaseEvent + Content *OrderReadyToShipContent `json:"content"` +} + +// VariantUpdatedEvent represents a variant_updated webhook event +type VariantUpdatedEvent struct { + BaseEvent + Content *VariantUpdatedContent `json:"content"` +} + +// SubscriptionMovedOutEvent represents a subscription_moved_out webhook event +type SubscriptionMovedOutEvent struct { + BaseEvent + Content *SubscriptionMovedOutContent `json:"content"` +} + +// PaymentScheduleSchemeCreatedEvent represents a payment_schedule_scheme_created webhook event +type PaymentScheduleSchemeCreatedEvent struct { + BaseEvent + Content *PaymentScheduleSchemeCreatedContent `json:"content"` +} + +// BusinessEntityUpdatedEvent represents a business_entity_updated webhook event +type BusinessEntityUpdatedEvent struct { + BaseEvent + Content *BusinessEntityUpdatedContent `json:"content"` +} + +// SubscriptionScheduledResumptionRemovedEvent represents a subscription_scheduled_resumption_removed webhook event +type SubscriptionScheduledResumptionRemovedEvent struct { + BaseEvent + Content *SubscriptionScheduledResumptionRemovedContent `json:"content"` +} + +// PaymentInitiatedEvent represents a payment_initiated webhook event +type PaymentInitiatedEvent struct { + BaseEvent + Content *PaymentInitiatedContent `json:"content"` +} + +// FeatureArchivedEvent represents a feature_archived webhook event +type FeatureArchivedEvent struct { + BaseEvent + Content *FeatureArchivedContent `json:"content"` +} + +// SubscriptionReactivatedWithBackdatingEvent represents a subscription_reactivated_with_backdating webhook event +type SubscriptionReactivatedWithBackdatingEvent struct { + BaseEvent + Content *SubscriptionReactivatedWithBackdatingContent `json:"content"` +} + +// OmnichannelSubscriptionImportedEvent represents a omnichannel_subscription_imported webhook event +type OmnichannelSubscriptionImportedEvent struct { + BaseEvent + Content *OmnichannelSubscriptionImportedContent `json:"content"` +} + +// TokenExpiredEvent represents a token_expired webhook event +type TokenExpiredEvent struct { + BaseEvent + Content *TokenExpiredContent `json:"content"` +} + +// CardAddedEvent represents a card_added webhook event +type CardAddedEvent struct { + BaseEvent + Content *CardAddedContent `json:"content"` +} + +// CouponCreatedEvent represents a coupon_created webhook event +type CouponCreatedEvent struct { + BaseEvent + Content *CouponCreatedContent `json:"content"` +} + +// RuleDeletedEvent represents a rule_deleted webhook event +type RuleDeletedEvent struct { + BaseEvent + Content *RuleDeletedContent `json:"content"` +} + +// ItemPriceEntitlementsUpdatedEvent represents a item_price_entitlements_updated webhook event +type ItemPriceEntitlementsUpdatedEvent struct { + BaseEvent + Content *ItemPriceEntitlementsUpdatedContent `json:"content"` +} + +// ItemPriceDeletedEvent represents a item_price_deleted webhook event +type ItemPriceDeletedEvent struct { + BaseEvent + Content *ItemPriceDeletedContent `json:"content"` +} + +// VirtualBankAccountDeletedEvent represents a virtual_bank_account_deleted webhook event +type VirtualBankAccountDeletedEvent struct { + BaseEvent + Content *VirtualBankAccountDeletedContent `json:"content"` +} + +// PaymentScheduleSchemeDeletedEvent represents a payment_schedule_scheme_deleted webhook event +type PaymentScheduleSchemeDeletedEvent struct { + BaseEvent + Content *PaymentScheduleSchemeDeletedContent `json:"content"` +} + +// SubscriptionCreatedEvent represents a subscription_created webhook event +type SubscriptionCreatedEvent struct { + BaseEvent + Content *SubscriptionCreatedContent `json:"content"` +} + +// SubscriptionEntitlementsCreatedEvent represents a subscription_entitlements_created webhook event +type SubscriptionEntitlementsCreatedEvent struct { + BaseEvent + Content *SubscriptionEntitlementsCreatedContent `json:"content"` +} + +// OrderReturnedEvent represents a order_returned webhook event +type OrderReturnedEvent struct { + BaseEvent + Content *OrderReturnedContent `json:"content"` +} + +// SubscriptionDeletedEvent represents a subscription_deleted webhook event +type SubscriptionDeletedEvent struct { + BaseEvent + Content *SubscriptionDeletedContent `json:"content"` +} + +// PaymentSourceAddedEvent represents a payment_source_added webhook event +type PaymentSourceAddedEvent struct { + BaseEvent + Content *PaymentSourceAddedContent `json:"content"` +} + +// SubscriptionMovedInEvent represents a subscription_moved_in webhook event +type SubscriptionMovedInEvent struct { + BaseEvent + Content *SubscriptionMovedInContent `json:"content"` +} + +// ItemPriceCreatedEvent represents a item_price_created webhook event +type ItemPriceCreatedEvent struct { + BaseEvent + Content *ItemPriceCreatedContent `json:"content"` +} + +// SubscriptionScheduledCancellationRemovedEvent represents a subscription_scheduled_cancellation_removed webhook event +type SubscriptionScheduledCancellationRemovedEvent struct { + BaseEvent + Content *SubscriptionScheduledCancellationRemovedContent `json:"content"` +} + +// PaymentRefundedEvent represents a payment_refunded webhook event +type PaymentRefundedEvent struct { + BaseEvent + Content *PaymentRefundedContent `json:"content"` +} + +// UsageFileIngestedEvent represents a usage_file_ingested webhook event +type UsageFileIngestedEvent struct { + BaseEvent + Content *UsageFileIngestedContent `json:"content"` +} + +// ProductCreatedEvent represents a product_created webhook event +type ProductCreatedEvent struct { + BaseEvent + Content *ProductCreatedContent `json:"content"` +} + +// OmnichannelSubscriptionMovedInEvent represents a omnichannel_subscription_moved_in webhook event +type OmnichannelSubscriptionMovedInEvent struct { + BaseEvent + Content *OmnichannelSubscriptionMovedInContent `json:"content"` +} + +// DifferentialPriceCreatedEvent represents a differential_price_created webhook event +type DifferentialPriceCreatedEvent struct { + BaseEvent + Content *DifferentialPriceCreatedContent `json:"content"` +} + +// TransactionCreatedEvent represents a transaction_created webhook event +type TransactionCreatedEvent struct { + BaseEvent + Content *TransactionCreatedContent `json:"content"` +} + +// OmnichannelSubscriptionItemDowngradeScheduledEvent represents a omnichannel_subscription_item_downgrade_scheduled webhook event +type OmnichannelSubscriptionItemDowngradeScheduledEvent struct { + BaseEvent + Content *OmnichannelSubscriptionItemDowngradeScheduledContent `json:"content"` +} + +// PaymentSucceededEvent represents a payment_succeeded webhook event +type PaymentSucceededEvent struct { + BaseEvent + Content *PaymentSucceededContent `json:"content"` +} + +// SubscriptionCanceledWithBackdatingEvent represents a subscription_canceled_with_backdating webhook event +type SubscriptionCanceledWithBackdatingEvent struct { + BaseEvent + Content *SubscriptionCanceledWithBackdatingContent `json:"content"` +} + +// UnbilledChargesVoidedEvent represents a unbilled_charges_voided webhook event +type UnbilledChargesVoidedEvent struct { + BaseEvent + Content *UnbilledChargesVoidedContent `json:"content"` +} + +// QuoteCreatedEvent represents a quote_created webhook event +type QuoteCreatedEvent struct { + BaseEvent + Content *QuoteCreatedContent `json:"content"` +} + +// CouponSetDeletedEvent represents a coupon_set_deleted webhook event +type CouponSetDeletedEvent struct { + BaseEvent + Content *CouponSetDeletedContent `json:"content"` +} + +// AttachedItemCreatedEvent represents a attached_item_created webhook event +type AttachedItemCreatedEvent struct { + BaseEvent + Content *AttachedItemCreatedContent `json:"content"` +} + +// SalesOrderCreatedEvent represents a sales_order_created webhook event +type SalesOrderCreatedEvent struct { + BaseEvent + Content *SalesOrderCreatedContent `json:"content"` +} + +// CustomerChangedEvent represents a customer_changed webhook event +type CustomerChangedEvent struct { + BaseEvent + Content *CustomerChangedContent `json:"content"` +} + +// SubscriptionStartedEvent represents a subscription_started webhook event +type SubscriptionStartedEvent struct { + BaseEvent + Content *SubscriptionStartedContent `json:"content"` +} + +// SubscriptionActivatedEvent represents a subscription_activated webhook event +type SubscriptionActivatedEvent struct { + BaseEvent + Content *SubscriptionActivatedContent `json:"content"` +} + +// PaymentSourceExpiringEvent represents a payment_source_expiring webhook event +type PaymentSourceExpiringEvent struct { + BaseEvent + Content *PaymentSourceExpiringContent `json:"content"` +} + +// SubscriptionReactivatedEvent represents a subscription_reactivated webhook event +type SubscriptionReactivatedEvent struct { + BaseEvent + Content *SubscriptionReactivatedContent `json:"content"` +} + +// OrderUpdatedEvent represents a order_updated webhook event +type OrderUpdatedEvent struct { + BaseEvent + Content *OrderUpdatedContent `json:"content"` +} + +// SubscriptionScheduledPauseRemovedEvent represents a subscription_scheduled_pause_removed webhook event +type SubscriptionScheduledPauseRemovedEvent struct { + BaseEvent + Content *SubscriptionScheduledPauseRemovedContent `json:"content"` +} + +// SubscriptionCancellationReminderEvent represents a subscription_cancellation_reminder webhook event +type SubscriptionCancellationReminderEvent struct { + BaseEvent + Content *SubscriptionCancellationReminderContent `json:"content"` +} + +// SubscriptionCreatedWithBackdatingEvent represents a subscription_created_with_backdating webhook event +type SubscriptionCreatedWithBackdatingEvent struct { + BaseEvent + Content *SubscriptionCreatedWithBackdatingContent `json:"content"` +} + +// SubscriptionRampCreatedEvent represents a subscription_ramp_created webhook event +type SubscriptionRampCreatedEvent struct { + BaseEvent + Content *SubscriptionRampCreatedContent `json:"content"` +} + +// OrderDeletedEvent represents a order_deleted webhook event +type OrderDeletedEvent struct { + BaseEvent + Content *OrderDeletedContent `json:"content"` +} + +// OmnichannelSubscriptionItemPauseScheduledEvent represents a omnichannel_subscription_item_pause_scheduled webhook event +type OmnichannelSubscriptionItemPauseScheduledEvent struct { + BaseEvent + Content *OmnichannelSubscriptionItemPauseScheduledContent `json:"content"` +} + +// GiftUpdatedEvent represents a gift_updated webhook event +type GiftUpdatedEvent struct { + BaseEvent + Content *GiftUpdatedContent `json:"content"` +} + +// SubscriptionTrialExtendedEvent represents a subscription_trial_extended webhook event +type SubscriptionTrialExtendedEvent struct { + BaseEvent + Content *SubscriptionTrialExtendedContent `json:"content"` +} + +// OmnichannelSubscriptionItemGracePeriodStartedEvent represents a omnichannel_subscription_item_grace_period_started webhook event +type OmnichannelSubscriptionItemGracePeriodStartedEvent struct { + BaseEvent + Content *OmnichannelSubscriptionItemGracePeriodStartedContent `json:"content"` +} + +// CardExpiryReminderEvent represents a card_expiry_reminder webhook event +type CardExpiryReminderEvent struct { + BaseEvent + Content *CardExpiryReminderContent `json:"content"` +} + +// TokenCreatedEvent represents a token_created webhook event +type TokenCreatedEvent struct { + BaseEvent + Content *TokenCreatedContent `json:"content"` +} + +// PromotionalCreditsAddedEvent represents a promotional_credits_added webhook event +type PromotionalCreditsAddedEvent struct { + BaseEvent + Content *PromotionalCreditsAddedContent `json:"content"` +} + +// SubscriptionRampUpdatedEvent represents a subscription_ramp_updated webhook event +type SubscriptionRampUpdatedEvent struct { + BaseEvent + Content *SubscriptionRampUpdatedContent `json:"content"` +} + +// CustomerEntitlementsUpdatedEvent represents a customer_entitlements_updated webhook event +type CustomerEntitlementsUpdatedEvent struct { + BaseEvent + Content *CustomerEntitlementsUpdatedContent `json:"content"` +} + +// PaymentSourceExpiredEvent represents a payment_source_expired webhook event +type PaymentSourceExpiredEvent struct { + BaseEvent + Content *PaymentSourceExpiredContent `json:"content"` +} + +// CustomerMovedOutEvent represents a customer_moved_out webhook event +type CustomerMovedOutEvent struct { + BaseEvent + Content *CustomerMovedOutContent `json:"content"` +} + +// SubscriptionEntitlementsUpdatedEvent represents a subscription_entitlements_updated webhook event +type SubscriptionEntitlementsUpdatedEvent struct { + BaseEvent + Content *SubscriptionEntitlementsUpdatedContent `json:"content"` +} + +// OmnichannelSubscriptionItemDunningExpiredEvent represents a omnichannel_subscription_item_dunning_expired webhook event +type OmnichannelSubscriptionItemDunningExpiredEvent struct { + BaseEvent + Content *OmnichannelSubscriptionItemDunningExpiredContent `json:"content"` +} + +// HierarchyCreatedEvent represents a hierarchy_created webhook event +type HierarchyCreatedEvent struct { + BaseEvent + Content *HierarchyCreatedContent `json:"content"` +} + +// AttachedItemDeletedEvent represents a attached_item_deleted webhook event +type AttachedItemDeletedEvent struct { + BaseEvent + Content *AttachedItemDeletedContent `json:"content"` +} + +// OmnichannelSubscriptionItemScheduledCancellationRemovedEvent represents a omnichannel_subscription_item_scheduled_cancellation_removed webhook event +type OmnichannelSubscriptionItemScheduledCancellationRemovedEvent struct { + BaseEvent + Content *OmnichannelSubscriptionItemScheduledCancellationRemovedContent `json:"content"` +} + +// ItemUpdatedEvent represents a item_updated webhook event +type ItemUpdatedEvent struct { + BaseEvent + Content *ItemUpdatedContent `json:"content"` +} + +// CouponSetCreatedEvent represents a coupon_set_created webhook event +type CouponSetCreatedEvent struct { + BaseEvent + Content *CouponSetCreatedContent `json:"content"` +} + +// PaymentIntentUpdatedEvent represents a payment_intent_updated webhook event +type PaymentIntentUpdatedEvent struct { + BaseEvent + Content *PaymentIntentUpdatedContent `json:"content"` +} + +// OrderResentEvent represents a order_resent webhook event +type OrderResentEvent struct { + BaseEvent + Content *OrderResentContent `json:"content"` +} + +// OmnichannelSubscriptionItemScheduledDowngradeRemovedEvent represents a omnichannel_subscription_item_scheduled_downgrade_removed webhook event +type OmnichannelSubscriptionItemScheduledDowngradeRemovedEvent struct { + BaseEvent + Content *OmnichannelSubscriptionItemScheduledDowngradeRemovedContent `json:"content"` +} + +// OmnichannelSubscriptionCreatedEvent represents a omnichannel_subscription_created webhook event +type OmnichannelSubscriptionCreatedEvent struct { + BaseEvent + Content *OmnichannelSubscriptionCreatedContent `json:"content"` +} + +// TaxWithheldRecordedEvent represents a tax_withheld_recorded webhook event +type TaxWithheldRecordedEvent struct { + BaseEvent + Content *TaxWithheldRecordedContent `json:"content"` +} + +// PriceVariantCreatedEvent represents a price_variant_created webhook event +type PriceVariantCreatedEvent struct { + BaseEvent + Content *PriceVariantCreatedContent `json:"content"` +} + +// DifferentialPriceDeletedEvent represents a differential_price_deleted webhook event +type DifferentialPriceDeletedEvent struct { + BaseEvent + Content *DifferentialPriceDeletedContent `json:"content"` +} + +// SubscriptionItemsRenewedEvent represents a subscription_items_renewed webhook event +type SubscriptionItemsRenewedEvent struct { + BaseEvent + Content *SubscriptionItemsRenewedContent `json:"content"` +} + +// RuleCreatedEvent represents a rule_created webhook event +type RuleCreatedEvent struct { + BaseEvent + Content *RuleCreatedContent `json:"content"` +} + +// ContractTermCancelledEvent represents a contract_term_cancelled webhook event +type ContractTermCancelledEvent struct { + BaseEvent + Content *ContractTermCancelledContent `json:"content"` +} + +// ContractTermRenewedEvent represents a contract_term_renewed webhook event +type ContractTermRenewedEvent struct { + BaseEvent + Content *ContractTermRenewedContent `json:"content"` +} + +// InvoiceDeletedEvent represents a invoice_deleted webhook event +type InvoiceDeletedEvent struct { + BaseEvent + Content *InvoiceDeletedContent `json:"content"` +} + +// ItemPriceEntitlementsRemovedEvent represents a item_price_entitlements_removed webhook event +type ItemPriceEntitlementsRemovedEvent struct { + BaseEvent + Content *ItemPriceEntitlementsRemovedContent `json:"content"` +} + +// SalesOrderUpdatedEvent represents a sales_order_updated webhook event +type SalesOrderUpdatedEvent struct { + BaseEvent + Content *SalesOrderUpdatedContent `json:"content"` +} + +// OmnichannelSubscriptionItemDunningStartedEvent represents a omnichannel_subscription_item_dunning_started webhook event +type OmnichannelSubscriptionItemDunningStartedEvent struct { + BaseEvent + Content *OmnichannelSubscriptionItemDunningStartedContent `json:"content"` +} + +// OmnichannelSubscriptionItemChangeScheduledEvent represents a omnichannel_subscription_item_change_scheduled webhook event +type OmnichannelSubscriptionItemChangeScheduledEvent struct { + BaseEvent + Content *OmnichannelSubscriptionItemChangeScheduledContent `json:"content"` +} + +// PendingInvoiceUpdatedEvent represents a pending_invoice_updated webhook event +type PendingInvoiceUpdatedEvent struct { + BaseEvent + Content *PendingInvoiceUpdatedContent `json:"content"` +} + +// QuoteUpdatedEvent represents a quote_updated webhook event +type QuoteUpdatedEvent struct { + BaseEvent + Content *QuoteUpdatedContent `json:"content"` +} + +// AttachedItemUpdatedEvent represents a attached_item_updated webhook event +type AttachedItemUpdatedEvent struct { + BaseEvent + Content *AttachedItemUpdatedContent `json:"content"` +} + +// PaymentSourceUpdatedEvent represents a payment_source_updated webhook event +type PaymentSourceUpdatedEvent struct { + BaseEvent + Content *PaymentSourceUpdatedContent `json:"content"` +} + +// BusinessEntityDeletedEvent represents a business_entity_deleted webhook event +type BusinessEntityDeletedEvent struct { + BaseEvent + Content *BusinessEntityDeletedContent `json:"content"` +} + +// AuthorizationVoidedEvent represents a authorization_voided webhook event +type AuthorizationVoidedEvent struct { + BaseEvent + Content *AuthorizationVoidedContent `json:"content"` +} + +// SubscriptionRampDeletedEvent represents a subscription_ramp_deleted webhook event +type SubscriptionRampDeletedEvent struct { + BaseEvent + Content *SubscriptionRampDeletedContent `json:"content"` +} + +// PlanDeletedEvent represents a plan_deleted webhook event +type PlanDeletedEvent struct { + BaseEvent + Content *PlanDeletedContent `json:"content"` +} + +// AddonDeletedEvent represents a addon_deleted webhook event +type AddonDeletedEvent struct { + BaseEvent + Content *AddonDeletedContent `json:"content"` +} + +// AddonUpdatedEvent represents a addon_updated webhook event +type AddonUpdatedEvent struct { + BaseEvent + Content *AddonUpdatedContent `json:"content"` +} + +// AddonCreatedEvent represents a addon_created webhook event +type AddonCreatedEvent struct { + BaseEvent + Content *AddonCreatedContent `json:"content"` +} + +// PlanCreatedEvent represents a plan_created webhook event +type PlanCreatedEvent struct { + BaseEvent + Content *PlanCreatedContent `json:"content"` +} + +// PlanUpdatedEvent represents a plan_updated webhook event +type PlanUpdatedEvent struct { + BaseEvent + Content *PlanUpdatedContent `json:"content"` +} diff --git a/webhook/handler.go b/webhook/handler.go new file mode 100644 index 00000000..cc7a95e2 --- /dev/null +++ b/webhook/handler.go @@ -0,0 +1,2986 @@ +package webhook + +import ( + "encoding/json" + "errors" + "fmt" + "io" + "net/http" + + "github.com/chargebee/chargebee-go/v3/enum" +) + +type WebhookHandler struct { + RequestValidator func(*http.Request) error + OnError func(http.ResponseWriter, *http.Request, error) + OnUnhandledEvent func(enum.EventType, []byte) error + + OnAddUsagesReminder func(AddUsagesReminderEvent) error + + OnAddonCreated func(AddonCreatedEvent) error + + OnAddonDeleted func(AddonDeletedEvent) error + + OnAddonUpdated func(AddonUpdatedEvent) error + + OnAttachedItemCreated func(AttachedItemCreatedEvent) error + + OnAttachedItemDeleted func(AttachedItemDeletedEvent) error + + OnAttachedItemUpdated func(AttachedItemUpdatedEvent) error + + OnAuthorizationSucceeded func(AuthorizationSucceededEvent) error + + OnAuthorizationVoided func(AuthorizationVoidedEvent) error + + OnBusinessEntityCreated func(BusinessEntityCreatedEvent) error + + OnBusinessEntityDeleted func(BusinessEntityDeletedEvent) error + + OnBusinessEntityUpdated func(BusinessEntityUpdatedEvent) error + + OnCardAdded func(CardAddedEvent) error + + OnCardDeleted func(CardDeletedEvent) error + + OnCardExpired func(CardExpiredEvent) error + + OnCardExpiryReminder func(CardExpiryReminderEvent) error + + OnCardUpdated func(CardUpdatedEvent) error + + OnContractTermCancelled func(ContractTermCancelledEvent) error + + OnContractTermCompleted func(ContractTermCompletedEvent) error + + OnContractTermCreated func(ContractTermCreatedEvent) error + + OnContractTermRenewed func(ContractTermRenewedEvent) error + + OnContractTermTerminated func(ContractTermTerminatedEvent) error + + OnCouponCodesAdded func(CouponCodesAddedEvent) error + + OnCouponCodesDeleted func(CouponCodesDeletedEvent) error + + OnCouponCodesUpdated func(CouponCodesUpdatedEvent) error + + OnCouponCreated func(CouponCreatedEvent) error + + OnCouponDeleted func(CouponDeletedEvent) error + + OnCouponSetCreated func(CouponSetCreatedEvent) error + + OnCouponSetDeleted func(CouponSetDeletedEvent) error + + OnCouponSetUpdated func(CouponSetUpdatedEvent) error + + OnCouponUpdated func(CouponUpdatedEvent) error + + OnCreditNoteCreated func(CreditNoteCreatedEvent) error + + OnCreditNoteCreatedWithBackdating func(CreditNoteCreatedWithBackdatingEvent) error + + OnCreditNoteDeleted func(CreditNoteDeletedEvent) error + + OnCreditNoteUpdated func(CreditNoteUpdatedEvent) error + + OnCustomerBusinessEntityChanged func(CustomerBusinessEntityChangedEvent) error + + OnCustomerChanged func(CustomerChangedEvent) error + + OnCustomerCreated func(CustomerCreatedEvent) error + + OnCustomerDeleted func(CustomerDeletedEvent) error + + OnCustomerEntitlementsUpdated func(CustomerEntitlementsUpdatedEvent) error + + OnCustomerMovedIn func(CustomerMovedInEvent) error + + OnCustomerMovedOut func(CustomerMovedOutEvent) error + + OnDifferentialPriceCreated func(DifferentialPriceCreatedEvent) error + + OnDifferentialPriceDeleted func(DifferentialPriceDeletedEvent) error + + OnDifferentialPriceUpdated func(DifferentialPriceUpdatedEvent) error + + OnDunningUpdated func(DunningUpdatedEvent) error + + OnEntitlementOverridesAutoRemoved func(EntitlementOverridesAutoRemovedEvent) error + + OnEntitlementOverridesRemoved func(EntitlementOverridesRemovedEvent) error + + OnEntitlementOverridesUpdated func(EntitlementOverridesUpdatedEvent) error + + OnFeatureActivated func(FeatureActivatedEvent) error + + OnFeatureArchived func(FeatureArchivedEvent) error + + OnFeatureCreated func(FeatureCreatedEvent) error + + OnFeatureDeleted func(FeatureDeletedEvent) error + + OnFeatureReactivated func(FeatureReactivatedEvent) error + + OnFeatureUpdated func(FeatureUpdatedEvent) error + + OnGiftCancelled func(GiftCancelledEvent) error + + OnGiftClaimed func(GiftClaimedEvent) error + + OnGiftExpired func(GiftExpiredEvent) error + + OnGiftScheduled func(GiftScheduledEvent) error + + OnGiftUnclaimed func(GiftUnclaimedEvent) error + + OnGiftUpdated func(GiftUpdatedEvent) error + + OnHierarchyCreated func(HierarchyCreatedEvent) error + + OnHierarchyDeleted func(HierarchyDeletedEvent) error + + OnInvoiceDeleted func(InvoiceDeletedEvent) error + + OnInvoiceGenerated func(InvoiceGeneratedEvent) error + + OnInvoiceGeneratedWithBackdating func(InvoiceGeneratedWithBackdatingEvent) error + + OnInvoiceUpdated func(InvoiceUpdatedEvent) error + + OnItemCreated func(ItemCreatedEvent) error + + OnItemDeleted func(ItemDeletedEvent) error + + OnItemEntitlementsRemoved func(ItemEntitlementsRemovedEvent) error + + OnItemEntitlementsUpdated func(ItemEntitlementsUpdatedEvent) error + + OnItemFamilyCreated func(ItemFamilyCreatedEvent) error + + OnItemFamilyDeleted func(ItemFamilyDeletedEvent) error + + OnItemFamilyUpdated func(ItemFamilyUpdatedEvent) error + + OnItemPriceCreated func(ItemPriceCreatedEvent) error + + OnItemPriceDeleted func(ItemPriceDeletedEvent) error + + OnItemPriceEntitlementsRemoved func(ItemPriceEntitlementsRemovedEvent) error + + OnItemPriceEntitlementsUpdated func(ItemPriceEntitlementsUpdatedEvent) error + + OnItemPriceUpdated func(ItemPriceUpdatedEvent) error + + OnItemUpdated func(ItemUpdatedEvent) error + + OnMrrUpdated func(MrrUpdatedEvent) error + + OnNetdPaymentDueReminder func(NetdPaymentDueReminderEvent) error + + OnOmnichannelOneTimeOrderCreated func(OmnichannelOneTimeOrderCreatedEvent) error + + OnOmnichannelOneTimeOrderItemCancelled func(OmnichannelOneTimeOrderItemCancelledEvent) error + + OnOmnichannelSubscriptionCreated func(OmnichannelSubscriptionCreatedEvent) error + + OnOmnichannelSubscriptionImported func(OmnichannelSubscriptionImportedEvent) error + + OnOmnichannelSubscriptionItemCancellationScheduled func(OmnichannelSubscriptionItemCancellationScheduledEvent) error + + OnOmnichannelSubscriptionItemCancelled func(OmnichannelSubscriptionItemCancelledEvent) error + + OnOmnichannelSubscriptionItemChangeScheduled func(OmnichannelSubscriptionItemChangeScheduledEvent) error + + OnOmnichannelSubscriptionItemChanged func(OmnichannelSubscriptionItemChangedEvent) error + + OnOmnichannelSubscriptionItemDowngradeScheduled func(OmnichannelSubscriptionItemDowngradeScheduledEvent) error + + OnOmnichannelSubscriptionItemDowngraded func(OmnichannelSubscriptionItemDowngradedEvent) error + + OnOmnichannelSubscriptionItemDunningExpired func(OmnichannelSubscriptionItemDunningExpiredEvent) error + + OnOmnichannelSubscriptionItemDunningStarted func(OmnichannelSubscriptionItemDunningStartedEvent) error + + OnOmnichannelSubscriptionItemExpired func(OmnichannelSubscriptionItemExpiredEvent) error + + OnOmnichannelSubscriptionItemGracePeriodExpired func(OmnichannelSubscriptionItemGracePeriodExpiredEvent) error + + OnOmnichannelSubscriptionItemGracePeriodStarted func(OmnichannelSubscriptionItemGracePeriodStartedEvent) error + + OnOmnichannelSubscriptionItemPauseScheduled func(OmnichannelSubscriptionItemPauseScheduledEvent) error + + OnOmnichannelSubscriptionItemPaused func(OmnichannelSubscriptionItemPausedEvent) error + + OnOmnichannelSubscriptionItemReactivated func(OmnichannelSubscriptionItemReactivatedEvent) error + + OnOmnichannelSubscriptionItemRenewed func(OmnichannelSubscriptionItemRenewedEvent) error + + OnOmnichannelSubscriptionItemResubscribed func(OmnichannelSubscriptionItemResubscribedEvent) error + + OnOmnichannelSubscriptionItemResumed func(OmnichannelSubscriptionItemResumedEvent) error + + OnOmnichannelSubscriptionItemScheduledCancellationRemoved func(OmnichannelSubscriptionItemScheduledCancellationRemovedEvent) error + + OnOmnichannelSubscriptionItemScheduledChangeRemoved func(OmnichannelSubscriptionItemScheduledChangeRemovedEvent) error + + OnOmnichannelSubscriptionItemScheduledDowngradeRemoved func(OmnichannelSubscriptionItemScheduledDowngradeRemovedEvent) error + + OnOmnichannelSubscriptionItemUpgraded func(OmnichannelSubscriptionItemUpgradedEvent) error + + OnOmnichannelSubscriptionMovedIn func(OmnichannelSubscriptionMovedInEvent) error + + OnOmnichannelTransactionCreated func(OmnichannelTransactionCreatedEvent) error + + OnOrderCancelled func(OrderCancelledEvent) error + + OnOrderCreated func(OrderCreatedEvent) error + + OnOrderDeleted func(OrderDeletedEvent) error + + OnOrderDelivered func(OrderDeliveredEvent) error + + OnOrderReadyToProcess func(OrderReadyToProcessEvent) error + + OnOrderReadyToShip func(OrderReadyToShipEvent) error + + OnOrderResent func(OrderResentEvent) error + + OnOrderReturned func(OrderReturnedEvent) error + + OnOrderUpdated func(OrderUpdatedEvent) error + + OnPaymentFailed func(PaymentFailedEvent) error + + OnPaymentInitiated func(PaymentInitiatedEvent) error + + OnPaymentIntentCreated func(PaymentIntentCreatedEvent) error + + OnPaymentIntentUpdated func(PaymentIntentUpdatedEvent) error + + OnPaymentRefunded func(PaymentRefundedEvent) error + + OnPaymentScheduleSchemeCreated func(PaymentScheduleSchemeCreatedEvent) error + + OnPaymentScheduleSchemeDeleted func(PaymentScheduleSchemeDeletedEvent) error + + OnPaymentSchedulesCreated func(PaymentSchedulesCreatedEvent) error + + OnPaymentSchedulesUpdated func(PaymentSchedulesUpdatedEvent) error + + OnPaymentSourceAdded func(PaymentSourceAddedEvent) error + + OnPaymentSourceDeleted func(PaymentSourceDeletedEvent) error + + OnPaymentSourceExpired func(PaymentSourceExpiredEvent) error + + OnPaymentSourceExpiring func(PaymentSourceExpiringEvent) error + + OnPaymentSourceLocallyDeleted func(PaymentSourceLocallyDeletedEvent) error + + OnPaymentSourceUpdated func(PaymentSourceUpdatedEvent) error + + OnPaymentSucceeded func(PaymentSucceededEvent) error + + OnPendingInvoiceCreated func(PendingInvoiceCreatedEvent) error + + OnPendingInvoiceUpdated func(PendingInvoiceUpdatedEvent) error + + OnPlanCreated func(PlanCreatedEvent) error + + OnPlanDeleted func(PlanDeletedEvent) error + + OnPlanUpdated func(PlanUpdatedEvent) error + + OnPriceVariantCreated func(PriceVariantCreatedEvent) error + + OnPriceVariantDeleted func(PriceVariantDeletedEvent) error + + OnPriceVariantUpdated func(PriceVariantUpdatedEvent) error + + OnProductCreated func(ProductCreatedEvent) error + + OnProductDeleted func(ProductDeletedEvent) error + + OnProductUpdated func(ProductUpdatedEvent) error + + OnPromotionalCreditsAdded func(PromotionalCreditsAddedEvent) error + + OnPromotionalCreditsDeducted func(PromotionalCreditsDeductedEvent) error + + OnPurchaseCreated func(PurchaseCreatedEvent) error + + OnQuoteCreated func(QuoteCreatedEvent) error + + OnQuoteDeleted func(QuoteDeletedEvent) error + + OnQuoteUpdated func(QuoteUpdatedEvent) error + + OnRecordPurchaseFailed func(RecordPurchaseFailedEvent) error + + OnRefundInitiated func(RefundInitiatedEvent) error + + OnRuleCreated func(RuleCreatedEvent) error + + OnRuleDeleted func(RuleDeletedEvent) error + + OnRuleUpdated func(RuleUpdatedEvent) error + + OnSalesOrderCreated func(SalesOrderCreatedEvent) error + + OnSalesOrderUpdated func(SalesOrderUpdatedEvent) error + + OnSubscriptionActivated func(SubscriptionActivatedEvent) error + + OnSubscriptionActivatedWithBackdating func(SubscriptionActivatedWithBackdatingEvent) error + + OnSubscriptionAdvanceInvoiceScheduleAdded func(SubscriptionAdvanceInvoiceScheduleAddedEvent) error + + OnSubscriptionAdvanceInvoiceScheduleRemoved func(SubscriptionAdvanceInvoiceScheduleRemovedEvent) error + + OnSubscriptionAdvanceInvoiceScheduleUpdated func(SubscriptionAdvanceInvoiceScheduleUpdatedEvent) error + + OnSubscriptionBusinessEntityChanged func(SubscriptionBusinessEntityChangedEvent) error + + OnSubscriptionCanceledWithBackdating func(SubscriptionCanceledWithBackdatingEvent) error + + OnSubscriptionCancellationReminder func(SubscriptionCancellationReminderEvent) error + + OnSubscriptionCancellationScheduled func(SubscriptionCancellationScheduledEvent) error + + OnSubscriptionCancelled func(SubscriptionCancelledEvent) error + + OnSubscriptionChanged func(SubscriptionChangedEvent) error + + OnSubscriptionChangedWithBackdating func(SubscriptionChangedWithBackdatingEvent) error + + OnSubscriptionChangesScheduled func(SubscriptionChangesScheduledEvent) error + + OnSubscriptionCreated func(SubscriptionCreatedEvent) error + + OnSubscriptionCreatedWithBackdating func(SubscriptionCreatedWithBackdatingEvent) error + + OnSubscriptionDeleted func(SubscriptionDeletedEvent) error + + OnSubscriptionEntitlementsCreated func(SubscriptionEntitlementsCreatedEvent) error + + OnSubscriptionEntitlementsUpdated func(SubscriptionEntitlementsUpdatedEvent) error + + OnSubscriptionItemsRenewed func(SubscriptionItemsRenewedEvent) error + + OnSubscriptionMovedIn func(SubscriptionMovedInEvent) error + + OnSubscriptionMovedOut func(SubscriptionMovedOutEvent) error + + OnSubscriptionMovementFailed func(SubscriptionMovementFailedEvent) error + + OnSubscriptionPauseScheduled func(SubscriptionPauseScheduledEvent) error + + OnSubscriptionPaused func(SubscriptionPausedEvent) error + + OnSubscriptionRampApplied func(SubscriptionRampAppliedEvent) error + + OnSubscriptionRampCreated func(SubscriptionRampCreatedEvent) error + + OnSubscriptionRampDeleted func(SubscriptionRampDeletedEvent) error + + OnSubscriptionRampDrafted func(SubscriptionRampDraftedEvent) error + + OnSubscriptionRampUpdated func(SubscriptionRampUpdatedEvent) error + + OnSubscriptionReactivated func(SubscriptionReactivatedEvent) error + + OnSubscriptionReactivatedWithBackdating func(SubscriptionReactivatedWithBackdatingEvent) error + + OnSubscriptionRenewalReminder func(SubscriptionRenewalReminderEvent) error + + OnSubscriptionRenewed func(SubscriptionRenewedEvent) error + + OnSubscriptionResumed func(SubscriptionResumedEvent) error + + OnSubscriptionResumptionScheduled func(SubscriptionResumptionScheduledEvent) error + + OnSubscriptionScheduledCancellationRemoved func(SubscriptionScheduledCancellationRemovedEvent) error + + OnSubscriptionScheduledChangesRemoved func(SubscriptionScheduledChangesRemovedEvent) error + + OnSubscriptionScheduledPauseRemoved func(SubscriptionScheduledPauseRemovedEvent) error + + OnSubscriptionScheduledResumptionRemoved func(SubscriptionScheduledResumptionRemovedEvent) error + + OnSubscriptionShippingAddressUpdated func(SubscriptionShippingAddressUpdatedEvent) error + + OnSubscriptionStarted func(SubscriptionStartedEvent) error + + OnSubscriptionTrialEndReminder func(SubscriptionTrialEndReminderEvent) error + + OnSubscriptionTrialExtended func(SubscriptionTrialExtendedEvent) error + + OnTaxWithheldDeleted func(TaxWithheldDeletedEvent) error + + OnTaxWithheldRecorded func(TaxWithheldRecordedEvent) error + + OnTaxWithheldRefunded func(TaxWithheldRefundedEvent) error + + OnTokenConsumed func(TokenConsumedEvent) error + + OnTokenCreated func(TokenCreatedEvent) error + + OnTokenExpired func(TokenExpiredEvent) error + + OnTransactionCreated func(TransactionCreatedEvent) error + + OnTransactionDeleted func(TransactionDeletedEvent) error + + OnTransactionUpdated func(TransactionUpdatedEvent) error + + OnUnbilledChargesCreated func(UnbilledChargesCreatedEvent) error + + OnUnbilledChargesDeleted func(UnbilledChargesDeletedEvent) error + + OnUnbilledChargesInvoiced func(UnbilledChargesInvoicedEvent) error + + OnUnbilledChargesVoided func(UnbilledChargesVoidedEvent) error + + OnUsageFileIngested func(UsageFileIngestedEvent) error + + OnVariantCreated func(VariantCreatedEvent) error + + OnVariantDeleted func(VariantDeletedEvent) error + + OnVariantUpdated func(VariantUpdatedEvent) error + + OnVirtualBankAccountAdded func(VirtualBankAccountAddedEvent) error + + OnVirtualBankAccountDeleted func(VirtualBankAccountDeletedEvent) error + + OnVirtualBankAccountUpdated func(VirtualBankAccountUpdatedEvent) error + + OnVoucherCreateFailed func(VoucherCreateFailedEvent) error + + OnVoucherCreated func(VoucherCreatedEvent) error + + OnVoucherExpired func(VoucherExpiredEvent) error +} + +func (h *WebhookHandler) ParseAndDispatch(body []byte) error { + if h == nil { + return errors.New("webhook handler not configured") + } + eventType, err := ParseEventType(body) + if err != nil { + return err + } + switch eventType { + + case enum.EventTypeAddUsagesReminder: + if h.OnAddUsagesReminder != nil { + var e AddUsagesReminderEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnAddUsagesReminder(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeAddonCreated: + if h.OnAddonCreated != nil { + var e AddonCreatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnAddonCreated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeAddonDeleted: + if h.OnAddonDeleted != nil { + var e AddonDeletedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnAddonDeleted(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeAddonUpdated: + if h.OnAddonUpdated != nil { + var e AddonUpdatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnAddonUpdated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeAttachedItemCreated: + if h.OnAttachedItemCreated != nil { + var e AttachedItemCreatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnAttachedItemCreated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeAttachedItemDeleted: + if h.OnAttachedItemDeleted != nil { + var e AttachedItemDeletedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnAttachedItemDeleted(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeAttachedItemUpdated: + if h.OnAttachedItemUpdated != nil { + var e AttachedItemUpdatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnAttachedItemUpdated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeAuthorizationSucceeded: + if h.OnAuthorizationSucceeded != nil { + var e AuthorizationSucceededEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnAuthorizationSucceeded(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeAuthorizationVoided: + if h.OnAuthorizationVoided != nil { + var e AuthorizationVoidedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnAuthorizationVoided(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeBusinessEntityCreated: + if h.OnBusinessEntityCreated != nil { + var e BusinessEntityCreatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnBusinessEntityCreated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeBusinessEntityDeleted: + if h.OnBusinessEntityDeleted != nil { + var e BusinessEntityDeletedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnBusinessEntityDeleted(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeBusinessEntityUpdated: + if h.OnBusinessEntityUpdated != nil { + var e BusinessEntityUpdatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnBusinessEntityUpdated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeCardAdded: + if h.OnCardAdded != nil { + var e CardAddedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnCardAdded(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeCardDeleted: + if h.OnCardDeleted != nil { + var e CardDeletedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnCardDeleted(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeCardExpired: + if h.OnCardExpired != nil { + var e CardExpiredEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnCardExpired(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeCardExpiryReminder: + if h.OnCardExpiryReminder != nil { + var e CardExpiryReminderEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnCardExpiryReminder(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeCardUpdated: + if h.OnCardUpdated != nil { + var e CardUpdatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnCardUpdated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeContractTermCancelled: + if h.OnContractTermCancelled != nil { + var e ContractTermCancelledEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnContractTermCancelled(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeContractTermCompleted: + if h.OnContractTermCompleted != nil { + var e ContractTermCompletedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnContractTermCompleted(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeContractTermCreated: + if h.OnContractTermCreated != nil { + var e ContractTermCreatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnContractTermCreated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeContractTermRenewed: + if h.OnContractTermRenewed != nil { + var e ContractTermRenewedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnContractTermRenewed(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeContractTermTerminated: + if h.OnContractTermTerminated != nil { + var e ContractTermTerminatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnContractTermTerminated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeCouponCodesAdded: + if h.OnCouponCodesAdded != nil { + var e CouponCodesAddedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnCouponCodesAdded(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeCouponCodesDeleted: + if h.OnCouponCodesDeleted != nil { + var e CouponCodesDeletedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnCouponCodesDeleted(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeCouponCodesUpdated: + if h.OnCouponCodesUpdated != nil { + var e CouponCodesUpdatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnCouponCodesUpdated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeCouponCreated: + if h.OnCouponCreated != nil { + var e CouponCreatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnCouponCreated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeCouponDeleted: + if h.OnCouponDeleted != nil { + var e CouponDeletedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnCouponDeleted(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeCouponSetCreated: + if h.OnCouponSetCreated != nil { + var e CouponSetCreatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnCouponSetCreated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeCouponSetDeleted: + if h.OnCouponSetDeleted != nil { + var e CouponSetDeletedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnCouponSetDeleted(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeCouponSetUpdated: + if h.OnCouponSetUpdated != nil { + var e CouponSetUpdatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnCouponSetUpdated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeCouponUpdated: + if h.OnCouponUpdated != nil { + var e CouponUpdatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnCouponUpdated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeCreditNoteCreated: + if h.OnCreditNoteCreated != nil { + var e CreditNoteCreatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnCreditNoteCreated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeCreditNoteCreatedWithBackdating: + if h.OnCreditNoteCreatedWithBackdating != nil { + var e CreditNoteCreatedWithBackdatingEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnCreditNoteCreatedWithBackdating(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeCreditNoteDeleted: + if h.OnCreditNoteDeleted != nil { + var e CreditNoteDeletedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnCreditNoteDeleted(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeCreditNoteUpdated: + if h.OnCreditNoteUpdated != nil { + var e CreditNoteUpdatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnCreditNoteUpdated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeCustomerBusinessEntityChanged: + if h.OnCustomerBusinessEntityChanged != nil { + var e CustomerBusinessEntityChangedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnCustomerBusinessEntityChanged(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeCustomerChanged: + if h.OnCustomerChanged != nil { + var e CustomerChangedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnCustomerChanged(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeCustomerCreated: + if h.OnCustomerCreated != nil { + var e CustomerCreatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnCustomerCreated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeCustomerDeleted: + if h.OnCustomerDeleted != nil { + var e CustomerDeletedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnCustomerDeleted(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeCustomerEntitlementsUpdated: + if h.OnCustomerEntitlementsUpdated != nil { + var e CustomerEntitlementsUpdatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnCustomerEntitlementsUpdated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeCustomerMovedIn: + if h.OnCustomerMovedIn != nil { + var e CustomerMovedInEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnCustomerMovedIn(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeCustomerMovedOut: + if h.OnCustomerMovedOut != nil { + var e CustomerMovedOutEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnCustomerMovedOut(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeDifferentialPriceCreated: + if h.OnDifferentialPriceCreated != nil { + var e DifferentialPriceCreatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnDifferentialPriceCreated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeDifferentialPriceDeleted: + if h.OnDifferentialPriceDeleted != nil { + var e DifferentialPriceDeletedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnDifferentialPriceDeleted(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeDifferentialPriceUpdated: + if h.OnDifferentialPriceUpdated != nil { + var e DifferentialPriceUpdatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnDifferentialPriceUpdated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeDunningUpdated: + if h.OnDunningUpdated != nil { + var e DunningUpdatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnDunningUpdated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeEntitlementOverridesAutoRemoved: + if h.OnEntitlementOverridesAutoRemoved != nil { + var e EntitlementOverridesAutoRemovedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnEntitlementOverridesAutoRemoved(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeEntitlementOverridesRemoved: + if h.OnEntitlementOverridesRemoved != nil { + var e EntitlementOverridesRemovedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnEntitlementOverridesRemoved(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeEntitlementOverridesUpdated: + if h.OnEntitlementOverridesUpdated != nil { + var e EntitlementOverridesUpdatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnEntitlementOverridesUpdated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeFeatureActivated: + if h.OnFeatureActivated != nil { + var e FeatureActivatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnFeatureActivated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeFeatureArchived: + if h.OnFeatureArchived != nil { + var e FeatureArchivedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnFeatureArchived(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeFeatureCreated: + if h.OnFeatureCreated != nil { + var e FeatureCreatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnFeatureCreated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeFeatureDeleted: + if h.OnFeatureDeleted != nil { + var e FeatureDeletedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnFeatureDeleted(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeFeatureReactivated: + if h.OnFeatureReactivated != nil { + var e FeatureReactivatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnFeatureReactivated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeFeatureUpdated: + if h.OnFeatureUpdated != nil { + var e FeatureUpdatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnFeatureUpdated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeGiftCancelled: + if h.OnGiftCancelled != nil { + var e GiftCancelledEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnGiftCancelled(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeGiftClaimed: + if h.OnGiftClaimed != nil { + var e GiftClaimedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnGiftClaimed(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeGiftExpired: + if h.OnGiftExpired != nil { + var e GiftExpiredEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnGiftExpired(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeGiftScheduled: + if h.OnGiftScheduled != nil { + var e GiftScheduledEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnGiftScheduled(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeGiftUnclaimed: + if h.OnGiftUnclaimed != nil { + var e GiftUnclaimedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnGiftUnclaimed(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeGiftUpdated: + if h.OnGiftUpdated != nil { + var e GiftUpdatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnGiftUpdated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeHierarchyCreated: + if h.OnHierarchyCreated != nil { + var e HierarchyCreatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnHierarchyCreated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeHierarchyDeleted: + if h.OnHierarchyDeleted != nil { + var e HierarchyDeletedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnHierarchyDeleted(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeInvoiceDeleted: + if h.OnInvoiceDeleted != nil { + var e InvoiceDeletedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnInvoiceDeleted(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeInvoiceGenerated: + if h.OnInvoiceGenerated != nil { + var e InvoiceGeneratedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnInvoiceGenerated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeInvoiceGeneratedWithBackdating: + if h.OnInvoiceGeneratedWithBackdating != nil { + var e InvoiceGeneratedWithBackdatingEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnInvoiceGeneratedWithBackdating(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeInvoiceUpdated: + if h.OnInvoiceUpdated != nil { + var e InvoiceUpdatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnInvoiceUpdated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeItemCreated: + if h.OnItemCreated != nil { + var e ItemCreatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnItemCreated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeItemDeleted: + if h.OnItemDeleted != nil { + var e ItemDeletedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnItemDeleted(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeItemEntitlementsRemoved: + if h.OnItemEntitlementsRemoved != nil { + var e ItemEntitlementsRemovedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnItemEntitlementsRemoved(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeItemEntitlementsUpdated: + if h.OnItemEntitlementsUpdated != nil { + var e ItemEntitlementsUpdatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnItemEntitlementsUpdated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeItemFamilyCreated: + if h.OnItemFamilyCreated != nil { + var e ItemFamilyCreatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnItemFamilyCreated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeItemFamilyDeleted: + if h.OnItemFamilyDeleted != nil { + var e ItemFamilyDeletedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnItemFamilyDeleted(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeItemFamilyUpdated: + if h.OnItemFamilyUpdated != nil { + var e ItemFamilyUpdatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnItemFamilyUpdated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeItemPriceCreated: + if h.OnItemPriceCreated != nil { + var e ItemPriceCreatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnItemPriceCreated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeItemPriceDeleted: + if h.OnItemPriceDeleted != nil { + var e ItemPriceDeletedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnItemPriceDeleted(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeItemPriceEntitlementsRemoved: + if h.OnItemPriceEntitlementsRemoved != nil { + var e ItemPriceEntitlementsRemovedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnItemPriceEntitlementsRemoved(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeItemPriceEntitlementsUpdated: + if h.OnItemPriceEntitlementsUpdated != nil { + var e ItemPriceEntitlementsUpdatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnItemPriceEntitlementsUpdated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeItemPriceUpdated: + if h.OnItemPriceUpdated != nil { + var e ItemPriceUpdatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnItemPriceUpdated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeItemUpdated: + if h.OnItemUpdated != nil { + var e ItemUpdatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnItemUpdated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeMrrUpdated: + if h.OnMrrUpdated != nil { + var e MrrUpdatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnMrrUpdated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeNetdPaymentDueReminder: + if h.OnNetdPaymentDueReminder != nil { + var e NetdPaymentDueReminderEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnNetdPaymentDueReminder(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeOmnichannelOneTimeOrderCreated: + if h.OnOmnichannelOneTimeOrderCreated != nil { + var e OmnichannelOneTimeOrderCreatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnOmnichannelOneTimeOrderCreated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeOmnichannelOneTimeOrderItemCancelled: + if h.OnOmnichannelOneTimeOrderItemCancelled != nil { + var e OmnichannelOneTimeOrderItemCancelledEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnOmnichannelOneTimeOrderItemCancelled(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeOmnichannelSubscriptionCreated: + if h.OnOmnichannelSubscriptionCreated != nil { + var e OmnichannelSubscriptionCreatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnOmnichannelSubscriptionCreated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeOmnichannelSubscriptionImported: + if h.OnOmnichannelSubscriptionImported != nil { + var e OmnichannelSubscriptionImportedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnOmnichannelSubscriptionImported(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeOmnichannelSubscriptionItemCancellationScheduled: + if h.OnOmnichannelSubscriptionItemCancellationScheduled != nil { + var e OmnichannelSubscriptionItemCancellationScheduledEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnOmnichannelSubscriptionItemCancellationScheduled(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeOmnichannelSubscriptionItemCancelled: + if h.OnOmnichannelSubscriptionItemCancelled != nil { + var e OmnichannelSubscriptionItemCancelledEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnOmnichannelSubscriptionItemCancelled(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeOmnichannelSubscriptionItemChangeScheduled: + if h.OnOmnichannelSubscriptionItemChangeScheduled != nil { + var e OmnichannelSubscriptionItemChangeScheduledEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnOmnichannelSubscriptionItemChangeScheduled(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeOmnichannelSubscriptionItemChanged: + if h.OnOmnichannelSubscriptionItemChanged != nil { + var e OmnichannelSubscriptionItemChangedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnOmnichannelSubscriptionItemChanged(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeOmnichannelSubscriptionItemDowngradeScheduled: + if h.OnOmnichannelSubscriptionItemDowngradeScheduled != nil { + var e OmnichannelSubscriptionItemDowngradeScheduledEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnOmnichannelSubscriptionItemDowngradeScheduled(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeOmnichannelSubscriptionItemDowngraded: + if h.OnOmnichannelSubscriptionItemDowngraded != nil { + var e OmnichannelSubscriptionItemDowngradedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnOmnichannelSubscriptionItemDowngraded(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeOmnichannelSubscriptionItemDunningExpired: + if h.OnOmnichannelSubscriptionItemDunningExpired != nil { + var e OmnichannelSubscriptionItemDunningExpiredEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnOmnichannelSubscriptionItemDunningExpired(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeOmnichannelSubscriptionItemDunningStarted: + if h.OnOmnichannelSubscriptionItemDunningStarted != nil { + var e OmnichannelSubscriptionItemDunningStartedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnOmnichannelSubscriptionItemDunningStarted(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeOmnichannelSubscriptionItemExpired: + if h.OnOmnichannelSubscriptionItemExpired != nil { + var e OmnichannelSubscriptionItemExpiredEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnOmnichannelSubscriptionItemExpired(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeOmnichannelSubscriptionItemGracePeriodExpired: + if h.OnOmnichannelSubscriptionItemGracePeriodExpired != nil { + var e OmnichannelSubscriptionItemGracePeriodExpiredEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnOmnichannelSubscriptionItemGracePeriodExpired(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeOmnichannelSubscriptionItemGracePeriodStarted: + if h.OnOmnichannelSubscriptionItemGracePeriodStarted != nil { + var e OmnichannelSubscriptionItemGracePeriodStartedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnOmnichannelSubscriptionItemGracePeriodStarted(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeOmnichannelSubscriptionItemPauseScheduled: + if h.OnOmnichannelSubscriptionItemPauseScheduled != nil { + var e OmnichannelSubscriptionItemPauseScheduledEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnOmnichannelSubscriptionItemPauseScheduled(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeOmnichannelSubscriptionItemPaused: + if h.OnOmnichannelSubscriptionItemPaused != nil { + var e OmnichannelSubscriptionItemPausedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnOmnichannelSubscriptionItemPaused(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeOmnichannelSubscriptionItemReactivated: + if h.OnOmnichannelSubscriptionItemReactivated != nil { + var e OmnichannelSubscriptionItemReactivatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnOmnichannelSubscriptionItemReactivated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeOmnichannelSubscriptionItemRenewed: + if h.OnOmnichannelSubscriptionItemRenewed != nil { + var e OmnichannelSubscriptionItemRenewedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnOmnichannelSubscriptionItemRenewed(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeOmnichannelSubscriptionItemResubscribed: + if h.OnOmnichannelSubscriptionItemResubscribed != nil { + var e OmnichannelSubscriptionItemResubscribedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnOmnichannelSubscriptionItemResubscribed(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeOmnichannelSubscriptionItemResumed: + if h.OnOmnichannelSubscriptionItemResumed != nil { + var e OmnichannelSubscriptionItemResumedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnOmnichannelSubscriptionItemResumed(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeOmnichannelSubscriptionItemScheduledCancellationRemoved: + if h.OnOmnichannelSubscriptionItemScheduledCancellationRemoved != nil { + var e OmnichannelSubscriptionItemScheduledCancellationRemovedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnOmnichannelSubscriptionItemScheduledCancellationRemoved(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeOmnichannelSubscriptionItemScheduledChangeRemoved: + if h.OnOmnichannelSubscriptionItemScheduledChangeRemoved != nil { + var e OmnichannelSubscriptionItemScheduledChangeRemovedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnOmnichannelSubscriptionItemScheduledChangeRemoved(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeOmnichannelSubscriptionItemScheduledDowngradeRemoved: + if h.OnOmnichannelSubscriptionItemScheduledDowngradeRemoved != nil { + var e OmnichannelSubscriptionItemScheduledDowngradeRemovedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnOmnichannelSubscriptionItemScheduledDowngradeRemoved(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeOmnichannelSubscriptionItemUpgraded: + if h.OnOmnichannelSubscriptionItemUpgraded != nil { + var e OmnichannelSubscriptionItemUpgradedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnOmnichannelSubscriptionItemUpgraded(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeOmnichannelSubscriptionMovedIn: + if h.OnOmnichannelSubscriptionMovedIn != nil { + var e OmnichannelSubscriptionMovedInEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnOmnichannelSubscriptionMovedIn(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeOmnichannelTransactionCreated: + if h.OnOmnichannelTransactionCreated != nil { + var e OmnichannelTransactionCreatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnOmnichannelTransactionCreated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeOrderCancelled: + if h.OnOrderCancelled != nil { + var e OrderCancelledEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnOrderCancelled(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeOrderCreated: + if h.OnOrderCreated != nil { + var e OrderCreatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnOrderCreated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeOrderDeleted: + if h.OnOrderDeleted != nil { + var e OrderDeletedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnOrderDeleted(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeOrderDelivered: + if h.OnOrderDelivered != nil { + var e OrderDeliveredEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnOrderDelivered(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeOrderReadyToProcess: + if h.OnOrderReadyToProcess != nil { + var e OrderReadyToProcessEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnOrderReadyToProcess(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeOrderReadyToShip: + if h.OnOrderReadyToShip != nil { + var e OrderReadyToShipEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnOrderReadyToShip(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeOrderResent: + if h.OnOrderResent != nil { + var e OrderResentEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnOrderResent(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeOrderReturned: + if h.OnOrderReturned != nil { + var e OrderReturnedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnOrderReturned(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeOrderUpdated: + if h.OnOrderUpdated != nil { + var e OrderUpdatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnOrderUpdated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypePaymentFailed: + if h.OnPaymentFailed != nil { + var e PaymentFailedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnPaymentFailed(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypePaymentInitiated: + if h.OnPaymentInitiated != nil { + var e PaymentInitiatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnPaymentInitiated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypePaymentIntentCreated: + if h.OnPaymentIntentCreated != nil { + var e PaymentIntentCreatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnPaymentIntentCreated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypePaymentIntentUpdated: + if h.OnPaymentIntentUpdated != nil { + var e PaymentIntentUpdatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnPaymentIntentUpdated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypePaymentRefunded: + if h.OnPaymentRefunded != nil { + var e PaymentRefundedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnPaymentRefunded(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypePaymentScheduleSchemeCreated: + if h.OnPaymentScheduleSchemeCreated != nil { + var e PaymentScheduleSchemeCreatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnPaymentScheduleSchemeCreated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypePaymentScheduleSchemeDeleted: + if h.OnPaymentScheduleSchemeDeleted != nil { + var e PaymentScheduleSchemeDeletedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnPaymentScheduleSchemeDeleted(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypePaymentSchedulesCreated: + if h.OnPaymentSchedulesCreated != nil { + var e PaymentSchedulesCreatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnPaymentSchedulesCreated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypePaymentSchedulesUpdated: + if h.OnPaymentSchedulesUpdated != nil { + var e PaymentSchedulesUpdatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnPaymentSchedulesUpdated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypePaymentSourceAdded: + if h.OnPaymentSourceAdded != nil { + var e PaymentSourceAddedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnPaymentSourceAdded(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypePaymentSourceDeleted: + if h.OnPaymentSourceDeleted != nil { + var e PaymentSourceDeletedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnPaymentSourceDeleted(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypePaymentSourceExpired: + if h.OnPaymentSourceExpired != nil { + var e PaymentSourceExpiredEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnPaymentSourceExpired(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypePaymentSourceExpiring: + if h.OnPaymentSourceExpiring != nil { + var e PaymentSourceExpiringEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnPaymentSourceExpiring(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypePaymentSourceLocallyDeleted: + if h.OnPaymentSourceLocallyDeleted != nil { + var e PaymentSourceLocallyDeletedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnPaymentSourceLocallyDeleted(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypePaymentSourceUpdated: + if h.OnPaymentSourceUpdated != nil { + var e PaymentSourceUpdatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnPaymentSourceUpdated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypePaymentSucceeded: + if h.OnPaymentSucceeded != nil { + var e PaymentSucceededEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnPaymentSucceeded(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypePendingInvoiceCreated: + if h.OnPendingInvoiceCreated != nil { + var e PendingInvoiceCreatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnPendingInvoiceCreated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypePendingInvoiceUpdated: + if h.OnPendingInvoiceUpdated != nil { + var e PendingInvoiceUpdatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnPendingInvoiceUpdated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypePlanCreated: + if h.OnPlanCreated != nil { + var e PlanCreatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnPlanCreated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypePlanDeleted: + if h.OnPlanDeleted != nil { + var e PlanDeletedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnPlanDeleted(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypePlanUpdated: + if h.OnPlanUpdated != nil { + var e PlanUpdatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnPlanUpdated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypePriceVariantCreated: + if h.OnPriceVariantCreated != nil { + var e PriceVariantCreatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnPriceVariantCreated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypePriceVariantDeleted: + if h.OnPriceVariantDeleted != nil { + var e PriceVariantDeletedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnPriceVariantDeleted(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypePriceVariantUpdated: + if h.OnPriceVariantUpdated != nil { + var e PriceVariantUpdatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnPriceVariantUpdated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeProductCreated: + if h.OnProductCreated != nil { + var e ProductCreatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnProductCreated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeProductDeleted: + if h.OnProductDeleted != nil { + var e ProductDeletedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnProductDeleted(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeProductUpdated: + if h.OnProductUpdated != nil { + var e ProductUpdatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnProductUpdated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypePromotionalCreditsAdded: + if h.OnPromotionalCreditsAdded != nil { + var e PromotionalCreditsAddedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnPromotionalCreditsAdded(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypePromotionalCreditsDeducted: + if h.OnPromotionalCreditsDeducted != nil { + var e PromotionalCreditsDeductedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnPromotionalCreditsDeducted(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypePurchaseCreated: + if h.OnPurchaseCreated != nil { + var e PurchaseCreatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnPurchaseCreated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeQuoteCreated: + if h.OnQuoteCreated != nil { + var e QuoteCreatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnQuoteCreated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeQuoteDeleted: + if h.OnQuoteDeleted != nil { + var e QuoteDeletedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnQuoteDeleted(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeQuoteUpdated: + if h.OnQuoteUpdated != nil { + var e QuoteUpdatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnQuoteUpdated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeRecordPurchaseFailed: + if h.OnRecordPurchaseFailed != nil { + var e RecordPurchaseFailedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnRecordPurchaseFailed(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeRefundInitiated: + if h.OnRefundInitiated != nil { + var e RefundInitiatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnRefundInitiated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeRuleCreated: + if h.OnRuleCreated != nil { + var e RuleCreatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnRuleCreated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeRuleDeleted: + if h.OnRuleDeleted != nil { + var e RuleDeletedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnRuleDeleted(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeRuleUpdated: + if h.OnRuleUpdated != nil { + var e RuleUpdatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnRuleUpdated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeSalesOrderCreated: + if h.OnSalesOrderCreated != nil { + var e SalesOrderCreatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnSalesOrderCreated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeSalesOrderUpdated: + if h.OnSalesOrderUpdated != nil { + var e SalesOrderUpdatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnSalesOrderUpdated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeSubscriptionActivated: + if h.OnSubscriptionActivated != nil { + var e SubscriptionActivatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnSubscriptionActivated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeSubscriptionActivatedWithBackdating: + if h.OnSubscriptionActivatedWithBackdating != nil { + var e SubscriptionActivatedWithBackdatingEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnSubscriptionActivatedWithBackdating(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeSubscriptionAdvanceInvoiceScheduleAdded: + if h.OnSubscriptionAdvanceInvoiceScheduleAdded != nil { + var e SubscriptionAdvanceInvoiceScheduleAddedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnSubscriptionAdvanceInvoiceScheduleAdded(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeSubscriptionAdvanceInvoiceScheduleRemoved: + if h.OnSubscriptionAdvanceInvoiceScheduleRemoved != nil { + var e SubscriptionAdvanceInvoiceScheduleRemovedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnSubscriptionAdvanceInvoiceScheduleRemoved(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeSubscriptionAdvanceInvoiceScheduleUpdated: + if h.OnSubscriptionAdvanceInvoiceScheduleUpdated != nil { + var e SubscriptionAdvanceInvoiceScheduleUpdatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnSubscriptionAdvanceInvoiceScheduleUpdated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeSubscriptionBusinessEntityChanged: + if h.OnSubscriptionBusinessEntityChanged != nil { + var e SubscriptionBusinessEntityChangedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnSubscriptionBusinessEntityChanged(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeSubscriptionCanceledWithBackdating: + if h.OnSubscriptionCanceledWithBackdating != nil { + var e SubscriptionCanceledWithBackdatingEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnSubscriptionCanceledWithBackdating(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeSubscriptionCancellationReminder: + if h.OnSubscriptionCancellationReminder != nil { + var e SubscriptionCancellationReminderEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnSubscriptionCancellationReminder(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeSubscriptionCancellationScheduled: + if h.OnSubscriptionCancellationScheduled != nil { + var e SubscriptionCancellationScheduledEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnSubscriptionCancellationScheduled(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeSubscriptionCancelled: + if h.OnSubscriptionCancelled != nil { + var e SubscriptionCancelledEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnSubscriptionCancelled(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeSubscriptionChanged: + if h.OnSubscriptionChanged != nil { + var e SubscriptionChangedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnSubscriptionChanged(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeSubscriptionChangedWithBackdating: + if h.OnSubscriptionChangedWithBackdating != nil { + var e SubscriptionChangedWithBackdatingEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnSubscriptionChangedWithBackdating(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeSubscriptionChangesScheduled: + if h.OnSubscriptionChangesScheduled != nil { + var e SubscriptionChangesScheduledEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnSubscriptionChangesScheduled(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeSubscriptionCreated: + if h.OnSubscriptionCreated != nil { + var e SubscriptionCreatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnSubscriptionCreated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeSubscriptionCreatedWithBackdating: + if h.OnSubscriptionCreatedWithBackdating != nil { + var e SubscriptionCreatedWithBackdatingEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnSubscriptionCreatedWithBackdating(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeSubscriptionDeleted: + if h.OnSubscriptionDeleted != nil { + var e SubscriptionDeletedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnSubscriptionDeleted(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeSubscriptionEntitlementsCreated: + if h.OnSubscriptionEntitlementsCreated != nil { + var e SubscriptionEntitlementsCreatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnSubscriptionEntitlementsCreated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeSubscriptionEntitlementsUpdated: + if h.OnSubscriptionEntitlementsUpdated != nil { + var e SubscriptionEntitlementsUpdatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnSubscriptionEntitlementsUpdated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeSubscriptionItemsRenewed: + if h.OnSubscriptionItemsRenewed != nil { + var e SubscriptionItemsRenewedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnSubscriptionItemsRenewed(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeSubscriptionMovedIn: + if h.OnSubscriptionMovedIn != nil { + var e SubscriptionMovedInEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnSubscriptionMovedIn(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeSubscriptionMovedOut: + if h.OnSubscriptionMovedOut != nil { + var e SubscriptionMovedOutEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnSubscriptionMovedOut(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeSubscriptionMovementFailed: + if h.OnSubscriptionMovementFailed != nil { + var e SubscriptionMovementFailedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnSubscriptionMovementFailed(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeSubscriptionPauseScheduled: + if h.OnSubscriptionPauseScheduled != nil { + var e SubscriptionPauseScheduledEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnSubscriptionPauseScheduled(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeSubscriptionPaused: + if h.OnSubscriptionPaused != nil { + var e SubscriptionPausedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnSubscriptionPaused(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeSubscriptionRampApplied: + if h.OnSubscriptionRampApplied != nil { + var e SubscriptionRampAppliedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnSubscriptionRampApplied(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeSubscriptionRampCreated: + if h.OnSubscriptionRampCreated != nil { + var e SubscriptionRampCreatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnSubscriptionRampCreated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeSubscriptionRampDeleted: + if h.OnSubscriptionRampDeleted != nil { + var e SubscriptionRampDeletedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnSubscriptionRampDeleted(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeSubscriptionRampDrafted: + if h.OnSubscriptionRampDrafted != nil { + var e SubscriptionRampDraftedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnSubscriptionRampDrafted(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeSubscriptionRampUpdated: + if h.OnSubscriptionRampUpdated != nil { + var e SubscriptionRampUpdatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnSubscriptionRampUpdated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeSubscriptionReactivated: + if h.OnSubscriptionReactivated != nil { + var e SubscriptionReactivatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnSubscriptionReactivated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeSubscriptionReactivatedWithBackdating: + if h.OnSubscriptionReactivatedWithBackdating != nil { + var e SubscriptionReactivatedWithBackdatingEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnSubscriptionReactivatedWithBackdating(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeSubscriptionRenewalReminder: + if h.OnSubscriptionRenewalReminder != nil { + var e SubscriptionRenewalReminderEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnSubscriptionRenewalReminder(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeSubscriptionRenewed: + if h.OnSubscriptionRenewed != nil { + var e SubscriptionRenewedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnSubscriptionRenewed(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeSubscriptionResumed: + if h.OnSubscriptionResumed != nil { + var e SubscriptionResumedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnSubscriptionResumed(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeSubscriptionResumptionScheduled: + if h.OnSubscriptionResumptionScheduled != nil { + var e SubscriptionResumptionScheduledEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnSubscriptionResumptionScheduled(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeSubscriptionScheduledCancellationRemoved: + if h.OnSubscriptionScheduledCancellationRemoved != nil { + var e SubscriptionScheduledCancellationRemovedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnSubscriptionScheduledCancellationRemoved(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeSubscriptionScheduledChangesRemoved: + if h.OnSubscriptionScheduledChangesRemoved != nil { + var e SubscriptionScheduledChangesRemovedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnSubscriptionScheduledChangesRemoved(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeSubscriptionScheduledPauseRemoved: + if h.OnSubscriptionScheduledPauseRemoved != nil { + var e SubscriptionScheduledPauseRemovedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnSubscriptionScheduledPauseRemoved(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeSubscriptionScheduledResumptionRemoved: + if h.OnSubscriptionScheduledResumptionRemoved != nil { + var e SubscriptionScheduledResumptionRemovedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnSubscriptionScheduledResumptionRemoved(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeSubscriptionShippingAddressUpdated: + if h.OnSubscriptionShippingAddressUpdated != nil { + var e SubscriptionShippingAddressUpdatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnSubscriptionShippingAddressUpdated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeSubscriptionStarted: + if h.OnSubscriptionStarted != nil { + var e SubscriptionStartedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnSubscriptionStarted(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeSubscriptionTrialEndReminder: + if h.OnSubscriptionTrialEndReminder != nil { + var e SubscriptionTrialEndReminderEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnSubscriptionTrialEndReminder(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeSubscriptionTrialExtended: + if h.OnSubscriptionTrialExtended != nil { + var e SubscriptionTrialExtendedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnSubscriptionTrialExtended(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeTaxWithheldDeleted: + if h.OnTaxWithheldDeleted != nil { + var e TaxWithheldDeletedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnTaxWithheldDeleted(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeTaxWithheldRecorded: + if h.OnTaxWithheldRecorded != nil { + var e TaxWithheldRecordedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnTaxWithheldRecorded(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeTaxWithheldRefunded: + if h.OnTaxWithheldRefunded != nil { + var e TaxWithheldRefundedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnTaxWithheldRefunded(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeTokenConsumed: + if h.OnTokenConsumed != nil { + var e TokenConsumedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnTokenConsumed(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeTokenCreated: + if h.OnTokenCreated != nil { + var e TokenCreatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnTokenCreated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeTokenExpired: + if h.OnTokenExpired != nil { + var e TokenExpiredEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnTokenExpired(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeTransactionCreated: + if h.OnTransactionCreated != nil { + var e TransactionCreatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnTransactionCreated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeTransactionDeleted: + if h.OnTransactionDeleted != nil { + var e TransactionDeletedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnTransactionDeleted(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeTransactionUpdated: + if h.OnTransactionUpdated != nil { + var e TransactionUpdatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnTransactionUpdated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeUnbilledChargesCreated: + if h.OnUnbilledChargesCreated != nil { + var e UnbilledChargesCreatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnUnbilledChargesCreated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeUnbilledChargesDeleted: + if h.OnUnbilledChargesDeleted != nil { + var e UnbilledChargesDeletedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnUnbilledChargesDeleted(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeUnbilledChargesInvoiced: + if h.OnUnbilledChargesInvoiced != nil { + var e UnbilledChargesInvoicedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnUnbilledChargesInvoiced(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeUnbilledChargesVoided: + if h.OnUnbilledChargesVoided != nil { + var e UnbilledChargesVoidedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnUnbilledChargesVoided(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeUsageFileIngested: + if h.OnUsageFileIngested != nil { + var e UsageFileIngestedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnUsageFileIngested(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeVariantCreated: + if h.OnVariantCreated != nil { + var e VariantCreatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnVariantCreated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeVariantDeleted: + if h.OnVariantDeleted != nil { + var e VariantDeletedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnVariantDeleted(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeVariantUpdated: + if h.OnVariantUpdated != nil { + var e VariantUpdatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnVariantUpdated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeVirtualBankAccountAdded: + if h.OnVirtualBankAccountAdded != nil { + var e VirtualBankAccountAddedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnVirtualBankAccountAdded(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeVirtualBankAccountDeleted: + if h.OnVirtualBankAccountDeleted != nil { + var e VirtualBankAccountDeletedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnVirtualBankAccountDeleted(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeVirtualBankAccountUpdated: + if h.OnVirtualBankAccountUpdated != nil { + var e VirtualBankAccountUpdatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnVirtualBankAccountUpdated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeVoucherCreateFailed: + if h.OnVoucherCreateFailed != nil { + var e VoucherCreateFailedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnVoucherCreateFailed(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeVoucherCreated: + if h.OnVoucherCreated != nil { + var e VoucherCreatedEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnVoucherCreated(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + case enum.EventTypeVoucherExpired: + if h.OnVoucherExpired != nil { + var e VoucherExpiredEvent + if err := json.Unmarshal(body, &e); err != nil { + return err + } + return h.OnVoucherExpired(e) + } else { + return h.handleUnhandledEvent(eventType, body) + } + + default: + return h.handleUnhandledEvent(eventType, body) + } + return nil +} + +func (h *WebhookHandler) HTTPHandler() http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if h == nil { + http.Error(w, "webhook handler not configured", http.StatusInternalServerError) + return + } + if h.RequestValidator != nil { + if err := h.RequestValidator(r); err != nil { + h.handleError(w, r, err) + return + } + } + defer r.Body.Close() + body, err := io.ReadAll(r.Body) + if err != nil { + h.handleError(w, r, err) + return + } + if err := h.ParseAndDispatch(body); err != nil { + h.handleError(w, r, err) + return + } + w.WriteHeader(http.StatusOK) + }) +} + +func (h *WebhookHandler) handleError(w http.ResponseWriter, r *http.Request, err error) { + if h.OnError != nil { + h.OnError(w, r, err) + return + } + http.Error(w, err.Error(), http.StatusInternalServerError) +} + +func (h *WebhookHandler) handleUnhandledEvent(eventType enum.EventType, body []byte) error { + if h.OnUnhandledEvent != nil { + return h.OnUnhandledEvent(eventType, body) + } + return fmt.Errorf("unhandled event type: %s", eventType) +} diff --git a/webhook/parser.go b/webhook/parser.go new file mode 100644 index 00000000..6e1e8e4f --- /dev/null +++ b/webhook/parser.go @@ -0,0 +1,25 @@ +package webhook + +import ( + "encoding/json" + "errors" + "github.com/chargebee/chargebee-go/v3" + "github.com/chargebee/chargebee-go/v3/enum" + "strings" +) + +// ParseEventType reads only the event_type (and validates api_version) from the webhook payload +func ParseEventType(body []byte) (enum.EventType, error) { + var envelope struct { + EventType enum.EventType `json:"event_type"` + ApiVersion string `json:"api_version"` + } + if err := json.Unmarshal(body, &envelope); err != nil { + return "", err + } + envVersion := chargebee.APIVersion + if envelope.ApiVersion != "" && strings.ToUpper(envelope.ApiVersion) != strings.ToUpper(envVersion) { + return "", errors.New("API version [" + strings.ToUpper(envelope.ApiVersion) + "] in response does not match with client library API version [" + strings.ToUpper(envVersion) + "]") + } + return envelope.EventType, nil +}