ActiveMerchant 是否支持基于订阅的交易

发布于 2024-10-02 09:57:44 字数 264 浏览 1 评论 0原文

我正在尝试将 ActiveMerchant 集成到我的 Rails 应用程序中。我有某些计划,如果订阅就会限制用户访问。由于你们所有人可能都知道什么是基于订阅的应用程序,因此我不会解释我的应用程序。请给我推荐一些实现这一目标的例子。我已经看过 Railscasts 第 141 集到 146 集,但 Ryan 只演示了 Paypal Web Payments Standard 和 Paypal Web Payments Pro。我也读了很多博客,但没有帮助。

请帮忙。

提前致谢。

I am trying to integrate ActiveMerchant in my rails app. I have certain plans that if subscribed limit the user access. As you all guyz might be knowing what a subscription based app is, I am not going into explaining my app. Please suggest me some examples for making this happen. I have already viewed the railscasts episodes 141 through 146 but Ryan has only demonstrated Paypal Web Payments Standard and Paypal Web Payments Pro. I have also read a bunch of blogs but it didn't help.

Please help.

Thanks in Advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甜扑 2024-10-09 09:57:44

迟到总比不到好,不是吗?

ActiveMerchant 的实际主分支包含一个集成到 PaypalGateway 和 PaypalExpressGateway 中的重复类。

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

  • 无论设置如何:initial_amount,仅设置计费协议都不会显示任何价格。包含商品将在 billing_agreement[:description] 上方显示该商品的价格。所以我不确定这如何影响捕获,这就是我这些天正在测试的内容。
  • IPN 通知。它们在下面的代码片段中丢失了。更新如下...

    类 PaymentsController <应用控制器
      包括 ActiveMerchant::Billing
    
    
      # GET /订阅/:id/结帐
      默认结帐
        payment_request = PAYPAL_EXPRESS_GATEWAY.setup_purchase(@subscription.price_in_cents,
            :计费协议=> {
                :类型=> “定期付款”,
                :描述=> ‘认购协议’,
            },
    
            :货币=> '瑞士法郎',
            :no_shipping =>真的,
            :allow_guest_checkout =>真的,
            :allow_note =>;错误的,
            :初始金额=> @subscription.price_in_cents,
            : 语言环境 => '德',
            :ip =>请求.remote_ip,
            :return_url => url_for(:action => :confirm, :only_path => false),
            :cancel_return_url => url_for(:action => :取消, :only_path => false),
            # 看起来 :notify_url 没有在这里使用,而是在下一节中使用 
        )
    
        如果 payment_request.success?
          重定向到 PAYPAL_EXPRESS_GATEWAY.redirect_url_for( payment_request.token )
        别的
          # 渲染一些非正式的东西
          渲染:文本=> payment_request.inspect.to_s 并返回
        结尾
      结尾
    
      # POST /订阅/:id/确认 
      # 具有 token 和 PayerID 的参数
      确定确认
        配置文件 = PAYPAL_EXPRESS_GATEWAY.recurring(@subscription.price_in_cents, nil, 
            :描述=> ‘认购协议’,
            :开始日期 => Date.tomorrow, # 如果日期不是将来的日期,PayPal 会抛出错误
            :句号=> '年',
            :频率=> 1、
            :金额=> @subscription.price_in_cents,
            :货币=> '瑞士法郎',
            :初始金额=> @subscription.price_in_cents,
            :auto_bill_outstanding =>真的,
    
            :令牌=>参数[:令牌]
        )
    
        # 配置文件有 profile_id 和 profile_status。记住状态,因为它通过 IPN 更新。
        @debug = {:params =>; params.inspect.to_s, :profile => profile.inspect.to_s }
    
        # 渲染一些非正式的东西
        渲染:文本=> @debug.to_s 并返回
      结尾
    
    
      # 实施而不是仅仅记录
      默认通知
        日志 = Logger.new 'log/ipn.log'
        log.debug params.inspect
        渲染:文本=> params.inspect.to_s 并返回
      结尾
    
    
      # 省略私有方法
    
    结尾
    

您想查看 PaypalRecurringAPIPaypalExpressGateway< /a> / PayPalGateway 查看处理哪些选项以及在 xml 请求的哪个位置。

编辑关于贝宝和定期计费的更新、修订的截屏视频是通过单独的贝宝-重复出现的宝石。如果您无法让它与 ActiveMerchant 一起使用,这也许会有所帮助。

Better late than never, huh?

The actual master branch of ActiveMerchant contains a recurring class integrated into both the PaypalGateway and PaypalExpressGateway.

Here's a demo snippet which works. I'm just not sure about a few points (I will update the answer as soon as I figured them out), which are:

  • Just setting the billing agreement does not show any price regardless of setting :initial_amount. Including an Item will show the item's price above the billing_agreement[:description]. So I am not sure how this affects capturings, which is what I am testing these days.
  • IPN notifications. They're missing in the following snippet. Update following...

    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
    

You want to have a look into PaypalRecurringAPI and PaypalExpressGateway / PayPalGateway to see which options are processed and in which place of the xml request.

edit The newer, revised screencast about paypal and recurring billing is done with a separate paypal-recurring gem. Maybe this helps if you can't get it to work with ActiveMerchant.

-残月青衣踏尘吟 2024-10-09 09:57:44

活跃商家支持其某些网关的定期付款 ( 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 要求。

Active merchant supports recurring payments for some of its gateways ( https://github.com/Shopify/active_merchant/wiki/GatewayFeatureMatrix ).

Each has slightly different syntax ( https://github.com/Shopify/active_merchant/blob/master/lib/active_merchant/billing/gateways/authorize_net_cim.rb) but can accomplish what you want.

I would recommend however you pick your payment gateway and use a specific APi for it. AM lags behind somewhat (from my experience) and recurring payments are not its primary goal.

There are also services out there that will handle all the gateway interaction for you and you just deal with there API. It makes it easier to accept payment and handle Pci DSS requirements in the case of 3rd party hosted payment pages.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文