x

Facing Problem in Create Customer Card API in PHP

Can someone help me out for the issue which I am Facing? When every we call "Create Customer Card" API, where we are declaring card nonce set method in a proper manner. We are getting the error mentioned below. Please help me out to resolve this issue.


The error which I am facing:-

"[HTTP/1.1 404 Not Found] {"errors":[{"category":"INVALID_REQUEST_ERROR","code":"NOT_FOUND","detail":"Resource not found.","field":"card_nonce"}]}"


The code which I implemented:-

$cardNonce = "CBASEHeNj8jtJvjRATnei51PuqQ";
$customerId = "CBASEBtOGbDFSuJmTLYv3tNlFJwgAQ";
//CBESELFVX42cZQW1COtx9eOsZb8
//Configure OAuth2 access token for authorization: oauth2
\SquareConnect\Configuration::getDefaultConfiguration()->setAccessToken [REDACTED];

$api_instance = new \SquareConnect\Api\CustomersApi();
$customer_id = "CBASEBtOGbDFSuJmTLYv3tNlFJwgAQ"; // string | The ID of the customer to link the card on file to.
$body = new \SquareConnect\Model\CreateCustomerCardRequest(); // \SquareConnect\Model\CreateCustomerCardRequest | An object containing the fields to POST for the request. See the corresponding object definition for field details.
$body->setCardNonce($cardNonce);
$body->setCardholderName("Siddharth Raval");

try {
$result = $api_instance->createCustomerCard($customer_id, $body);
//$result = $customersApi->createCustomerCard($customer_id, $body);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling CustomersApi->createCustomerCard: ', $e->getMessage(), PHP_EOL;
}

658 Views
Message 1 of 2
Report
1 REPLY 1
Admin

Hi again @nimapatel.

 

I just checked in with the API team for you. The issue here is you are passing `CBASEHeNj8jtJvjRATnei51PuqQ`  — whereas we (Square) created the nonce with `cnon:` prepended.

 

So the the first line of code should look like this:
```$cardNonce = "cnon:CBASEHeNj8jtJvjRATnei51PuqQ";```

 

I'm also sending you a private message - click the profile icon in the top right of your screen to read it! 

️ Helen
Seller Community Manager

639 Views
Message 2 of 2
Report