<!-- stripe plugin -->

<input type="hidden" name="stripe-token" id="stripe-token" value="" />

<script type="text/javascript" src="https://js.stripe.com/v2/"></script>
<script type="text/javascript">Stripe.setPublishableKey('{$config.stripe_publishable_key}');</script>
<script type="text/javascript">

var img_url = '{$smarty.const.RL_PLUGINS_URL}stripe/static/';

{literal}
$(document).ready(function() {
	$('#billing-form').prepend('<div class="submit-cell"><div class="name">{/literal}{$lang.your_email}{literal}</div><div class="field single-field"><input type="text" name="f[email]" value="{/literal}{$smarty.post.email}{literal}" class="wauto" maxlength="50" size="35" /></div></div>');
	$('#form-checkout').prepend($('#stripe-token'));
	$('#btn-checkout, #form-checkout input[type="submit"]').click(function() {
		if ($('input[name="gateway"]:checked').val() != 'stripe') {
			$('#stripe-form').remove();
			return true;
		}
	 	stripeGenerateToken();	
	 	return false;
	});
	$("input.numeric").numeric();
});

var stripeGenerateToken = function() {
	Stripe.createToken({
		number: $('input[name="f[card_number]"]').val(),
		exp_month: $('select[name="f[exp_month]"]').val(),
		exp_year: $('select[name="f[exp_year]"]').val(){/literal}{if $config.stripe_cvc},{/if}{literal}
		{/literal}{if $config.stripe_cvc}cvc: $('input[name="f[card_verification_code]"]').val(){/if}{literal}
	}, stripeResponseHandler);
}

var stripeResponseHandler = function(status, response) {
	if (response.error) {
		printMessage('error', response.error.message);
		return false;
	} else {
		$('#stripe-token').val(response['id']);
		$("#form-checkout").submit();
	}
}
{/literal}
</script>

<!-- end stripe plugin -->