Environment:
Ruby 1.9.2
Rails 3.2.8
gem 'ActiveMerchant' 1.34.1
I want to use Paypal recurring payment option for auto-renewal option.
For this, I am using Paypal payment option which goes to paypal website for allowing user to login and confirm payment and then process.
It is working fine for normal payment (not recurring payment). For normal payment, I used:
In Class:
ActiveMerchant::Billing::Base.mode = :test
@@paypal_express_gateway = ActiveMerchant::Billing::PaypalExpressGateway.new(
:login => '[email protected]',
:password => 'password',
:signature => 'Signature'
)
In express_checkout
method:
setup_response = @@paypal_express_gateway.setup_purchase(@@amount,
:ip => request.remote_ip,
:return_url => url_for(:action => 'confirm', :only_path => false),
:cancel_return_url => url_for(:action => 'new', :only_path => false)
)
redirect_to @@paypal_express_gateway.redirect_url_for(setup_response.token)
In confirm
method:
details_response = @@paypal_express_gateway.details_for(params[:token])
Then details_response
returns with success method true
or false
. And I send it to complete or error page. That is I want in recurring payment.
For recurring payment with PaypalExpressCheckout, I used following:
In class:
ActiveMerchant::Billing::Base.mode = :test
@@paypal_express_gateway = ActiveMerchant::Billing::PaypalExpressGateway.new(
:login => '[email protected]',
:password => 'password',
:signature => 'Signature'
)
In express_checkout
method:
setup_response = @@paypal_express_gateway.setup_purchase(@@amount, <br>
:ip => request.remote_ip, <br>
:return_url => url_for(:action => 'confirm', :only_path => false),
:cancel_return_url => url_for(:action => 'new', :only_path => false)
)
redirect_to @@paypal_express_gateway.redirect_url_for(setup_response.token)
In confirm
method:
details_response = @@paypal_express_gateway.recurring(@@amount, "", options = {
:token => params[:token],
:period => "Month",
:frequency => 3,
:start_date => Time.now,
:description => "Checking recurring auto-renewal"
})
Now I am getting error undefined method "add_credit_card" for #<ActiveMerchant::Billing::PaypalExpressGateway:0x00000006c831a0>
The recurring method is defined Here (Active Merchant) which will return profile_id.
So I want to use PaypalExpressGateway (not PaypalGateway) for recurring payment where developer can't send credit_card details to recurring method as Payment is done on Paypal website.
Then why is credit_card parameter being used in case of PaypalExpressGateway. And method "build_create_profile_request(options)" called by recurring
method should not check for credit_card as I am not passing any parameter 'credit_card' in options.(see line no 127 in given link)
Please check code and let me know where I am wrong. If anyone can provide me prepared code, then it will be more useful.
I tried many blogs and solutions but not succeed. Please give me solution for this ASAP.