Skip to content

Commit 506a1a3

Browse files
committed
feat: Update charge route
1 parent 14a4223 commit 506a1a3

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

app/api/event_invoices.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from app.api.orders import order_misc_routes
2020

2121

22-
2322
class EventInvoiceList(ResourceList):
2423
"""
2524
List and Create Event Invoices
@@ -121,4 +120,28 @@ def charge_paypal_payment_invoice(invoice_identifier):
121120
Create a paypal payment.
122121
:return: The payment id of the created payment.
123122
"""
124-
pass
123+
try:
124+
paypal_payment_id = request.json['data']['attributes']['paypal_payment_id']
125+
paypal_payer_id = request.json['data']['attributes']['paypal_payer_id']
126+
except:
127+
return BadRequestError({'source': ''}, 'Bad Request Error').respond()
128+
event_invoice = safe_query(db, EventInvoice, 'identifier', invoice_identifier, 'identifier')
129+
# save the paypal payment_id with the order
130+
event_invoice.paypal_token = paypal_payment_id
131+
save_to_db(event_invoice)
132+
133+
# create the transaction.
134+
status, error = PayPalPaymentsManager.execute_payment(paypal_payer_id, paypal_payment_id)
135+
136+
if status:
137+
# successful transaction hence update the order details.
138+
event_invoice.paid_via = 'paypal'
139+
event_invoice.status = 'completed'
140+
event_invoice.transaction_id = paypal_payment_id
141+
event_invoice.completed_at = datetime.utcnow()
142+
save_to_db(event_invoice)
143+
144+
return True, 'Charge successful'
145+
else:
146+
# return the error message from Paypal
147+
return False, error

0 commit comments

Comments
 (0)