3

I'm trying to refund a charge created with the Stripe API. However, when I use the $charge->refunds->create() function, I get the following error:

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

This is the code that I use to refund the charge:

    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.');
    }

As you can see, I perform a vardump after I get the charge associated with the deposit. This is what the vardump outputs:

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) { } }

When I used echo json_encode($deposit), it printed {}. I don't understand why that would be if var_dump outputs the above info, but that might be significant in why this isn't working.

sepehr
  • 17,110
  • 7
  • 81
  • 119
terpak
  • 1,131
  • 3
  • 17
  • 35
  • I also checked to make sure that the charge ID in the var dump matched the charge ID in the Stripe dashboard exactly. – terpak Sep 12 '14 at 18:33

1 Answers1

4

Just figured out that I'm using an older version of Stripe that creates refunds via the $charge->refund() function rather than the newer $charge->refunds->create() function.

terpak
  • 1,131
  • 3
  • 17
  • 35