ActiveMerchant是否支持基于订阅的交易[英] Does ActiveMerchant support Subscription Based transaction

本文是小编为大家收集整理的关于ActiveMerchant是否支持基于订阅的交易的处理方法,想解了ActiveMerchant是否支持基于订阅的交易的问题怎么解决?ActiveMerchant是否支持基于订阅的交易问题的解决办法?那么可以参考本文帮助大家快速定位并解决问题。

问题描述

我正在尝试将 ActiveMerchant 集成到我的 rails 应用程序中.我有某些计划,如果订阅限制用户访问.你们可能都知道什么是基于订阅的应用程序,所以我不打算解释我的应用程序.请给我一些例子来实现这一点.我已经看过 railscasts 第 141 到 146 集,但 Ryan 只演示了 Paypal Web Payments Standard 和 Paypal Web Payments Pro.我也阅读了很多博客,但没有帮助.

请帮忙.

提前致谢.

推荐答案

迟到总比没有好,对吧?

ActiveMerchant 的实际主分支包含一个集成到 PaypalGateway 和 PaypalExpressGateway 中的循环类.

这是一个有效的演示片段.我只是不确定几点(我会在弄清楚后立即更新答案),它们是:

  • 无论设置 :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 一起工作,这可能会有所帮助.

本文地址:https://www.itbaoku.cn/post/786466.html