Calculate new subscription cost on upgrade / downgrade - php

I am currently developing a subscription system for a web application.
I need help regarding the approach for new subscription costs when a user decides to downgrade or upgrade their account.
I created a image to make an example of a user that keeps changing levels.
A user can choose to pay each month, quarter or year.
I want to add a discount when the user decides to downgrade. The discount is currently factored into the new cost using this formula:
[final plan cost] = [new plan cost] * 12 - [discount] / [12 - month / 3 - quarter / 1 - year]
If we have a user that keeps changing plans like this, how can I calculate the discount dynamically? It's easy for one change - I can take the difference between the two plans and multiply it for each payment that was made before. But I need some help regarding the approach for several changes, and how I can keep track of the discount.

I think you should put all that information in a database table and just call the cells. If the user it at the plan where they are getting the discount based on the sub; then
eg
if(price is this)
discount is {discount value from the database} x price of subscription..
You will not have to worry if someone changes their subscription in the middle of the month, all you have to do is put that information in a different table and at the end of the month all the application would do is apply the new subscription and do the calculations. It is not hard just the approach..

Related

How to calculate shipping cost based on Woocommerce booking time slots?

I have a woocommerce shop with the woocommerce booking system. At my website, you can book meal deliveries based on time slots. I used the booking system because some meals are available some days. And, you can book meals on multiple days in one order.
My problem is that I want to apply a fixed shipping cost (3,5euros) based on deliveries/time slots. I can’t group meals of the same delivery in one order.
My question is : is there a way to make a php script to calculate shipping cost based on delivery time slots?
My current cart page and what i need
currently, i use this calculation method on woocommerce settings : 3,5 * [qty]
The problem in my case is that don't want to charge multiple times for the same delivery.
Thank you!

Stripe: Subscription and recurring plans

I want to know is there any scenario supported by stripe with recurring plans,
If a user subscribes to a plan A that costs $300 and its billing cycle is 3 months and he/she upgrades to
a new plan i.e., Plan B costs $600 i.e., also for 3 months recurring period, after 1 month or less subscription period of using plan A then we need
to upgrade that user to plan B with following conditions:
-100$ should be deducated from 300$ for 1 month or less than 30 days and 200 will be remaining in his wallet
-He/she will have to pay 600-200(Remaining from plan A payment)=400$ for the new plan i.e., Plan B
-Similarly, if He/she subscribed to plan B first then he can also subscribe to plan A after the usage of 1 month or less
than 30 days then the deducated amount from his wallet would be 600/3=200$ the deducated amount will be 200$ and the remaining amount is
400$ that will be added in his wallet then if he/she subscribed to plan A then there will be deductions of 300 from 400$ which is in his/her wallet now
so his/her remaining balance will be 100$.
-Please explain is it possible with the stripe? If yes then please help me for this issue.
Sorry for the english grammatical mistakes
Thank you
When you update a subscription, there is a prorate option, which defaults to true, so that the user will automatically be charged for any difference in the price of the new plan, adjusted for their time in the current billing period.
https://stripe.com/docs/api#update_subscription-prorate
That should be all that's required for your first example.
I don't totally follow on your other examples, but it seems that you could simplify it by simply using multiple plans.
https://stripe.com/docs/billing/subscriptions/multiplan
Generally, either you have different tiers of plans, which users might upgrade/downgrade, in which case you likely just want to update their existing subscription with proration. Or, if users might be subscribing to multiple plans at the same time, then you would simply allow users to sign up for multiple plans, which Stripe fully supports. There shouldn't be much of a reason to try to do both at once for the same set of plans.

How to build a monthly subscription with Stripe?

I am working with Stripe subscription and I don't want to create different plans with xy users included but set the price simple to 10$ per user per month. See the pricing at https://www.box.com/en_GB/pricing/ to get an idea what I mean.
How can i realize that subscription behavior in Stripe? Do I need to create an own plan for every count of users? (eg. oneuserplan 10$, twouserplan 20$, threeuserplan 30$,.....)
Or can I somehow multiply the 10$/month base subscription with with the count of users?
You can find a quantity field in stripe documentation
The quantity you'd like to apply to the subscription you're creating.
For example, if your plan is $10/user/month, and your customer has 5
users, you could pass 5 as the quantity to have the customer charged
$50 (5 x $10) monthly....

E-Commerce / Cart - Stock

just a logic question.
I'm building a shop based on Laravel and other stuff but that's not the point.
The point is, how to handle stock addition / deduction.
Right now, I have a package (my item) with the qty of (let's say) 20 in the shop. Every time a user try to add this item (and the qty) to the cart or updates the qty of the item in the cart, I check if:
- Count of QTY of the PAID orders is < QTY OF ITEM - I do not count the qty of other orders which are not paid.
Is this correct? Or do I have to include orders with "pending payment" or other ?
Quite difficult to find the right way. What is the best way to manage stock ?
I'd say it all depends on how the logic and implementation you want to add is.
Think of it this way on a case-by-case scenario (me being the customer):
If i am allowed to create an order and never pay for it (changed my mind, out of money, forgot about it)
Will you reserve the stock for me forever?
If i create an order, i come back to pay a week later but you are out-of-stock
Will you make sure i get the item somehow?
Will you prompt me that the stocks have changed for some of my items and i need to review my order?
Will you just cancel my order as stock in not available?
If i make an order and while i am trying to find my credit card to pay someone else buys the last items before me, what will you do then?
Conclusion:
In case 1 the store is at a disadvantage and probably will face problems for keeping stock for items that are never going to be actually purchased.
In case 2 it was my fault for not making sure i paid for the orders promised in a reasonable amount of time so i would accept the scenario of "losing" the item
In case 3 it was probably the system's fault for not keeping the items for me as promised when making my order as it could be a matter of minutes or even seconds.
From this i would suggest you used a time based reservation of items, prompting the users to settle their payments in a reasonable amount of time (1 day, 1 week, 1 month... it depends on you) for which their orders are considered active.
By counting the active pending orders and just cancelling them after some time, you would keep customers happy since you are delivering as promised and them feeling obligated to pay their order or risk losing up on the items in their order.

how to implement dynamic calculating price in magento based on weight ?

Hi i’m developing a eCommerce site in Magento for jewellery business and its based on a “weight”, not the price because gold rate is changing in day by day or more then 3 times in a day.So it is not possible to change the product price every time according to gold rate. Then, how to manage the prices on this scenario?
Example case: Today I have added a 18K gold ring of 10gm to my site and right now gold rate is Rs30,000 per 10gm, so today price of this ring is Rs30,000 but, Next day the rate will be changed (Rs32,000 per 10gm) then, my product price must be changed from Rs30,000 to Rs32,000.
This is not possible to update the price of all products every time.
I am using Magento platform. Please, Share your idea regarding this situation.
To make this simple, you should work on a 2 ways solutions.
In the frontend, do not show price ($_product->getPrice()) but just show the real price according to weight.
Example if you have price/grm stored in the backend use $product->getWeight * Mage::getStoreConfig('mycompany/gold/dayprice').
That way price will be shown dynamically in the product page or list page.
Now you should use an Observer on the add to cart event to change the price to the good one.
This way, don't matter what price is set on the product because showing and adding will use the formulae.

Categories