<{if $webshop->hasPayPalCheckout()}>

	<{assign var="client_id" value=$webshop->getPayPalClientId()}>

	<script src="https://www.paypal.com/sdk/js?client-id=<{$client_id|escape}>&currency=<{$webshop->getCurrency()}>" data-order-id="<{$basket_id}>"></script>

	<div id="paypal-button-container"></div>

	<{assign var="secret" value=$webshop->getPayPalSecret($basket_id)}>

	<script>
		paypal.Buttons({
			createOrder: function(data, actions) {
				return actions.order.create({
					purchase_units: [{
						amount: {
							value: '<{$total_price|number_format:2:".":""}>'
						},
						custom_id: '<{$basket_id}>',
						reference_id: '<{$secret}>'
					}]
				});
			},
			onApprove: function(data, actions) {
				return actions.order.capture().then(function(details) {
					var stackie = [];
					stackie.push('basket_id=' + encodeURIComponent(details.purchase_units[0].custom_id));
					stackie.push('pplc='      + encodeURIComponent(details.purchase_units[0].reference_id));
					stackie.push('name='      + encodeURIComponent(details.purchase_units[0].shipping.name.full_name));
					stackie.push('address='   + encodeURIComponent(details.purchase_units[0].shipping.address.address_line_1));
					stackie.push('address2='  + encodeURIComponent(details.purchase_units[0].shipping.address.address_line_2));
					stackie.push('zipcode='   + encodeURIComponent(details.purchase_units[0].shipping.address.postal_code));
					stackie.push('city='      + encodeURIComponent(details.purchase_units[0].shipping.address.admin_area_2));
					stackie.push('email='     + encodeURIComponent(details.payer.email_address));
					stackie.push('payer='     + encodeURIComponent(details.payer.payer_id));
					stackie.push('id='        + encodeURIComponent(details.id));

					var url = '<{$webshop->getUrl()}>/thanks?' + stackie.join('&');

					top.location.href = url;
				});
			}
		}).render('#paypal-button-container');
	</script>

<{/if}>