stripe.blade.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <tr>
  2. <td>
  3. @if(isset($payment['name']))
  4. {{ ucwords($payment['name']) }}
  5. @else
  6. <p class="alert alert-danger">You need to have <strong>name</strong> key in your config</p>
  7. @endif
  8. </td>
  9. <td>
  10. @if(isset($payment['description']))
  11. {{ $payment['description'] }}
  12. @endif
  13. </td>
  14. <td>
  15. @if(isset($payment['name']))
  16. <form action="{{ route('checkout.execute') }}" method="post" class="pull-right" id="stripeForm">
  17. <input type="hidden" name="payment" value="{{ config('stripe.name') }}">
  18. <input type="hidden" name="stripeToken" value="">
  19. <input type="hidden" class="billing_address" name="billing_address" value="">
  20. <input type="hidden" class="delivery_address_id" name="delivery_address" value="">
  21. <input type="hidden" class="courier" name="courier" value="">
  22. {{ csrf_field() }}
  23. <button id="paywithstripe" class="btn btn-primary">Pay with {{ ucwords($payment['name']) }} <i class="fa fa-cc-stripe"></i></button>
  24. </form>
  25. @endif
  26. </td>
  27. </tr>
  28. <script src="{{ url('https://checkout.stripe.com/checkout.js') }}"></script>
  29. <script type="text/javascript">
  30. $(document).ready(function () {
  31. let handler = StripeCheckout.configure({
  32. key: "{{ config('stripe.key') }}",
  33. locale: 'auto',
  34. token: function(token) {
  35. // You can access the token ID with `token.id`.
  36. // Get the token ID to your server-side code for use.
  37. console.log(token.id);
  38. $('input[name="stripeToken"]').val(token.id);
  39. $('#stripeForm').submit();
  40. }
  41. });
  42. document.getElementById('paywithstripe').addEventListener('click', function(e) {
  43. let total = parseFloat("{{ $total }}");
  44. let shipping = parseFloat($('#shippingFeeC').val());
  45. let amount = total + shipping;
  46. // Open Checkout with further options:
  47. handler.open({
  48. name: "{{ config('stripe.name') }}",
  49. description: "{{ config('stripe.description') }}",
  50. currency: "{{ config('cart.currency') }}",
  51. amount: amount * 100,
  52. email: "{{ $customer->email }}"
  53. });
  54. e.preventDefault();
  55. });
  56. // Close Checkout on page navigation:
  57. window.addEventListener('popstate', function() {
  58. handler.close();
  59. });
  60. });
  61. </script>