druhoytza979667566 2019-03-19 17:21
浏览 68
已采纳

在进行条带api充电后捕获状态

I am looking for the php code syntax to capture if the call was successful or failed to stripe API. I need to capture one of the objects property to determine this but I am not sure what the best approach is. Here's a sample response from a successful ACH api charge. I am looking for the php code syntax to capture if call was successful or failed

Stripe\Charge Object
(
[id] => py_1EFlRJBuwnzOEo57Poikh194
[object] => charge
[amount] => 50
[amount_refunded] => 0
[application] => 
[application_fee] => 
[application_fee_amount] => 
[balance_transaction] => txn_1EFlRJBuwnzOEo57dupt8SWp
[captured] => 1
[created] => 1553015365
[currency] => usd
[customer] => cus_Ec6cAdg6N2yYcF
[description] => 
[destination] => 
[dispute] => 
[failure_code] => 
[failure_message] => 
[fraud_details] => Array
    (
    )

[invoice] => 
[livemode] => 
[metadata] => Stripe\StripeObject Object
    (
    )

[on_behalf_of] => 
[order] => 
[outcome] => Stripe\StripeObject Object
    (
        [network_status] => approved_by_network
        [reason] => 
        [risk_level] => not_assessed
        [seller_message] => Payment complete.
        [type] => authorized
    )

[paid] => 
[payment_intent] => 
[receipt_email] => 
[receipt_number] => 
[receipt_url] => https://pay.stripe.com/receipts/acct_1E8sOiBuwnzOEo57/py_1EFlRJBuwnzOEo57Poikh194/rcpt_EjDtGP7iknHI9RCBJ3iUODNC6bVBVyM
[refunded] => 
[refunds] => Stripe\Collection Object
    (
        [object] => list
        [data] => Array
            (
            )

        [has_more] => 
        [total_count] => 0
        [url] => /v1/charges/py_1EFlRJBuwnzOEo57Poikh194/refunds
    )

[review] => 
[shipping] => 
[source] => Stripe\BankAccount Object
    (
        [id] => ba_1E8sTZBuwnzOEo57MKqXEvb7
        [object] => bank_account
        [account_holder_name] => Rassi Stern
        [account_holder_type] => individual
        [bank_name] => STRIPE TEST BANK
        [country] => US
        [currency] => usd
        [customer] => cus_Ec6cAdg6N2yYcF
        [fingerprint] => 9l7up0pswCYSO7eu
        [last4] => 6789
        [metadata] => Stripe\StripeObject Object
            (
            )

        [routing_number] => 110000000
        [status] => verified
    )

[source_transfer] => 
[statement_descriptor] => 
[status] => pending
[transfer_data] => 
[transfer_group] => 
    )
  • 写回答

2条回答 默认 最新

  • douba9425 2019-03-19 17:38
    关注

    Are you using the Stripe PHP library?

    I implemented something like this:

    try {
        $charge = \Stripe\Charge::create(array(
            "amount" => $amount, // in pence - min 30p
            "currency" => $currency,
            "description" => $description,
            "statement_descriptor" => $statementDescriptor,
            "source" => $token,
            "metadata" => array (
                'code' => $code
            ),
            "receipt_email" => $email
        ));
        $success = true;
    } catch(\Stripe\Error\Card $e) {
        $success = false;
        // Some other stuff to capture the reason for failure and tell the user etc.
    }
    

    If you're not using their library, it's probably worth investigating it: there are a lot of varying reasons why a payment could succeed or fail, so looking through that massive Charge Object for the answer may not 100% yield the results you want.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable