6

私はActiveMerchantを使用して、RailsアプリにPaypalのエクスプレスチェックアウトへのアクセスを提供しています。https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_ECCustomizingで説明されているように、レビューページに注文の詳細を含めたいと思います。

これはできますか?

現在、私のコントローラーコードは次のようになっています。

def paypal
  #currently, options is unused, I'm not sure where to send this info
  options = { 
              :L_NAME0=>"Tickets", 
              :L_QTY0=>@payment.quantity, 
              :L_DESC0=>"Tickets for #{@payment.event_name}",
              :L_AMT0=>@payment.unit_price
            }

  #the actual code that gets used
  setup_response = gateway.setup_purchase(@payment.amount,
    :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)
  )
  redirect_to gateway.redirect_url_for(setup_response.token)
end

私がやろうとしていることが可能である場合、何を変更する必要がありますか?

4

4 に答える 4

11

activemerchantバージョンが以上であることを確認してください1.12.0

EXPRESS_GATEWAY.setup_purchase(220,
  :items => [{:name => "チケット", :quantity => 22,:description => "232323のチケット", :amount => 10}],
  :return_url => 'example.com',
  :cancel_return_url => 'example.com'
)

お役に立てれば :)

于 2011-04-25T06:33:27.667 に答える
4

@Soleone私はあなたの解決策を試しますが、うまくいきません。

xml.tag! 'n2:OrderDescription', options[:description]
xml.tag! 'n2:Name', options[:name]
xml.tag! 'n2:Description', options[:desc]
xml.tag! 'n2:Amount', options[:amount]
xml.tag! 'n2:Quantity', options[:quantity]

xml 構造が正しくないと思います。注文項目が複数あるので、このようにする必要があります

xml.tag! 'n2:OrderItems' do
    xml.tag! 'n2:OrderItem' do
        xml.tag! 'n2:Name', options[:name]
        xml.tag! 'n2:Description', options[:desc]
        xml.tag! 'n2:Amount', options[:amount]
        xml.tag! 'n2:Quantity', options[:quantity]
    end
end

しかし、実際には正しい構造がわかりません。今探しています。

====更新

SOAP api doc を見つけました

xml.tag! 'n2:PaymentDetails' do
    xml.tag! 'n2:PaymentDetailsItem' do
        xml.tag! 'n2:Name', options[:name]
        xml.tag! 'n2:Description', options[:desc]
        xml.tag! 'n2:Amount', options[:amount]
        xml.tag! 'n2:Quantity', options[:quantity]
    end
end

しかし、うまくいきません。誰が助けてくれますか?

=====更新====

PaymentDetails パラメータを追加する方法を試しましたが、まだうまくいかないようです。SetExpressCheckoutReq xml のスキーマが見つかりました前のもの、あなたの助けを願っています。

======ファイナル========

私はこの問題を修正しました。新しいバージョンの ActiveMerchant は注文詳細のレビューをサポートし、mwagg はこれに関するパッチをプッシュしました。皆さんはこのバージョンを使用できますhttps://github.com/mwagg/active_merchant

于 2011-01-14T07:21:28.487 に答える
3

次の表で使用可能なパラメーターを確認できます (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

ただし、namequantityおよびamountフィールドは現在、activemerchant ではサポートされていません。リポジトリをフォークして自分で挿入し、プロジェクトのコピーを使用する必要があります。コードを見て、それが他のコードでどのように行われるかを見ると、非常に簡単です。

たとえば、注文名、アイテムの数量、アイテムの単価を追加するには、OrderDescriptiongets の後に次の行を挿入します。

  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) 
}

それがうまくいくことを願っています、頑張ってください!

于 2011-01-14T02:03:57.050 に答える
1

これを機能させるのにも問題がありました。解決策は、すべてのアイテムの金額の合計が注文の小計である必要があり、小計、送料、手数料、および税金の合計が注文の合計値になる必要があるということです。私のペイパルコントローラーは次のようになります。

def begin_paypal
  # ...
  options = express_options(@order)
  # ... 
  response = EXPRESS_GATEWAY.setup_purchase(@order.gross_price_in_cent, options)
  redirect_to EXPRESS_GATEWAY.redirect_url_for(response.token)
end

private
def express_options order
  options = {}
  options[:ip] = request.remote_ip
  options[:order_id] = order.bearbeitungsnummer

  # subtotal, shipping, handling and tax must sum up to the orders total value
  # subtotal must be the sum of all amounts of all items
  options[:subtotal] = order.gross_price_in_cent
  options[:shipping] = 0
  options[:handling] = 0
  options[:tax] = 0

  options[:items] = order.line_items.map do |line_item|
    {
      :name => line_item.product.name,
      :number => line_item.product.kcode,
      :quantity => line_item.quantity,
      :description => line_item.product.beschreibung,
      :amount => line_item.gross_price_in_cent,
      :url => nil
    }
  end
  # ...
end

正常に動作します

于 2011-11-15T12:56:57.427 に答える