您可以在此表中查看可用参数(仅中间列适用,因为 activemerchant 正在使用 SOAP API):
https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_ECCustomizing#id086NA300I5Z__id086NAC0J0PN
为了最好地理解 activemerchant 是如何做的,它可能是直接查看实现。您可以看到相关参数被插入到 SOAP XML 请求中(当前),从插入的第 98 行开始OrderTotal
:
https://github.com/Shopify/active_merchant/blob/master/lib/active_merchant/billing/gateways/paypal_express.rb#L98
请注意如何从options
哈希中获取参数,以便您可以在此处看到要为每个参数传递的正确符号。
在您列出以下参数的情况下,您可以这样做:
def paypal
options = {
:name => "Tickets",
:quantity => @payment.quantity,
:description => "Tickets for #{@payment.event_name}",
:amount => @payment.unit_price
:ip => request.remote_ip,
:return_url => url_for(:action=>:confirm, :id=>@payment.id, :only_path=>false),
:cancel_return_url => url_for(:action=>:show, :id=>@payment.id, :only_path=>false)
}
# the actual code that gets used
setup_response = gateway.setup_purchase(@payment.amount, options)
redirect_to gateway.redirect_url_for(setup_response.token)
end
name
但请注意:activemerchant 目前不支持quantity
和字段。amount
您必须分叉存储库并自己插入这些并使用您的项目副本。当您查看代码并了解它是如何与其他代码一起完成时,这真的非常简单。
例如,要添加订单名称、商品数量和商品单价,您可以在OrderDescription
插入后添加这些行:
xml.tag! 'n2:Name', options[:name]
xml.tag! 'n2:Amount', options[:amount]
xml.tag! 'n2:Quantity', options[:quantity]
希望有帮助!
更新:
好的,我认为根据 SOAP API 的 XML 模式,您必须在 activemerchant 中像这样指定它:
xml.tag! 'n2:PaymentDetails' do
items = options[:items] || []
items.each do |item|
xml.tag! 'n2:PaymentDetailsItem' do
xml.tag! 'n2:Name', item[:name]
xml.tag! 'n2:Description', item[:desc]
xml.tag! 'n2:Amount', item[:amount]
xml.tag! 'n2:Quantity', item[:quantity]
end
end
end
你会像这样在 Rails 应用程序中传递所有项目:
options = {
:items => [
{
:name => "Tickets",
:quantity => @payment.quantity,
:description => "Tickets for #{@payment.event_name}",
:amount => @payment.unit_price
},
{
:name => "Other product",
:quantity => @other_payment.quantity,
:description => "Something else for #{@other_payment.event_name}",
:amount => @other_payment.unit_price
}
]
:ip => request.remote_ip,
:return_url => url_for(:action=>:confirm, :id=>@payment.id, :only_path=>false),
:cancel_return_url => url_for(:action=>:show, :id=>@payment.id, :only_path=>false)
}
希望效果更好,祝你好运!