-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ webserver API for wallet/*/payments 🗃️ ⚠️ (#4683)
- Loading branch information
Showing
41 changed files
with
1,818 additions
and
234 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
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
112 changes: 112 additions & 0 deletions
112
...core_postgres_database/migration/versions/fc6ea424f586_new_payments_transactions_table.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,112 @@ | ||
"""new payments_transactions table | ||
Revision ID: fc6ea424f586 | ||
Revises: 763666c698fb | ||
Create Date: 2023-09-04 14:13:28.201570+00:00 | ||
""" | ||
from typing import Final | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "fc6ea424f586" | ||
down_revision = "763666c698fb" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
# auto-update modified | ||
# TRIGGERS ------------------------ | ||
_TABLE_NAME: Final[str] = "payments_transactions" | ||
_TRIGGER_NAME: Final[str] = "trigger_auto_update" # NOTE: scoped on table | ||
_PROCEDURE_NAME: Final[ | ||
str | ||
] = f"{_TABLE_NAME}_auto_update_modified()" # NOTE: scoped on database | ||
modified_timestamp_trigger = sa.DDL( | ||
f""" | ||
DROP TRIGGER IF EXISTS {_TRIGGER_NAME} on {_TABLE_NAME}; | ||
CREATE TRIGGER {_TRIGGER_NAME} | ||
BEFORE INSERT OR UPDATE ON {_TABLE_NAME} | ||
FOR EACH ROW EXECUTE PROCEDURE {_PROCEDURE_NAME}; | ||
""" | ||
) | ||
|
||
# PROCEDURES ------------------------ | ||
update_modified_timestamp_procedure = sa.DDL( | ||
f""" | ||
CREATE OR REPLACE FUNCTION {_PROCEDURE_NAME} | ||
RETURNS TRIGGER AS $$ | ||
BEGIN | ||
NEW.modified := current_timestamp; | ||
RETURN NEW; | ||
END; | ||
$$ LANGUAGE plpgsql; | ||
""" | ||
) | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table( | ||
"payments_transactions", | ||
sa.Column("payment_id", sa.String(), nullable=False), | ||
sa.Column("price_dollars", sa.Numeric(scale=2), nullable=False), | ||
sa.Column("osparc_credits", sa.Numeric(scale=2), nullable=False), | ||
sa.Column("product_name", sa.String(), nullable=False), | ||
sa.Column("user_id", sa.BigInteger(), nullable=False), | ||
sa.Column("user_email", sa.String(), nullable=False), | ||
sa.Column("wallet_id", sa.BigInteger(), nullable=False), | ||
sa.Column("comment", sa.Text(), nullable=True), | ||
sa.Column("initiated_at", sa.DateTime(timezone=True), nullable=False), | ||
sa.Column("completed_at", sa.DateTime(timezone=True), nullable=True), | ||
sa.Column("success", sa.Boolean(), nullable=True), | ||
sa.Column("errors", sa.Text(), nullable=True), | ||
sa.Column( | ||
"created", | ||
sa.DateTime(timezone=True), | ||
server_default=sa.text("now()"), | ||
nullable=False, | ||
), | ||
sa.Column( | ||
"modified", | ||
sa.DateTime(timezone=True), | ||
server_default=sa.text("now()"), | ||
nullable=False, | ||
), | ||
sa.PrimaryKeyConstraint("payment_id"), | ||
) | ||
op.create_index( | ||
op.f("ix_payments_transactions_user_id"), | ||
"payments_transactions", | ||
["user_id"], | ||
unique=False, | ||
) | ||
op.create_index( | ||
op.f("ix_payments_transactions_wallet_id"), | ||
"payments_transactions", | ||
["wallet_id"], | ||
unique=False, | ||
) | ||
# ### end Alembic commands ### | ||
|
||
# custom | ||
op.execute(update_modified_timestamp_procedure) | ||
op.execute(modified_timestamp_trigger) | ||
|
||
|
||
def downgrade(): | ||
|
||
# custom | ||
op.execute(f"DROP TRIGGER IF EXISTS {_TRIGGER_NAME} on {_TABLE_NAME};") | ||
op.execute(f"DROP FUNCTION {_PROCEDURE_NAME};") | ||
|
||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_index( | ||
op.f("ix_payments_transactions_wallet_id"), table_name="payments_transactions" | ||
) | ||
op.drop_index( | ||
op.f("ix_payments_transactions_user_id"), table_name="payments_transactions" | ||
) | ||
op.drop_table("payments_transactions") | ||
# ### end Alembic commands ### |
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
104 changes: 104 additions & 0 deletions
104
packages/postgres-database/src/simcore_postgres_database/models/payments_transactions.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,104 @@ | ||
import sqlalchemy as sa | ||
|
||
from ._common import ( | ||
column_created_datetime, | ||
column_modified_datetime, | ||
register_modified_datetime_auto_update_trigger, | ||
) | ||
from .base import metadata | ||
|
||
payments_transactions = sa.Table( | ||
"payments_transactions", | ||
metadata, | ||
sa.Column( | ||
"payment_id", | ||
sa.String, | ||
nullable=False, | ||
primary_key=True, | ||
doc="Identifer of the payment provided by payment gateway", | ||
), | ||
sa.Column( | ||
"price_dollars", | ||
sa.Numeric(scale=2), | ||
nullable=False, | ||
doc="Total amount of the transaction (in dollars). E.g. 1234.12 $", | ||
), | ||
# | ||
# Concept/Info | ||
# | ||
sa.Column( | ||
"osparc_credits", | ||
sa.Numeric(scale=2), | ||
nullable=False, | ||
doc="Amount of credits that will be added to the wallet_id " | ||
"once the transaction completes successfuly." | ||
"E.g. 1234.12 credits", | ||
), | ||
sa.Column( | ||
"product_name", | ||
sa.String, | ||
nullable=False, | ||
doc="Product name from which the transaction took place", | ||
), | ||
sa.Column( | ||
"user_id", | ||
sa.BigInteger, | ||
nullable=False, | ||
doc="User unique identifier", | ||
index=True, | ||
), | ||
sa.Column( | ||
"user_email", | ||
sa.String, | ||
nullable=False, | ||
doc="User email at the time of the transaction", | ||
), | ||
sa.Column( | ||
"wallet_id", | ||
sa.BigInteger, | ||
nullable=False, | ||
doc="Wallet identifier owned by the user", | ||
index=True, | ||
), | ||
sa.Column( | ||
"comment", | ||
sa.Text, | ||
nullable=True, | ||
doc="Extra comment on this payment (optional)", | ||
), | ||
# | ||
# States | ||
# | ||
sa.Column( | ||
"initiated_at", | ||
sa.DateTime(timezone=True), | ||
nullable=False, | ||
doc="Timestamps when transaction initated (successful respose to /init)", | ||
), | ||
sa.Column( | ||
"completed_at", | ||
sa.DateTime(timezone=True), | ||
nullable=True, | ||
doc="Timestamps when transaction completed (payment acked)", | ||
), | ||
sa.Column( | ||
"success", | ||
sa.Boolean, | ||
nullable=True, | ||
doc="Transation still incomplete (=null) or " | ||
"completed successfuly (=true) " | ||
"completed with failures (=false).", | ||
), | ||
sa.Column( | ||
"errors", | ||
sa.Text, | ||
nullable=True, | ||
doc="Stores error messages in case of transaction failure", | ||
), | ||
# timestamps for this row | ||
column_created_datetime(timezone=True), | ||
column_modified_datetime(timezone=True), | ||
) | ||
|
||
|
||
register_modified_datetime_auto_update_trigger(payments_transactions) |
Oops, something went wrong.