0

I have been trying to generate a Public API key for my USAePay account to use with a USAePay Client JS iFrame using PHP.

The CURL request keeps returning error code 80: Transaction type not allowed from this source.

I have tried with and without a pin and in both test mode using sandbox.usaepay. . . and in regular mode without the sandbox in the URL (changing the SourceKey in the console appropriately).

Is it possible that there is something wrong with my PHP code, or am I missing some other setting?

$seed = "abcdefghijklmnop";
$apikey = "mysourcekeyfromconsole";
$apipin = "1234";
$prehash = $apikey . $seed . $apipin;
$apihash = "s2/" . $seed . "/" . hash("sha256",$prehash);
$authKey = base64_encode($apikey . ':' . $apihash);
//print("Authorization: Basic " . $authKey);

$curl = curl_init();

curl_setopt_array($curl, [
    CURLOPT_URL => "https://sandbox.usaepay.com/api/v2/publickey",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "GET"
]);

curl_setopt($curl, CURLOPT_HTTPHEADER, [
    "Content-Type: application.json",
    "Authorization: Basic " . $authKey
]);

$response = curl_exec($curl);
$error = curl_error($curl);

curl_close($curl);
TemiU
  • 21
  • 2
  • In your USAePay settings, do you have the option to whitelist IP addresses to authorise where the requests come from? If so, is the IP that this script is running on, in that list? – David Nov 27 '19 at 10:31
  • Probably not related, but the `Content-Type` should be `application/json`, not `application.json` – brombeer Nov 27 '19 at 10:44
  • I tried it again without using the sandbox, and this time it worked. I do not know what the difference was, since I did not change anything else, and had tried without the sandbox previously. I wonder if it took time for the API key to update in USAePay? – TemiU Nov 27 '19 at 11:17
  • @TemiU Often the keys are different between the sandbox and live environments, though I've not looked at the documentation for this API, and that wouldn't explain why it didn't work in live originally. – David Nov 27 '19 at 11:56

1 Answers1

0

It seems that this does not work from the sandbox, only from "https://usaepay.com/api/v2/publickey". I don't know why it did not work initially when I tried that, unless I changed some other code or setting. Now, though, when I try to change my code to sandbox, it returns an error, and without sandbox, it returns the public key.

TemiU
  • 21
  • 2