def charge_paypal_order_payment(order): payment_details = PayPalPaymentsManager.get_approved_payment_details( order) if 'PAYERID' in payment_details: capture_result = PayPalPaymentsManager.capture_payment( order, payment_details['PAYERID']) if capture_result['ACK'] == 'Success': order.paid_via = 'paypal' order.status = 'completed' order.transaction_id = capture_result[ 'PAYMENTINFO_0_TRANSACTIONID'] order.completed_at = datetime.utcnow() save_to_db(order) invoice_id = order.get_invoice_number() order_url = make_frontend_url( path="/{identifier}/view/".format( identifier=order.identifier)) # trigger_after_purchase_notifications(order.user.email, order.event_id, order.event, invoice_id, # order_url) # send_email_for_after_purchase(order.user.email, invoice_id, order_url, order.event.name, # order.event.organizer_name) # send_notif_for_after_purchase(order.user, invoice_id, order_url) return True, order else: return False, capture_result['L_SHORTMESSAGE0'] else: return False, 'Payer ID missing. Payment flow tampered.'
def charge_paypal_order_payment(order): payment_details = PayPalPaymentsManager.get_approved_payment_details(order) if 'PAYERID' in payment_details: capture_result = PayPalPaymentsManager.capture_payment(order, payment_details['PAYERID']) if capture_result['ACK'] == 'Success': order.paid_via = 'paypal' order.status = 'completed' order.transaction_id = capture_result['PAYMENTINFO_0_TRANSACTIONID'] order.completed_at = datetime.utcnow() save_to_db(order) invoice_id = order.get_invoice_number() order_url = make_frontend_url(path="/{identifier}/view/".format(identifier=order.identifier)) # trigger_after_purchase_notifications(order.user.email, order.event_id, order.event, invoice_id, # order_url) # send_email_for_after_purchase(order.user.email, invoice_id, order_url, order.event.name, # order.event.organizer_name) # send_notif_for_after_purchase(order.user, invoice_id, order_url) return True, order else: return False, capture_result['L_SHORTMESSAGE0'] else: return False, 'Payer ID missing. Payment flow tampered.'
def charge_paypal_payment_invoice(invoice_identifier): """ Create a paypal payment. :return: The payment id of the created payment. """ try: paypal_payment_id = request.json['data']['attributes'][ 'paypal_payment_id'] paypal_payer_id = request.json['data']['attributes']['paypal_payer_id'] except Exception as e: return BadRequestError({'source': e}, 'Bad Request Error').respond() event_invoice = safe_query(db, EventInvoice, 'identifier', invoice_identifier, 'identifier') # save the paypal payment_id with the order event_invoice.paypal_token = paypal_payment_id save_to_db(event_invoice) # execute the invoice transaction. status, error = PayPalPaymentsManager.execute_payment( paypal_payer_id, paypal_payment_id) if status: # successful transaction hence update the order details. event_invoice.paid_via = 'paypal' event_invoice.status = 'paid' event_invoice.transaction_id = paypal_payment_id event_invoice.completed_at = datetime.datetime.now() save_to_db(event_invoice) return jsonify(status="Charge Successful", payment_id=paypal_payment_id) else: # return the error message from Paypal return jsonify(status="Charge Unsuccessful", error=error)
def charge_paypal_order_payment(order, paypal_payer_id, paypal_payment_id): """ Charge the user through paypal. :param order: Order for which to charge for. :param paypal_payment_id: payment_id :param paypal_payer_id: payer_id :return: """ # save the paypal payment_id with the order order.paypal_token = paypal_payment_id save_to_db(order) # create the transaction. status, error = PayPalPaymentsManager.execute_payment( paypal_payer_id, paypal_payment_id ) if status: # successful transaction hence update the order details. order.paid_via = 'paypal' order.status = 'completed' order.transaction_id = paypal_payment_id order.completed_at = datetime.utcnow() save_to_db(order) # create tickets create_pdf_tickets_for_holder(order) # send email and notifications send_email_to_attendees(order, order.user_id) send_notif_to_attendees(order, order.user_id) order_url = make_frontend_url( path='/orders/{identifier}'.format(identifier=order.identifier) ) for organizer in order.event.organizers: send_notif_ticket_purchase_organizer( organizer, order.invoice_number, order_url, order.event.name, order.id ) if order.event.owner: send_notif_ticket_purchase_organizer( order.event.owner, order.invoice_number, order_url, order.event.name, order.id, ) return True, 'Charge successful' else: # payment failed hence expire the order order.status = 'expired' save_to_db(order) # delete related attendees to unlock the tickets delete_related_attendees_for_order(order) # return the error message from Paypal return False, error
def generate_payment_url(self, data): if 'POST' in request.method or ('GET' in request.method and 'regenerate' in request.args) and 'completed' != \ data["status"]: if data['payment_mode'] == 'stripe': data['payment_url'] = 'stripe://payment' elif data['payment_mode'] == 'paypal': order = Order.query.filter_by(id=data['id']).first() data['payment_url'] = PayPalPaymentsManager.get_checkout_url(order) return data
def generate_payment_url(self, data): if 'POST' in request.method or ('GET' in request.method and 'regenerate' in request.args) and 'completed' != \ data["status"]: if data['payment_mode'] == 'stripe': data['payment_url'] = 'stripe://payment' elif data['payment_mode'] == 'paypal': order = Order.query.filter_by(id=data['id']).first() data['payment_url'] = PayPalPaymentsManager.get_checkout_url( order) return data
def verify_mobile_paypal_payment(order_identifier): """ Verify paypal payment made on mobile client :return: The status of order verification """ try: payment_id = request.json['data']['attributes']['payment-id'] except TypeError: raise BadRequestError({'source': ''}, 'Bad Request Error') order = safe_query(Order, 'identifier', order_identifier, 'identifier') status, error = PayPalPaymentsManager.verify_payment(payment_id, order) return jsonify(status=status, error=error)
def create_paypal_payment(order_identifier): """ Create a paypal payment. :return: The payment id of the created payment. """ try: return_url = request.json['data']['attributes']['return-url'] cancel_url = request.json['data']['attributes']['cancel-url'] except TypeError: raise BadRequestError({'source': ''}, 'Bad Request Error') order = safe_query(Order, 'identifier', order_identifier, 'identifier') status, response = PayPalPaymentsManager.create_payment(order, return_url, cancel_url) if status: return jsonify(status=True, payment_id=response) return jsonify(status=False, error=response)
def create_paypal_payment(order_identifier): """ Create a paypal payment. :return: The payment id of the created payment. """ try: return_url = request.json['data']['attributes']['return-url'] cancel_url = request.json['data']['attributes']['cancel-url'] except TypeError: return BadRequestError({'source': ''}, 'Bad Request Error').respond() order = safe_query(db, Order, 'identifier', order_identifier, 'identifier') status, response = PayPalPaymentsManager.create_payment(order, return_url, cancel_url) if status: return jsonify(status=True, payment_id=response) else: return jsonify(status=False, error=response)
def create_paypal_payment_invoice(invoice_identifier): """ Create a paypal payment. :return: The payment id of the created payment. """ try: return_url = request.json['data']['attributes']['return-url'] cancel_url = request.json['data']['attributes']['cancel-url'] except TypeError: return BadRequestError({'source': ''}, 'Bad Request Error').respond() event_invoice = safe_query(db, EventInvoice, 'identifier', invoice_identifier, 'identifier') status, response = PayPalPaymentsManager.create_payment( event_invoice, return_url, cancel_url) if status: return jsonify(status=True, payment_id=response) else: return jsonify(status=False, error=response)
def create_paypal_payment_invoice(invoice_identifier): """ Create a paypal payment. :return: The payment id of the created payment. """ try: return_url = request.json['data']['attributes']['return-url'] cancel_url = request.json['data']['attributes']['cancel-url'] except TypeError: raise BadRequestError({'source': ''}, 'Bad Request Error') event_invoice = safe_query(EventInvoice, 'identifier', invoice_identifier, 'identifier') billing_email = get_settings()['admin_billing_paypal_email'] status, response = PayPalPaymentsManager.create_payment( event_invoice, return_url, cancel_url, payee_email=billing_email) if status: return jsonify(status=True, payment_id=response) return jsonify(status=False, error=response)
def charge_paypal_order_payment(order, paypal_payer_id, paypal_payment_id): """ Charge the user through paypal. :param order: Order for which to charge for. :param paypal_payment_id: payment_id :param paypal_payer_id: payer_id :return: """ # save the paypal payment_id with the order order.paypal_token = paypal_payment_id save_to_db(order) # create the transaction. status, error = PayPalPaymentsManager.execute_payment( paypal_payer_id, paypal_payment_id ) if status: # successful transaction hence update the order details. order.paid_via = 'paypal' order.status = 'completed' order.transaction_id = paypal_payment_id order.completed_at = datetime.utcnow() save_to_db(order) on_order_completed(order) return True, 'Charge successful' # payment failed hence expire the order order.status = 'expired' save_to_db(order) # delete related attendees to unlock the tickets delete_related_attendees_for_order(order) # return the error message from Paypal return False, error