Skip to content

Instantly share code, notes, and snippets.

@andrew-grischenko
Created August 11, 2019 10:32
Show Gist options
  • Save andrew-grischenko/c5e1f0b6312011de726fa8dbd28750af to your computer and use it in GitHub Desktop.
Save andrew-grischenko/c5e1f0b6312011de726fa8dbd28750af to your computer and use it in GitHub Desktop.
<!-- Payment confirmation request and form submission script -->
<script>
var urlParams = new URLSearchParams(window.location.search);
var access_code = urlParams.get('AccessCode');
// Request payment confimration from teh payment gateway
$.ajax({
url: "https://paymentrequest2.azurewebsites.net/api/PaymentStatus?transaction=" + access_code,
dataType: 'json',
success: function(response){
if( response && response.Transactions.length > 0 && response.Transactions[0].TransactionStatus ){
// We've got the response and its a confirmed payment
// Fill in the fields and submit the entity form
$("#cr591_reference").val(transaction = response.Transactions[0].TransactionID);
$("#cr591_verification").val(access_code);
$("#cr591_amount").val( response.Transactions[0].TotalAmount / 100 );
$("#InsertButton").click();
} else {
// There was an error - timeout, empty reponse or failed payment
window.location.href = '/payment?error=true';
}
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment