[英]authorize.net laravel empty response
I am trying to integrate authorize.net into my laravel shopping cart using the PHP SDK. 我正在尝试使用PHP SDK将authorize.net集成到我的laravel购物车中。 I am only in the sandbox environment currently.
我目前仅在沙盒环境中。 I have it processing the transaction (I can see it in the admin and get the email) but the returned response is all null values.
我让它处理交易(我可以在管理员中看到它并获取电子邮件),但是返回的响应都是空值。
Code is still a little dirty 代码还是有点脏
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use net\authorize\api\contract\v1 as AnetAPI;
use net\authorize\api\controller as AnetController;
class PaymentController extends Controller
{
//
public function authnet_chargeCard()
{
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
$merchantAuthentication->setName(env('AUTHNET_ID'));
$merchantAuthentication->setTransactionKey(env('AUTHNET_KEY'));
$refId = 'ref' . time();
define("AUTHORIZENET_LOG_FILE", "phplog");
// Create the payment data for a credit card
$creditCard = new AnetAPI\CreditCardType();
$creditCard->setCardNumber("4111111111111111");
$creditCard->setExpirationDate("1226");
$creditCard->setCardCode("123");
$paymentOne = new AnetAPI\PaymentType();
$paymentOne->setCreditCard($creditCard);
$order = new AnetAPI\OrderType();
$order->setInvoiceNumber("COW-100");
$order->setDescription("New Item");
//create a transaction
$amount=100;
$transactionRequestType = new AnetAPI\TransactionRequestType();
$transactionRequestType->setTransactionType( "authCaptureTransaction");
$transactionRequestType->setAmount($amount);
$transactionRequestType->setOrder($order);
$transactionRequestType->setPayment($paymentOne);
$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);
//dd($response);
if ($response != null)
{
$tresponse = $response->getTransactionResponse();
if (($tresponse != null) && ($tresponse->getResponseCode()== \SampleCode\Constants::RESPONSE_OK) )
{
echo "Charge Credit Card AUTH CODE : " . $tresponse->getAuthCode() . "\n";
echo "Charge Credit Card TRANS ID : " . $tresponse->getTransId() . "\n";
}
else
{
echo "Charge Credit Card ERROR : Invalid response\n";
}
}
else
{
echo "Charge Credit card Null response returned";
}
}
}
Every time my response looks like: 每当我的回应如下:
CreateTransactionResponse {#352 ▼
-transactionResponse: null
-profileResponse: null
-refId: null
-messages: null
-sessionToken: null
}
I have even tried temporarily setting the $VERIFY_PEER to false 我什至尝试将$ VERIFY_PEER临时设置为false
Not sure where I went wrong... cleaned up the composer file ... updated it and boom good to go. 不知道我哪里出了错...清理了作曲家文件...对其进行了更新,一切顺利。 Sorry to waste virtual space and time with this one.
很抱歉浪费这个虚拟的空间和时间。
public function chargeCreditCard(Request $request)
{
// Common setup for API credentials
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
$merchantAuthentication->setName(env('AUTHNET_ID'));
$merchantAuthentication->setTransactionKey(env('AUTHNET_KEY'));
$refId = 'ref'.time();
// Create the payment data for a credit card
$creditCard = new AnetAPI\CreditCardType();
$creditCard->setCardNumber("4242424242424242");
$creditCard->setExpirationDate( "2038-12");
//$expiry = $request->card_expiry_year . '-' . $request->card_expiry_month;
//$creditCard->setExpirationDate($expiry);
$paymentOne = new AnetAPI\PaymentType();
$paymentOne->setCreditCard($creditCard);
// Create a transaction
$transactionRequestType = new AnetAPI\TransactionRequestType();
$transactionRequestType->setTransactionType("authCaptureTransaction");
$transactionRequestType->setAmount($request->camount);
$transactionRequestType->setPayment($paymentOne);
$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);
if ($response != null)
{
$tresponse = $response->getTransactionResponse();
if ($tresponse != null)
{
if($tresponse->getResponseCode() == 1 || $tresponse->getResponseCode() == 4 ){
if($tresponse->getResponseCode() == 4){
$authCode = "pending";
}else{
$authCode = $tresponse->getAuthCode();
}
$transId = $tresponse->getTransId();
$result = ['authCode' => $authCode, 'transId' => $transId];
$res = $this->transData($result);
if($res){
Session::flash('success', "The order is successfully placed!");
return redirect('/');
}
}else{
$response = $response->getTransactionResponse()->getErrors()[0]->getErrorText();
Session::flash('error', $response);
return redirect('/');
}
}
else
{
echo "Charge Credit Card Null response returned";
}
}
else
{
echo "Charge Credit Card Null response returned";
}
return redirect('/');
}
Try above code, its working for me. 尝试上面的代码,它对我有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.