x

createCustomerCard: Customer with ID not found

I'm using PHP and Sandbox credentials. I can charge a card ( but with no customer info ) and create a new customer. Although, when I try to add a card to a customer, I get this :
 
Exception when calling customersApi->createCustomerCard: [HTTP/1.1 404 Not Found] {"errors":[{"category":"INVALID_REQUEST_ERROR","code":"NOT_FOUND","detail":"Customer with ID `The-Customers-Id` not found."}]}

 Can anyone point me tords a solution or an example of adding a card to a customer in PHP?
 

I have a newly created nonce for this transaction, the postal code used on the customer, the square customer id created on a previous transaction. Still get this error. Checked everything bazillion times, what am I overlooking?


 

5,122 Views
Message 1 of 20
Report
19 REPLIES 19
Admin

Hi @LocalAK! The only way to see customers through the API is if the customer is added through the API with the customer_id (https://docs.connect.squareup.com/api/connect/v2#endpoint-charge) parameter enabled.

 

Before you can attach a customer_id to a transaction, you’ll need to use the CreateCustomer (https://docs.connect.squareup.com/api/connect/v2#endpoint-createcustomer) endpoint to generate a customer_id.

 

Sorry for the frustration this caused! If you have any other questions, please let us know.

️ Helen
Seller Community Manager

Did you find help in the Seller Community? Mark a Best Answer to help others.
5,071 Views
Message 2 of 20
Report

I'm not sure what happened to my last post, it was here for a few minutes. Then gone.

Thank you for your time @Helen,

I am able to create a customer id with CreateCustomer.

* I am unable to add a card to the customer with createCustomerCard ( original see post ), I'm following the information on this page : https://docs.connect.squareup.com/api/connect/v2#endpoint-createcustomercard

This is the full debug output :

( I CHANGED THE NONCE, CUSTOMER ID AND OTHER "SENSITIVE" INFORMATION.  )


[DEBUG] HTTP Request body ~BEGIN~ {"card_nonce":"CBASEEheG_zYgedwCckfcogAQ","billing_address":{"postalCode":"99710"}} ~END~ [DEBUG] HTTP Response body ~BEGIN~ {"errors":[{"category":"INVALID_REQUEST_ERROR","code":"NOT_FOUND","detail":"Customer with ID `P1E9NGSCEVSEPBSCWNK4` not found."}]} ~END~ * Trying 74.122.190.85... * Connected to connect.squareup.com (74.122.190.85) port 443 (#0) * ALPN, offering http/1.1 * Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH * successfully set certificate verify locations: * CAfile: /etc/ssl/certs/ca-certificates.crt CApath: /etc/ssl/certs * SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256 * ALPN, server did not agree to a protocol * Server certificate: * subject: C=US; ST=California; L=San Francisco; O=Square, Inc.; CN=*.squareup.com * start date: Nov 18 22:01:28 2017 GMT * expire date: Dec 15 22:31:28 2018 GMT * subjectAltName: connect.squareup.com matched * issuer: C=US; O=Entrust, Inc.; OU=See www.entrust.net/legal-terms; OU=(c) 2012 Entrust, Inc. - for authorized use only; CN=Entrust Certification Authority - L1K * SSL certificate verify ok.> POST /v2/customers/P1E9NGSCEVSEPBSCWNK4/cards HTTP/1.1 Host: connect.squareup.com User-Agent: Square-Connect-PHP/2.5.1 Accept: application/json Content-Type: application/json Authorization: Bearer sandbox-sq0atb-aUgdfsrFgQ_s-bfgDASF1 Content-Length: 88 * upload completely sent off: 88 out of 88 bytes< HTTP/1.1 404 Not Found< Content-Type: application/json< Vary: Origin, Accept-Encoding< X-Content-Type-Options: nosniff< X-Download-Options: noopen< X-Frame-Options: SAMEORIGIN< X-Permitted-Cross-Domain-Policies: none< X-Xss-Protection: 1; mode=block< Date: Fri, 06 Apr 2018 01:15:24 GMT< keep-alive: timeout=60< Strict-Transport-Security: max-age=631152000< content-length: 136< * Connection #0 to host connect.squareup.com left intact
CustomerId : P1E9NGSCEVSEPBSCWNK4
 


Exception when calling $CustomersApi->createCustomerCard: [HTTP/1.1 404 Not Found] {"errors":[{"category":"INVALID_REQUEST_ERROR","code":"NOT_FOUND","detail":"Customer with ID `P1E9NGSCEVSEPBSCWNK4` not found."}]}


 

*  The Customer Id was created on the preveous page by the user and saved to a local database and used to add a card to "this" customer.

Do you have another idea?

5,032 Views
Message 3 of 20
Report

Thank you @Helen for your time.

I've posted two responces and they are deleted when I get back, so I am just "testing" with this message.

5,049 Views
Message 4 of 20
Report

I am able to create a customer id with CreateCustomer.
 
 * I am unable to add a card to the customer with createCustomerCard ( original see post ), I'm following the information on this page : https://docs.connect.squareup.com/api/connect/v2#endpoint-createcustomercard

5,048 Views
Message 5 of 20
Report

Your solution was to another problem.

Do you have any additional advice on my question or where I could find a working example of how to add a Card Nonce to a Customer ID in PHP?

The Square API docs and Github examples do not have an example of how to add a card to a customer in PHP.
The url other laguages use for square just gives me a 404 ( explained everything in this tread ).
 
Thanks again @Helen

4,962 Views
Message 6 of 20
Report

[DEBUG] HTTP Request body ~BEGIN~ {"card_nonce":"VALID NONCE","billing_address":{"postalCode":"VALID POSTAL CODE"}} ~END~ [DEBUG] HTTP Response body ~BEGIN~ {"errors":[{"category":"INVALID_REQUEST_ERROR","code":"NOT_FOUND","detail":"Customer with ID `CUSTOMER ID FROM SQUARE` not found."}]} ~END~ * Trying AN IP ADDRESS... * Connected to connect.squareup.com (AN IP ADDRESS) port 443 (#0) * ALPN, offering http/1.1 * Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH * successfully set certificate verify locations: * CAfile: /etc/ssl/certs/ca-certificates.crt CApath: /etc/ssl/certs * SSL connection using TLSv1.2 / SSL CONNECT CERTIFICATE * ALPN, server did not agree to a protocol * Server certificate: * subject: C=US; ST=California; L=San Francisco; O=Square, Inc.; CN=*.squareup.com * start date: Nov 18 22:01:28 2017 GMT * expire date: Dec 15 22:31:28 2018 GMT * subjectAltName: connect.squareup.com matched * issuer: C=US; O=Entrust, Inc.; OU=See www.entrust.net/legal-terms; OU=(c) 2012 Entrust, Inc. - for authorized use only; CN=Entrust Certification Authority - L1K * SSL certificate verify ok.> POST /v2/customers/CUSTOMER ID FROM SQUARE/cards HTTP/1.1 Host: connect.squareup.com User-Agent: Square-Connect-PHP/2.5.1 Accept: application/json Content-Type: application/json Authorization: Bearer sandbox Content-Length: 88 * upload completely sent off: 88 out of 88 bytes< HTTP/1.1 404 Not Found< Content-Type: application/json< Vary: Origin, Accept-Encoding< X-Content-Type-Options: nosniff< X-Download-Options: noopen< X-Frame-Options: SAMEORIGIN< X-Permitted-Cross-Domain-Policies: none< X-Xss-Protection: 1; mode=block< Date: Fri, 06 Apr 2018 01:15:24 GMT< keep-alive: timeout=60< Strict-Transport-Security: max-age=631152000< content-length: 136< * Connection #0 to host connect.squareup.com left intact  


Exception when calling $CustomersApi->createCustomerCard: [HTTP/1.1 404 Not Found] {"errors":[{"category":"INVALID_REQUEST_ERROR","code":"NOT_FOUND","detail":"Customer with ID `CUSTOMER ID FROM SQUARE` not found."}]}


 

*  The Customer Id was created on the preveous page by the user and saved to a local database and used to add a card to "this" customer.

Do you have any more ideas?

4,988 Views
Message 7 of 20
Report
Admin

Hi again! I'm sorry, it looks like a few of your posts were marked as spam. I've unmarked them and tidied up this thread but if anything is missing let me know!

 

What you're seeing may be caused by the delay that occurs when creating a customer with the CreateCustomer endpoint. On average, the delay is about .4 seconds. Please wait a second before using the CreateCutomerCard endpoint. 

️ Helen
Seller Community Manager

Did you find help in the Seller Community? Mark a Best Answer to help others.
4,965 Views
Message 8 of 20
Report

@Helen,

I have my visitors create a customer id with square, then I have them chose account type, billing type (single payment or reoccurring) before they are asked to provide card information. They are assigned a Square customer ID "long" before I attempt to add the card nonce to the customer id. 

Then I get the output I have posted here before.

Any ideas?
 

 

Thanks for your time on fixing my "spam". I was VERY confusing and didn't want to post duplicate information.

But I was unaware you knew something was wrong.
 

Thanks again

4,959 Views
Message 9 of 20
Report

Hello again everyone!

Update : I've been doing lots of research and I'm not able to find how to add a card to a customer with Square & PHP.

To further explain what I'm trying to do, this link shows how to do my objective manually from within the Dashboard :

https://www.sellercommunity.com/t5/Professional-Services-Group/Invoices-Update-Recurring-Invoices-am...

 

I don't think the correct customer ID is being sent to PHP via the API and I can't find a way to confirm a customer ID.

When I add a card nonce to a customer, I get the same 404 I stated in my first post.

Any ideas?

@Helen?

4,646 Views
Message 10 of 20
Report
Admin

Hey @LocalAK, sorry for the delay—I'm stepping in for Helen today.

 

I had the chance to run this by our API Team and they've suggested the following: it sounds like you may be calling the CreateCustomer endpoint with your production API credentials; however, when you call the CreateCustomerCard endpoint, you're using your sandbox credentials. You'll need to be sure that you're using the same credentials for both endpoints (whether it be in sandbox or production).

 

Hope this helps get you in the right direction—please let us know if anything else comes up.

️ Tom | he/him
Seller Community Manager | Square, Inc.
Find step-by-step help in our Support Center
4,644 Views
Message 11 of 20
Report

Thanks @Tom,
 
 I felt hopeful while I replaced the access token with my sandbox token.
 
But, I get a 404 on create customer card.

CustomersApi->createCustomerCard: [HTTP/1.1 404 Not Found] {"errors":[{"category":"INVALID_REQUEST_ERROR","code":"NOT_FOUND","detail":"Customer with ID `CBASEHQSDFSFFxCrEgAQ` not found."}]}

This is with sandbox createing the customer id and sandbox trying to create customers card.

Any thoughts?

Thanks again for your time Tom.

4,649 Views
Message 12 of 20
Report

Hey @LocalAK! I'm stepping in for @Tom. This is really turning into a team effort now. 😂

 

It looks like you're missing an underscore for the customer_id. Try using CBASEHQtwK_ZknPv5OgAd6MxCrEgAQ instead of CBASEHQtwKZknPv5OgAd6MxCrEgAQ to use the CreateCustomerCard endpoint with no errors! 

 

Let me know how it goes! 

4,632 Views
Message 13 of 20
Report

Hey Chad,

I changed the customer id.

I am able to get a customer id from the Square API and PHP saves it for the customer and they have an option to setup reoccurring payment. When my server tries to add a card to the customer, I get a 404 error.
I'm using the Sandbox access token when creating the customer id ( with no issues and I can make a charge to it).

But, When I try  ( also using sandbox ) :

<?php

// Code removed for forum

$defaultApiConfig = new \SquareConnect\Configuration();
$defaultApiConfig->setAccessToken($access_token);

$defaultApiClient = new \SquareConnect\ApiClient($defaultApiConfig);
$CustomersApi = new SquareConnect\Api\CustomersApi($defaultApiClient);

try {
 $result = $CustomersApi->createCustomerCard(
  $customer_id,
  array(
   "card_nonce"=>$nonce,
   "billing_address"=>array(
    'postalCode' => $postal_code
    )
   )
  );
 $customer_card = $result->getCard();

}catch(Exception $e){
echo "Customer Id : $customer_id<br>";
  echo "Exception when calling CustomersApi->createCustomerCard: ', $e->getMessage(), PHP_EOL;
}
?>

 

 
I get this error when running above code.

( Please Note : Customer ID was changed for the forum )

 CustomersApi->createCustomerCard: [HTTP/1.1 404 Not Found] {"errors":[{"category":"INVALID_REQUEST_ERROR","code":"NOT_FOUND","detail":"Customer with ID `CBASEHQSDFSFFxCrEgAQ` not found."}]}  

There are no example of adding a card to a customer id in PHP and this page might help someone else using the language on the page:
https://docs.connect.squareup.com/articles/processing-recurring-payments-ruby?q=add%20card

But it does not help php developers and I dislike shooting in the dark.

I've been working on this issue every day for about two weeks.

Can you offer a url with an example in PHP to add a card to a customer?
Is the above code correct?

4,621 Views
Message 14 of 20
Report
Admin

Hey @LocalAK, sorry for the delayed response. Chad and I checked in with our API Team and they took another look. As far as they can tell, it appears that you're not including the underscore "_". You should be able to see the customer by including the underscore "_". Hope this clears things up!

️ Tom | he/him
Seller Community Manager | Square, Inc.
Find step-by-step help in our Support Center
4,599 Views
Message 15 of 20
Report

[SOLVED]... then not solved.

Hey Tom,

Thanks for your patience.

So, if the customer id needs an underscore. That was part of the problem.

I had this for the customer id :

$customerId = preg_replace('/[^\w]/', '', $squareOutput);

 

 

With "\w", I was thinking it was leaving the underscores alone.

 

I was missing a "-" after "w" in preg_replace. The line should have read : 

$customerId = preg_replace('/[^\w-]/', '', $squareOutput); 

 

 

With that changed. IT WORKED! Once.
Square does not give underscores every time and errors when it doesn't.


When this solution was pointed out, I thought it was because of my edits for this forum.  Special thanks @Chad
 
Many Thanks To @Tom, @Chad@Helen, thanks Team!

Thanks @Square!

I'll be processing cards after....


 

4,583 Views
Message 16 of 20
Report

False Hope.

After the problem was "fixed", an hour or so later I noticed the underscores are not always provided by square. Hyphens and underscores are random in customer ids.

 

Some customer id's don't have any at all. I was happy this problem was solved, but it wasn't. Is this normal?
  
What am I doing wrong?

 

I now getting these two errors randomly :

Exception when calling CustomersApi->createCustomerCard: [HTTP/1.1 301 Moved Permanently]

 

AND

 

Exception when calling CustomersApi->createCustomerCard: [HTTP/1.1 400 Bad Request] {"errors":[{"category":"INVALID_REQUEST_ERROR","code":"BAD_REQUEST","detail":"The postal code in billing address doesn't match the one used for card nonce creation."}]}

 

I have deleted the customer id and started over many times, with the same customer info every time. Same two errors randomly.

 

Is there a way to check sandbox customer info @Tom?

It says my postal code does not match, but I typed them the same many times.
Any thoughts?

4,572 Views
Message 17 of 20
Report

Oh no @LocalAK!

 

I'm sorry to hear about the trouble I'm kind of at my whits end for this issue. I recommend reaching out to our API Support Team, they will be able to take a closer look into this. We can only help so much on the Seller Community since we don't have access to your account. 

4,544 Views
Message 18 of 20
Report

Thanks @Chad, I'll do that.

4,542 Views
Message 19 of 20
Report

New Info :
 
 The customer shows in the Dashboard. But no reference to a customer id.
 
 So, I don't know what else to do but conclude that the createCustomer api is not giving me the correct customer id. The given customer does not match a customer?
  
  
  ** How can I verify a customer id in the Dashboard?

5,004 Views
Message 20 of 20
Report