php - Authorize.Net 沙箱在 laravel 中不起作用
问题描述
控制器:PaymentController.php
use net\authorize\api\contract\v1 as AnetAPI;
use net\authorize\api\controller as AnetController;
public function check()
{
return view('payment.payment');
}
public function chargeCreditCard(Request $request)
{
// Common setup for API credentials
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
$merchantAuthentication->setName(config('services.authorize.login'));
$merchantAuthentication->setTransactionKey(config('services.authorize.key'));
$refId = 'ref'.time();
// Create the payment data for a credit card
$creditCard = new AnetAPI\CreditCardType();
$creditCard->setCardNumber($request->cnumber);
// $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) && ($tresponse->getResponseCode()=="1"))
{
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";
}
return redirect('/');
}
查看:支付/Payment.blade.php
<div class="flex-center position-ref full-height">
<div class="content">
<h1>Authorize Payment Integration</h1>
<form class="" action="{{ url('/checkout') }}" method="post">
{{ csrf_field() }}
<h3>Credit Card Information</h3>
<div class="form-group">
<label for="cnumber">Card Number</label>
<input type="text" class="form-control" id="cnumber" name="cnumber" placeholder="Enter Card Number">
</div>
<div class="form-group">
<label for="card-expiry-month">Expiration Month</label>
<select name="card_expiry_month" class="form-control" required="required">
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option>
<option value="6">June</option>
<option value="7">July</option>
<option value="8">August</option>
<option value="9">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
</div>
<div class="form-group">
<label for="card-expiry-year">Expiration Year</label>
<select name="card_expiry_year" class="form-control" required="required">
<option value="2019">2019</option>
<option value="2020">2020</option>
<option value="2021">2021</option>
<option value="2022">2022</option>
<option value="2023">2023</option>
<option value="2024">2024</option>
<option value="2025">2025</option>
<option value="2026">2026</option>
<option value="2027">2027</option>
<option value="2028">2028</option>
<option value="2029">2029</option>
</select>
</div>
<div class="form-group">
<label for="ccode">Card Code</label>
<input type="text" class="form-control" id="ccode" name="ccode" placeholder="Enter Card Code">
</div>
<div class="form-group">
<label for="camount">Amount</label>
<input type="text" class="form-control" id="camount" name="camount" placeholder="Enter Amount" >
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
</div>
路由.php
Route::get('/checkout', 'PaymentController@check');
Route::post('/checkout', 'PaymentController@chargeCreditCard');
在这段代码中,我集成了 Authorize.Net 支付网关 API。现在,问题是当我点击提交时,什么也没有发生。如果我没有错,那么问题就出在form action=""
这就是为什么它不去checkout
。那么,我该如何解决这个问题呢?请帮我。
谢谢你
解决方案
推荐阅读
- kubernetes - Cloud Composer 无法连接到 Cloud SQL 代理服务
- swift - 为什么 Swift 编译器将此标记为错误?
- jsf - Wildfly 上的 MyFaces - io.undertow.request 错误:UT005023:对 %s 的异常处理请求
- android - Android Studio 无法运行应用程序
- ruby-on-rails - PG gem 不会安装在 Rails 应用程序中:Gem::Ext::BuildError: ERROR: Failed to build gem native extension
- angular - ngx-toastr 未在第一次单击时显示或 Ui 未使用 google map api 在 angular 5 Digest 周期中更新
- ios - 有没有办法用动画滚动到collectionView中的一个单元格,而不显示其间的所有单元格?
- google-sheets - 删除谷歌表格单元格中所有字符和特殊符号的功能
- azure - 连接到 Azure SQL DW 中的主数据库
- c# - 批量删除操作程序不起作用