-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #379 from GooeyAI/pricing-v2-improvements
Pricing improvements and bug fixes
- Loading branch information
Showing
32 changed files
with
1,110 additions
and
623 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
app_users/migrations/0018_appusertransaction_plan_appusertransaction_reason.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# Generated by Django 4.2.7 on 2024-07-14 20:51 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
def forwards_func(apps, schema_editor): | ||
from payments.plans import PricingPlan | ||
from app_users.models import TransactionReason | ||
|
||
# We get the model from the versioned app registry; | ||
# if we directly import it, it'll be the wrong version | ||
AppUserTransaction = apps.get_model("app_users", "AppUserTransaction") | ||
db_alias = schema_editor.connection.alias | ||
objects = AppUserTransaction.objects.using(db_alias) | ||
|
||
for transaction in objects.all(): | ||
if transaction.amount <= 0: | ||
transaction.reason = TransactionReason.DEDUCT | ||
else: | ||
# For old transactions, we didn't have a subscription field. | ||
# It just so happened that all monthly subscriptions we offered had | ||
# different amounts from the one-time purchases. | ||
# This uses that heuristic to determine whether a transaction | ||
# was a subscription payment or a one-time purchase. | ||
transaction.reason = TransactionReason.ADDON | ||
for plan in PricingPlan: | ||
if ( | ||
transaction.amount == plan.credits | ||
and transaction.charged_amount == plan.monthly_charge * 100 | ||
): | ||
transaction.plan = plan.db_value | ||
transaction.reason = TransactionReason.SUBSCRIBE | ||
transaction.save(update_fields=["reason", "plan"]) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('app_users', '0017_alter_appuser_subscription'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='appusertransaction', | ||
name='plan', | ||
field=models.IntegerField(blank=True, choices=[(1, 'Basic Plan'), (2, 'Premium Plan'), (3, 'Starter'), (4, 'Creator'), (5, 'Business'), (6, 'Enterprise / Agency')], default=None, help_text="User's plan at the time of this transaction.", null=True), | ||
), | ||
migrations.AddField( | ||
model_name='appusertransaction', | ||
name='reason', | ||
field=models.IntegerField(choices=[(1, 'Deduct'), (2, 'Addon'), (3, 'Subscribe'), (4, 'Sub-Create'), (5, 'Sub-Cycle'), (6, 'Sub-Update'), (7, 'Auto-Recharge')], default=0, help_text='The reason for this transaction.<br><br>Deduct: Credits deducted due to a run.<br>Addon: User purchased an add-on.<br>Subscribe: Applies to subscriptions where no distinction was made between create, update and cycle.<br>Sub-Create: A subscription was created.<br>Sub-Cycle: A subscription advanced into a new period.<br>Sub-Update: A subscription was updated.<br>Auto-Recharge: Credits auto-recharged due to low balance.'), | ||
), | ||
migrations.RunPython(forwards_func, migrations.RunPython.noop), | ||
migrations.AlterField( | ||
model_name='appusertransaction', | ||
name='reason', | ||
field=models.IntegerField(choices=[(1, 'Deduct'), (2, 'Addon'), (3, 'Subscribe'), (4, 'Sub-Create'), (5, 'Sub-Cycle'), (6, 'Sub-Update'), (7, 'Auto-Recharge')], help_text='The reason for this transaction.<br><br>Deduct: Credits deducted due to a run.<br>Addon: User purchased an add-on.<br>Subscribe: Applies to subscriptions where no distinction was made between create, update and cycle.<br>Sub-Create: A subscription was created.<br>Sub-Cycle: A subscription advanced into a new period.<br>Sub-Update: A subscription was updated.<br>Auto-Recharge: Credits auto-recharged due to low balance.'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
bots/migrations/0077_savedrun_error_code_savedrun_error_type_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Generated by Django 4.2.7 on 2024-07-12 19:30 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('bots', '0076_alter_workflowmetadata_default_image_and_more'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='savedrun', | ||
name='error_code', | ||
field=models.IntegerField(blank=True, default=None, help_text='The HTTP status code of the error. If this is not set, 500 is assumed.', null=True), | ||
), | ||
migrations.AddField( | ||
model_name='savedrun', | ||
name='error_type', | ||
field=models.TextField(blank=True, default='', help_text='The exception type'), | ||
), | ||
migrations.AlterField( | ||
model_name='savedrun', | ||
name='error_msg', | ||
field=models.TextField(blank=True, default='', help_text='The error message. If this is not set, the run is deemed successful.'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.