Skip to content

Instantly share code, notes, and snippets.

@DreadfulCode
Created October 2, 2017 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DreadfulCode/7c5f3f72bd2c6cce4c9f156d8c70d583 to your computer and use it in GitHub Desktop.
Save DreadfulCode/7c5f3f72bd2c6cce4c9f156d8c70d583 to your computer and use it in GitHub Desktop.
Authorize.net signature timestamp
<?php
namespace app\controllers\api;
use app\models\api\campaign\view\AuthorizePostbackRequest;
use yii\helpers\Url;
use app\components\ApiController;
use yii\helpers\Json;
use yii\web\ServerErrorHttpException;
use yii\db\Exception;
use yii\web\UnauthorizedHttpException;
class AuthorizenetController extends ApiController
{
public function actionSignature()
{
$action="https://test.authorize.net/gateway/transact.dll"; //The url of where the Direct Post is going to take place
$x_login=LOGIN_ID; //the Login Id of authorize.net account
$transaction_id=ACCOUNT_NUMBER; //The transaction id of Authorize.net account
$x_relay_url= Url::to(['/postback/authorize-postback'], true); //This return url of the Direct Post postback from Authorize.net-- in PostbackController
$x_amount= $this->request->post('x_amount') ? $this->request->post('x_amount') : 0;
if($x_amount && $x_amount > 0)
{
$x_fp_sequence = rand(1, 1000);
$x_fp_timestamp=time();
$x_fp_hash= hash_hmac("md5", $x_login . "^" . $x_fp_sequence . "^" . $x_fp_timestamp . "^" . $x_amount . "^", $transaction_id);
$response = [
'action'=> $action,
'x_login'=> $x_login,
'x_fp_sequence'=> $x_fp_sequence,
'x_fp_timestamp'=> $x_fp_timestamp,
'x_fp_hash'=> $x_fp_hash,
'x_relay_url'=> $x_relay_url
];
return $response;
}
else
{
throw new ServerErrorHttpException('Card amount must be greater than zero');
}
}
}
@DreadfulCode
Copy link
Author

This is an example of how to create an Authorize.net signature for the Direct Payment Method according to their guide here:
http://developer.authorize.net/api/upgrade_guide/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment