The Foxy forums are on the move!

We're in the process of moving our forums over to a new system, and so these forums are now read-only.
If you have a question about your store in the meantime, please don't hesitate to reach out to us via email.

Can't seem to fix "Cart Validation Error"


I am using the FoxyShop 4.7.4 plugin for Wordpress, and am building my ByNow button links as follows. I have a Foxycart php class that looks like this:

class FoxyCart

private $apiKey;
private $siteUrl;

public function __construct($apiKey,$siteUrl)
$this->apiKey = $apiKey;
$this->siteUrl = $siteUrl;

* @param $buyButtonParams array price,code,Weight,Category,image,quantity
* @return string
public function generateCartURL($buyButtonParams)

// $atc = ’';
$buyButtonUrl = $this->siteUrl;

$first = true;
foreach($buyButtonParams as $key => $value){
$prefix = $first === true ? '?' : '&';
$buyButtonUrl .= $prefix . $this->getVerification($key, $value, $buyButtonParams['code']. $value) . "=" . urlencode($value);
$first = false;

return $buyButtonUrl;

function getVerification($var_name, $var_value, $var_code, $var_parent_code = "", $for_value = false) {
$encodedVal = htmlspecialchars($var_code . $var_parent_code . $var_name . $var_value);
$label = ($for_value) ? $var_value : $var_name;
return $label . '||' . hash_hmac('sha256', $encodedVal, $this->apiKey) . ($var_value === "--OPEN--" ? "||open" : "");

I build my button link like this:

$buy = new FoxyCart($myApiKey,'https://******'); // **** redacted
$buyLink = $buy->generateCartURL(array(
The link that gets built looks like this:

What I see on the panel created on the RHS of the page is:
a window showing the following messages:

Cart Validation Error: name
Cart Validation Error: code
Cart Validation Error: category
Cart Validation Error: price
The product is a downloadable and I have created a category for it called ebook_echapter_pdf_downloadables under downloadables and uploaded the file to it in my Foxy account. This product shows in the list of available products in the ebook_echapter_pdf_downloadables as having been uploaded on 2019-09-01 23:37:40 and having zero sales so far.

The API Key I am using is the store secret I see on my Advanced Settings page.

Can anyone help me understand what I'm doing wrong?

Many thanks,
  • fc_adamfc_adam FoxyCart Team

    Thanks for including such a detailed summary of what you're doing. I believe the issue you are seeing is caused by how you're passing through the code attribute - it's also including the value with it: $buyButtonParams['code']. $value.

    I think if you update your encoding line to look like this, it should work for you:
    $buyButtonUrl .= $prefix . $this->getVerification($key, $value, $buyButtonParams['code']) . "=" . urlencode($value);
    Just as a quick aside - FoxyShop would take care of encoding any of the product buy buttons for you automatically, removing the need to do it manually. You can enable product signing from the FoxyShop settings page.
  • Perfect. Working now.

    Thank you!
Sign In or Register to comment.