Post by JGAN » Fri Sep 14, 2018 3:05 am

There is an issue with the official Square/iSenseLabs payment extension where customers are unable to checkout if they use a saved credit card or try to save a new credit card AND their square customer ID stored in the squareup_customer DB is not found when calling the Square API. The API will return an error like this:

Code: Select all

Customer with ID "foobar" not found!
And the customer will not be able to checkout as payment won't be processed.

In the Square extension file /catalog/controller/payment/squareup.php, the function checkout() retrieves the customer's Square ID from the squareup_customer DB here:

Code: Select all

$square_customer = $this->imodule_model_credit_card->getCustomer($this->customer->getId());
Then in the same function, if the customer is logged in and has chosen to use a saved credit card or save a new credit card, it will then call the Square API to add a new credit card under the customer's Square ID as found in the squareup_customer DB:

Code: Select all

$square_card = $this->squareup_api->addCard($square_customer['square_customer_id'], $card_data);
The API file with all the API call functions is /library/api.php. The addCard() function will attempt to add the credit card to the Square endpoint and return the Square card ID. It sends the Square customer ID and card nonce stored in the squareup_customer and squareup_token DB respectively to the API, however, if the Square customer ID does not match the customer ID stored on Square's end, it will return an error instead of the card ID.

The api.php file contains a function API(), which is used to actually handle all the CURL executions. However, it is setup so that if the Square API returns an error, it will throw an exception and break:

Code: Select all

if (!empty($return['errors'])) {
                throw new Exception\Api($this->registry, $return['errors']);
} else {
                return $return;
This means that if the Square API is unable to find the customer ID stored in squareup_customer, instead of processing the payment it will throw an exception and prevent the customer from checking out.

The workaround right now is to delete the row in squareup_customer (via the browser or CLI) containing the incorrect customer ID and let the API recreate the customer on its own. However, to do this as part of the extension would probably require rewriting the way the api() function handles errors returned from the API.

Alternatively, an API call to the Square RetrieveCustomer endpoint could be implemented so that before calling addCard(), the controller will check to see if the customer exists on Square's end, and if not, delete the customer in the squareup_customer DB before proceeding to call addCard().

Any further insight on implementing a fix is appreciated, thanks!

New member


Wed Jan 13, 2016 7:52 pm

Post by straightlight » Fri Sep 14, 2018 6:03 am

No OC version posted with inquiry.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.

Straightlight Administrator / Quality Assurance Analyst / Programmer / Opencart Tester

Legendary Member


Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: No registered users and 11 guests