admin管理员组

文章数量:1410689

How can I pass a custom value (in this case a user ID from Firebase) through to a Stripe webhook?

I'm trying to associate a charge.succeeded event with the user ID so I can write the value to the DB from the node server and change the user's routing on the site.

Is this doable or is there a better way to acplish this?

  <form action="/charge" method="POST">
    <script src=".js" class="stripe-button"
      data-key="pk_"
      data-amount="3495"
      data-zip-code="true"
      metadata="test metadata test"
      data-description="Download and save your document"
      data-locale="auto">
    </script>
  </form>

How can I pass a custom value (in this case a user ID from Firebase) through to a Stripe webhook?

I'm trying to associate a charge.succeeded event with the user ID so I can write the value to the DB from the node server and change the user's routing on the site.

Is this doable or is there a better way to acplish this?

  <form action="/charge" method="POST">
    <script src="https://checkout.stripe./checkout.js" class="stripe-button"
      data-key="pk_"
      data-amount="3495"
      data-zip-code="true"
      metadata="test metadata test"
      data-description="Download and save your document"
      data-locale="auto">
    </script>
  </form>
Share Improve this question edited Jun 28, 2018 at 22:34 dmulter 2,7683 gold badges17 silver badges25 bronze badges asked Jun 13, 2016 at 20:29 Rob WintersRob Winters 1611 silver badge10 bronze badges 2
  • Put the metadata in a hidden field in the form, and then use it in the server script that creates the charge. – Barmar Commented Jun 13, 2016 at 20:36
  • Remember, Checkout doesn't actually create the charge itself. It just converts the CC# to a token, which you then use in your server script to create a customer and charge. – Barmar Commented Jun 13, 2016 at 20:38
Add a ment  | 

1 Answer 1

Reset to default 4

Create a metadata [1] field when you're constructing the charge [2]. When you get the charge.succeeded-event, it should be on the Charge object.

If you're going to accept this value from checkout, you'll need to pass another field along with the form that is getting submitted, then use that to construct the metadata. I've included an example of how to pass additional fields along with the form that is submitted by checkout below:

<form action="/charge" method="POST">

    <script src="https://checkout.stripe./checkout.js" class="stripe-button"
      data-key="pk_"
      data-amount="3495"
      data-zip-code="true"
      metadata="test metadata test"
      data-description="Download and save your document"
      data-locale="auto">
    </script>

    <!-- THE STUFF YOU'RE MISSING IS BELOW -->

    <input type="text" name="extra-field"></input>

</form>

Just remember though, you'll need to actually issue the Create a Charge [2] API request in your backend for the charge to be made. This is just what gets displayed to the user.

Does that make sense?


[1] https://stripe./docs/api#metadata

[2] https://stripe./docs/api#create_charge

本文标签: javascriptStripe Checkout How to pass a value through to webhookStack Overflow