Hi,

Let's say we have the follwing user levels setup and pricing:
Monthly Quarterly Yearly
1st \$10 \$30 \$100
2nd \$20 \$60 \$200
3rd \$30 \$90 \$300
4th \$40 \$120 \$400

<scenario #1>
1. User signup with 1st level at \$100/year.
2. During the 2nd month on 20th day, user decides to upgrade to 3rd level at \$300/year.
3. How does current PayPal gateway handle this situation?
4. Does it simply charge addition \$200 for the 1st year and \$300 there after? Or does it calculate the difference on some kind of prorate formula? If so what is that?

<scenario #2>
1. User signup with 3rd level at \$300/year.
2. During the 7th month on 5th day, user decides to downgrade to 2nd level at \$200/year.
3. How does current PayPal gateway handle this situation?
4. Does it simply refund the difference of \$100 for the 1st year and charge \$200 there after? Or does it calculate the difference on some kind of prorate formula? If so what is that?

• Timothy Bowers

Hey there.

For scenario #1 I believe it would pro rata the current payment as if it were on the next plan. Then a new subscription date would be set for the next payment.

For scenario #2 You see Paypal couldn't issue any kind of refund, they can only be done within 60 days of the transaction date. So I would assume it would pro rata the current payment as if it were on the lower plan and then schedule a new payment for when that's used up just like it would in Scenario #1

It's pretty much how memberships are handled here at DEV, the plugin which handles this is similar to Pro Sites.

Take care.

• luckyseven_f

Hi Timothy,

Thanks for your response. We are currently developing an alternative gateway to PayPal for Pro Sites for our local market.

If PayPal gateway is using Pro rata formula to calculate the handling of upgrade/downgrade/cancel routine, could you direct me to the line numbers in gateway-paypal.php file?

• luckyseven_f

Hi Timothy,

If we use 30 days, the pro rata calculation would come out something like this for above scenarios:

<scenario #1>
* \$100 / 12 / 30 = \$.27 daily cost * 50 days = \$16.66 used amount

* \$100 - \$16.66 = \$83.33 remainder

* \$300 applied - \$83.33 = \$216.66 2nd month 21 day new contract starts with this amount being charged

<scenario #2>
* \$300 / 12 / 30 = \$.83 daily cost * 185 days = \$154.16 used amount

* \$300 - \$154.16 = \$145.83 remainder

* \$145.83 - \$100 applied = \$45.83 credit remains and 7th month 6th day new contract starts without any new charging

* Credit amount of \$45.83 will be automatically reimbursed on next contract period

Can you please confirm whether my understanding of pro rata calculations is correct?

Thx.

• Timothy Bowers

You can find the math here:

/pro-sites/pro-sites.php line 1321

I won't paste it all but it starts with:

``//some complicated math calculating the prorated amt left and applying it to the price of new plan``

Take care.

• luckyseven_f

Hi Timothy,

We are trying to use calc_upgrade function in our self-developed payment gateway. But that function it is only returning a time stamp. And I have filled all the parameter in that function.

Could you please guide me on how to use this function from a payment gateway add-on to Pro Sites plugin.

• Timothy Bowers

Hey there.

That's what the function is intended to do:

/*
* This is rather complicated, but essentialy it works like:
* Pass it a new amt and period, then it finds the old amt
* and period, to calculate how much money is unused from their last payment.
* Then it takes that money and applies it to the cost per day of the new plan,
* returning the timestamp of the day the first payment of the new plan should take place.
*/

If you look at the function it's this which is returned:

returning the timestamp of the day the first payment of the new plan should take place.

Take care.