How do you use SBI Veritrans payment online with php

PHP TECHNOLOGY

Posted on 2014-12-04 08:31:10


Understand about Veritrans Veritrans is unit of Japanese which supply all apis for payment bills online with card visit example: VISA CARD, MASTER CARD… 

 I will guide guys how to use SBI Veritrans API with PHP. Code javascript request require payment to server

function check_payment() {
$(".form_waku").hide();
$("#tb_ssl").hide();
var data = '';
data += 'cardNumber=4111-1111-1111-1111';
data += '&cardExpire=12/13';
data += '&amount=987654321';
data += '&securityCode=1234';
data += '&withCapture=0';
data += '&orderId=sdbcard<?php echo time() ?>';
data += '&jpo1=10';
$.ajax({
type: "POST",
data: data,
url: "/frontpages/AuthorizeExec",
success: function(data) {
if (data == 'success') {
return true;
}
else {
alert("カード情報が不正です。再度チェックしてください。");
return false;
}
}
});
}

With behind code which has some information about card, cost money… is pushed to server.

Function /frontpages/AuthorizeExcec will process transaction on server. 

If data return success which is success transaction.

function AuthorizeExec() {
		define('MDK_DIR', WWW_ROOT . 'tgMdk' . DS);
		define('INPUT_PAGE', 'Authorize.php');
		define('TXN_FAILURE_CODE', 'failure');
		define('TXN_PENDING_CODE', 'pending');
		define('TXN_SUCCESS_CODE', 'success');
		define('TRUE_FLAG_CODE', 'true');
		define('FALSE_FLAG_CODE', 'false');
		define('ERROR_PAGE_TITLE', 'System Error');
		define('NORMAL_PAGE_TITLE', '取引結果');
		require_once(MDK_DIR."3GPSMDK.php");
 
		/* ********************* */
		/* 携帯用TRAD処理        */
		/* ********************* */
		//include_once("../trad/trad.php");
 
 
		/**
		* 取引ID
		*/
		$order_id = htmlspecialchars(@$_POST["orderId"]);
 
		/**
		* 支払金額
		*/
		$payment_amount = htmlspecialchars(@$_POST["amount"]);
 
		/**
		* 与信方法
		*/
		$is_with_capture = htmlspecialchars(@$_POST["withCapture"]);
		if ("1" == $is_with_capture) {
		$is_with_capture = TRUE_FLAG_CODE;
		} else {
		$is_with_capture = FALSE_FLAG_CODE;
		}
		/**
		* カード番号
		*/
		$card_number = htmlspecialchars(@$_POST["cardNumber"]);
 
		/**
		* カード有効期限 MM/YY
		*/
		$card_expire = htmlspecialchars(@$_POST["cardExpire"]);
 
		/**
		* 支払オプション
		*/
		$jpo1 = htmlspecialchars(@$_POST["jpo1"]);
		$jpo2 = htmlspecialchars(@$_POST["jpo2"]);
 
		if ((!empty($jpo1)) && (("10" == $jpo1)|| ("80" == $jpo1))) {
		$jpo = $jpo1;
		}else if ((!empty($jpo1) && ("61" == $jpo1)) && (!empty($jpo2))) {
		$jpo = $jpo1."C".$jpo2;
		}
 
		/**
		* セキュリティコード
		*/
		$security_code = htmlspecialchars(@$_POST["securityCode"]);
 
		/**
		* 必須パラメータ値チェック
		*/
		//サーバ内部指定
 
		/**
		* 要求電文パラメータ値の指定
		*/
		$request_data = new CardAuthorizeRequestDto();
 
		$request_data->setOrderId($order_id);
		$request_data->setAmount($payment_amount);
		$request_data->setCardNumber($card_number);
		$request_data->setCardExpire($card_expire);
		$request_data->setWithCapture($is_with_capture);
		if (isset($jpo)) {
		$request_data->setJpo($jpo);
		}
		if (isset($security_code)) {
		$request_data->setSecurityCode($security_code);
		}
 
 
		/* ******************** */
		/* 携帯版 TRAD対応      */
		/* ******************** */
		//$trad_data = new TradRequestDto();
		//$trad_data->setScaleCode("902");
		//$request_data->setOptionParams(array($trad_data));
 
 
		/**
		* 実施
		*/
		$transaction = new TGMDK_Transaction();
		$response_data = $transaction->execute($request_data);
 
		//予期しない例外
		if (!isset($response_data)) {
		$page_title = ERROR_PAGE_TITLE;
		//想定応答の取得
		} else {
		$page_title = NORMAL_PAGE_TITLE;
 
		/**
		 * 取引ID取得
		 */
		$result_order_id = $response_data->getOrderId();
		/**
		 * 結果コード取得
		 */
		$txn_status = $response_data->getMStatus();
		/**
		 * 詳細コード取得
		 */
		$txn_result_code = $response_data->getVResultCode();
		/**
		 * エラーメッセージ取得
		 */
		$error_message = $response_data->getMerrMsg();
		/**
		 * trAd URL取得
		 */
		$trad_url = $response_data->getTradUrl();
 
 
		// 成功
		if (TXN_SUCCESS_CODE === $txn_status) {
 
		} else if (TXN_PENDING_CODE === $txn_status) {
		// 失敗
		} else if (TXN_FAILURE_CODE === $txn_status) {
		} else {
		$page_title = ERROR_PAGE_TITLE;
		}
		}
		echo $txn_status;
		die();
 
	}

- You must download file tgmdk  then you push them to your project. You can config url of API to folder (folder tgMdk) at define('MDK_DIR',WWW_ROOT . 'tgMdk' . DS);

 -  You take care only latest code.

// 成功
if (TXN_SUCCESS_CODE === $txn_status) {
			
} else if (TXN_PENDING_CODE === $txn_status) {
// 失敗
} else if (TXN_FAILURE_CODE === $txn_status) {

} else {
	$page_title = ERROR_PAGE_TITLE;
}

This code return status of transaction. We can implement operations with each status SUCCESS, PENDING, FAILURE… Some variables related to transaction which is returned from system. We can use them

$result_order_id; // order id (transaction id)
$txn_status;  // trạng thái của giao dịch (SUCCESS, PENDING, FAILURE)
$txn_result_code; 
$error_message;
$trad_url;

You can see file mdk.log to read more information. SUMMARY + Data input

  + cardNumber=4111-1111-1111-1111';
  + cardExpire=12/13;
  + amount=987654321;
  + securityCode=1234;
  + withCapture=0;
  + orderId=sdbcard<?php echo time() ?>;
  + jpo1=10;

+ Data output

$result_order_id; // order id (transaction id)
$txn_status;  // trạng thái của giao dịch (SUCCESS, PENDING, FAILURE)
$txn_result_code; 
$error_message;
$trad_url;