【问题标题】:how to get transaction id in stripe payment gateway如何在条带支付网关中获取交易ID
【发布时间】: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


【解决方案1】:

您将在变量 $charge 中获得 API 响应。注释掉 $result = s"success";write echo($charge);。您将看到响应。在响应中,以'tx_' 开头的'balance_transaction' 值是事务ID。请将其保存到您的数据库中以供进一步使用。

查看条带 API 文档:https://stripe.com/docs/api/charges/object

【讨论】:

    猜你喜欢
    • 2023-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-15
    • 2022-08-19
    • 2013-11-02
    • 2012-06-23
    • 2014-04-02
    相关资源
    最近更新 更多