Bod has asked for the wisdom of the Perl Monks concerning the following question:
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...
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Multidimensional arrays
by choroba (Cardinal) on Jun 06, 2023 at 15:22 UTC | |
by Bod (Parson) on Jun 06, 2023 at 15:52 UTC | |
by choroba (Cardinal) on Jun 06, 2023 at 16:00 UTC | |
by Bod (Parson) on Jun 06, 2023 at 17:12 UTC | |
by ablanke (Monsignor) on Jun 06, 2023 at 22:51 UTC | |
by hv (Prior) on Jun 06, 2023 at 16:02 UTC | |
by Bod (Parson) on Jun 06, 2023 at 17:15 UTC | |
Re: Multidimensional arrays
by eyepopslikeamosquito (Archbishop) on Jun 07, 2023 at 01:28 UTC | |
by Bod (Parson) on Jun 07, 2023 at 20:49 UTC | |
by eyepopslikeamosquito (Archbishop) on Jun 07, 2023 at 23:19 UTC | |
by kcott (Archbishop) on Jun 08, 2023 at 01:45 UTC | |
Re: Multidimensional arrays
by kcott (Archbishop) on Jun 07, 2023 at 00:06 UTC | |
by Bod (Parson) on Jun 07, 2023 at 20:37 UTC | |
by kcott (Archbishop) on Jun 08, 2023 at 01:22 UTC | |
Re: Multidimensional arrays
by Arunbear (Prior) on Jun 07, 2023 at 16:57 UTC | |
by Bod (Parson) on Jun 07, 2023 at 20:44 UTC | |
Re: Multidimensional arrays
by misterperl (Friar) on Jun 06, 2023 at 18:13 UTC | |
by Bod (Parson) on Jun 06, 2023 at 21:50 UTC |