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
1 Answer
Reset to default 4Create 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
版权声明:本文标题:javascript - Stripe Checkout- How to pass a value through to webhook? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744784111a2624890.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论