Roh*_*hit 5 ruby rubygems paypal ruby-on-rails activemerchant
我想在我的rails应用程序中集成ActiveMerchant.我有一些计划,如果订阅限制用户访问.正如你们所有人都知道基于订阅的应用程序是什么,我不打算解释我的应用程序.请告诉我一些实现这一目标的例子.我已经查看过轨道广播141到146,但Ryan只演示了Paypal Web Payments标准和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
Run Code Online (Sandbox Code Playgroud)您想了解PaypalRecurringAPI和PaypalExpressGateway/PayPalGateway,以了解处理哪些选项以及xml请求的位置.
编辑关于paypal和定期计费的更新,修订的截屏视频是使用单独的PayPal-recurring gem完成的.如果您无法使用ActiveMerchant,这可能会有所帮助.
活跃商家支持其某些网关的定期付款(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。在第 3 方托管支付页面的情况下,它可以更轻松地接受付款并处理 Pci DSS 要求。
归档时间: |
|
查看次数: |
1680 次 |
最近记录: |