javascriptruby-on-railspaypalpayment-processingpaypal-buttons

paypal integration in rails using js


So guys, I am trying to get custom payments using js (paypal buttons) in a multivendor site(built using rails).the price for the listing is present in @listing.price . I have to implement this price as the checkout price in paypal (using paypal buttons if possible).

<script> // Render the PayPal button into #paypal-button-container paypal.Buttons({ price = document.getElementById('price'); // Set up the transaction createOrder: function(data, actions) { return actions.order.create({ purchase_units: [{ amount: { value: 'price' } }] }); },

    }).render('#paypal-button-container');


</script>

this code shows the correct value(price of the listing)

<%= @listing.price %>

STill something im missing.could you help..if possible Is THERE any other way for multivendor payment processing in rails (other than stripe...as outside US)


Solution

  • The main issue from what I see is that you aren't attempting to pass the price through your <div id="price">..

    To pass the <%= @listing.price %> to Javascript, try setting a data attribute on the <div id="price"> as such: <div id="price" data-price="<%= @listing.price %>">. Then you should be able to receive it in javascript by price.dataset.price. #dataset refers to all data attributes that are on a div and #price is the arbitrary name you give the data-attribute.