From 8ed1ba0c8a0b55b3bdcb29b55eb26491046cc806 Mon Sep 17 00:00:00 2001 From: Anthony Hivert Date: Wed, 22 Aug 2018 16:17:27 +0200 Subject: [PATCH] Add payment status in comeback url params --- payzen/utils.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/payzen/utils.py b/payzen/utils.py index 0a33c38..9574fe1 100644 --- a/payzen/utils.py +++ b/payzen/utils.py @@ -1,7 +1,8 @@ import hashlib -from decimal import Decimal, ROUND_HALF_UP import operator from datetime import datetime +from decimal import ROUND_HALF_UP, Decimal +from urllib.parse import urlparse class SEPAMandateFormData: @@ -30,11 +31,18 @@ def __init__(self, user, payzen_id, comeback_url, payzen_certificate, self.vads_version = payzen_version self.vads_payment_cards = '' - self.vads_url_cancel = comeback_url - self.vads_url_error = comeback_url - self.vads_url_refused = comeback_url - self.vads_url_return = comeback_url - self.vads_url_success = comeback_url + query_param_name = 'payment' + if urlparse(comeback_url)[4]: + # already have query params + join_char = '&' + else: + join_char = '?' + + self.vads_url_cancel = join_char.join([comeback_url, '%s=cancel' % query_param_name]) + self.vads_url_error = join_char.join([comeback_url, '%s=error' % query_param_name]) + self.vads_url_refused = join_char.join([comeback_url, '%s=refused' % query_param_name]) + self.vads_url_return = join_char.join([comeback_url, '%s=return' % query_param_name]) + self.vads_url_success = join_char.join([comeback_url, '%s=success' % query_param_name]) if redirect_timeout is not None: self.vads_redirect_success_timeout = str(redirect_timeout)