更新 Stripe 价格(payment_intent)

huangapple go评论74阅读模式
英文:

Update Stripe Price (payment_intent)

问题

我正在创建一个网站,人们可以从下拉菜单中选择他们的订阅时长(1/3/6/12个月)。选择一个选项将打开一个模态框,显示Stripe支付表单。

不幸的是,只有在将代码拆分成多个文件时才能正常工作(请参阅Stripe文档示例=>https://stripe.com/docs/payments/quickstart)。

如果没有表单被提交,我不知道如何正确更新价格,以使其与所选的订阅匹配。PHP和HTML不是最好的朋友。是否有人有解决这个问题的想法?

我尝试使用带有iframe的表单提交,以便在不刷新页面的情况下查看表单,不幸的是,变量没有传递到“create.php”文件,因为我必须使用if语句来区分不同的订阅。

英文:

I'm currently creating a website where people can choose their subscription length (1/3/6/12 months) from a dropdown. Selecting one will open a modal which displays the Stripe payment forms.

Unfortunately, it only works if I split up the code into multiple files (see Stripe Docs example => https://stripe.com/docs/payments/quickstart).

I don't know how I can update the price properly so it matches the selected subscription. PHP and HTML are not best friends, if no form is being submitted. Does anyone have an idea how to solve this?

I tried using form submits with iframe so I see the forms without page refresh, unfortunately the variables are not being transmitted to the "create.php" file since I have to use if statements to differ between the subscriptions.

答案1

得分: 0

所以,我找到了这个问题的解决方案。我不能在同一个文件中创建PaymentIntent和表单,所以我肯定必须将这两者分开。

但是,我成功使用了PaymentIntent的更新方法,并在同一个文件中使用了表单。所以现在当有人从下拉菜单中选择订阅时,会触发表单提交,打开一个Bootstrap模态框,在其中我嵌入了一个包含处理更新方法并显示Stripe表单内容的文件的iframe。

也许这对某人有帮助,我认为这是一个相当不错的解决方案。

英文:

So, I've found a solution for this problem. I can't have the PaymentIntent Creation and the forms in the same file, so I definitely had to split up these two.

But I was able to use the Update Method for the PaymentIntent and use the forms in the same file. So now when someone selects a subscription from the dropdown, a form submit happens, which opens a bootstrap-modal in which I've embedded an iframe with the content of the file which handles the Update Method and displays the Stripe forms.

Maybe this helps someone, I think this is a pretty cool solution.

huangapple
  • 本文由 发表于 2023年6月9日 00:14:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/76433853.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定