github.com/stripe/stripe-go/v76@v76.25.0/event.go (about) 1 // 2 // 3 // File generated from our OpenAPI spec 4 // 5 // 6 7 package stripe 8 9 import ( 10 "encoding/json" 11 "fmt" 12 "strconv" 13 ) 14 15 // Description of the event (for example, `invoice.created` or `charge.refunded`). 16 type EventType string 17 18 // List of values that EventType can take 19 const ( 20 EventTypeAccountApplicationAuthorized EventType = "account.application.authorized" 21 EventTypeAccountApplicationDeauthorized EventType = "account.application.deauthorized" 22 EventTypeAccountExternalAccountCreated EventType = "account.external_account.created" 23 EventTypeAccountExternalAccountDeleted EventType = "account.external_account.deleted" 24 EventTypeAccountExternalAccountUpdated EventType = "account.external_account.updated" 25 EventTypeAccountUpdated EventType = "account.updated" 26 EventTypeApplicationFeeCreated EventType = "application_fee.created" 27 EventTypeApplicationFeeRefundUpdated EventType = "application_fee.refund.updated" 28 EventTypeApplicationFeeRefunded EventType = "application_fee.refunded" 29 EventTypeBalanceAvailable EventType = "balance.available" 30 EventTypeBillingPortalConfigurationCreated EventType = "billing_portal.configuration.created" 31 EventTypeBillingPortalConfigurationUpdated EventType = "billing_portal.configuration.updated" 32 EventTypeBillingPortalSessionCreated EventType = "billing_portal.session.created" 33 EventTypeCapabilityUpdated EventType = "capability.updated" 34 EventTypeCashBalanceFundsAvailable EventType = "cash_balance.funds_available" 35 EventTypeChargeCaptured EventType = "charge.captured" 36 EventTypeChargeDisputeClosed EventType = "charge.dispute.closed" 37 EventTypeChargeDisputeCreated EventType = "charge.dispute.created" 38 EventTypeChargeDisputeFundsReinstated EventType = "charge.dispute.funds_reinstated" 39 EventTypeChargeDisputeFundsWithdrawn EventType = "charge.dispute.funds_withdrawn" 40 EventTypeChargeDisputeUpdated EventType = "charge.dispute.updated" 41 EventTypeChargeExpired EventType = "charge.expired" 42 EventTypeChargeFailed EventType = "charge.failed" 43 EventTypeChargePending EventType = "charge.pending" 44 EventTypeChargeRefundUpdated EventType = "charge.refund.updated" 45 EventTypeChargeRefunded EventType = "charge.refunded" 46 EventTypeChargeSucceeded EventType = "charge.succeeded" 47 EventTypeChargeUpdated EventType = "charge.updated" 48 EventTypeCheckoutSessionAsyncPaymentFailed EventType = "checkout.session.async_payment_failed" 49 EventTypeCheckoutSessionAsyncPaymentSucceeded EventType = "checkout.session.async_payment_succeeded" 50 EventTypeCheckoutSessionCompleted EventType = "checkout.session.completed" 51 EventTypeCheckoutSessionExpired EventType = "checkout.session.expired" 52 EventTypeClimateOrderCanceled EventType = "climate.order.canceled" 53 EventTypeClimateOrderCreated EventType = "climate.order.created" 54 EventTypeClimateOrderDelayed EventType = "climate.order.delayed" 55 EventTypeClimateOrderDelivered EventType = "climate.order.delivered" 56 EventTypeClimateOrderProductSubstituted EventType = "climate.order.product_substituted" 57 EventTypeClimateProductCreated EventType = "climate.product.created" 58 EventTypeClimateProductPricingUpdated EventType = "climate.product.pricing_updated" 59 EventTypeCouponCreated EventType = "coupon.created" 60 EventTypeCouponDeleted EventType = "coupon.deleted" 61 EventTypeCouponUpdated EventType = "coupon.updated" 62 EventTypeCreditNoteCreated EventType = "credit_note.created" 63 EventTypeCreditNoteUpdated EventType = "credit_note.updated" 64 EventTypeCreditNoteVoided EventType = "credit_note.voided" 65 EventTypeCustomerCreated EventType = "customer.created" 66 EventTypeCustomerDeleted EventType = "customer.deleted" 67 EventTypeCustomerDiscountCreated EventType = "customer.discount.created" 68 EventTypeCustomerDiscountDeleted EventType = "customer.discount.deleted" 69 EventTypeCustomerDiscountUpdated EventType = "customer.discount.updated" 70 EventTypeCustomerSourceCreated EventType = "customer.source.created" 71 EventTypeCustomerSourceDeleted EventType = "customer.source.deleted" 72 EventTypeCustomerSourceExpiring EventType = "customer.source.expiring" 73 EventTypeCustomerSourceUpdated EventType = "customer.source.updated" 74 EventTypeCustomerSubscriptionCreated EventType = "customer.subscription.created" 75 EventTypeCustomerSubscriptionDeleted EventType = "customer.subscription.deleted" 76 EventTypeCustomerSubscriptionPaused EventType = "customer.subscription.paused" 77 EventTypeCustomerSubscriptionPendingUpdateApplied EventType = "customer.subscription.pending_update_applied" 78 EventTypeCustomerSubscriptionPendingUpdateExpired EventType = "customer.subscription.pending_update_expired" 79 EventTypeCustomerSubscriptionResumed EventType = "customer.subscription.resumed" 80 EventTypeCustomerSubscriptionTrialWillEnd EventType = "customer.subscription.trial_will_end" 81 EventTypeCustomerSubscriptionUpdated EventType = "customer.subscription.updated" 82 EventTypeCustomerTaxIDCreated EventType = "customer.tax_id.created" 83 EventTypeCustomerTaxIDDeleted EventType = "customer.tax_id.deleted" 84 EventTypeCustomerTaxIDUpdated EventType = "customer.tax_id.updated" 85 EventTypeCustomerUpdated EventType = "customer.updated" 86 EventTypeCustomerCashBalanceTransactionCreated EventType = "customer_cash_balance_transaction.created" 87 EventTypeFileCreated EventType = "file.created" 88 EventTypeFinancialConnectionsAccountCreated EventType = "financial_connections.account.created" 89 EventTypeFinancialConnectionsAccountDeactivated EventType = "financial_connections.account.deactivated" 90 EventTypeFinancialConnectionsAccountDisconnected EventType = "financial_connections.account.disconnected" 91 EventTypeFinancialConnectionsAccountReactivated EventType = "financial_connections.account.reactivated" 92 EventTypeFinancialConnectionsAccountRefreshedBalance EventType = "financial_connections.account.refreshed_balance" 93 EventTypeFinancialConnectionsAccountRefreshedOwnership EventType = "financial_connections.account.refreshed_ownership" 94 EventTypeFinancialConnectionsAccountRefreshedTransactions EventType = "financial_connections.account.refreshed_transactions" 95 EventTypeIdentityVerificationSessionCanceled EventType = "identity.verification_session.canceled" 96 EventTypeIdentityVerificationSessionCreated EventType = "identity.verification_session.created" 97 EventTypeIdentityVerificationSessionProcessing EventType = "identity.verification_session.processing" 98 EventTypeIdentityVerificationSessionRedacted EventType = "identity.verification_session.redacted" 99 EventTypeIdentityVerificationSessionRequiresInput EventType = "identity.verification_session.requires_input" 100 EventTypeIdentityVerificationSessionVerified EventType = "identity.verification_session.verified" 101 EventTypeInvoiceCreated EventType = "invoice.created" 102 EventTypeInvoiceDeleted EventType = "invoice.deleted" 103 EventTypeInvoiceFinalizationFailed EventType = "invoice.finalization_failed" 104 EventTypeInvoiceFinalized EventType = "invoice.finalized" 105 EventTypeInvoiceMarkedUncollectible EventType = "invoice.marked_uncollectible" 106 EventTypeInvoicePaid EventType = "invoice.paid" 107 EventTypeInvoicePaymentActionRequired EventType = "invoice.payment_action_required" 108 EventTypeInvoicePaymentFailed EventType = "invoice.payment_failed" 109 EventTypeInvoicePaymentSucceeded EventType = "invoice.payment_succeeded" 110 EventTypeInvoiceSent EventType = "invoice.sent" 111 EventTypeInvoiceUpcoming EventType = "invoice.upcoming" 112 EventTypeInvoiceUpdated EventType = "invoice.updated" 113 EventTypeInvoiceVoided EventType = "invoice.voided" 114 EventTypeInvoiceItemCreated EventType = "invoiceitem.created" 115 EventTypeInvoiceItemDeleted EventType = "invoiceitem.deleted" 116 EventTypeIssuingAuthorizationCreated EventType = "issuing_authorization.created" 117 EventTypeIssuingAuthorizationRequest EventType = "issuing_authorization.request" 118 EventTypeIssuingAuthorizationUpdated EventType = "issuing_authorization.updated" 119 EventTypeIssuingCardCreated EventType = "issuing_card.created" 120 EventTypeIssuingCardUpdated EventType = "issuing_card.updated" 121 EventTypeIssuingCardholderCreated EventType = "issuing_cardholder.created" 122 EventTypeIssuingCardholderUpdated EventType = "issuing_cardholder.updated" 123 EventTypeIssuingDisputeClosed EventType = "issuing_dispute.closed" 124 EventTypeIssuingDisputeCreated EventType = "issuing_dispute.created" 125 EventTypeIssuingDisputeFundsReinstated EventType = "issuing_dispute.funds_reinstated" 126 EventTypeIssuingDisputeSubmitted EventType = "issuing_dispute.submitted" 127 EventTypeIssuingDisputeUpdated EventType = "issuing_dispute.updated" 128 EventTypeIssuingTokenCreated EventType = "issuing_token.created" 129 EventTypeIssuingTokenUpdated EventType = "issuing_token.updated" 130 EventTypeIssuingTransactionCreated EventType = "issuing_transaction.created" 131 EventTypeIssuingTransactionUpdated EventType = "issuing_transaction.updated" 132 EventTypeMandateUpdated EventType = "mandate.updated" 133 EventTypePaymentIntentAmountCapturableUpdated EventType = "payment_intent.amount_capturable_updated" 134 EventTypePaymentIntentCanceled EventType = "payment_intent.canceled" 135 EventTypePaymentIntentCreated EventType = "payment_intent.created" 136 EventTypePaymentIntentPartiallyFunded EventType = "payment_intent.partially_funded" 137 EventTypePaymentIntentPaymentFailed EventType = "payment_intent.payment_failed" 138 EventTypePaymentIntentProcessing EventType = "payment_intent.processing" 139 EventTypePaymentIntentRequiresAction EventType = "payment_intent.requires_action" 140 EventTypePaymentIntentSucceeded EventType = "payment_intent.succeeded" 141 EventTypePaymentLinkCreated EventType = "payment_link.created" 142 EventTypePaymentLinkUpdated EventType = "payment_link.updated" 143 EventTypePaymentMethodAttached EventType = "payment_method.attached" 144 EventTypePaymentMethodAutomaticallyUpdated EventType = "payment_method.automatically_updated" 145 EventTypePaymentMethodDetached EventType = "payment_method.detached" 146 EventTypePaymentMethodUpdated EventType = "payment_method.updated" 147 EventTypePayoutCanceled EventType = "payout.canceled" 148 EventTypePayoutCreated EventType = "payout.created" 149 EventTypePayoutFailed EventType = "payout.failed" 150 EventTypePayoutPaid EventType = "payout.paid" 151 EventTypePayoutReconciliationCompleted EventType = "payout.reconciliation_completed" 152 EventTypePayoutUpdated EventType = "payout.updated" 153 EventTypePersonCreated EventType = "person.created" 154 EventTypePersonDeleted EventType = "person.deleted" 155 EventTypePersonUpdated EventType = "person.updated" 156 EventTypePlanCreated EventType = "plan.created" 157 EventTypePlanDeleted EventType = "plan.deleted" 158 EventTypePlanUpdated EventType = "plan.updated" 159 EventTypePriceCreated EventType = "price.created" 160 EventTypePriceDeleted EventType = "price.deleted" 161 EventTypePriceUpdated EventType = "price.updated" 162 EventTypeProductCreated EventType = "product.created" 163 EventTypeProductDeleted EventType = "product.deleted" 164 EventTypeProductUpdated EventType = "product.updated" 165 EventTypePromotionCodeCreated EventType = "promotion_code.created" 166 EventTypePromotionCodeUpdated EventType = "promotion_code.updated" 167 EventTypeQuoteAccepted EventType = "quote.accepted" 168 EventTypeQuoteCanceled EventType = "quote.canceled" 169 EventTypeQuoteCreated EventType = "quote.created" 170 EventTypeQuoteFinalized EventType = "quote.finalized" 171 EventTypeRadarEarlyFraudWarningCreated EventType = "radar.early_fraud_warning.created" 172 EventTypeRadarEarlyFraudWarningUpdated EventType = "radar.early_fraud_warning.updated" 173 EventTypeRefundCreated EventType = "refund.created" 174 EventTypeRefundUpdated EventType = "refund.updated" 175 EventTypeReportingReportRunFailed EventType = "reporting.report_run.failed" 176 EventTypeReportingReportRunSucceeded EventType = "reporting.report_run.succeeded" 177 EventTypeReportingReportTypeUpdated EventType = "reporting.report_type.updated" 178 EventTypeReviewClosed EventType = "review.closed" 179 EventTypeReviewOpened EventType = "review.opened" 180 EventTypeSetupIntentCanceled EventType = "setup_intent.canceled" 181 EventTypeSetupIntentCreated EventType = "setup_intent.created" 182 EventTypeSetupIntentRequiresAction EventType = "setup_intent.requires_action" 183 EventTypeSetupIntentSetupFailed EventType = "setup_intent.setup_failed" 184 EventTypeSetupIntentSucceeded EventType = "setup_intent.succeeded" 185 EventTypeSigmaScheduledQueryRunCreated EventType = "sigma.scheduled_query_run.created" 186 EventTypeSourceCanceled EventType = "source.canceled" 187 EventTypeSourceChargeable EventType = "source.chargeable" 188 EventTypeSourceFailed EventType = "source.failed" 189 EventTypeSourceMandateNotification EventType = "source.mandate_notification" 190 EventTypeSourceRefundAttributesRequired EventType = "source.refund_attributes_required" 191 EventTypeSourceTransactionCreated EventType = "source.transaction.created" 192 EventTypeSourceTransactionUpdated EventType = "source.transaction.updated" 193 EventTypeSubscriptionScheduleAborted EventType = "subscription_schedule.aborted" 194 EventTypeSubscriptionScheduleCanceled EventType = "subscription_schedule.canceled" 195 EventTypeSubscriptionScheduleCompleted EventType = "subscription_schedule.completed" 196 EventTypeSubscriptionScheduleCreated EventType = "subscription_schedule.created" 197 EventTypeSubscriptionScheduleExpiring EventType = "subscription_schedule.expiring" 198 EventTypeSubscriptionScheduleReleased EventType = "subscription_schedule.released" 199 EventTypeSubscriptionScheduleUpdated EventType = "subscription_schedule.updated" 200 EventTypeTaxSettingsUpdated EventType = "tax.settings.updated" 201 EventTypeTaxRateCreated EventType = "tax_rate.created" 202 EventTypeTaxRateUpdated EventType = "tax_rate.updated" 203 EventTypeTerminalReaderActionFailed EventType = "terminal.reader.action_failed" 204 EventTypeTerminalReaderActionSucceeded EventType = "terminal.reader.action_succeeded" 205 EventTypeTestHelpersTestClockAdvancing EventType = "test_helpers.test_clock.advancing" 206 EventTypeTestHelpersTestClockCreated EventType = "test_helpers.test_clock.created" 207 EventTypeTestHelpersTestClockDeleted EventType = "test_helpers.test_clock.deleted" 208 EventTypeTestHelpersTestClockInternalFailure EventType = "test_helpers.test_clock.internal_failure" 209 EventTypeTestHelpersTestClockReady EventType = "test_helpers.test_clock.ready" 210 EventTypeTopupCanceled EventType = "topup.canceled" 211 EventTypeTopupCreated EventType = "topup.created" 212 EventTypeTopupFailed EventType = "topup.failed" 213 EventTypeTopupReversed EventType = "topup.reversed" 214 EventTypeTopupSucceeded EventType = "topup.succeeded" 215 EventTypeTransferCreated EventType = "transfer.created" 216 EventTypeTransferReversed EventType = "transfer.reversed" 217 EventTypeTransferUpdated EventType = "transfer.updated" 218 EventTypeTreasuryCreditReversalCreated EventType = "treasury.credit_reversal.created" 219 EventTypeTreasuryCreditReversalPosted EventType = "treasury.credit_reversal.posted" 220 EventTypeTreasuryDebitReversalCompleted EventType = "treasury.debit_reversal.completed" 221 EventTypeTreasuryDebitReversalCreated EventType = "treasury.debit_reversal.created" 222 EventTypeTreasuryDebitReversalInitialCreditGranted EventType = "treasury.debit_reversal.initial_credit_granted" 223 EventTypeTreasuryFinancialAccountClosed EventType = "treasury.financial_account.closed" 224 EventTypeTreasuryFinancialAccountCreated EventType = "treasury.financial_account.created" 225 EventTypeTreasuryFinancialAccountFeaturesStatusUpdated EventType = "treasury.financial_account.features_status_updated" 226 EventTypeTreasuryInboundTransferCanceled EventType = "treasury.inbound_transfer.canceled" 227 EventTypeTreasuryInboundTransferCreated EventType = "treasury.inbound_transfer.created" 228 EventTypeTreasuryInboundTransferFailed EventType = "treasury.inbound_transfer.failed" 229 EventTypeTreasuryInboundTransferSucceeded EventType = "treasury.inbound_transfer.succeeded" 230 EventTypeTreasuryOutboundPaymentCanceled EventType = "treasury.outbound_payment.canceled" 231 EventTypeTreasuryOutboundPaymentCreated EventType = "treasury.outbound_payment.created" 232 EventTypeTreasuryOutboundPaymentExpectedArrivalDateUpdated EventType = "treasury.outbound_payment.expected_arrival_date_updated" 233 EventTypeTreasuryOutboundPaymentFailed EventType = "treasury.outbound_payment.failed" 234 EventTypeTreasuryOutboundPaymentPosted EventType = "treasury.outbound_payment.posted" 235 EventTypeTreasuryOutboundPaymentReturned EventType = "treasury.outbound_payment.returned" 236 EventTypeTreasuryOutboundTransferCanceled EventType = "treasury.outbound_transfer.canceled" 237 EventTypeTreasuryOutboundTransferCreated EventType = "treasury.outbound_transfer.created" 238 EventTypeTreasuryOutboundTransferExpectedArrivalDateUpdated EventType = "treasury.outbound_transfer.expected_arrival_date_updated" 239 EventTypeTreasuryOutboundTransferFailed EventType = "treasury.outbound_transfer.failed" 240 EventTypeTreasuryOutboundTransferPosted EventType = "treasury.outbound_transfer.posted" 241 EventTypeTreasuryOutboundTransferReturned EventType = "treasury.outbound_transfer.returned" 242 EventTypeTreasuryReceivedCreditCreated EventType = "treasury.received_credit.created" 243 EventTypeTreasuryReceivedCreditFailed EventType = "treasury.received_credit.failed" 244 EventTypeTreasuryReceivedCreditSucceeded EventType = "treasury.received_credit.succeeded" 245 EventTypeTreasuryReceivedDebitCreated EventType = "treasury.received_debit.created" 246 EventTypeInvoiceItemUpdated EventType = "invoiceitem.updated" 247 EventTypeOrderCreated EventType = "order.created" 248 EventTypeRecipientCreated EventType = "recipient.created" 249 EventTypeRecipientDeleted EventType = "recipient.deleted" 250 EventTypeRecipientUpdated EventType = "recipient.updated" 251 EventTypeSKUCreated EventType = "sku.created" 252 EventTypeSKUDeleted EventType = "sku.deleted" 253 EventTypeSKUUpdated EventType = "sku.updated" 254 ) 255 256 // List events, going back up to 30 days. Each event data is rendered according to Stripe API version at its creation time, specified in [event object](https://stripe.com/docs/api/events/object) api_version attribute (not according to your current Stripe API version or Stripe-Version header). 257 type EventListParams struct { 258 ListParams `form:"*"` 259 // Only return events that were created during the given date interval. 260 Created *int64 `form:"created"` 261 // Only return events that were created during the given date interval. 262 CreatedRange *RangeQueryParams `form:"created"` 263 // Filter events by whether all webhooks were successfully delivered. If false, events which are still pending or have failed all delivery attempts to a webhook endpoint will be returned. 264 DeliverySuccess *bool `form:"delivery_success"` 265 // Specifies which fields in the response should be expanded. 266 Expand []*string `form:"expand"` 267 // A string containing a specific event name, or group of events using * as a wildcard. The list will be filtered to include only events with a matching event property. 268 Type *string `form:"type"` 269 // An array of up to 20 strings containing specific event names. The list will be filtered to include only events with a matching event property. You may pass either `type` or `types`, but not both. 270 Types []*string `form:"types"` 271 } 272 273 // AddExpand appends a new field to expand. 274 func (p *EventListParams) AddExpand(f string) { 275 p.Expand = append(p.Expand, &f) 276 } 277 278 // Retrieves the details of an event. Supply the unique identifier of the event, which you might have received in a webhook. 279 type EventParams struct { 280 Params `form:"*"` 281 // Specifies which fields in the response should be expanded. 282 Expand []*string `form:"expand"` 283 } 284 285 // AddExpand appends a new field to expand. 286 func (p *EventParams) AddExpand(f string) { 287 p.Expand = append(p.Expand, &f) 288 } 289 290 type EventData struct { 291 // Object is a raw mapping of the API resource contained in the event. 292 // Although marked with json:"-", it's still populated independently by 293 // a custom UnmarshalJSON implementation. 294 // Object containing the API resource relevant to the event. For example, an `invoice.created` event will have a full [invoice object](https://stripe.com/docs/api#invoice_object) as the value of the object key. 295 Object map[string]interface{} `json:"-"` 296 // Object containing the names of the updated attributes and their values prior to the event (only included in events of type `*.updated`). If an array attribute has any updated elements, this object contains the entire array. In Stripe API versions 2017-04-06 or earlier, an updated array attribute in this object includes only the updated array elements. 297 PreviousAttributes map[string]interface{} `json:"previous_attributes"` 298 Raw json.RawMessage `json:"object"` 299 } 300 301 // Information on the API request that triggers the event. 302 type EventRequest struct { 303 // ID is the request ID of the request that created an event, if the event 304 // was created by a request. 305 // ID of the API request that caused the event. If null, the event was automatic (e.g., Stripe's automatic subscription handling). Request logs are available in the [dashboard](https://dashboard.stripe.com/logs), but currently not in the API. 306 ID string `json:"id"` 307 308 // IdempotencyKey is the idempotency key of the request that created an 309 // event, if the event was created by a request and if an idempotency key 310 // was specified for that request. 311 // The idempotency key transmitted during the request, if any. *Note: This property is populated only for events on or after May 23, 2017*. 312 IdempotencyKey string `json:"idempotency_key"` 313 } 314 315 // Events are our way of letting you know when something interesting happens in 316 // your account. When an interesting event occurs, we create a new `Event` 317 // object. For example, when a charge succeeds, we create a `charge.succeeded` 318 // event, and when an invoice payment attempt fails, we create an 319 // `invoice.payment_failed` event. Certain API requests might create multiple 320 // events. For example, if you create a new subscription for a 321 // customer, you receive both a `customer.subscription.created` event and a 322 // `charge.succeeded` event. 323 // 324 // Events occur when the state of another API resource changes. The event's data 325 // field embeds the resource's state at the time of the change. For 326 // example, a `charge.succeeded` event contains a charge, and an 327 // `invoice.payment_failed` event contains an invoice. 328 // 329 // As with other API resources, you can use endpoints to retrieve an 330 // [individual event](https://stripe.com/docs/api#retrieve_event) or a [list of events](https://stripe.com/docs/api#list_events) 331 // from the API. We also have a separate 332 // [webhooks](http://en.wikipedia.org/wiki/Webhook) system for sending the 333 // `Event` objects directly to an endpoint on your server. You can manage 334 // webhooks in your 335 // [account settings](https://dashboard.stripe.com/account/webhooks). Learn how 336 // to [listen for events](https://stripe.com/docs/webhooks) 337 // so that your integration can automatically trigger reactions. 338 // 339 // When using [Connect](https://stripe.com/docs/connect), you can also receive event notifications 340 // that occur in connected accounts. For these events, there's an 341 // additional `account` attribute in the received `Event` object. 342 // 343 // We only guarantee access to events through the [Retrieve Event API](https://stripe.com/docs/api#retrieve_event) 344 // for 30 days. 345 type Event struct { 346 APIResource 347 // The connected account that originates the event. 348 Account string `json:"account"` 349 // The Stripe API version used to render `data`. This property is populated only for events on or after October 31, 2014. 350 APIVersion string `json:"api_version"` 351 // Time at which the object was created. Measured in seconds since the Unix epoch. 352 Created int64 `json:"created"` 353 Data *EventData `json:"data"` 354 // Unique identifier for the object. 355 ID string `json:"id"` 356 // Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode. 357 Livemode bool `json:"livemode"` 358 // String representing the object's type. Objects of the same type share the same value. 359 Object string `json:"object"` 360 // Number of webhooks that haven't been successfully delivered (for example, to return a 20x response) to the URLs you specify. 361 PendingWebhooks int64 `json:"pending_webhooks"` 362 // Information on the API request that triggers the event. 363 Request *EventRequest `json:"request"` 364 // Description of the event (for example, `invoice.created` or `charge.refunded`). 365 Type EventType `json:"type"` 366 } 367 368 // EventList is a list of Events as retrieved from a list endpoint. 369 type EventList struct { 370 APIResource 371 ListMeta 372 Data []*Event `json:"data"` 373 } 374 375 // GetObjectValue returns the value from the e.Data.Object bag based on the keys hierarchy. 376 func (e *Event) GetObjectValue(keys ...string) string { 377 return getValue(e.Data.Object, keys) 378 } 379 380 // GetPreviousValue returns the value from the e.Data.Prev bag based on the keys hierarchy. 381 func (e *Event) GetPreviousValue(keys ...string) string { 382 return getValue(e.Data.PreviousAttributes, keys) 383 } 384 385 // UnmarshalJSON handles deserialization of the EventData. 386 // This custom unmarshaling exists so that we can keep both the map and raw data. 387 func (e *EventData) UnmarshalJSON(data []byte) error { 388 type eventdata EventData 389 var ee eventdata 390 err := json.Unmarshal(data, &ee) 391 if err != nil { 392 return err 393 } 394 395 *e = EventData(ee) 396 return json.Unmarshal(e.Raw, &e.Object) 397 } 398 399 // getValue returns the value from the m map based on the keys. 400 func getValue(m map[string]interface{}, keys []string) string { 401 node := m[keys[0]] 402 403 for i := 1; i < len(keys); i++ { 404 key := keys[i] 405 406 sliceNode, ok := node.([]interface{}) 407 if ok { 408 intKey, err := strconv.Atoi(key) 409 if err != nil { 410 panic(fmt.Sprintf( 411 "Cannot access nested slice element with non-integer key: %s", 412 key)) 413 } 414 node = sliceNode[intKey] 415 continue 416 } 417 418 mapNode, ok := node.(map[string]interface{}) 419 if ok { 420 node = mapNode[key] 421 continue 422 } 423 424 panic(fmt.Sprintf( 425 "Cannot descend into non-map non-slice object with key: %s", key)) 426 } 427 428 if node == nil { 429 return "" 430 } 431 432 return fmt.Sprintf("%v", node) 433 }