-
Notifications
You must be signed in to change notification settings - Fork 1.9k
feat: Omise charge route and payment flow #6004
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| from datetime import datetime | ||
|
|
||
| from flask import request, jsonify, Blueprint, url_for, redirect | ||
| import omise | ||
| import logging | ||
|
|
||
| from flask_jwt import current_identity as current_user | ||
| from flask_rest_jsonapi import ResourceDetail, ResourceList, ResourceRelationship | ||
|
|
@@ -33,7 +34,7 @@ | |
| from app.models.order import Order, OrderTicket, get_updatable_fields | ||
| from app.models.ticket_holder import TicketHolder | ||
| from app.models.user import User | ||
| from app.api.helpers.payment import AliPayPaymentsManager | ||
| from app.api.helpers.payment import AliPayPaymentsManager, OmisePaymentsManager | ||
|
|
||
|
|
||
| order_misc_routes = Blueprint('order_misc', __name__, url_prefix='/v1') | ||
|
|
@@ -499,3 +500,32 @@ def alipay_return_uri(order_identifier): | |
| return jsonify(status=False, error='Charge object failure') | ||
| except TypeError: | ||
| return jsonify(status=False, error='Source object status error') | ||
|
|
||
|
|
||
| @order_misc_routes.route('/orders/<string:order_identifier>/omise-checkout', methods=['POST', 'GET']) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. expected 2 blank lines, found 1 |
||
| def omise_checkout(order_identifier): | ||
| """ | ||
| Charging the user and returning payment response for Omise Gateway | ||
| :param order_identifier: | ||
| :return: JSON response of the payment status. | ||
| """ | ||
| token = request.form.get('omiseToken') | ||
| order = safe_query(db, Order, 'identifier', order_identifier, 'identifier') | ||
| order.status = 'completed' | ||
| save_to_db(order) | ||
| try: | ||
| charge = OmisePaymentsManager.charge_payment(order_identifier, token) | ||
| print(charge.status) | ||
| except omise.errors.BaseError as e: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. undefined name 'omise' |
||
| logging.error(f"""OmiseError: {repr(e)}. See https://www.omise.co/api-errors""") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please make the syntax python 3.6 compatible
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Upgrade your python please |
||
| return jsonify(status=False, error="Omise Failure Message: {}".format(str(e))) | ||
| except Exception as e: | ||
| logging.error(repr(e)) | ||
| if charge.failure_code is not None: | ||
| logging.warning("Omise Failure Message: {} ({})".format(charge.failure_message, charge.failure_code)) | ||
| return jsonify(status=False, error="Omise Failure Message: {} ({})". | ||
| format(charge.failure_message, charge.failure_code)) | ||
| else: | ||
| logging.info(f"Successful charge: {charge.id}. Order ID: {order_identifier}") | ||
|
|
||
| return redirect(make_frontend_url('orders/{}/view'.format(order_identifier))) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expected 2 blank lines, found 1