7 posts / 0 new
Last post
tigersheepdevel...
Missing or invalid API Key

I am getting the 401 error "Missing or invalid API Key" on LIVE, even though I have checked that I am using the LIVE API Key and Secret, and merchant token from my live merchant account. I am also using the live URL: https://api.payeezy.com/v1/transactions
I am using Payeezy.js and sending tokenized request to Payeezy with PHP after creating token with JavaScript. My code worked fine in sandbox and all I did was switch out the key, secret, merchant and ta token values for the live ones and it stopped working.

Here is my code:

JavaScript

$('#payment-info-form').off('submit').on('submit', function(event) {
$(this).find('button').prop('disabled', true).html(' Processing Payment');
$('.errorInfo').html('');
var apiKey = document.getElementById('apikey').value;
var js_security_key = document.getElementById('js_security_key').value;
var ta_token = document.getElementById('ta_token').value;
Payeezy.setApiKey(apiKey);
Payeezy.setJs_Security_Key(js_security_key);
Payeezy.setTa_token(ta_token);
Payeezy.createToken(responseHandler);
return false;
});
var responseHandler = function(status, response) {
var form = $('#payment-info-form');
if (status !== 201) {
$('#payment-result').html('');
if (status !== 400) {
var error = response['Error']['messages'];
var errormsg = error[0]['description'];
var errorcode = error[0]['code'];
console.log('Error Code: ' + errorcode + ' Error Message: ' + errormsg);
} else {
$('#payment-result').html('');
app.processPayment(response.token);
}
};

This is the token that should be getting sent to the PHP script:

{
"merchant_ref": "GLOBAL ELECTRONIC SERV",
"transaction_type": "purchase",
"method": "token",
"amount": 200,
"currency_code": "USD",
"token": {
"token_type": "FDToken",
"token_data": token
}
}

PHP

<?php
require_once('secret.php');
$checkdata = json_decode($_POST["data"]);
if (is_numeric($checkdata->amount)) {
$serviceURL = 'https://api-cert.payeezy.com/v1/transactions';
$reqbody = $_POST["data"];

list($usec, $sec) = explode(" ", microtime());
$timestamp = round(((float)$usec + (float)$sec) * 1000);
$timestamp = $timestamp - 5000;
$nonce = rand();

$summarize = "";
$summarize .= $apikey;
$summarize .= $nonce;
$summarize .= $timestamp;
$summarize .= $token;
$summarize .= $reqbody;

$hmac = hash_hmac('SHA256', $summarize, $apisecret);

$hmac_enc = base64_encode($hmac);

$curl = curl_init($serviceURL);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $reqbody);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_VERBOSE, true);

$headers = array(
'Content-type: application/json',
'Authorization: ' . $hmac_enc,
'apikey: ' . $apikey,
'token: ' . $token,
'timestamp: ' . $timestamp,
'nonce: ' . $nonce
);

curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
$json_response = curl_exec($curl);

$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);

if ($status != 201) {
die("Error: call to URL $serviceURL failed with status $status, response $json_response, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl));
}

curl_close($curl);

$response = json_decode($json_response, true);
unset($response['token']);

echo json_encode($response);
} else {
echo 'Amount must be an integer';
}
?>


rohitrajagopal3538
Re: Missing or invalid API Key

Hello,

Please check that your API key enabled for Live. You can check this by viewing the API properties and making sure that the "Live" checkbox is checked.

Is it that the tokenization request is succeeding and the PHP payment transaction is failing? Or are both of them failing?

Regards,

Payeezy team

 


tigersheepdevel...
Re: Missing or invalid API Key

The API Key is enabled for Live, I have checked several times.

The tokenization request is failing. It never creates the token to send to the PHP.


rohitrajagopal3538
Re: Missing or invalid API Key

Also, in the PHP code you pasted, you are using the sandbox API URL. Please change it to https://api.payeezy.com/v1/transactions

Regards,

Payeezy team


tigersheepdevel...
Re: Missing or invalid API Key

I have changed my URL in the PHP to https://api.payeezy.com/v1/transactions
The tokenization request is still failing.


tigersheepdevel...
Re: Missing or invalid API Key

I am still having the same error of "missing or invalid API key". I have made sure that the API key, API secret and merchant token I'm using are all from live API and live merchant. I have changed the URL to live URL (https://api.payeezy.com/v1/transactions). I am still not getting a successful token response (tokenization request is still failing with the same error). What do I do next?


tigersheepdevel...
Re: Missing or invalid API Key

I have found the solution. I needed to update the URL in the payeezy_v3.2.js file as well in order to send request to correct URL for the token creation. No errors now. Thank you so much for your help.