Skip to content

Instantly share code, notes, and snippets.

@rafeequl
Created October 27, 2014 14:12
Show Gist options
  • Save rafeequl/72a2255fadc5bf986095 to your computer and use it in GitHub Desktop.
Save rafeequl/72a2255fadc5bf986095 to your computer and use it in GitHub Desktop.
Two Click part 1
<html>
<head>
<title>Two Click</title>
</head>
<body>
<h1>Two Click</h1>
<form action="two_click_charge.php" method="POST" id="payment-form">
<p>
<label>PIN</label>
<input id="card-pin" name="card-pin" size="20" type="text" autocomplete="off"/>
</p>
<input id="token_id" name="token_id" type="hidden" />
<button class="submit-button" type="submit">Save</button>
</form>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="https://api.sandbox.veritrans.co.id/v2/assets/js/veritrans.js"></script>
<script type="text/javascript">
$(function(){
/* Change with Production API URL when you're ready to go live. */
Veritrans.url = "https://api.sandbox.veritrans.co.id/v2/token";
/* Use your own KEY from Merchant Administration Portal. */
Veritrans.client_key = "your server key";
var card = function(){
return {
'card_cvv' : $("#card-pin").val(),
'token_id' : "<from db>",
'two_click' : true,
}
};
/* Handler when user click the 'Pay' button. */
$('.submit-button').click(function(event){
event.preventDefault();
$(this).attr("disabled", "disabled");
Veritrans.token(card, callback);
return false;
});
/* Callback function to handle asynchronous event */
function callback(response) {
alert(JSON.stringify(response));
if (response.status_code == '200') {/* Normal transaction. */
// store token data in input #saved_token_id and then submit form to merchant server
$("#token_id").val(response.token_id);
$("#payment-form").submit();
} else {/* Fail to acquire token */
// Enable the submit button
$('.submit-button').removeAttr('disabled');
// Show status message.
$('#message').text(response.status_message);
}
}
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment