Commit b7df55aa authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_payzen: Use nice error when integration_site is not configured

parent 6cca1c8d
...@@ -3,7 +3,6 @@ if REQUEST is not None: ...@@ -3,7 +3,6 @@ if REQUEST is not None:
raise Unauthorized raise Unauthorized
portal = context.getPortalObject() portal = context.getPortalObject()
integration_site = portal.restrictedTraverse(portal.portal_preferences.getPreferredPayzenIntegrationSite())
_, transaction_id = context.PaymentTransaction_getPayzenId() _, transaction_id = context.PaymentTransaction_getPayzenId()
if transaction_id is not None: if transaction_id is not None:
...@@ -13,19 +12,17 @@ if transaction_id is not None: ...@@ -13,19 +12,17 @@ if transaction_id is not None:
now = DateTime().toZone('UTC') now = DateTime().toZone('UTC')
today = now.asdatetime().strftime('%Y%m%d') today = now.asdatetime().strftime('%Y%m%d')
preferred_integration_site = portal.portal_preferences.getPreferredPayzenIntegrationSite()
integration_site = portal.restrictedTraverse(preferred_integration_site)
if integration_site is None or not preferred_integration_site:
raise ValueError("Integration Site not found or not configured: %s" %
preferred_integration_site)
transaction_id = str(portal.portal_ids.generateNewId( transaction_id = str(portal.portal_ids.generateNewId(
id_group='%s_%s' % (integration_site.getRelativeUrl(), today), id_group='%s_%s' % (integration_site.getRelativeUrl(), today),
id_generator='uid')).zfill(6) id_generator='uid')).zfill(6)
mapping_id = '%s_%s' % (today, transaction_id)
# integration_site.Causality[mapping_id].setDestinationReference(context.getRelativeUrl())
# try:
# integration_site.getCategoryFromMapping('Causality/%s' % mapping_id, create_mapping_line=True, create_mapping=True)
# except ValueError:
# mapping = integration_site.Causality[mapping_id]
# mapping.setDestinationReference('%s' % context.getRelativeUrl())
# else:
# raise ValueError, "Payzen transaction_id already exists"
try: try:
# Init for use later. # Init for use later.
...@@ -35,6 +32,8 @@ try: ...@@ -35,6 +32,8 @@ try:
create_mapping=True) create_mapping=True)
except ValueError: except ValueError:
pass pass
mapping_id = '%s_%s' % (today, transaction_id)
integration_site.Causality[context.getId().replace('-', '_')].setDestinationReference(mapping_id) integration_site.Causality[context.getId().replace('-', '_')].setDestinationReference(mapping_id)
return context.PaymentTransaction_getPayzenId() return context.PaymentTransaction_getPayzenId()
...@@ -3,7 +3,12 @@ if REQUEST is not None: ...@@ -3,7 +3,12 @@ if REQUEST is not None:
raise Unauthorized raise Unauthorized
portal = context.getPortalObject() portal = context.getPortalObject()
integration_site = portal.restrictedTraverse(portal.portal_preferences.getPreferredPayzenIntegrationSite()) preferred_integration_site = portal.portal_preferences.getPreferredPayzenIntegrationSite()
integration_site = portal.restrictedTraverse(preferred_integration_site)
if integration_site is None or not preferred_integration_site:
raise ValueError("Integration Site not found or not configured: %s" %
preferred_integration_site)
payzen_id = integration_site.getCategoryFromMapping('Causality/%s' % context.getId().replace('-', '_')) payzen_id = integration_site.getCategoryFromMapping('Causality/%s' % context.getId().replace('-', '_'))
if payzen_id != 'causality/%s' % context.getId().replace('-', '_'): if payzen_id != 'causality/%s' % context.getId().replace('-', '_'):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment