javascript - Stripe Checkout- How to pass a value through to webhook? - Stack Overflow

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

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744784112a4593517.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信