Sha256: 9c21c71ba0406f367db970c5c403408aca0ffd1464e3815b9a85c00d16f58928
Contents?: true
Size: 1.67 KB
Versions: 4
Compression:
Stored size: 1.67 KB
Contents
<script src="https://www.paypal.com/sdk/js?client-id=<%= payment_method.preferred_client_id %>"></script> <div id="paypal-button-container"></div> <script> paypal.Buttons({ createOrder: async function(data, actions) { try { const response = await fetch('/paypal/create_order', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-CSRF-Token': '<%= form_authenticity_token %>' }, body: JSON.stringify({ payment_method_id: '<%= payment_method.id %>' }) }); if (!response.ok) { throw new Error(`Server error: ${response.statusText}`); } const orderData = await response.json(); if (!orderData.orderID) { throw new Error('Order ID not found in response'); } return orderData.orderID; } catch (error) { console.error('Error creating PayPal order:', error); alert('There was an issue creating the PayPal order. Please try again later.'); return null; } }, onApprove: function(data, actions) { return fetch('/paypal/capture_order', { method: 'post', headers: { 'Content-Type': 'application/json', 'X-CSRF-Token': '<%= form_authenticity_token %>' }, body: JSON.stringify({ orderID: data.orderID, payment_method_id: '<%= payment_method.id %>' }) }).then(function(res) { return res.json(); }).then(function(details) { window.location.href = '<%= spree.order_path(@order) %>'; }); } }).render('#paypal-button-container'); </script>
Version data entries
4 entries across 4 versions & 1 rubygems