条纹创建退款不起作用

时间:2014-09-12 18:32:39

标签: php mysql stripe-payments

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

  

在非对象

上调用成员函数create()

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

    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。这就是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输出上述信息,但这可能是重要的,为什么这不起作用。

1 个答案:

答案 0 :(得分:4)

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