We operate a few sites with subscriptions. Until recently, the subscription cost has been fixed with just three plan options - monthly, 6 monthly or annually. However, we now want to increase the cost on one site for new members but not existing members. Existing members will have their current subscription rate locked for life.
Currently, the three subscription rates are declared in a parameters file:
The price code is passed to Stripe during the checkout process.our $stripe_price_1 = 'price_123245'; our $stripe_price_6 = 'price_123267'; our $stripe_price_12 = 'price_123289';
Having multiple prices in the future means we need to adopt a different approach. Users have the option to change between payment plans so they can swap from monthly or annually, etc. Therefore, we need to know which pricing level they are on as well as the plan. We can (and currently do) easily get the plan from Stripe. But getting the level is more tricky. We'd have to get the price code and work backwards.
So, I am thinking of adding two fields to the Subscription table of the database - priceLevel and pricePlan - and replacing the above declarations with a two dimensional Perl array of hashref:
The two dimensions of the array corresponding to the two newly added database fields.my @price; $price[1,1] = { 'name' => 'Early Adopter', 'plan' => 1, 'length' => 1, 'price' => 3.49, 'stripe' => 'price_123245', }; $price[1,6] = { 'name' => 'Early Adopter', 'plan' => 1, 'length' => 6, 'price' => 18.99, 'stripe' => 'price_123267', }; $price[1,12] = { 'name' => 'Early Adopter', 'plan' => 1, 'length' => 12, 'price' => 32.49, 'stripe' => 'price_123289', }; $price[2,1] = { 'name' => 'First Increase', 'plan' => 2, 'length' => 1, 'price' => 3.99, 'stripe' => 'price_123445', }; $price[2,6] = { ... }; $price[2,12] = { 'name' => 'First Increase', 'plan' => 2, 'length' => 12, 'price' => 33.99, 'stripe' => 'price_123489', }; $price[3,1] = { ... }; $price[3,6] = { ... }; $price[3,12] = { ... };
I have two doubts about this approach...
Any advice very welcome...
In reply to Multidimensional arrays by Bod
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |