我想使用Authorize.Net
付款,但卡在中间。
没有任何错误消息,
我在authCaptureTransaction
使用SANDBOX,
首先,我创建了带金额的令牌,返回网址。
$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
生成令牌后,我将其添加到表单并发布到
http://test.authorize.net/payment/payment
它重定向到付款,但在成功/取消后,它返回到具有空响应的url。 请参考下面的代码。
//function for generating coupon
function getAnAcceptPaymentPage($amount)
{
/* Create a merchantAuthenticationType object with authentication details
retrieved from the constants file */
$merchantAuthentication = new \net\authorize\api\contract\v1\MerchantAuthenticationType();
$merchantAuthentication->setName(Yii::$app->params['authLoginName']);
$merchantAuthentication->setTransactionKey(Yii::$app->params['authTransId']);
// Set the transaction's refId
$refId = 'ref' . time();
//create a transaction
$transactionRequestType = new \net\authorize\api\contract\v1\TransactionRequestType();//AnetAPI\TransactionRequestType();
$transactionRequestType->setTransactionType("authCaptureTransaction");
$transactionRequestType->setAmount($amount);
// Set Hosted Form options
$setting1 = new \net\authorize\api\contract\v1\SettingType();//AnetAPI\SettingType();
$setting1->setSettingName("hostedPaymentButtonOptions");
$setting1->setSettingValue("{\"text\": \"Pay\"}");
$setting2 = new \net\authorize\api\contract\v1\SettingType();//AnetAPI\SettingType();
$setting2->setSettingName("hostedPaymentOrderOptions");
$setting2->setSettingValue("{\"show\": true}");
$setting3 = new \net\authorize\api\contract\v1\SettingType();//AnetAPI\SettingType();
$setting3->setSettingName("hostedPaymentReturnOptions");
$returnUrlSuccess = helpers\Url::to('site/receipt', TRUE);
$returnUrlCancel = helpers\Url::to('site/cancel', TRUE);
$setting3->setSettingValue("{\"url\": \"".$returnUrlSuccess."\", \"cancelUrl\": \"".$returnUrlCancel."\", \"showReceipt\": true}");
// Build transaction request
$request = new \net\authorize\api\contract\v1\GetHostedPaymentPageRequest();//AnetAPI\Get HostedPaymentPageRequest();
$request->setMerchantAuthentication($merchantAuthentication);
$request->setRefId($refId);
$request->setTransactionRequest($transactionRequestType);
$request->addToHostedPaymentSettings($setting1);
$request->addToHostedPaymentSettings($setting2);
$request->addToHostedPaymentSettings($setting3);
//execute request
$controller = new \net\authorize\api\controller\GetHostedPaymentPageController($request);//AnetController\GetHostedPaymentPageController($request);
$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
if (($response != null) && ($response->getMessages()->getResultCode() == "Ok")) {
echo $response->getToken();
} else {
echo "ERROR : Failed to get hosted payment page token\n";
$errorMessages = $response->getMessages()->getMessage();
echo "RESPONSE : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n";die;
}
return $response;
}
//main function
public function actionPayment()
{
$token = $this->getAnAcceptPaymentPage($pack->package_cost);
$token = $token->getToken(); //Generating token successfully
return $this->render('/package/payform', [
'pack' => $pack, 'token' =>$token, 'userDetails' => $user, 'url'=>$url,
]);
}
//form where i put token
//payform.php
{
<form target="payframe" id="send_hptoken" action="http://test.authorize.net/payment/payment" method="post">
<input type="hidden" name="token" value="<?php echo $token;?>">
<input type="submit" value="Get Accept Hosted page"/>
</form>
}
//return success function
public function actionReceipt()
{
//receiving email of payment received but no response here
//empty response;
//tried $_POST, $_GET, $_REQUEST
print_r($_POST);
die;
}
//return cancel function
public function actionCancel()
{
//empty response;
//tried $_POST, $_GET, $_REQUEST
print_r($_POST);
die;
}
请让我知道我在这里失踪了什么。