#burgershot240

1 messages ยท Page 1 of 1 (latest)

arctic juncoBOT
versed storm
#

Hi ๐Ÿ‘‹

Can you share a Customer ID for me to check

hollow aurora
versed storm
#

And when you retrieve this customer and simply echo $customer, what do you see?

hollow aurora
# versed storm And when you retrieve this customer and simply `echo $customer`, what do you see...

I tried Laravel's Log::debug($customer) . Is that OK?

[2023-07-11 00:26:50] local.DEBUG: Stripe\Customer JSON: {
    "id": "cus_OEpecP253nmnPM",
    "object": "customer",
    "address": {
        "city": null,
        "country": "JP",
        "line1": null,
        "line2": null,
        "postal_code": null,
        "state": null
    },
    "balance": 0,
    "created": 1689002808,
    "currency": "jpy",
    "default_source": null,
    "delinquent": false,
    "description": null,
    "discount": null,
    "email": "{email}",
    "invoice_prefix": "07560AE5",
    "invoice_settings": {
        "custom_fields": null,
        "default_payment_method": null,
        "footer": null,
        "rendering_options": null
    },
    "livemode": false,
    "metadata": [],
    "name": "\u3042",
    "next_invoice_sequence": 2,
    "phone": null,
    "preferred_locales": [
        "ja"
    ],
    "shipping": null,
    "tax_exempt": "none",
    "test_clock": null
}
versed storm
#

Hmmm... that is odd. I see the metadata on that Customer

hollow aurora
#

Below is the full code of the Controller that recieve customer.subscription.created webhook.

// customer.subscription.created
case $stripeService::WEBHOOK_CUSTOMER_SUBSUCRIPTION_CREATED:
 Log::debug($event->type . '(' . self::class. ':' .__LINE__ . ')');
 $subscriptionData = $event->data->object; 
 $customerIdFromWebhook = $subscriptionData->customer;

 Log::debug(self::class.':'.__LINE__ . ' customerId:'.$customerIdFromWebhook );

 $stripeSecretKey = env('STRIPE_SECRET_KEY');
 \Stripe\Stripe::setApiKey($stripeSecretKey);
 Log::debug(self::class.':'.__LINE__);

 // retrive customer data
 $customer = \Stripe\Customer::retrieve($customerIdFromWebhook);
 Log::debug($customer);
 exit;
versed storm
#

Okay

hollow aurora
versed storm
#

Okay yes I can see it being returned there.

#

But retrieving the customer should return all the properties. metadata isn't a property that requires expansion to view.

hollow aurora
versed storm
#

We don't store logs of GET request payloads so that is expected

#

OKAY. So the metadata was empty at 2023-07-10 15:26:50 UTC when the GET request was made. The metadata was set at 2023-07-10 15:26:53 UTC

hollow aurora
# versed storm OKAY. So the metadata _was_ empty at `2023-07-10 15:26:50 UTC` when the GET req...

I got it. Thank you . I probably misunderstood that webhooks come my server customer.subscription.created webhook first when cusomer completes payment...
I set the metadata when checkout.session.completed webhook fired.

Is there any way to contain the metadata to customer.subscription.created webhook?
Should I try get the metadata at checkout.session.completed webhook ?

I see the metadata on that webhook's json.

versed storm
#

Is there any way to contain the metadata to customer.subscription.created webhook?
This doesn't make sense to me. You decide when you update your Customer in your code. You can do it whenever you want.

arctic juncoBOT
hollow aurora
#

when I received the webhook, there are not customer's metadata (empty array ) so that I thought I don't have any way to receive the metadata then.
but I think I could retrieve the metadata when I receive checkout.session.completed webhook.

brittle plover
#

Hello! I'm taking over and catching up...

#

Using the other Events you mentioned may not work in all cases because those fire before the metadata is set.

hollow aurora
# brittle plover It sounds like what you should do is listen for `customer.updated` Events so you...

I see.

My app generates checkout link with metadata when customer starts checkout session on my aao to link checkout/stripe customer data and my app's database.
So when checkout session completed, I know that two events fire which is checkout.session.completed and customer.subscription.created.

When fired those events, I want to retrieve metadata of my app's user Id to link payment status between my app database and Stripe customer data.
From above info, I'm tried to ask like those questions.. Are there any misunderstanding yet..?
You mean customer.updated fires when above case?

I'm sorry for bad English though.

thank you.

brittle plover
#

Let me know if this is incorrect or not: as I understand it you have code listening for checkout.session.completed Events and when those Events happen you set metadata on the associated Customer. You then want to listen for an Event that will let you know that metadata was set on the Customer, correct?

hollow aurora
# brittle plover Let me know if this is incorrect or not: as I understand it you have code listen...

as I understand it you have code listening for checkout.session.completed Events
That's correct.
when those Events happen you set metadata on the associated Customer. You then want to listen for an Event that will let you know that metadata was set on the Customer, correct?
Incorrect, I think.
I just want to get metadata when those events fired because I already set the metadata(== user ID of my app) when customer starts/generates checkout session from my app.

brittle plover
#

Okay, so what triggers you setting metadata on the Customer?

hollow aurora
brittle plover
#

No, sorry. You have code that's setting metdata on the Customer, right?

hollow aurora
# brittle plover No, sorry. You have code that's setting metdata on the Customer, right?

Oh, yes. I have the code below. (proper reply?)

$sessionParams = [
    'line_items' => $lineItems,
    'mode' => $mode,
    // back to line
    'success_url' => "https://line.me/R/oaMessage/{$line_account_id}/",
    'cancel_url' => "https://line.me/R/oaMessage/{$line_account_id}/",
    'automatic_tax' => [
        'enabled' => true,
    ],
    // here
    'metadata' => [
        'line_user_id' => $lineUserId,
    ],
];

$checkout_session = \Stripe\Checkout\Session::create($sessionParams);

return $checkout_session->url;
brittle plover
#

That's the code that creates a Checkout Session, but you're talking about metadata on a Customer. Where's the code that sets that?

hollow aurora
brittle plover
#

That sets metadata on the Checkout Session, not the Customer.

#

Maybe we've been talking past each other... are you trying to get an Event when metadata is set on the Checkout Session or when metadata is set on the Customer object? Or something else?