Worldpay と Rails/Activemerchant のオフサイト決済がどのように連携するかを示す簡単なアプリを作成しました。
デモ Rails アプリ-
https://github.com/daemonsy/Worldpay-Rails--Off-Site--Integration-Example
World Pay がホストする支払いの場合、基本的にpost
支払い URL への が必要です。test-
テストモードの場合は、secure.worldpay.com に追加してください。WP では、顧客にページを表示するために、金額、通貨、インストール ID、および cartId が必要です。
<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 ">
ソース: http://www.worldpay.com/support/kb/bg/htmlredirect/rhtml.html
button
これにより、顧客がクレジット カードの詳細を入力して購入を完了する World Pay に注文を運ぶシンプルなフォームが作成されます。show
上記のコードを注文コントローラーのページに埋め込みました。例えば、<input type="hidden" name="amount" value="<%=@order.amount"%>>
。buy this
そのため、注文を送信した後にクリックできます。POST
to World Payを達成するには多くの方法があります。
その後、World Pay は買い物客の応答ページを表示したり、送信したりできますpayment response
。支払い応答が機能するようにするには、コントローラの 1 つに支払い応答callback URL
を設定できます。例 => http://mysite.com/payment-backend
これはPOST
リクエストになるため、それを処理するようにコントローラーをセットアップする必要があります。これがActivemerchant
キックの場所です。たとえば、
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
したがって、通知オブジェクトはパラメーターを読み取り、request.raw_post
クエリを実行できるオブジェクトに設定します。アクティブなマーチャント ドキュメントは、どのリターン パラメータがマッピングされているかを示すのに役立つことがわかりました。
このコントローラーは非常に大雑把な例であることに注意してください。World Pay は、応答を検証するためのいくつかの方法を提供しており、これは Active Merchant によってサポートされています。
WorldPay::Notifications の ActiveMerchant ドキュメント
http://rdoc.info/github/Shopify/active_merchant/master/ActiveMerchant/Billing/Integrations/WorldPay
World Pay 支払い応答ドキュメント
http://www.worldpay.com/support/kb/bg /paymentresponse/payment_response.html