@{
    ViewData["Title"] = @"Créditer";
}
<h1>@ViewData["Title"]</h1>
<environment names="Development">
<em>Gimmy da flooze</em>
</environment>

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

<script src="https://www.paypalobjects.com/api/checkout.js"></script>
<environment names="lua,coiffure,zicmoove,yavsc,yavscpre">
    <script>
        var CREATE_PAYMENT_URL = 'http://pschneider.fr:85/api/payment/create';
        var EXECUTE_PAYMENT_URL = 'http://pschneider.fr:85/api/payment/execute';
        var PAYPAL_ENV = 'sandbox';
    </script>
</environment>
<environment names="Development">
    <script>
        var CREATE_PAYMENT_URL = 'http://pschneider.fr:85/api/payment/create';
        var EXECUTE_PAYMENT_URL = 'http://pschneider.fr:85/api/payment/execute';
        var PAYPAL_ENV = 'sandbox';
    </script>
</environment>
<script>
    paypal.Button.render({
    
        env: PAYPAL_ENV, // 'production', Optional: specify 'sandbox' environment
    
        payment: function(resolve, reject) {
                
            return paypal.request.post(CREATE_PAYMENT_URL)
                .then(function(data) { resolve(data.id); })
                .catch(function(err) { reject(err); });
        },

        onAuthorize: function(data) {
        
            // Note: you can display a confirmation page before executing
            
            return paypal.request.post(EXECUTE_PAYMENT_URL,
                    { paymentID: data.paymentID, payerID: data.payerID })
                    
                .then(function(data) { /* Go to a success page */ })
                .catch(function(err) { /* Go to an error page  */ });
        }

    }, '#paypal-button');
</script>
