I have a code that retrieve json result from snaptoken when the pay-button is clicked and the transaction process ended.
<script src="https://app.sandbox.midtrans.com/snap/snap.js"> </script>
<script type="text/javascript">
document.getElementById('pay-button').onclick = function() {
// SnapToken acquired from previous step
snap.pay('<?php echo $snapToken ?>', {
// Optional
onSuccess: function(result) {
/* You may add your own js here, this is just example */
document.getElementById('result-json').innerHTML += JSON.stringify(result, null, 2);
console.log(JSON.stringify(result, null, 2));
},
// Optional
onPending: function(result) {
/* You may add your own js here, this is just example */
document.getElementById('result-json').innerHTML += JSON.stringify(result, null, 2);
console.log(JSON.stringify(result, null, 2));
},
// Optional
onError: function(result) {
/* You may add your own js here, this is just example */
document.getElementById('result-json').innerHTML += JSON.stringify(result, null, 2);
console.log(JSON.stringify(result, null, 2));
}
});
};
</script>
the code is from midtrans docs and the output looks like this
{
"Status_code": "201",
"Status_message": "Success, Transaction Is Found",
"Transaction_id": "6ce0790e-F214-455c-8f3c-77269b23b8cb",
"Order_id": "1836559779",
"Gross_amount": "270000.00",
"Payment_type": "Gopay",
"Transaction_time": "2022-07-15 15:04:52",
"Transaction_status": "Pending",
"Fraud_status": "Accept",
"Finish_redirect_url": "Http://Example.Com?Order_id=1836559779&Status_code=201&Transaction_status=Pending"
}
its there a way to store the invoice payment into database with mysql?
i tried to change it into object json using parse() although it still gets an error
onPending: function(result) {
/* You may add your own js here, this is just example */
var stringjson = document.getElementById('result-json').innerHTML += JSON.stringify(
result, null, 2);
var objectjson = document.getElementById('result-json').innerHTML = JSON.parse(
stringjson);
console.log(objectjson);
},