Created
April 8, 2020 05:27
-
-
Save mrsaicharan1/0b15018f892c587696236c6046e90c42 to your computer and use it in GitHub Desktop.
Alipay - Route which creates the source and returns external redirection url
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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