56 lines
2.4 KiB
PHP
56 lines
2.4 KiB
PHP
<html>
|
|
|
|
<head>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700" rel="stylesheet">
|
|
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.4.1/css/all.css" integrity="sha384-5sAR7xN1Nv6T6+dT2mhtzEpVJvfS3NScPQTrOxhwjIuvcA67KV2R5Jz6kr4abQsz" crossorigin="anonymous">
|
|
|
|
<!-- @TODO: replace SET_YOUR_CLIENT_KEY_HERE with your client key -->
|
|
<script type="text/javascript" src="https://app.sandbox.midtrans.com/snap/snap.js"
|
|
data-client-key="SB-Mid-client-dD1qABPfsyhMfqkP"></script>
|
|
<!-- Note: replace with src="https://app.midtrans.com/snap/snap.js" for Production environment -->
|
|
<script src="https://code.jquery.com/jquery-3.7.1.min.js" integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
|
|
</head>
|
|
|
|
<body>
|
|
<button id="pay-button">Pay!</button>
|
|
{{-- memasukkan data ke name dengan lanjutan sbmit formulir--}}
|
|
<form action="" id="submit_form" method="POST">
|
|
@csrf
|
|
<input type="hidden" name="json" id="json_callback">
|
|
</form>
|
|
<script type="text/javascript">
|
|
var payButton = document.getElementById('pay-button');
|
|
payButton.addEventListener('click', function() {
|
|
window.snap.pay('{{$snap_token}}', {
|
|
onSuccess: function(result){
|
|
/* You may add your own implementation here */
|
|
alert("payment success!"); console.log(result);
|
|
send_response_to_form(result);
|
|
},
|
|
onPending: function(result){
|
|
/* You may add your own implementation here */
|
|
alert("wating your payment!"); console.log(result);
|
|
send_response_to_form(result);
|
|
},
|
|
onError: function(result){
|
|
/* You may add your own implementation here */
|
|
alert("payment failed!"); console.log(result);
|
|
send_response_to_form(result);
|
|
},
|
|
onClose: function(){
|
|
/* You may add your own implementation here */
|
|
alert('you closed the popup without finishing the payment');
|
|
}
|
|
})
|
|
});
|
|
|
|
// membuat function
|
|
function send_response_to_form(result) {
|
|
document.getElementById('json_callback').value = JSON.stringify(result);
|
|
$('submit_form').submit();
|
|
}
|
|
</script>
|
|
</body>
|
|
|
|
</html> |