Skip to content
This repository has been archived by the owner on Dec 19, 2019. It is now read-only.

start_at when creating recurring profile #23

Open
Bushjumper opened this issue Jan 17, 2013 · 11 comments
Open

start_at when creating recurring profile #23

Bushjumper opened this issue Jan 17, 2013 · 11 comments

Comments

@Bushjumper
Copy link

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?

@v1nc3ntlaw
Copy link

Yes, I misunderstanding start_time, too. This explain save my time. Thanks!

@samuelsimoes
Copy link

I think this should be in the docs too!

@theDanielJLewis
Copy link

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?

@rapcal
Copy link

rapcal commented Jun 10, 2014

@danieljlewis if you want monthly payments, just use start_at: Date.current + 1.month

@theDanielJLewis
Copy link

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

@rapcal
Copy link

rapcal commented Jun 10, 2014

@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

@theDanielJLewis
Copy link

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!

@rapcal
Copy link

rapcal commented Jun 10, 2014

Glad I could help

@johhansantana
Copy link

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?

@samuelsimoes
Copy link

@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:https://blog.samuelsimoes.com/rails/2014/11/01/part-1-rails-with-paypal-subscription-guide.html, maybe it can help you.

@johhansantana
Copy link

@samuelsimoes thank you, I will read it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants