次の表で使用可能なパラメーターを確認できます (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
、quantity
およびamount
フィールドは現在、activemerchant ではサポートされていません。リポジトリをフォークして自分で挿入し、プロジェクトのコピーを使用する必要があります。コードを見て、それが他のコードでどのように行われるかを見ると、非常に簡単です。
たとえば、注文名、アイテムの数量、アイテムの単価を追加するには、OrderDescription
gets の後に次の行を挿入します。
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)
}
それがうまくいくことを願っています、頑張ってください!