0

这是我的 checkout.php 页面。我看不到此表单提交费用将在条带上发生。

<div class="row">
<div class='col-sm-offset-9 col-sm-3'>
<form action="process.php" method="POST">
<script
src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="pk_test_Ccg6bLuZ261haQizFhV8Ma9k"
data-amount="<?php echo $amount?>"
data-name="Skarten.com"
data-description="Widget"
data-image="https://stripe.com/img/documentation/checkout/marketplace.png"
data-shipping-address="true"
data-email="<?php echo $user->get_email()?>"      
data-locale="auto">
</script>
</form>
</div>
</div>

这是我的 process.php。但我的问题是如何从条纹获得任何确认。如果收费成功与否。

session_start();
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
require_once('stripe-php/init.php');// add the php library for stripe

\Stripe\Stripe::setApiKey("sk_test_8UDgizhVo91Z8MJqk7G9n9BN");

// Token is created using Checkout or Elements!
// Get the payment token ID submitted by the form:
$token = $_POST['stripeToken'];
$amount=$_SESSION['amount'];

// Charge the user's card:
$charge = \Stripe\Charge::create(array(
  "amount" => $amount,
  "currency" => "usd",
 "description" => "Example charge",
 "metadata" => array("order_id" => 6735),    
 "source" => $token,
));
4

2 回答 2

1

如果收费成功,Charge 对象将填充具有 Charge ID 的内容。如果不成功,该 API 方法\Stripe\Charge::create()将引发异常(可能是 Card Error 异常)。您可以在此处了解有关这些的更多信息:

https://stripe.com/docs/api#error_handling

希望这有助于您入门!

于 2018-03-16T21:47:10.177 回答
0

获得 100% 确认结果的最佳方法是使用Stripe Webhooks

Stripe 将向您的端点发送有关您注册的任何事件的有效负载

Stripe 将向您发送一个Event对象,该对象将包含特定事件的响应以及详细信息。

在您的情况下,您需要捕获Charge.succeeded事件,该事件将保存Charge 对象,您可以在其中获取有关它的详细信息!

于 2018-03-18T05:59:14.473 回答