2

この問題について:ActiveMerchant + PaypalExpressCheckout + Rails 3.2

Rails3.2アプリでPaypalExpressCheckoutを構築しようとしています。そこにあるチュートリアルのほとんどは時代遅れなので、私はいくつかに従って、PaypalExpressCheckout統合ガイドを読みました。Sandobxとペイパルの情報はすでに設定しています。

ビューから[今すぐ購入]リンクをクリックして支払いを処理しようとすると、次のようになります。

<%= link_to image_tag('http://img36.imageshack.us/img36/249/buttonpaypal.png'),
action: 'checkout', controller: 'orders'%>

次のエラーが発生します。

This transaction is invalid. Please return to the recipient's website to complete
you transaction using their regular checkout flow.

Return to merchant
At this time, we are unable to process your request. Please return to and try
another option.

---私のコントローラー:

class OrdersController < ApplicationController
  include ActiveMerchant::Billing 
  def checkout
   setup_response = ::GATEWAY.setup_purchase(2000,
        :ip                => request.remote_ip,
        :return_url        => url_for('confirm'),
        :cancel_return_url => url_for(root_path)
   ) 
  redirect_to ::GATEWAY.redirect_url_for(setup_response.token)
 end
end

---私のイニシャライザーActiveMerchant.rb:

 ActiveMerchant::Billing::Base.mode = :test
  ::GATEWAY = ActiveMerchant::Billing::PaypalExpressGateway.new(
  :login => "I_PUT_MY_EMAIL_HERE",
  :password => "I_PUT_MY_PASS_HERE",
  :signature => "I_PUT_MY_SIGNATURE_HERE",
  :allow_guest_checkout => true
 )

---私のルート:routes.rb:

 resources :orders do
   # Im not sure why 'get :checkout' by itself doesn't work.
   get :checkout, :on => :new
   get :confirm
   get :complete
 end

「ページ/インデックス」を取得

これが要点です:https ://gist.github.com/11be6cef6a97632343b9

誰かが私に「最近の」チュートリアルを教えてもらえますか、または私がここで間違っていることを理解するのを手伝ってくれますか?

4

2 に答える 2

6

最も簡単な方法は、次のようにすることです。

1.)ペイパルテストアカウントを作成する必要があります。

2.)カートモデルを作成します。

$ rails g model Cart purchased_at:datetime

3.)カートモデルタイプ:

class Cart < ActiveRecord::Base

  def paypal_url(return_url)

    values = {
      # get it form your http://sandbox.paypal.com account
      :business => 'ENTER_THE_SELLER_PAYPAL_EMAIL_ADDRESS',
      :cmd => '_cart',
      :upload => 1,
      :return => return_url,
      :invoice => id
    }
    # These values set up the details for the item on paypal.
       values.merge!({
        # The amount is in cents
        "amount_1" => ENTER_AN_AMOUNT_HERE,
        "item_name_1" => ENTER_THE_ITEM_NAME_HERE,
        "item_number_1" => 1,
        "quantity_1" => 1
      })

    "https://www.sandbox.paypal.com/cgi-bin/webscr?" + values.to_query

  end
end

4.)appllication_controller.rbファイルにこれを追加します

  def current_cart
     session[:cart_id] ||= Cart.create!.id
     @current_cart ||= Cart.find(session[:cart_id])
   end

5.)チェックアウトボタンが必要なビューで、次を追加します。

# 'products_url' is just the url where you would like to redirect
# the user after the transaction
<%= link_to 'Buy with PAYPAL', @cart.paypal_url(products_url) %>

6.)コントローラーで、チェックアウトするビューのアクションを表示します。これを追加します。

def show
  ...
  @cart = current_cart
end

それでおしまい!これは、ラインアイテムを使用せずにこのカートを作成したため、「実際の」カートがないPaypalExpressCheckoutです。ただし、Railscast#141 Paypal Basics http://railscasts.com/episodes/141-paypal-basicsに従って、広告申込情報を追加できます。

于 2012-07-05T20:46:09.100 に答える
4

ここに最近のチュートリアルがあります:http ://spin.atomicobject.com/2011/10/24/integrating-paypal-express-with-rails-3-1-part-1/ 。

于 2012-07-04T05:21:09.217 に答える