An error occurred: 40030: Customer Not Found, using UsaEpay soap API

Hi,
I am attempting to implement the “convertPaymentMethodToToken” method from USAePay soap api documentations. For the function to work, it is required to fetch the customer number from the UsaEpay acct, and it generates a Method ID through a “getCustomer” request, that will be used for the conversion. However, the implementation works only for a single customer and fails when I try to process multiple customers at once. The error message I receive is: “An error occurred while fetching details of customer ‘customer1’: 40030: Customer Not Found…”. I have a large customer database of over 20,000 customers, and my goal is to convert each of their payment methods to tokens efficiently, without having to perform individual conversions for each customer. The USAePay documentation only provides information on how to implement the feature for a single customer.

here is my code by getting Method ID for a single customer (and it is working fine)

<?php 


$wsdl = "https://secure.usaepay.com/soap/gate/INBGTWZC/usaepay.wsdl";
$sourceKey = "your soruce key";
$pin = "1234";

function getClient($wsdl) {
  return new SoapClient($wsdl, array(
    'trace' => 1,
    'exceptions' => 1,
    'stream_context' => stream_context_create(
      array(
        'ssl' => array(
          'verify_peer' => false,
          'verify_peer_name' => false,
          'allow_self_signed' => true
        )
      )
    )
  ));
}

function getToken($sourceKey, $pin) {
  $seed = time() . rand();

  return array(
    'SourceKey' => $sourceKey,
    'PinHash' => array(
      'Type' => 'sha1',
      'Seed' => $seed,
      'HashValue' => sha1($sourceKey . $seed . $pin)
    ),
    'ClientIP' => $_SERVER['REMOTE_ADDR']
  );
}

$client = getClient($wsdl);
$token = getToken($sourceKey, $pin);

try {
    $custnum='customer number';
    print_r($client->getCustomer($token,$custnum));
  } catch (Exception $e) {
    // Code to handle the exception
    echo "An error occurred: " . $e->getMessage();
  }
    
  
?>

here is the successful response (with Method ID included)

and here is the code I’m trying to do the same thing but with multiple customers (without having to enter the customer numbers manually)

<?php 

$wsdl = "https://sandbox.usaepay.com/soap/gate/43R1QPKU/usaepay.wsdl";
$sourceKey = "your api key";
$pin = "1234";

function getClient($wsdl) {
  return new SoapClient($wsdl, array(
    'trace' => 1,
    'exceptions' => 1,
    'stream_context' => stream_context_create(
      array(
        'ssl' => array(
          'verify_peer' => false,
          'verify_peer_name' => false,
          'allow_self_signed' => true
        )
      )
    )
  ));
}

function getToken($sourceKey, $pin) {
  $seed = time() . rand();

  return array(
    'SourceKey' => $sourceKey,
    'PinHash' => array(
      'Type' => 'sha1',
      'Seed' => $seed,
      'HashValue' => sha1($sourceKey . $seed . $pin)
    ),
    'ClientIP' => $_SERVER['REMOTE_ADDR']
  );
}

$client = getClient($wsdl);
$token = getToken($sourceKey, $pin);

$custnums = array();
for ($i = 1; $i <= 3; $i++) {
    $custnums[] = 'customer' . $i;
}

$methodIDs = array();
foreach ($custnums as $custnum) {
  try {
    $result = $client->getCustomer($token, $custnum);
    $methodID = $result[0]->MethodID;
    $methodIDs[] = $methodID;
    error_log("Method ID for customer $custnum: $methodID");
  } catch (Exception $e) {
    echo " An error occurred: " . $e->getMessage();
  }
}

?>

but getting the above error message,

I’ve already been working on it all day,

Can anyone help me with this?
please let me know if you need more info

Thanks in advance

Are customer1, customer2 and customer3 valid customer numbers in the api service? In the single request example it’s written customer number, might there just be a space missing?

Sponsor our Newsletter | Privacy Policy | Terms of Service