我在哪里调用“付款成功"?消息来自?

编程入门 行业动态 更新时间:2024-10-10 10:26:13
本文介绍了我在哪里调用“付款成功"?消息来自?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已将 Stripe 集成到我的网站中.下面的代码是直接从 stripe 的文档中复制的.尽管此代码与我的实现之间存在细微差别,但这些差异与问题无关,因为我的代码和代码都显示正常工作

I have integrated Stripe into my site. The code below is copied directly from stripe's documentation. Although there are minor differences between this code and my implementation, such differences are not relevant to the question as both my code and the code is shown work correctly

首先我安装相关文件.

composer.json

composer.json

{ "require": { "stripe/stripe-php": "*" } }

然后我用 JavaScript 结帐.(这个示例费用"收费 9.99 美元,但您懂的.下面是一个简单的结帐,我的是自定义结帐,但这对问题没有影响.)

Then I make a checkout in JavaScript. (This one charges $9.99 for "Example Charge" but you get the idea. Below is a simple checkout, mine is a custom checkout, but that should not make a difference to the question.)

<form action="nextpage.php" method="POST"> <script src="checkout.stripe/checkout.js" class="stripe-button" data-key="<test key here>" data-amount="999" data-name="<myName>" data-description="Example charge" data-image="stripe/img/documentation/checkout/marketplace.png" data-locale="auto" data-currency="aud"> </script> </form>

这个结帐非常擅长捕捉大多数错误,如果它找不到任何错误,它会传递一个令牌让我收费.

This checkout is pretty good at catching most errors, and if it can't find any, it passes a token on for me to charge.

最后,我添加了一个页面来创建费用

Finally, I added a page to create the charge

require 'vendor/autoload.php'; \Stripe\Stripe::setApiKey("<test key here>"); $token = $_POST['stripeToken']; $charge = \Stripe\Charge::create([ 'amount' => 999, 'currency' => 'aud', 'description' => 'Example charge', 'source' => $token, ]);

到目前为止还不错.在测试环境中,这总是成功的.或者,如果我测试一张不应该成功的卡,它总是在结账时失败.

So far it is good. In the testing environment, this always succeeds. Or, if I test a card that should not succeed, it always fails at the checkout.

但是,假设令牌已成功创建,但问题发生在服务器端.如何检测?

However, suppose the token is created successfully, but then the issue happens server side. How do I detect that?

更具体地说,如果我有一个像 alert("您的付款已成功") 或 echo "您的付款已成功",从哪里调用它的正确位置?

More specifically, if I were to have a function like alert("Your payment has been successful") or echo "Your payment has been successful", Where would be the correct place to call that from?

推荐答案

刚发布不久就想通了.

首先我注意到 $charge 是这个上下文中的输出,所以我运行了 echo var_dump($charge);,它打开了大量的信息.

First I noticed that $charge is an output in this context, so I ran echo var_dump($charge); which opened up a massive wealth of information.

我可以在这里找到api参考,而不是在那里查看,向下滚动到收费对象".其中,status(与$charge['status']相关)可以确认是否成功.

Rather than look at it there, I can find the api reference here, scroll down to "The Charge Object". Within that, status (relating to $charge['status']) can confirm if it was successful or not.

工作代码 if($charge['status'] === "succeeded"){} 是放置成功消息的正确位置.

The working code if($charge['status'] === "succeeded"){} is the correct place to put a success message.

更多推荐

我在哪里调用“付款成功"?消息来自?

本文发布于:2023-11-26 07:51:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1633258.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:我在   消息   quot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!