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条)

报告相同问题?

悬赏问题

  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?