0

I am working on a project and implementing stripe. I've got most of it working without any issues but I'm following what the documentation says (or at least I believe I am) but I keep getting an error back from stripe when I attempt to delete a saved card from a customer.

I am using the following code:

$customer = \Stripe\Customer::retrieve($stripeCustomerId);
$customer->sources->retrieve($cardId)->delete();

I got this code from the API documentation at https://stripe.com/docs/api/cards/delete.

The error I am getting back is:

Invalid Stripe request received. Cards cannot be accessed without a customer ID, account ID or recipient ID.

UPDATE

Below is a snippet of the customer response object showing the card id

10/03/2019 20:35:43 -29178-:INFO: D:\wamp64\www\API\classes\AccountManagement.php:1718: Stripe\Customer Object
(
    [id] => cus_EftaJCbcAIUaZW
    [object] => customer
    [account_balance] => 0
    [created] => 1552247956
    [currency] => gbp
    [default_source] => card_1ECYFHHvLpy648dRWUxb184n

And below is the CardId that I am using from the customer object to call customer->sources->retrive(cardId)->delete();

10/03/2019 20:35:43 -29178-:INFO: D:\wamp64\www\API\classes\AccountManagement.php:1719: Got Card ID of 'card_1ECYFHHvLpy648dRWUxb184n'

10/03/2019 20:35:43 -29178-:INFO: D:\wamp64\www\API\classes\AccountManagement.php:1763: Invalid Stripe request received. Cards cannot be accessed without a customer ID, account ID or recipient ID.

8
  • is $stripeCustomerId a valid customer id? and $cardId a valid card? also, what version of stripe's php SDK are you using?
    – duck
    Mar 10, 2019 at 20:16
  • @duck I've updated my question with the snippet of the customer object and the card ID I am using to delete the card. The Card ID from default_source is what I am using which match and it also matches what I see in the stripe dashboard. I'm using 6.30.2 for the PHP Stripe version
    – Boardy
    Mar 10, 2019 at 20:40
  • That's odd, I'm slightly stumped on this, just tried with same PHP SDK version and works about how you expect. $customer = \Stripe\Customer::create(["source"=>"tok_visa"]); echo $customer; $card = $customer->sources->retrieve($customer->default_source); echo $card; echo $card->delete();
    – duck
    Mar 10, 2019 at 21:07
  • Weird, I notice you fetched the card and then did a delete so I thought maybe that's the problem, but no, when I fetch the card, I can print the card object fine but then as soon as I call delete on it I get the error.
    – Boardy
    Mar 10, 2019 at 21:16
  • Weird for sure. It should work either way. Anything unusual in your Stripe error logs? dashboard.stripe.com/test/logs?success=false
    – duck
    Mar 10, 2019 at 21:33

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.