#alal-webhooks

1 messages · Page 1 of 1 (latest)

toxic brook
#

What event are you trying to find the customer in that you can't?

tired storm
#

the customer.subscription.created, for example.

#

let's say I manually create a subscription for a customer, the webhook events are sent to my server, but I have no way to identify which user this was done for, because I don't have the customer id or subscription id at hand to compare it with

toxic brook
#

Can you send me an event you were having trouble finding this in?

#

An ID for an event

tired storm
#

sure, this is the latest one I received:

{
  id: 'evt_1K7h88BAJ1EKIKXO16qkDx8T',
  object: 'event',
  api_version: '2020-03-02',
  created: 1639750192,
  data: {
    object: {
      id: 'sub_1K7h88BAJ1EKIKXOtUEUDrXn',
      object: 'subscription',
      application_fee_percent: null,
      automatic_tax: [Object],
      billing_cycle_anchor: 1639750192,
      billing_thresholds: null,
      cancel_at: null,
      cancel_at_period_end: false,
      canceled_at: null,
      collection_method: 'send_invoice',
      created: 1639750192,
      current_period_end: 1642428592,
      current_period_start: 1639750192,
      customer: 'cus_KnHT4NlcirPbfP',
      days_until_due: 30,
      default_payment_method: 'pm_1K7guOBAJ1EKIKXOrnZFd9ib',
      default_source: null,
      default_tax_rates: [],
      discount: null,
      ended_at: null,
      items: [Object],
      latest_invoice: 'in_1K7h88BAJ1EKIKXOS8es56qA',
      livemode: false,
      metadata: {},
      next_pending_invoice_item_invoice: null,
      pause_collection: null,
      payment_settings: [Object],
      pending_invoice_item_interval: null,
      pending_setup_intent: null,
      pending_update: null,
      plan: [Object],
      quantity: 1,
      schedule: null,
      start_date: 1639750192,
      status: 'active',
      tax_percent: null,
      transfer_data: null,
      trial_end: null,
      trial_start: null
    }
  },
  livemode: false,
  pending_webhooks: 3,
  request: {
    id: 'req_85ItVJGa9CAghG',
    idempotency_key: 'e019dc2a-dfee-43d2-8eb1-2701793c46dc'
  },
  type: 'customer.subscription.created'
}```
toxic brook
#

Ah I see, so you have the IDs sub_1K7h88BAJ1EKIKXOtUEUDrXn and cus_KnHT4NlcirPbfP and need info on them

tired storm
#

oh, do you mean I need to populate those

toxic brook
#

In that case, we recommend just retrieving them with a separate API call

#

They should already be populated at this point

#

Actually maybe no need to look up the subscription, that event is the details on that subscription

tired storm
#

ok, i get your point. But I believe it is also possible that if I make an API call at this point, i might timeout on responding to the stripe event.

#

so, what's the strategy in general? When I receive an event, I should simply respond with a 200 immediately, and then process the event asynchronously? (by making API calls to retrieve more details)

toxic brook
#

Yes, that is the recommendation

#

Respond as soon as you can and then process the event

tired storm
#

aha! that's the thing

#

great, that helped a lot! have a great day!

toxic brook
#

Of course, have a great day yourself!