【发布时间】:2020-05-16 07:28:02
【问题描述】:
我在 php 中使用条带支付网关。一切正常。但付款成功后不显示交易ID。如何获取交易ID?
if(isset($_POST['stripeToken']))
{
$amount_cents = str_replace(".","","1.00"); // Chargeble amount
$invoiceid = "14526321"; // Invoice ID
$description = "Invoice #" . $invoiceid . " - " . $invoiceid;
try {
$charge = Stripe_Charge::create(array(
"amount" => $amount_cents,
"currency" => "usd",
"source" => $_POST['stripeToken'],
"description" => $description)
);
// Payment has succeeded, no exceptions were thrown or otherwise caught
$result = "success";
} catch(Stripe_CardError $e) {
$error = $e->getMessage();
$result = "declined";
} catch (Stripe_InvalidRequestError $e) {
$result = "declined";
} catch (Stripe_AuthenticationError $e) {
$result = "declined";
} catch (Stripe_ApiConnectionError $e) {
$result = "declined";
} catch (Stripe_Error $e) {
$result = "declined";
} catch (Exception $e) {
}
// Charge the Customer instead of the card
if($result=="success") {
$response = "<div class='col-sm-offset-3 col-sm-9 text-success'>Your Payment has been processed successfully.</div>";
} else{
$response = "<div class='text-danger'>Stripe Payment Status : \".$result.</div>";
}
}
?>
以上代码用于表单提交后。
【问题讨论】:
-
您能澄清一下您期望的交易 ID 吗?你指的是收费的ID吗?基础余额交易? $charge->id 应该是费用的 ID,在这种情况下。
-
还指出
Stripe_Charge方法可以追溯到 1.X 版本的 stripe-php,它在 5 年前已被弃用,您应该真正考虑升级您的系统以使用最新版本的条带-php
标签: stripe-payments payment-gateway