Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Payment with authorize.net gives error User authentication failed due to invalid authentication values

I have followed the link for the payment https://github.com/AuthorizeNet/sdk-php but the response "User authentication failed due to invalid authentication values". The code works for developer but it does not work for developer but does not work for the live account.

require 'authorizesdk/vendor/autoload.php'; 
use net\authorize\api\contract\v1 as AnetAPI;
use net\authorize\api\controller as AnetController;

define("AUTHORIZENET_LOG_FILE","phplog");
/** Make sure that the WordPress bootstrap has run before continuing. */
require( dirname(__FILE__) . '/wp-load.php' );
global $wpdb;
 if ( is_user_logged_in() ) {
  $user_ID = get_current_user_id();
}

$creditcardno=$_POST['credit_card_number'];
$expdate=$_POST['year'].'-'.$_POST['month'];
$invoiceno=$_POST['x_invoice_num'];
$description=$_POST['x_description'];
$id=$_POST['x_id'];
$email=$_POST['x_email'];
//$creditcardno='';
//$expdate='16/06';
//$invoiceno=$_POST['x_invoice_num'];
//$description=$_POST['x_description'];
//$id=$_POST['x_id'];
//$email=$_POST['x_email'];


//44Wz7d8Zsr2F5zD6
// Common setup for API credentials  
  $merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
  $merchantAuthentication->setName("5Tb3S44sLp");
  $merchantAuthentication->setTransactionKey("****");
  $refId = 'ref' . time();

// Create the payment data for a credit card
  $creditCard = new AnetAPI\CreditCardType();
  $creditCard->setCardNumber($_POST['credit_card_number']);  
  $creditCard->setExpirationDate( $expdate);
  $paymentOne = new AnetAPI\PaymentType();
  $paymentOne->setCreditCard($creditCard);

    // Order info
  $order = new AnetAPI\OrderType();
  $order->setInvoiceNumber($invoiceno);
  $order->setDescription($description);

  // Customer info 
  $customer = new AnetAPI\CustomerDataType();
  $customer->setId($id);
  $customer->setEmail($mail);

    // Bill To
  $billto = new AnetAPI\CustomerAddressType();
  $billto->setFirstName($_POST['credit_card_fname']);
  $billto->setLastName($_POST['credit_card_lname']);
  $billto->setCompany($_POST['x_company']);
  $billto->setAddress($_POST['x_address']);
  $billto->setCity($_POST['x_city']);
  $billto->setState($_POST['x_state']);
  $billto->setZip($_POST['x_zip']);
  $billto->setCountry($_POST['x_country']);

// Create a transaction
  $transactionRequestType = new AnetAPI\TransactionRequestType();
  $transactionRequestType->setTransactionType("authCaptureTransaction");   
//  $transactionRequestType->setAmount($_POST['x_amount']);
  $transactionRequestType->setAmount($_POST['x_amount']);
  $transactionRequestType->setPayment($paymentOne);
  $transactionRequestType->setOrder($order);
  $transactionRequestType->setCustomer($customer);
  $transactionRequestType->setBillTo($billto);

  $request = new AnetAPI\CreateTransactionRequest();
  $request->setMerchantAuthentication($merchantAuthentication);
  $request->setRefId( $refId);
  $request->setTransactionRequest($transactionRequestType);
  $controller = new AnetController\CreateTransactionController($request);
  $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
echo '<pre>';
var_dump($response);exit;

Is there any thing that we have to setup properly for the live account.

like image 775
Anil Bhattarai100 Avatar asked Nov 29 '25 05:11

Anil Bhattarai100


1 Answers

I see, the problem over here is that you have set the live API Credentials but the The API environment still set to sandbox,

For that you need to change the last 3rd line from

$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);

to

$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::PRODUCTION);

this would solve the problem.

like image 84
KiKMak Avatar answered Dec 01 '25 18:12

KiKMak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!