Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I made a simple app to demonstrate how off-site payments for Worldpay and Rails/Activemerchant can work together. </p> <p><strong>Demo Rails App</strong>- <a href="https://github.com/daemonsy/Worldpay-Rails--Off-Site--Integration-Example" rel="noreferrer">https://github.com/daemonsy/Worldpay-Rails--Off-Site--Integration-Example</a></p> <p>For World Pay hosted payment, basically a <code>post</code> to their payment URL is required. Add <code>test-</code> to secure.worldpay.com for testing mode. WP requires amount, currency, installation ID and cartId to render the page to the customer.</p> <pre><code>&lt;form action="https://test-secure.worldpay.com/wcc/purchase" method=POST&gt; &lt;!-- This next line contains the testMode parameter - it specifies that the submission is a test submission --&gt; &lt;input type="hidden" name="testMode" value="100"&gt; &lt;!-- This next line contains a mandatory parameter. Put your Installation ID inside the quotes after value= --&gt; &lt;input type="hidden" name="instId" value="Your installation ID "&gt; &lt;!-- Another mandatory parameter. Put your own reference identifier for the item purchased inside the quotes after value= --&gt; &lt;input type="hidden" name="cartId" value="Your ID for the product "&gt; &lt;!-- Another mandatory parameter. Put the total cost of the item inside the quotes after value= --&gt; &lt;input type="hidden" name="amount" value="The cost of the product "&gt; &lt;!-- Another mandatory parameter. Put the code for the purchase currency inside the quotes after value= --&gt; &lt;input type="hidden" name="currency" value="currency code e.g. GBP, USD "&gt; &lt;!-- This creates the button. When it is selected in the browser, the form submits the purchase details to us. --&gt; &lt;input type=submit value=" Buy This "&gt; </code></pre> <p> Source: <a href="http://www.worldpay.com/support/kb/bg/htmlredirect/rhtml.html" rel="noreferrer">http://www.worldpay.com/support/kb/bg/htmlredirect/rhtml.html</a></p> <p>This creates a simple <code>button</code> 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 <code>show</code> page of an orders controller. e,g, <code>&lt;input type="hidden" name="amount" value="&lt;%=@order.amount"%&gt;&gt;</code>. So you can click <code>buy this</code> after submitting the order. There are many ways to achieve a <code>POST</code> to World Pay.</p> <p>After which, World Pay can show a shopper response page, send you <code>payment response</code> etc. For payment response to work, you can setup the payment response <code>callback URL</code> to one of your controllers. e.g. =><a href="http://mysite.com/payment-backend" rel="noreferrer">http://mysite.com/payment-backend</a></p> <p>This will be a <code>POST</code> request so you have to setup your controller to handle it. This is where <code>Activemerchant</code> kicks in. For example, </p> <pre><code>class BackendsController &lt; ApplicationController include ActiveMerchant::Billing::Integrations protect_from_forgery :except=&gt;[:worldpay_return] #in routes =&gt; match '/payment-backend'=&gt;'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 =&gt;"Order status for #{order.id} is #{order.status}" end end </code></pre> <p>So the Notification object will read the params in <code>request.raw_post</code> 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. </p> <p>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. </p> <p><strong>ActiveMerchant Docs on WorldPay::Notifications</strong> <a href="http://rdoc.info/github/Shopify/active_merchant/master/ActiveMerchant/Billing/Integrations/WorldPay" rel="noreferrer">http://rdoc.info/github/Shopify/active_merchant/master/ActiveMerchant/Billing/Integrations/WorldPay</a> <strong>World Pay Payment Response Docs</strong> <a href="http://www.worldpay.com/support/kb/bg/paymentresponse/payment_response.html" rel="noreferrer">http://www.worldpay.com/support/kb/bg/paymentresponse/payment_response.html</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload