Created
June 13, 2014 21:28
-
-
Save solepixel/31c58fa5d064e321de66 to your computer and use it in GitHub Desktop.
My Virtual Merchant Submission Button
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* My Virtual Merchant Submission Button | |
* Description: This button will allow users to send customers and clients to the My Virtual Merchant payment form | |
* Version: 1.0.0 | |
* Author: Brian DiChiara | |
* Author URI: http://www.briandichiara.com | |
*/ | |
$post_url = 'https://www.myvirtualmerchant.com/VirtualMerchant/process.do'; | |
$config = array( | |
# enter your Merchant ID here | |
'ssl_merchant_id' => '######', | |
# enter your PIN here | |
'ssl_pin' => '######', | |
# leave the rest of these settings the same | |
'ssl_user_id' => 'webpage', | |
'ssl_transaction_type' => 'ccsale', | |
'ssl_user_id' => 'webpage', | |
'ssl_show_form' => 'true' | |
); | |
$user_ip = filter_var( strip_tags( htmlspecialchars( $_SERVER['REMOTE_ADDR'] ) ), FILTER_VALIDATE_IP ); | |
if( $user_ip ){ | |
$config['ssl_cardholder_ip'] = $user_ip; | |
} | |
?> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Donation</title> | |
<style type="text/css"> | |
/* Style the page/button however you want */ | |
* { margin:0; padding:0; border:0; } | |
body { | |
padding:30px; | |
text-align: center; | |
background: #FFF; | |
} | |
.button { | |
padding:8px 15px 10px; | |
-moz-box-shadow:inset 0px 1px 0px 0px #f5978e; | |
-webkit-box-shadow:inset 0px 1px 0px 0px #f5978e; | |
box-shadow:inset 0px 1px 0px 0px #f5978e; | |
background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #f24537), color-stop(1, #c62d1f) ); | |
background:-moz-linear-gradient( center top, #f24537 5%, #c62d1f 100% ); | |
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#f24537', endColorstr='#c62d1f'); | |
background-color:#f24537; | |
border:1px solid #d02718; | |
display:inline-block; | |
color:#fff; | |
font-family:'Trebuchet MS', 'Arial', sans-serif; | |
font-size:16px; | |
text-decoration:none; | |
text-align:center; | |
text-shadow:1px 1px 0px #810e05; | |
text-transform: uppercase; | |
cursor: pointer; | |
} | |
.spinner { | |
display: inline-block; | |
width:48px; | |
height: 51px; | |
} | |
.spinner.hidden { | |
display: none; | |
} | |
.preload { | |
position: absolute; | |
width: 1px; | |
height: 1px; | |
overflow: hidden; | |
visibility: hidden; | |
top:0; | |
left:0; | |
} | |
body.in-iframe { | |
padding:0; | |
background: transparent; | |
} | |
</style> | |
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> | |
<script> | |
/** | |
* Detect if this page is inside an Iframe | |
* @return {bool} | |
*/ | |
function inIframe () { | |
try { | |
return window.self !== window.top; | |
} catch (e) { | |
return true; | |
} // try | |
} // inIframe | |
/** | |
* jQuery Document ready function | |
* @return {void} | |
*/ | |
$(function(){ | |
/** | |
* Form action that occurs when the form is submit. | |
* We are displaying a spinner animation and hiding the submit button | |
* @return {void} | |
*/ | |
function form_submit_action(){ | |
$('.spinner').removeClass('hidden'); | |
$('#donate-form').find('.button') | |
.css('visibility','hidden') | |
.css('position','absolute') | |
.css('width','1px') | |
.css('height','1px') | |
.css('overflow','hidden'); | |
} // form_submit_action | |
if( inIframe() ){ | |
// set a body class to know we are inside an iframe | |
$('body').addClass('in-iframe'); | |
} else { | |
// There's only one thing to do on this page outside of an iframe. Let's submit the form. | |
form_submit_action(); | |
// we're going to wait a few milliseconds to give the gif a chance to load. | |
setTimeout( function(){ | |
$('#donate-form').submit(); | |
}, 200 ); | |
} // if inIframe | |
/** | |
* Display the spinner and hide the button when the user clicks/submits the button | |
* @param {event} e Click event | |
* @return {bool} | |
*/ | |
$('#donate-form').on('submit', function(e){ | |
form_submit_action(); | |
return true; | |
}); // form.submit | |
}); // document.ready | |
</script> | |
</head> | |
<body> | |
<img src="spinner.gif" class="preload" /><!-- preload our spinner as quick as possible --> | |
<!-- | |
The form ID should stay "donate-form". If the form ID is changed, be sure to change it in the Javascript. | |
POST the form to the parent window in case form is in an iframe. | |
--> | |
<form action="<?php echo $post_url; ?>" method="POST" id="donate-form" target="_parent"> | |
<?php | |
/** | |
* Loop through all the config vars and output the form inputs. | |
* @var array | |
*/ | |
foreach( $config as $key => $value ): ?> | |
<input type="hidden" name="<?php echo $key; ?>" value="<?php echo $value; ?>" /> | |
<?php endforeach; ?> | |
<input type="submit" value="Donate Now" class="button" /> | |
<span class="spinner hidden"><img src="spinner.gif" /></span> | |
</form><!-- #donate-form --> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment