|
19 | 19 | from app.api.orders import order_misc_routes |
20 | 20 |
|
21 | 21 |
|
22 | | - |
23 | 22 | class EventInvoiceList(ResourceList): |
24 | 23 | """ |
25 | 24 | List and Create Event Invoices |
@@ -121,4 +120,28 @@ def charge_paypal_payment_invoice(invoice_identifier): |
121 | 120 | Create a paypal payment. |
122 | 121 | :return: The payment id of the created payment. |
123 | 122 | """ |
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