Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I do not receive the metadata when creating a checkout session #1406

Closed
EnriqueRapelaDeveloper opened this issue May 28, 2024 · 1 comment
Closed
Assignees
Labels
support Question better suited for the support team

Comments

@EnriqueRapelaDeveloper
Copy link

Describe the bug

I have an API with Ruby on Rails, and I'm creating a checkout session to make a payment. I leave you the code block below:

    session = Stripe::Checkout::Session.create(
      payment_method_types: ['card'],
      line_items: [{
        price_data: {
          currency: 'eur',
          product_data: {
            name: 'Invitación de boda'
          },
          unit_amount: 8000 # Put the correct amount or set in the database
        },
        quantity: 1
      }],
      mode: 'payment',
      success_url: "#{@base_url}/#{@payment_intent.uid}/confirm_payment", # FRONT URL FOR SUCCESS REDIRECT
      cancel_url: "#{@base_url}/#{@payment_intent.uid}/cancel", # FRONT URL FOR FAILED REDIRECT
      metadata: {
        uid: @payment_intent.uid
      }
    )

This is what is created in the dashboard:

{
  "metadata": {
    "uid": "ddf0f536-8e8f-4d58-8eb8-133c1858530f",
    "lol": "holaaa!"
  },
  "mode": "payment",
  "line_items": {
    "0": {
      "price_data": {
        "unit_amount": "8000",
        "currency": "eur",
        "product_data": {
          "name": "Invitación de boda"
        }
      },
      "quantity": "1"
    }
  },
  "cancel_url": "https://few-hands-cut.loca.lt/ddf0f536-8e8f-4d58-8eb8-133c1858530f/cancel",
  "success_url": "https://few-hands-cut.loca.lt/ddf0f536-8e8f-4d58-8eb8-133c1858530f/confirm_payment",
  "payment_method_types": {
    "0": "card"
  }
}

I see this from Developers/Registrations -> POST /v1/checkout/sessions

Then I get a callback when you complete the payment but I get empty metadata, I'll show you an example:

#<ActionController::Parameters {"id"=>"evt_3PLNFe01MXmFo9Yc06cnoAfj", "object"=>"event", "api_version"=>"2024-04-10", "created"=>1716892051, "data"=>{"object"=>{"id"=>"pi_3PLNFe01MXmFo9Yc0Duzpitk", "object"=>"payment_intent", "amount"=>8000, "amount_capturable"=>0, "amount_details"=>{"tip"=>{}}, "amount_received"=>8000, "application"=>nil, "application_fee_amount"=>nil, "automatic_payment_methods"=>nil, "canceled_at"=>nil, "cancellation_reason"=>nil, "capture_method"=>"automatic_async", "client_secret"=>"*****", "confirmation_method"=>"automatic", "created"=>1716892050, "currency"=>"eur", "customer"=>nil, "description"=>nil, "invoice"=>nil, "last_payment_error"=>nil, "latest_charge"=>"ch_3PLNFe01MXmFo9Yc09IaYaPZ", "livemode"=>false, "metadata"=>{}, "next_action"=>nil, "on_behalf_of"=>nil, "payment_method"=>"pm_1PLNFe01MXmFo9YcAJyGUUv8", "payment_method_configuration_details"=>nil, "payment_method_options"=>{"card"=>{"installments"=>nil, "mandate_options"=>nil, "network"=>nil, "request_three_d_secure"=>"automatic"}}, "payment_method_types"=>["card"], "processing"=>nil, "receipt_email"=>nil, "review"=>nil, "setup_future_usage"=>nil, "shipping"=>nil, "source"=>nil, "statement_descriptor"=>nil, "statement_descriptor_suffix"=>nil, "status"=>"succeeded", "transfer_data"=>nil, "transfer_group"=>nil}}, "livemode"=>false, "pending_webhooks"=>1, "request"=>{"id"=>"req_Y4hsW4KcmOjhVN", "idempotency_key"=>"9041d611-d94f-4331-818a-9146385c519b"}, "type"=>"payment_intent.succeeded", "controller"=>"api/v1/hooks/stripe", "action"=>"confirm_payment", "stripe"=>{"id"=>"evt_3PLNFe01MXmFo9Yc06cnoAfj", "object"=>"event", "api_version"=>"2024-04-10", "created"=>1716892051, "data"=>{"object"=>{"id"=>"pi_3PLNFe01MXmFo9Yc0Duzpitk", "object"=>"payment_intent", "amount"=>8000, "amount_capturable"=>0, "amount_details"=>{"tip"=>{}}, "amount_received"=>8000, "application"=>nil, "application_fee_amount"=>nil, "automatic_payment_methods"=>nil, "canceled_at"=>nil, "cancellation_reason"=>nil, "capture_method"=>"automatic_async", "client_secret"=>"******", "confirmation_method"=>"automatic", "created"=>1716892050, "currency"=>"eur", "customer"=>nil, "description"=>nil, "invoice"=>nil, "last_payment_error"=>nil, "latest_charge"=>"ch_3PLNFe01MXmFo9Yc09IaYaPZ", "livemode"=>false, "metadata"=>{}, "next_action"=>nil, "on_behalf_of"=>nil, "payment_method"=>"pm_1PLNFe01MXmFo9YcAJyGUUv8", "payment_method_configuration_details"=>nil, "payment_method_options"=>{"card"=>{"installments"=>nil, "mandate_options"=>nil, "network"=>nil, "request_three_d_secure"=>"automatic"}}, "payment_method_types"=>["card"], "processing"=>nil, "receipt_email"=>nil, "review"=>nil, "setup_future_usage"=>nil, "shipping"=>nil, "source"=>nil, "statement_descriptor"=>nil, "statement_descriptor_suffix"=>nil, "status"=>"succeeded", "transfer_data"=>nil, "transfer_group"=>nil}}, "livemode"=>false, "pending_webhooks"=>1, "request"=>{"id"=>"req_Y4hsW4KcmOjhVN", "idempotency_key"=>"9041d611-d94f-4331-818a-9146385c519b"}, "type"=>"payment_intent.succeeded"}} permitted: false>

Do you know what I'm doing wrong to not receive the metadata in the webhook?

To Reproduce

UP!

Expected behavior

I need to receive the metadata with the UID in the stripe webhook, to be able to locate the payment to which that webhook request refers.

Code snippets

No response

OS

macOs

Language version

Ruby 3.3.0

Library version

stripe 11.4.0

API version

2024-04-10

Additional context

No response

@remi-stripe
Copy link
Contributor

@EnriqueRapelaDeveloper Github issues are limited to bugs or feature requests with the SDK itself. Your question is an integration support question better directed at our support team: https://support.stripe.com/contact

To unblock you though, the metadata you set is on the Checkout Session but the Event you looked at is payment_intent.succeeded which describes a PaymentIntent. Those are two completely separate API resources with their own metadata so it's expected that they don't match. You should be listening for checkout.session.completed instead as the Event.
If you really want metadata on the PaymentIntent, you need to configure it on creation using the payment_jntent_data[metadata] parameter.

@ramya-stripe ramya-stripe added support Question better suited for the support team and removed bug labels Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
support Question better suited for the support team
Projects
None yet
Development

No branches or pull requests

3 participants