对于 World Pay 托管支付,基本上需要向其支付 URL 发送post。将 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 ">
这将是一个 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
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 ">
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.
发布评论
评论(1)
我制作了一个简单的应用程序来演示 Worldpay 和 Rails/Activemerchant 的场外支付如何协同工作。
演示 Rails 应用-
https://github.com/daemonsy/Worldpay-Rails--场外 - 集成示例
对于 World Pay 托管支付,基本上需要向其支付 URL 发送
post
。将test-
添加到 secure.worldpay.com 以进行测试模式。 WP 需要金额、货币、安装 ID 和 cartId 才能将页面呈现给客户。来源:http://www.worldpay.com/support/kb/bg /htmlredirect/rhtml.html
这将创建一个简单的
按钮
,将您的订单传送到 World Pay,客户将在其中输入信用卡详细信息并完成购买。我已将上述代码嵌入到订单控制器的show
页面中。 e,g,[电子邮件受保护]"%>>
。因此您可以在提交订单后点击购买
。有多种方法可以实现 World Pay 的POST
。之后,World Pay 可以显示购物者响应页面,向您发送
付款响应
等。为了使付款响应正常工作,您可以将付款响应回调 URL
设置为您的其中一个控制器。例如 =>http://mysite.com/ payment-backend这将是一个
POST
请求,因此您必须设置控制器来处理它。这就是Activemerchant
发挥作用的地方。例如,Notification 对象将读取
request.raw_post
中的参数,并将它们设置为您可以查询的对象。我发现活跃的商家文档对于告诉它映射哪些返回参数很有用。请注意,该控制器是一个非常粗略的示例。 World Pay 为您提供了几种验证响应的方法,这由 Active Merchant 支持。
WorldPay::通知上的 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
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. Addtest-
to secure.worldpay.com for testing mode. WP requires amount, currency, installation ID and cartId to render the page to the customer.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 theshow
page of an orders controller. e,g,<input type="hidden" name="amount" value="<%[email protected]"%>>
. So you can clickbuy this
after submitting the order. There are many ways to achieve aPOST
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 responsecallback URL
to one of your controllers. e.g. =>http://mysite.com/payment-backendThis will be a
POST
request so you have to setup your controller to handle it. This is whereActivemerchant
kicks in. For example,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