Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Active Merchant Integrations (off site payments) [closed]

My original question (below) was perhaps too specific, so I'm going to ask something more general!

Can anyone point me in the direction of a tutorial, example or documentation on using Active Merchant Integrations to support an offsite payment gateway?

Active Merchant's rdoc lists all of the following as supported offsite payment gateways but I haven't found any tutorials or examples on how to use ActiveMerchant::Billing::Integrations

  • 2 Checkout
  • Banca Sella GestPay
  • Chronopay
  • Direct-eBanking
  • DirecPay
  • HiTRUST
  • Moneybookers
  • Nochex
  • PayPal Website Payments Standard
  • SagePay Form
  • Valitor
  • WorldPay

As good as they may be, peepcode and rails casts only consider gateways, not integrations.

Many thanks!

My company is moving from PayPal Express Checkout to WorldPay Business Gateway (Hosted Payment Page). We're using Rails and Active Merchant.

  1. Does Active Merchant support WorldPay Business Gateway (Hosted Payment Page)? I think it does, judging by the rdoc
  2. What arguments must I supply to ActiveMerchant::Billing::Integrations::WorldPay.new ?

Thanks

like image 959
Mike Avatar asked Oct 19 '11 14:10

Mike


People also ask

What is Active Merchant?

Active Merchant is a simple payment abstraction library extracted from Shopify. The aim of the project is to feel natural to Ruby users and to abstract as many parts as possible away from the user to offer a consistent interface across all supported gateways. activemerchant.org.

What is an external payment gateway?

For the people buying items on your checkout page, an external payment gateway opens a new website in a separate browser tab. For example, websites that take PayPal payments must use the company's external payment gateway, sending their customers to the PayPal site for processing.


1 Answers

I made a simple app to demonstrate how off-site payments for Worldpay and Rails/Activemerchant can work together.

Demo Rails App- https://github.com/daemonsy/Worldpay-Rails--Off-Site--Integration-Example

For World Pay hosted payment, basically a post to their payment URL is required. Add test- to secure.worldpay.com for testing mode. WP requires amount, currency, installation ID and cartId to render the page to the customer.

<form action="https://test-secure.worldpay.com/wcc/purchase" method=POST>

<!-- This next line contains the testMode parameter - it specifies that the submission is a test submission -->
<input type="hidden" name="testMode" value="100">

<!-- This next line contains a mandatory parameter. Put your Installation ID inside the quotes after value= -->
<input type="hidden" name="instId" value="Your installation ID ">

<!-- Another mandatory parameter. Put your own reference identifier for the item purchased inside the quotes after value= -->
<input type="hidden" name="cartId" value="Your ID for the product ">

<!-- Another mandatory parameter. Put the total cost of the item inside the quotes after value= -->
<input type="hidden" name="amount" value="The cost of the product ">

<!-- Another mandatory parameter. Put the code for the purchase currency inside the quotes after value= -->
<input type="hidden" name="currency" value="currency code e.g. GBP, USD ">

<!-- This creates the button. When it is selected in the browser, the form submits the purchase details to us. -->
<input type=submit value=" Buy This ">

Source: http://www.worldpay.com/support/kb/bg/htmlredirect/rhtml.html

This creates a simple button that carries your order to World Pay where the customer will enter credit card details and complete the purchase. I've embedded the above code in the show page of an orders controller. e,g, <input type="hidden" name="amount" value="<%[email protected]"%>>. So you can click buy this after submitting the order. There are many ways to achieve a POST to World Pay.

After which, World Pay can show a shopper response page, send you payment response etc. For payment response to work, you can setup the payment response callback URL to one of your controllers. e.g. =>http://mysite.com/payment-backend

This will be a POST request so you have to setup your controller to handle it. This is where Activemerchant kicks in. For example,

class BackendsController < ApplicationController
  include ActiveMerchant::Billing::Integrations
  protect_from_forgery :except=>[:worldpay_return]

  #in routes => match '/payment-backend'=>'backends#worldpay_return'
  def worldpay_return
    notification = WorldPay::Notification.new(request.raw_post)  

    order = Order.find(notification.item_id)

    if notification.acknowledge
      begin
        if notification.complete?
          order.status = 'success'
        end
      rescue
        order.status = "failed"
        raise
      ensure
        order.save
      end
    end
  render :text =>"Order status for #{order.id} is #{order.status}" 

  end

end

So the Notification object will read the params in request.raw_post and set them up the an object where you can query. I found the active merchant docs useful in telling what return params are mapped by it.

Note that this controller is a very crude example. World Pay provides a few methods for you to validate the response and this is supported by Active Merchant.

ActiveMerchant Docs on WorldPay::Notifications http://rdoc.info/github/Shopify/active_merchant/master/ActiveMerchant/Billing/Integrations/WorldPay World Pay Payment Response Docs http://www.worldpay.com/support/kb/bg/paymentresponse/payment_response.html

like image 145
Damon Aw Avatar answered Sep 23 '22 04:09

Damon Aw