Skip to content
Permalink
Browse files

ipn handling

  • Loading branch information...
JeffVandrewJr committed Jan 28, 2019
1 parent 630b5b7 commit b72b64e49c16675e04bf6b8f560a15296345bae4
Showing with 57 additions and 9 deletions.
  1. +28 −9 app/api/routes.py
  2. +1 −0 app/models.py
  3. +28 −0 migrations/versions/5346190a2f75_.py
@@ -26,6 +26,7 @@ def update_sub():
if 'status' in invoice:
current_app.logger.info('IPN: ' + invoice['status'])
if invoice['status'] == "paid" or \
invoice['status'] == "complete" or \
invoice['status'] == "confirmed":
user = User.query.filter_by(
username=invoice['buyer']['name']).first()
@@ -34,15 +35,19 @@ def update_sub():
if user.role == 'admin':
return "Administrator should not make payments.", 200
elif invoice['status'] == "confirmed":
if user.expiration <= datetime.today():
base = datetime.today()
if user.last_payment != invoice['id']:
user.last_payment = invoice['id']
if user.expiration <= datetime.today():
base = datetime.today()
else:
base = user.expiration
user.expiration = base + timedelta(days=30)
user.role = invoice['orderId']
user.renew = True
db.session.commit()
return "Payment Accepted", 201
else:
base = user.expiration
user.expiration = base + timedelta(days=30)
user.role = invoice['orderId']
user.renew = True
db.session.commit()
return "Payment Accepted", 201
return "Payment Already Processed", 200
elif invoice['status'] == "paid":
# add a few hours if expired or almost expired
measure = user.expiration - timedelta(hours=6)
@@ -52,7 +57,21 @@ def update_sub():
user.role = invoice['orderId']
user.renew = False
db.session.commit()
return "Payment Accepted", 201
elif invoice['status'] == "complete":
# handle lightning payments
if user.last_payment != invoice['id']:
user.last_payment = invoice['id']
if user.expiration <= datetime.today():
base = datetime.today()
else:
base = user.expiration
user.expiration = base + timedelta(days=30)
user.role = invoice['orderId']
user.renew = True
db.session.commit()
return "Payment Accepted", 201
else:
return "Payment Already Processed", 200
else:
return "IPN Received", 200
else:
@@ -89,6 +89,7 @@ class User(UserMixin, db.Model):
renew = db.Column(db.Boolean, index=True)
mail_opt_out = db.Column(db.Boolean, index=True)
role = db.Column(db.String(64))
last_payment = db.Column(db.String(128))
square_id = db.Column(db.String(120), index=True)
square_card = db.Column(db.String(120), index=True)

@@ -0,0 +1,28 @@
"""empty message
Revision ID: 5346190a2f75
Revises: a908fb8b1d23
Create Date: 2019-01-28 03:05:26.706536
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '5346190a2f75'
down_revision = 'a908fb8b1d23'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('user', sa.Column('last_payment', sa.String(length=128), nullable=True))
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('user', 'last_payment')
# ### end Alembic commands ###

0 comments on commit b72b64e

Please sign in to comment.
You can’t perform that action at this time.