Skip to content

Instantly share code, notes, and snippets.

@mrsaicharan1
Created April 8, 2020 05:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrsaicharan1/0b15018f892c587696236c6046e90c42 to your computer and use it in GitHub Desktop.
Save mrsaicharan1/0b15018f892c587696236c6046e90c42 to your computer and use it in GitHub Desktop.
Alipay - Route which creates the source and returns external redirection url
@alipay_blueprint.route('/create_source/<string:order_identifier>', methods=['GET', 'POST'])
def create_source(order_identifier):
"""
Create a source object for alipay payments.
:param order_identifier:
:return: The alipay redirection link.
"""
try:
order = safe_query(db, Order, 'identifier', order_identifier, 'identifier')
source_object = AliPayPaymentsManager.create_source(amount=int(order.amount), currency='usd',
redirect_return_uri=url_for('alipay_blueprint.alipay_return_uri',
order_identifier=order.identifier, _external=True))
order.order_notes = source_object.id
save_to_db(order)
return jsonify(link=source_object.redirect['url'])
except TypeError:
return BadRequestError({'source': ''}, 'Source creation error').respond()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment