Using the wepay iframe - adamthedeveloper/wepay-rails GitHub Wiki

Normally when using the wepay-rails gem, you set up your checkout parameters and redirect the user to WePay:

checkout_params = {
    :amount => 10.99,
    :short_description => 'An item that costs $10.99'
}
init_checkout_and_send_user_to_wepay(checkout_params)

But what if you want to use WePay's iframe feature?

Easy. Instead of redirecting, call the init_checkout method, which returns a WepayCheckoutRecord:

checkout_params = {
    :amount => 10.99,
    :short_description => 'An item that costs $10.99',
    :mode => 'iframe'
}
@checkout = init_checkout(checkout_params)

Then you can use WePay's javascript api to create the iframe inside your view:

<script type="text/javascript" src="https://www.wepay.com/js/iframe.wepay.js">
</script>

<div id="checkout_div_id"></div>
<script type="text/javascript">
WePay.iframe_checkout("checkout_div_id", "<%= @checkout.checkout_uri %>");
</script>

And that's it. You can modify your checkout parameters in your controller as normal.

⚠️ **GitHub.com Fallback** ⚠️