2010-11-11 100 views
5

我正在嘗試將ActiveMerchant集成到我的Rails應用中。我有一定的計劃,如果訂閱限制用戶訪問。正如你們所有人都知道什麼是基於訂閱的應用程序,我不會解釋我的應用程序。請爲此提供一些示例。我已經看過了第141到146集的列表,但Ryan只演示了Paypal Web Payments Standard和Paypal Web Payments Pro。我也讀過一堆博客,但沒有幫助。ActiveMerchant是否支持基於訂閱的交易

請幫忙。

在此先感謝。

+0

本文相關文章也許對您有所幫助。 http://stackoverflow.com/questions/1683929/paypal-recurring-billing-and-activemerchant – 2010-11-11 15:13:20

回答

0

活動商戶支持部分網關的定期付款(https://github.com/Shopify/active_merchant/wiki/GatewayFeatureMatrix)。

每種語法都有稍微不同的語法(https://github.com/Shopify/active_merchant/blob/master/lib/active_merchant/billing/gateways/authorize_net_cim.rb),但可以實現您想要的功能。

但是我會推薦你​​選擇你的支付網關併爲它使用特定的APi。 AM有些落後(從我的經驗來看),經常性支付不是它的主要目標。

還有一些服務可以爲您處理所有的網關交互,並且您只需處理那裏的API。在第三方託管支付頁面的情況下,它可以更輕鬆地接受付款並處理Pci DSS要求。

+0

我想使用貝寶作爲網關,我也希望貝寶來處理交易,即如果用戶點擊訂閱按鈕,他被採取到paypal的網站,所有的交易都在那裏進行,如果IPN成功發送到我的網站,並且在交易完成後用戶回到我的網站(我認爲這有點像Paypal Web Payments Standard)。這可能是 – Rohit 2010-11-11 12:39:33

+0

這可以在AM之外的Paypals網站上處理。 – 2010-11-11 12:59:44

+0

但我想用PayPal做。有沒有可能請推薦一些東西。 – Rohit 2010-11-16 05:22:45

9

比從未更好的遲到,是吧?

ActiveMerchant的實際主分支包含集成到PaypalGatewayPaypalExpressGateway中的重複類。

這是一個演示片段,它的工作原理。我只是不知道幾點(我會盡快更新的答案,因爲我想通出來),它們分別是:

  • 只需設置結算協議沒有表現出任何價格,無論設置:initial_amount的。包括物品會顯示物品的價格高於billing_agreement[:description]。所以我不確定這是如何影響捕獲的,這正是我現在測試的結果。
  • IPN通知。它們在以下代碼片段中缺失。更新後...

    class PaymentsController < ApplicationController 
        include ActiveMerchant::Billing 
    
    
        # GET /subscriptions/:id/checkout 
        def checkout 
        payment_request = PAYPAL_EXPRESS_GATEWAY.setup_purchase(@subscription.price_in_cents, 
         :billing_agreement => { 
          :type => 'RecurringPayments', 
          :description => 'Subscription agreement', 
         }, 
    
         :currency => 'CHF', 
         :no_shipping => true, 
         :allow_guest_checkout => true, 
         :allow_note => false, 
         :initial_amount => @subscription.price_in_cents, 
         :locale => 'de', 
         :ip => request.remote_ip, 
         :return_url => url_for(:action => :confirm, :only_path => false), 
         :cancel_return_url => url_for(:action => :cancel, :only_path => false), 
         # Looks like :notify_url is not used here, but in the next section 
        ) 
    
        if payment_request.success? 
         redirect_to PAYPAL_EXPRESS_GATEWAY.redirect_url_for(payment_request.token) 
        else 
         # Render something informal 
         render :text => payment_request.inspect.to_s and return 
        end 
        end 
    
        # POST /subscriptions/:id/confirm 
        # params having token and PayerID 
        def confirm 
        profile = PAYPAL_EXPRESS_GATEWAY.recurring(@subscription.price_in_cents, nil, 
         :description => 'Subscription agreement', 
         :start_date => Date.tomorrow, # PayPal throws an error if the date is not in the future 
         :period => 'Year', 
         :frequency => 1, 
         :amount => @subscription.price_in_cents, 
         :currency => 'CHF', 
         :initial_amount => @subscription.price_in_cents, 
         :auto_bill_outstanding => true, 
    
         :token => params[:token] 
        ) 
    
        # profile has profile_id and profile_status. remember status because this gets updated via IPN. 
        @debug = {:params => params.inspect.to_s, :profile => profile.inspect.to_s } 
    
        # Render something informal 
        render :text => @debug.to_s and return 
        end 
    
    
        # implement instead of just log 
        def notification 
        log = Logger.new 'log/ipn.log' 
        log.debug params.inspect 
        render :text => params.inspect.to_s and return 
        end 
    
    
        # Private methods omitted 
    
    end 
    

你想看看到PaypalRecurringAPIPaypalExpressGateway/PayPalGateway看哪個選項的處理方法,並在哪個地方的XML請求。

編輯關於貝寶和經常性結算的新版經過修訂的截屏是使用獨立的paypal-recurring寶石完成的。如果你無法使用ActiveMerchant,這可能會有所幫助。

+0

根據[this](https://github.com/activemerchant/active_merchant/issues/1584),他們將放棄對ActiveMerchant v2定期付款的支持 – 2015-10-29 13:16:57