使用authorize.net付款会导致错误由于身份验证值无效,用户身份验证失败

时间:2015-11-17 08:40:47

标签: php authentication authorize.net

我已点击付款链接 https://github.com/AuthorizeNet/sdk-php 但响应"用户身份验证因无效的身份验证值而失败"。 该代码适用于开发人员,但它不适用于开发人员,但不适用于真实帐户。

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;

我们是否需要为真实账户正确设置。

1 个答案:

答案 0 :(得分:4)

我知道,这里的问题是您已设置了实时API凭据,但API环境仍设置为沙箱,

为此你需要改变

的最后一行
$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);

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

这可以解决问题。