# Passing payment ID to card's source ID causing INVALID\_CARD\_DATA

**URL:** <https://developer.squareup.com/forums/t/passing-payment-id-to-cards-source-id-causing-invalid-card-data/8876>\
**Category:** Questions\
**Tags:** payments-api, cards-api\
**Created:** [March 15, 2023, 5:26pm UTC](https://developer.squareup.com/forums/t/passing-payment-id-to-cards-source-id-causing-invalid-card-data/8876 "2023-03-15T17:26:26Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![bman](https://avatars.discourse-cdn.com/v4/letter/b/858c86/32.png) [@bman](https://developer.squareup.com/forums/u/bman)\
**Post date:** [March 15, 2023, 5:26pm UTC](https://developer.squareup.com/forums/t/passing-payment-id-to-cards-source-id-causing-invalid-card-data/8876/1 "2023-03-15T17:26:26Z")

</div>

As of recently I noticed our system for creating reusable card payments through Square is broken. This feature was working fine as of two weeks ago when I last worked with it. My basic square payment flow is as follows:

1. Take the card details on the frontend with web payments sdk, tokenize and send to backend
2. Use card details to place a payment via the payments api
3. Pass this payment id as the source\_id for the cards api alongside the original card details.

As of now I get a 400 error code response with reason being INVALID\_CARD\_DATA, and the field specified being “source\_id”

Does anyone know, has square modified something regarding this. I’ve been trying to find a blog post or anything related specifying this change in behavior? It feels odd that something previously working is no longer functioning. Behavior seems to be replicable in both sandbox and prod

---

<div class="post-metadata">

**Author:** ![Bryan-Square](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/bryan-square/32/38_2.png) [@Bryan-Square](https://developer.squareup.com/forums/u/Bryan-Square)\
**Post date:** [March 15, 2023, 5:49pm UTC](https://developer.squareup.com/forums/t/passing-payment-id-to-cards-source-id-causing-invalid-card-data/8876/2 "2023-03-15T17:49:28Z")

</div>

What’s your application ID and do you have some `payment_ids` that this happened with? 🙂

---

<div class="post-metadata">

**Author:** ![bman](https://avatars.discourse-cdn.com/v4/letter/b/858c86/32.png) [@bman](https://developer.squareup.com/forums/u/bman)\
**Post date:** [March 15, 2023, 5:58pm UTC](https://developer.squareup.com/forums/t/passing-payment-id-to-cards-source-id-causing-invalid-card-data/8876/3 "2023-03-15T17:58:54Z")

</div>

Application ID: sandbox-sq0idb-j6U0SMfEc8kVom5S3A7PZw  
Here’s an example of the body parameter passed to cardsApi.createCard on the server:

```json
{
    "sourceId": "jzhmzGdbbQpyc3ey1vgWqtSErqNZY",
    "card":
    {
        "billingAddress":
        {
            "addressLine1": "643 S Clinton St",
            "addressLine2": "",
            "locality": "Iowa City",
            "administrativeDistrictLevel1": "IA",
            "postalCode": "52240",
            "country": "US"
        },
        "customerId": "AKKCJBVNXAWQJZWTK627MQM04R"
    }
}

```

In this case source\_id would be the payment ID created from the tokenized card.

---

<div class="post-metadata">

**Author:** ![fixitkleb](https://avatars.discourse-cdn.com/v4/letter/f/b38774/32.png) [@fixitkleb](https://developer.squareup.com/forums/u/fixitkleb)\
**Post date:** [March 25, 2023, 4:41am UTC](https://developer.squareup.com/forums/t/passing-payment-id-to-cards-source-id-causing-invalid-card-data/8876/4 "2023-03-25T04:41:54Z")

</div>

I am having this same issue creating a card on file using a payment id as the source\_id for the createCardRequest as shown below(createCardRes-\>isSuccess() is false). For reference, I am using the PHP SDK here.

```
    $card = new \Square\Models\Card();
    $card->setCardholderName($_REQUEST['firstName'].' '.$_REQUEST['lastName']);
    $card->setBillingAddress($billingAddress);
    $card->setCustomerId($customer->getId());
    $card->setReferenceId($_REQUEST['customerId']);

    $createCardReq = new \Square\Models\CreateCardRequest(
        $payment->getId(),
        $payment->getId(),
        $card
    );

    $createCardRes = $client->getCardsApi()->createCard($createCardReq);

    if ($createCardRes->isSuccess()) {
        $card = $createCardRes->getResult();
    }

```

My application id is `sandbox-sq0idb-UGQmnALynusAQq30iGglNg`

My payment id is `bzHwDmwryyJGR1mEPVk9oWjbseHZY`

---

<div class="post-metadata">

**Author:** ![Bryan-Square](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/bryan-square/32/38_2.png) [@Bryan-Square](https://developer.squareup.com/forums/u/Bryan-Square)\
**Post date:** [March 27, 2023, 3:48pm UTC](https://developer.squareup.com/forums/t/passing-payment-id-to-cards-source-id-causing-invalid-card-data/8876/5 "2023-03-27T15:48:18Z")

</div>

If you use the test value `cnon:card-nonce-ok` does it work as expected? I believe this is because the payment was completed with one to the test cards. 🙂

---

<div class="post-metadata">

**Author:** ![bman](https://avatars.discourse-cdn.com/v4/letter/b/858c86/32.png) [@bman](https://developer.squareup.com/forums/u/bman)\
**Post date:** [March 27, 2023, 7:07pm UTC](https://developer.squareup.com/forums/t/passing-payment-id-to-cards-source-id-causing-invalid-card-data/8876/6 "2023-03-27T19:07:52Z")

</div>

Aha, thank you, seems like a silly mistake on my part!  
I was using test card (VISA) 4111 1111 1111 1111, CVV - 111  
I just tried (Mastercard) 5105 1051 0510 5100 CVV - 111 and now saving the customer is working fine!

---

<div class="post-metadata">

**Author:** ![Bryan-Square](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/bryan-square/32/38_2.png) [@Bryan-Square](https://developer.squareup.com/forums/u/Bryan-Square)\
**Post date:** [March 27, 2023, 7:12pm UTC](https://developer.squareup.com/forums/t/passing-payment-id-to-cards-source-id-causing-invalid-card-data/8876/7 "2023-03-27T19:12:40Z")

</div>

Glad to hear its working as expected. 🙂

---

<div class="post-metadata">

**Author:** ![fixitkleb](https://avatars.discourse-cdn.com/v4/letter/f/b38774/32.png) [@fixitkleb](https://developer.squareup.com/forums/u/fixitkleb)\
**Post date:** [March 28, 2023, 4:56am UTC](https://developer.squareup.com/forums/t/passing-payment-id-to-cards-source-id-causing-invalid-card-data/8876/8 "2023-03-28T04:56:10Z")

</div>

Ah, my issue here was the zip code I had saved on file varied from the one I was using in the client-side component 🤦. All is well 🙂

---

<div class="post-metadata">

**Author:** ![Bryan-Square](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/bryan-square/32/38_2.png) [@Bryan-Square](https://developer.squareup.com/forums/u/Bryan-Square)\
**Post date:** [March 28, 2023, 4:33pm UTC](https://developer.squareup.com/forums/t/passing-payment-id-to-cards-source-id-causing-invalid-card-data/8876/9 "2023-03-28T16:33:48Z")

</div>

Glad to hear you figured it out! This has also happened to me so many times. lol 🙂
