私はワールドペイとRails/Activemerchantためのオフサイト支払いは一緒に働くことができる方法を示すためにシンプルなアプリを作りました。
デモRailsのアプリケーション - 世界有料で https://github.com/daemonsy/Worldpay-Rails--Off-Site--Integration-Example
は基本的に自分の支払いURLへpost
が必要とされ、支払いを開催しました。テストモードの場合はtest-
をsecure.worldpay.comに追加してください。 WPには金額、通貨、インストールID、カートIDが必要です。
<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
を作成します。注文コントローラのshow
ページに上記のコードを埋め込んでいます。 e、g、<input type="hidden" name="amount" value="<%[email protected]"%>>
。注文後にbuy this
をクリックすることができます。ワールドペイにPOST
を達成する方法はたくさんあります。
その後、World Payで買い物客の回答ページが表示され、payment response
などが届きます。支払いの応答が機能するようにするには、コントローラの1つに支払いの応答callback URL
を設定します。例えば=>http://mysite.com/payment-backend
これはPOST
のリクエストになりますので、コントローラで処理するように設定する必要があります。例えば、
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
でActivemerchant
キックだから通知オブジェクトがrequest.raw_post
でのparamsを読んで、あなたが照会できるオブジェクトをそれらを設定する場所です。私はアクティブな商人のドキュメントが、それによってマップされる返品パラメータを伝えるのに役立つことを発見しました。
このコントローラは非常に粗末な例です。 World Payは、レスポンスを検証するためのいくつかの方法を提供しています。これはActive Merchantによってサポートされています。
WorldPayの上ActiveMerchantドキュメント::通知 http://rdoc.info/github/Shopify/active_merchant/master/ActiveMerchant/Billing/Integrations/WorldPay 世界ペイ決済応答ドキュメント http://www.worldpay.com/support/kb/bg/paymentresponse/payment_response.html
あなたはこれを解決するために管理していましたか? –
いいえまだ何も見つかりませんでした – Mike
オフサイト支払いを使用しているので、ワールドペイURLへの 'POST 'を行うことでプロセスを簡略化できますか?PaypalボタンAPIと同様です。 –