Active Merchant Integrations (off site payments) [closed]
Asked Answered
S

1

9

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

Strawn answered 19/10, 2011 at 14:10 Comment(6)
Did you manage to solve this? I'm also having trouble switching :(Epithelium
Nope. Still haven't found anything.Strawn
Since you're using offsite payment, could you simplify the process by doing the POST to a worldpay URL? Like the Paypal button API.Munda
@daemonsy - i.e. just not use ActiveMerchant?!Strawn
Actually I'm trying to do wp integration for my own project. But we are trying to use Gateway mode(i.e. on site). Which product are you doing? I'll digress a bit and try to come out with some code.Munda
We're wanting to do offsite. I was hoping to do it through ActiveMerchant Integrations so it would be easier to swap supplier in future rather than hardcode everything to WorldPay. Perhaps I've misunderstood what what little documentation there is on the subject but WorldPay is listed as a supported offsite gateway in ActiveMerchant's rdoc.Strawn
M
11

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

Munda answered 21/2, 2012 at 14:11 Comment(3)
Thanks. I look forward to trying this out in the near future!Strawn
No problem =). I love World Pay, but sigh, I wish they could improve their fugly hosted page just a little.Munda
Thanks.. cool answer, i'll try to adapt this to another payment processorGrissom

© 2022 - 2024 — McMap. All rights reserved.