, , ?
ActiveMerchant , PaypalGateway, PaypalExpressGateway.
-, . ( , ):
- ,
:initial_amount. Item billing_agreement[:description]. , , , . IPN. . ...
class PaymentsController < ApplicationController
include ActiveMerchant::Billing
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),
)
if payment_request.success?
redirect_to PAYPAL_EXPRESS_GATEWAY.redirect_url_for(payment_request.token)
else
render :text => payment_request.inspect.to_s and return
end
end
def confirm
profile = PAYPAL_EXPRESS_GATEWAY.recurring(@subscription.price_in_cents, nil,
:description => 'Subscription agreement',
: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]
)
@debug = {:params => params.inspect.to_s, :profile => profile.inspect.to_s }
render :text => @debug.to_s and return
end
def notification
log = Logger.new 'log/ipn.log'
log.debug params.inspect
render :text => params.inspect.to_s and return
end
end
PaypalRecurringAPI PaypalExpressGateway/PayPalGateway, , xml.
edit. , paypal-recurring gem. , , ActiveMerchant.