Quantcast
Channel: Square Developer Forums - Latest topics
Viewing all articles
Browse latest Browse all 1326

INVALID_CARD_DATA error when saving card on file from webhook (after successful payment)

$
0
0

Hi team,

I’m encountering an issue while trying to save a card on file via the Cards API after a successful payment.

Here’s the flow:
A customer makes a payment using a Square-hosted payment link (Checkout API).

  • The payment is successful — confirmed via the payment.created webhook.
  • In the webhook handler, I attempt to save the card on file using:
    • payment['id'] as the card token
    • customer_id from the same webhook payload

Here’s the code I use:
$card = new \Square\Models\Card();
$card->setCustomerId($customer_id);

$body = new \Square\Models\CreateCardRequest(
uniqid(), // idempotency key
$payment[‘id’], // payment ID used as token
$card
);
$response = $cardsApi->createCard($body);

The issue:

  • This works fine for most users — card is saved on file successfully.
  • But for one specific client , the same logic throws an INVALID_CARD_DATA error.
  • The payment still goes through successfully for that user.
    Any insights or guidance would be appreciated — thanks in advance! Please try to repond as soon as possible.

6 posts - 3 participants

Read full topic


Viewing all articles
Browse latest Browse all 1326

Trending Articles