From 22f4064544a72b336388e4c8309c3e0259519816 Mon Sep 17 00:00:00 2001 From: Shreyansh Dwivedi Date: Tue, 6 Aug 2019 15:31:25 +0530 Subject: [PATCH] enh: add stripe test key fields to settings model adds check to use test keys when app_environment is development --- app/api/helpers/payment.py | 10 +++++-- app/api/schema/settings.py | 2 ++ app/factories/setting.py | 2 ++ app/models/setting.py | 5 ++++ .../rev-2019-08-07-01:11:29-f5c3a4fd23fb_.py | 30 +++++++++++++++++++ 5 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 migrations/versions/rev-2019-08-07-01:11:29-f5c3a4fd23fb_.py diff --git a/app/api/helpers/payment.py b/app/api/helpers/payment.py index 3eddcfb74d..1921e08498 100644 --- a/app/api/helpers/payment.py +++ b/app/api/helpers/payment.py @@ -40,9 +40,13 @@ def get_credentials(event=None): """ if not event: settings = get_settings() - if settings['stripe_secret_key'] and settings["stripe_publishable_key"] and settings[ - 'stripe_secret_key'] != "" and \ - settings["stripe_publishable_key"] != "": + if settings['app_environment'] == 'development' and settings['stripe_test_secret_key'] and \ + settings['stripe_test_publishable_key']: + return { + 'SECRET_KEY': settings['stripe_test_secret_key'], + 'PUBLISHABLE_KEY': settings["stripe_test_publishable_key"] + } + elif settings['stripe_secret_key'] and settings["stripe_publishable_key"]: return { 'SECRET_KEY': settings['stripe_secret_key'], 'PUBLISHABLE_KEY': settings["stripe_publishable_key"] diff --git a/app/api/schema/settings.py b/app/api/schema/settings.py index 1a61252fbf..5cd4485d0c 100644 --- a/app/api/schema/settings.py +++ b/app/api/schema/settings.py @@ -82,6 +82,8 @@ class Meta: # Stripe Keys stripe_client_id = fields.Str(allow_none=True) stripe_publishable_key = fields.Str(allow_none=True) + stripe_test_secret_key = fields.Str(allow_none=True) + stripe_test_publishable_key = fields.Str(allow_none=True) # # Generators diff --git a/app/factories/setting.py b/app/factories/setting.py index de8b068e9b..fdbaea5b03 100644 --- a/app/factories/setting.py +++ b/app/factories/setting.py @@ -63,6 +63,8 @@ class Meta: stripe_client_id = common.string_ stripe_secret_key = common.string_ stripe_publishable_key = common.string_ + stripe_test_secret_key = common.string_ + stripe_test_publishable_key = common.string_ # PayPal Credentials paypal_mode = 'development' paypal_client = common.string_ diff --git a/app/models/setting.py b/app/models/setting.py index b84628f86e..d782d58802 100644 --- a/app/models/setting.py +++ b/app/models/setting.py @@ -83,6 +83,8 @@ class Setting(db.Model): stripe_client_id = db.Column(db.String) stripe_secret_key = db.Column(db.String) stripe_publishable_key = db.Column(db.String) + stripe_test_secret_key = db.Column(db.String) + stripe_test_publishable_key = db.Column(db.String) # AliPay Keys - Stripe Sources alipay_secret_key = db.Column(db.String) @@ -183,6 +185,7 @@ def __init__(self, fb_client_id=None, fb_client_secret=None, tw_consumer_key=None, stripe_client_id=None, stripe_secret_key=None, stripe_publishable_key=None, + stripe_test_secret_key=None, stripe_test_publishable_key=None, in_client_id=None, in_client_secret=None, tw_consumer_secret=None, sendgrid_key=None, secret=None, storage_place=None, @@ -271,6 +274,8 @@ def __init__(self, self.stripe_client_id = stripe_client_id self.stripe_publishable_key = stripe_publishable_key self.stripe_secret_key = stripe_secret_key + self.stripe_test_publishable_key = stripe_test_publishable_key + self.stripe_test_secret_key = stripe_test_secret_key self.web_app_url = web_app_url self.android_app_url = android_app_url self.email_service = email_service diff --git a/migrations/versions/rev-2019-08-07-01:11:29-f5c3a4fd23fb_.py b/migrations/versions/rev-2019-08-07-01:11:29-f5c3a4fd23fb_.py new file mode 100644 index 0000000000..11f82050cd --- /dev/null +++ b/migrations/versions/rev-2019-08-07-01:11:29-f5c3a4fd23fb_.py @@ -0,0 +1,30 @@ +"""add stripe test keys + +Revision ID: f5c3a4fd23fb +Revises: 4925dd5fd720 +Create Date: 2019-08-07 01:11:29.736517 + +""" + +from alembic import op +import sqlalchemy as sa +import sqlalchemy_utils + + +# revision identifiers, used by Alembic. +revision = 'f5c3a4fd23fb' +down_revision = '4925dd5fd720' + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('settings', sa.Column('stripe_test_publishable_key', sa.String(), nullable=True)) + op.add_column('settings', sa.Column('stripe_test_secret_key', sa.String(), nullable=True)) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column('settings', 'stripe_test_secret_key') + op.drop_column('settings', 'stripe_test_publishable_key') + # ### end Alembic commands ###