其他分享
首页 > 其他分享> > 条纹创建退款不起作用

条纹创建退款不起作用

作者:互联网

我正在尝试退还使用Stripe API创建的费用.但是,当我使用$charge-> refunds-> create()函数时,出现以下错误:

Call to a member function create() on a non-object

这是我用来退还费用的代码:

    public function return_deposit($mysqli){
        if ($mysqli === null) throw new Exception('Could not connect to database.');
        if ($this->status !== 0) throw new Exception('This deposit has already been processed!');

        Stripe::setApiKey(STRIPE_HIDDEN_KEY);

        $deposit = Stripe_Charge::retrieve($this->stripe_charge_id);
        var_dump($deposit);
        $refund = $deposit->refunds->create();

        $stmt = $mysqli->prepare('UPDATE `deposits` SET `stripe_refund_id`=?, `return_time`=CURRENT_TIMESTAMP, `status`=' . DEPOSIT_RETURNED . ' WHERE `did`=?');
        if (!$stmt) throw new Exception('Could not connect to database.');

        $stmt->bind_param('si', $refund->id, $this->did);
        if (!$stmt->execute()) throw new Exception('Could not connect to database.');
    }

如您所见,在收到与押金相关的费用后,我将进行一次手续.这是vardump的输出:

object(Stripe_Charge)#4 (5) { ["_apiKey":protected]=> string(32) "sk_live_*******************" ["_values":protected]=> array(22) { ["id"]=> string(27) "ch_**********************" ["object"]=> string(6) "charge" ["created"]=> int(1410545511) ["livemode"]=> bool(true) ["paid"]=> bool(true) ["amount"]=> int(100) ["currency"]=> string(3) "usd" ["refunded"]=> bool(false) ["card"]=> object(Stripe_Card)#13 (5) { ["_apiKey":protected]=> string(32) "sk_live_*******************" ["_values":protected]=> array(21) { ["id"]=> string(29) "card_*******************" ["object"]=> string(4) "card" ["last4"]=> string(4) "9008" ["brand"]=> string(10) "MasterCard" ["funding"]=> string(5) "debit" ["exp_month"]=> int(8) ["exp_year"]=> int(2018) ["fingerprint"]=> string(16) "****************" ["country"]=> string(2) "US" ["name"]=> NULL ["address_line1"]=> NULL ["address_line2"]=> NULL ["address_city"]=> NULL ["address_state"]=> NULL ["address_zip"]=> NULL ["address_country"]=> NULL ["cvc_check"]=> NULL ["address_line1_check"]=> NULL ["address_zip_check"]=> NULL ["customer"]=> string(18) "cus_************" ["type"]=> string(10) "MasterCard" } ["_unsavedValues":protected]=> object(Stripe_Util_Set)#14 (1) { ["_elts":"Stripe_Util_Set":private]=> array(0) { } } ["_transientValues":protected]=> object(Stripe_Util_Set)#15 (1) { ["_elts":"Stripe_Util_Set":private]=> array(0) { } } ["_retrieveOptions":protected]=> array(0) { } } ["captured"]=> bool(true) ["refunds"]=> array(0) { } ["balance_transaction"]=> string(28) "txn_*************************" ["failure_message"]=> NULL ["failure_code"]=> NULL ["amount_refunded"]=> int(0) ["customer"]=> string(18) "cus_************" ["invoice"]=> NULL ["description"]=> string(38) "******: Deposit for "Test This" for $1" ["dispute"]=> NULL ["metadata"]=> object(Stripe_AttachedObject)#16 (5) { ["_apiKey":protected]=> string(32) "sk_live_*********************" ["_values":protected]=> array(1) { ["bid"]=> string(2) "70" } ["_unsavedValues":protected]=> object(Stripe_Util_Set)#17 (1) { ["_elts":"Stripe_Util_Set":private]=> array(0) { } } ["_transientValues":protected]=> object(Stripe_Util_Set)#18 (1) { ["_elts":"Stripe_Util_Set":private]=> array(0) { } } ["_retrieveOptions":protected]=> array(0) { } } ["statement_description"]=> NULL ["receipt_email"]=> NULL } ["_unsavedValues":protected]=> object(Stripe_Util_Set)#10 (1) { ["_elts":"Stripe_Util_Set":private]=> array(0) { } } ["_transientValues":protected]=> object(Stripe_Util_Set)#11 (1) { ["_elts":"Stripe_Util_Set":private]=> array(0) { } } ["_retrieveOptions":protected]=> array(0) { } }

当我使用echo json_encode($deposit)时,它打印了{}.我不明白,如果var_dump输出上述信息,那会是为什么,但是这对于为什么不起作用可能很重要.

解决方法:

刚发现我使用的是Stripe的旧版本,该版本通过$charge-> refund()函数而不是较新的$charge-> refunds-> create()函数创建退款.

标签:stripe-payments,mysql,php
来源: https://codeday.me/bug/20191029/1957837.html