Skip to content

Commit

Permalink
feat(form): Add some extra information in metadata when creating stri…
Browse files Browse the repository at this point in the history
…pe session.
  • Loading branch information
vinci1it2000 committed Oct 18, 2024
1 parent b13e8ee commit facb61c
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions schedula/utils/form/server/credits.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,11 +569,14 @@ def create_payment():
try:
data = request.get_json() if request.is_json else dict(request.form)
data = json_secrets.secrets(data, False)
metadata = {
f'customer_{k}': getattr(cu, k)
for k in ('id', 'firstname', 'lastname')
if hasattr(cu, k)
}

metadata = {f'customer_{k}': getattr(cu, k) for k in (
'id', 'firstname', 'lastname', 'email'
) if hasattr(cu, k)}
metadata.update({f'customer_{k}': json.dumps(getattr(cu, k)) for k in (
'custom_data',
) if hasattr(cu, k)})

api_key = ca.config['STRIPE_SECRET_KEY']

if 'line_items' in data:
Expand Down Expand Up @@ -609,9 +612,7 @@ def create_payment():
except Exception as e:
return jsonify(error=str(e))

return jsonify(
clientSecret=session.client_secret, sessionId=session.id
)
return jsonify(clientSecret=session.client_secret, sessionId=session.id)


def checkout_session_completed(session_id):
Expand Down Expand Up @@ -733,10 +734,12 @@ def subscription_invoice_paid(event):
wallet_id=wallet.id, type_id=SUBSCRIPTION
).filter(Txn.valid_from <= start_time).order_by(
desc(Txn.valid_from)
).first().stripe_id
refund_charge(latest_invoice, start_time, db.session, (
CHARGE, SUBSCRIPTION
))
).first()
if latest_invoice:
latest_invoice = latest_invoice.stripe_id
refund_charge(latest_invoice, start_time, db.session, (
CHARGE, SUBSCRIPTION
))
transactions = []
for item in subscription.get('items').data:
product = item.price.product
Expand Down

0 comments on commit facb61c

Please sign in to comment.