<div id="paypal-button"></div>
<script src="https://www.paypalobjects.com/api/checkout.js"></script>
    <script>
      paypal.Button.render({
        env: 'sandbox',
        style: {
         size: 'responsive',
         color: 'gold',
         shape: 'rect',
         label: 'checkout',
         tagline: 'true'
        } ,
    // Or 'production'
        // Set up the payment:
        // 1. Add a payment callback
        payment: function(data, actions) {
          // 2. Make a request to your server
          return actions.request.post('{{route("approvePayment.create_payment")}}',{
            "_token": "{{ csrf_token() }}",
            "order_id": "1",
          })
            .then(function(res) {
              // 3. Return res.id from the response
              return res.id;
            });
        },
        // Execute the payment:
        // 1. Add an onAuthorize callback
        onAuthorize: function(data, actions) {
        // 2. Make a request to your server
        console.log(data, actions);
          return actions.request.post('{{route("approvePayment.order_success_update")}}', {
                    paymentID: data.paymentID,
                    payerID:   data.payerID,
                    "_token": "{{ csrf_token() }}",
                    "order_id": "1",
                    "order_data": JSON.stringify(data)
              })
            .then(function(res) {
                window.location.href = data.returnUrl;
              // 3. Show the buyer a confirmation message.
            });
        }
      }, '#paypal-button');
    </script>