stripe_app.blade.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <html>
  2. <head>
  3. <title>Stripe Payment</title>
  4. <meta name="viewport" content="width=device-width, initial-scale=1">
  5. <style>
  6. .loader {
  7. border: 16px solid #f3f3f3;
  8. border-radius: 50%;
  9. border-top: 16px solid #3498db;
  10. width: 120px;
  11. height: 120px;
  12. -webkit-animation: spin 2s linear infinite; /* Safari */
  13. animation: spin 2s linear infinite;
  14. margin: auto;
  15. }
  16. /* Safari */
  17. @-webkit-keyframes spin {
  18. 0% {
  19. -webkit-transform: rotate(0deg);
  20. }
  21. 100% {
  22. -webkit-transform: rotate(360deg);
  23. }
  24. }
  25. @keyframes spin {
  26. 0% {
  27. transform: rotate(0deg);
  28. }
  29. 100% {
  30. transform: rotate(360deg);
  31. }
  32. }
  33. </style>
  34. <script src="https://js.stripe.com/v3/"></script>
  35. </head>
  36. <body>
  37. <button id="checkout-button" style="display: none;"></button>
  38. <div class="loader"></div>
  39. <br>
  40. <br>
  41. <p style="width: 250px; margin: auto;">Don't close the tab. The payment is being processed . . .</p>
  42. <script type="text/javascript">
  43. // Create an instance of the Stripe object with your publishable API key
  44. var stripe = Stripe('{{ env("STRIPE_KEY") }}');
  45. var checkoutButton = document.getElementById('checkout-button');
  46. checkoutButton.addEventListener('click', function () {
  47. // Create a new Checkout Session using the server-side endpoint you
  48. // created in step 3.
  49. const data = {
  50. payment_type: '{{$payment_type}}',
  51. combined_order_id: '{{$combined_order_id}}',
  52. amount: '{{$amount}}',
  53. user_id: '{{$user_id}}'
  54. };
  55. fetch('{{ route('api.stripe.get_token') }}', {
  56. method: 'POST',
  57. headers: {
  58. 'Content-Type': 'application/json',
  59. },
  60. body: JSON.stringify(data),
  61. })
  62. .then(function (response) {
  63. return response.json();
  64. })
  65. .then(function (session) {
  66. return stripe.redirectToCheckout({sessionId: session.id});
  67. })
  68. .then(function (result) {
  69. console.log(result);
  70. // If `redirectToCheckout` fails due to a browser or network
  71. // error, you should display the localized error message to your
  72. // customer using `error.message`.
  73. if (result.error) {
  74. alert(result.error.message);
  75. }
  76. })
  77. .catch(function (error) {
  78. console.error('Error:', error);
  79. });
  80. });
  81. document.getElementById("checkout-button").click();
  82. </script>
  83. </body>
  84. </html>