Ruby on Rails online payments with Adyen (Part II)

Average rating: 0
0 votes

Thanks! You’ve rated this material!

In the previous article we uncovered how to do Ruby on Rails online payments with Adyen using encrypted form without redirect of users to external checkout pages. Now it’s time for another type of integration: Hosted Payment Pages (HPP).

Why Ruby on Rails online payments with Adyen HPP

You can easily do Ruby on Rails online payments with Stripe, BrainTree, and many others. We have experience integrating these online payments to Ruby on Rails web app during just one day. However, competitive advantage of Adyen’s HPP is that in addition to PayPal and credit card, Adyen’s HPP can allow your Ruby on Rails direct bank payment, with such mathods as SEPA, SOFORT, iDEAL, etc.

HPP provides a secure, flexible and easy way for customers to purchase services and goods:

  • Customers go to your site, then they select and add the services/items to a shopping cart.
  • Next, they are redirected to the hosted payment page, where they enter the billing details to process the payment.
  • After submitting they are redirected back to your web site, where they can see a summary information displaying the result of the payment processing.
  • You can customise the look of the HPP using Adyen’s skin technology and toolset to create a seamless checkout for your customers.

Prepare account for using HPP

Login to the Adyen Customer Area, create a new skin and configure the allowed payment methods.

Generagte HMAC key to be used in your payment request’s signature and add a method to prepare your HPP URI:

def gs(i) # adyen merchant signature params escaping
  i.gsub(':', ':').gsub('', '\')

def hpp_uri(order)
  user = order.user
  merchant_reference = "your_prefix_" + + "_" + + "_" +  rand(99999999).to_s
  merchant_account = ENV
  payment_amount = (*100).to_i.to_s
  currncy = order.currency
  session_validity ='%Y-%m-%dT%H:%M:%SZ')
  ship_before_date ='%Y-%m-%d')

  # ---- merchant signature ----
  string = "currencyCode:merchantAccount:merchantReference:paymentAmount:recurringContract:sessionValidity:shipBeforeDate:shopperEmail:shopperLocale:shopperReference:skinCode"
  string += ':'+gs(currency)
  string += ':'+gs(merchant_account)
  string += ':'+gs(merchant_reference)
  string += ':'+gs(payment_amount)
  string += ':ONECLICK'
  string += ':'+gs(session_validity)
  string += ':'+gs(ship_before_date)
  string += ':'+gs(
  string += ':'+gs(I18n.locale.to_s)
  string += ':'+gs(user.shopper_reference)
  string += ':'+gs('YOUR_HPP_SKIN_CODE')

  hmac = Order.create_hmac(string)
  # ---- merchant signature ----

  uri = ENV # ''
  uri += '?'
  uri += "merchantSig="+Rack::Utils.escape(hmac)
  uri += "&sessionValidity="+session_validity
  uri += "&shipBeforeDate="+ship_before_date
  uri += "&shopperLocale="+I18n.locale.to_s
  uri += "&merchantAccount="+merchant_account
  uri += "&paymentAmount="+payment_amount
  uri += "&currencyCode="+currency
  uri += "&skinCode="+'YOUR_HPP_SKIN_CODE'
  uri += "&merchantReference="+merchant_reference
  uri += "&shopperReference="+user.shopper_reference
  uri += "&recurringContract=ONECLICK"
  uri += "&shopperEmail="

Prepare your application to process HPP payments

Create a new endpoint in your Orders controller where user will be redirected after payment processing:

def payment_processed
  return redirect_to root_url, alert: 'Adyen request invalid' unless params

  order_id = params.split('_').to_i
  order = Order.find order_id

  if  .include?(params.downcase) ||
      Adyen.capture(params, (*100).to_i, order.currency) != ''

    # process failed payment
    redirect_to order, alert: I18n.t('payment_failed')
    # process success payment
    redirect_to order

Add this endpoint to your Adyen’s HPP skin:

Снимок экрана от 2016-04-28 13:29:12

In your Orders controller #create action setup redirect to Adyen HPP:

def create
  order =
    redirect_to Adyen.hpp_uri(order)
    render :new

And now you are ready for global online payments and EU direct bank payments!

Rate this article, if you like it

Thanks! You’ve rated this material!

Got a project? Let's discuss it!

    This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

    USA 490 Post Street STE 526 San Francisco, CA 94102
    Portugal IDEA Spaces - Palácio Sottomayor Palace Av. Fontes Pereira de Melo 16, 1050-121 Lisboa