Skip to content

Using the wepay iframe

mindeavor edited this page Apr 1, 2012 · 2 revisions

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>

<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.

Clone this wiki locally