ActiveMerchant是否支持基于订阅的事务 [英] Does ActiveMerchant support Subscription Based transaction
问题描述
我正在尝试将ActiveMerchant集成到我的Rails应用程序中。我有一定的计划,如果订阅限制用户访问。正如你们所有人都知道什么是基于订阅的应用程序,我不会解释我的应用程序。请为此提供一些示例。我已经看过了第141到146集的列表,但Ryan只演示了Paypal Web Payments Standard和Paypal Web Payments Pro。我也读了一些博客,但没有帮助。
请帮助。
谢谢Advance。
迟到比从未好过吧?
ActiveMerchant的实际主分支包含一个集成到 PaypalGateway
和 PaypalExpressGateway
。
下面是一个适用的演示片段。我只是不确定几点(我会尽快更新答案),它们是: IPN通知。它们在以下代码片段中缺失。更新以下...
:initial_amount
,仅设置结算协议就不会显示任何价格。包括一个项目将显示该项目的价格高于 billing_agreement [:description]
。所以我不确定这是如何影响捕捉的,这是我现在测试的。
类PaymentsController< ApplicationController的
包括ActiveMerchant ::结算
#GET /订阅/:ID /结帐
DEF结账
payment_request = PAYPAL_EXPRESS_GATEWAY.setup_purchase(@subscription。 price_in_cents,
:billing_agreement => {
:type =>'RecurringPayments',
:description =>'订阅协议',
},
:currency =>'CHF',
:no_shipping => true,
:allow_guest_checkout => true,
:allow_note => false,
: initial_amount => @ subscription.price_in_cents,
:区域设置=> '去',
:IP => request.remote_ip,
:return_url => url_for(:动作=> ;:confirm,:only_path => false),
:cancel_return_url => url_for(:action =>:cancel,:only_path => false),
#看起来像:notify_url不是在这里使用,但在下一节
)
如果payment_request.success?
redirect_to PAYPAL_EXPRESS_GATEWAY.redirect_url_for(payment_request.token)
else
#呈现一些非正式的
render:text => payment_request.inspect.to_s并返回
结束
结束
#POST /订阅/:id / confirm
#带有令牌和PayerID的参数
def确认
轮廓= PAYPAL_EXPRESS_GATEWAY.recurring(@ subscription.price_in_cents,零,
:描述=> '订阅协议',
:START_DATE => Date.tomorrow,#贝抛出如果错误日期不在将来
: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有profile_id和profile_status。记住状态,因为这通过IPN更新。
@debug = {:params => params.inspect.to_s,:profile => profile.inspect.to_s}
#渲染一些非正式的
render:text => @ debug.to_s并返回
结束
#实现而不是仅仅记录
def通知
log = Logger.new'log / ipn.log '
log.debug params.inspect
render:text => params.inspect.to_s并返回
结束
#私有方法省略
结束
您想查看 PaypalRecurringAPI 和 PaypalExpressGateway / PayPalGateway 查看哪些选项被处理以及xml请求在哪个位置。
编辑关于PayPal和定期结算的更新的,经过修改的截屏视频是通过单独的贝宝 - 复发宝石。如果你无法使用ActiveMerchant,这可能会有所帮助。
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.
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 thebilling_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.
这篇关于ActiveMerchant是否支持基于订阅的事务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!