#Phoenix_

1 messages · Page 1 of 1 (latest)

mossy latchBOT
graceful dragon
#

What's the event ID?

candid sky
#

[evt_1NApvIFgZUfXrKX66BWvyzsf]

#

The last one, right?

graceful dragon
#

This is a payment_method.attached, I believe you should listen to checkout.session.completed event in order to get the metadata from a checkout session object

candid sky
#

So webhook is wrong?

#
@app.route('/webhook', methods=['POST'])
def webhook():
    event = None
    payload = request.data
    sig_header = request.headers['STRIPE_SIGNATURE']

    try:
        event = stripe.Webhook.construct_event(
            payload, sig_header, 'whsec_45e053f0b777e02850555bdae985d3c594f095eb0b00e4c29ed083b5614cb0eb'
        )
    except ValueError as e:
        # Invalid payload
        raise e
    except stripe.error.SignatureVerificationError as e:
        # Invalid signature
        raise e

    # Handle the event
    if event['type'] == 'payment_intent.succeeded':
      print(event, '(*************)')
      payment_intent = event['data']['object']
      print(payment_intent, 'OOOOOOOOOOOOOOOO')

    # ... handle other event types
    else:
      print('Unhandled event type {}'.format(event['type']))

    return jsonify(success=True)

This is my webhook.

mossy latchBOT
stark tapir
candid sky
#

Would you like to provide some sample code to send metadata?
I still don't get metadata.

stark tapir
#

What have you tried? Where are you expecting to see the metadata?

candid sky
#

I want to see metadata in webhook response.
And sending metadata when creating checkout.

@app.route('/create-checkout-session', methods=['POST'])
def create_checkout_session():
    metadata = request.json["metadata"]
    price_id = request.json["price_id"]
    print(metadata, price_id)
    try:
        checkout_session = stripe.checkout.Session.create(
            line_items=[
                {
                    # Provide the exact Price ID (for example, pr_1234) of the product you want to sell
                    'price': price_id,
                    'quantity': 1
                },
            ],
            metadata = metadata,
            mode='subscription',
            success_url='http://localhost:3000/settings' + '?success=true',
            cancel_url='http://localhost:3000/settings' + '?canceled=true',
        )
    except Exception as e:
        print(e)
        return str(e)

    # return redirect(checkout_session.url, code=303)
    print(checkout_session.url)
    return jsonify({'redirectUrl': checkout_session.url}), 200
stark tapir
#

The metadata parameter sets on the Checkout Session object, and therefore only on checkout.session.* events (which you're not listening to)

candid sky
#

I am looking this. But as I have no much experience, I didn't get the point.

#

So I can use another parameters such as custom_fields?

stark tapir
#

Then your payment_intent.succeeded events will include those fields

candid sky
#

You can not pass payment_intent_data in subscription mode.
I am getting this error.

stark tapir
#

Ok, yep. I missed you were using mode: 'subscription'. Why specifically do you need metadata on the Payment Intent events?

candid sky
#

I want to send user_id in backend.

stark tapir
#

Then use checkout.session.completed events instead and your existing code will work

candid sky
#

Now I dont listen checkout.session.completed?

#

How can I change listening events?

stark tapir
#

Looks like you're using the CLI? stripe listen?

#

You likely need to add the checkout.session.completed event to your command: stripe listen --events=checkout.session.completed --forward-to=https://xxx

mossy latchBOT
candid sky
#

Phew.
Works fine now.

#

Thanks for your kind supporting!!