Open Bushjumper opened 11 years ago
Yes, I misunderstanding start_time, too. This explain save my time. Thanks!
I think this should be in the docs too!
This is also giving me double charges. I know this thread is old, but what's the code for setting that first recurring charge to one month from now?
@DanielJLewis if you want monthly payments, just use start_at: Date.current + 1.month
Thanks for the reply! I didn't expect one so quickly.
The difficulty is that my service offers both monthly and yearly subscription plans. So would it be better to use your code (with a simple conditional variable to make it 1.month or 1.year), or to setup a trial?
:trial_length => 1,
:trial_period => period,
:trial_frequency => 1
@DanielJLewis Can you use params? Then you could do something like: start_at: params[:plan] == "monthly" ? Date.current + 1.month : Date.current + 1.year
This wouldn't handle the trial period, though. For doing so, you could do something like:
start_at: (params[:plan] == "monthly" && account.expiration_date < Date.current) ? Date.current + 1.month : params[:plan] == "monthly" ? account.expiration_date + 1.month : (params[:plan] == "yearly" && account.expiration_date < Date.current) ? Date.current + 1.year : params[:plan] == "yearly" ? account.expiration_date + 1.year : nil
The trial period was only my thought of how to work around this issue. I'm not the Rails developer myself—I'm the one who hired the overseas devs. I want to launch and I spotted this glitch testing with live users (the problem doesn't show up in sandbox). So that to say I don't understand everything here. But here's a preview of the code. The if/else statement was already there, I just tapped into it for myself.
period = ''
delay = ''
if plan.duration == 1
period = "monthly"
delay = Date.current + 1.month
else
period = "yearly"
delay = Date.current + 1.year
end
ppr = PayPal::Recurring.new({
:amount => plan.price,
:currency => "USD",
:description => plan.title,
:frequency => 1,
:token => @user.paypal_token,
:period => period,
:reference => "1234",
:payer_id => payerID,
:start_at => delay,
:failed => 1,
:outstanding => :next_billing
})
This seems to work perfectly now. I get the instant initial payment, and their next billing date is set to start the recurring payment (1 month away for monthly, 1 year away for yearly).
Thanks for your help!
Glad I could help
How am I able to know the end_date of a monthly subscription, I want to know if the user cancels their recurring payment at 15 days before their subscription ends, how do I handle this?
@jsantana90 if I understood your question the notification has this information on next_payment_date
getter. If your user cancels the subscription you just need set the subscription's status as "canceled", but every time that you need check if it's valid you gonna need chekc some paid_until
stored attribute on the subscription. I wrote an extensive tutorial about this topic http://blog.samuelsimoes.com/rails/2014/11/01/part-1-rails-with-paypal-subscription-guide.html, maybe it can help you.
@samuelsimoes thank you, I will read it.
When creating the recurring profile, I assumed that start_at would be Time.now. This causes a double charge with PayPal: the initial checkout charge, and the first payment for the recurring profile.
The start_at should be the date that the first recurring payment should be taken eg. a month from now if your frequency is monthly.
Could the docs be updated to reflect this as it's not explicit?