Example #1
0
 def adjust_payment_form_data(self, data):
     data['postfinance_methods'] = get_payment_methods(data['event'], data['currency'])
     data['selected_method'] = selected_method = request.args.get('postfinance_method', '')
     base_amount = data['amount']
     if selected_method:
         method = get_payment_method(data['event'], data['currency'], selected_method)
         if method is None:
             raise UserValueError(_('Invalid currency'))
         modifier = Decimal(1 / (1 - method['fee'] / 100))
         data['amount'] = base_amount * modifier
         data['fee'] = data['amount'] - base_amount
         data['form_data'] = self._generate_form_data(data['amount'], data)
     else:
         data['form_data'] = None
         data['fee'] = None
         if data['event_settings']['apply_fees']:  # we don't know the final price
             data['amount'] = None
Example #2
0
    def _generate_form_data(self, amount, data):
        if amount is None:
            return {}
        registration = data['registration']
        personal_data = registration.get_personal_data()
        event = data['event']
        currency = data['currency']
        seed = data['settings']['hash_seed_{}'.format(currency.lower())]
        shop_id = data['settings']['shop_id_{}'.format(currency.lower())]
        method = get_payment_method(event, currency, data['selected_method'])
        if method is None:
            raise UserValueError(_('Invalid currency'))
        template_page = ''  # yes, apparently it's supposed to be empty..
        template_hash = sha512((seed + template_page).encode('utf-8')).hexdigest()
        order_id = self._get_order_id(data)
        locator = registration.locator.uuid

        address = re.sub(r'(\r?\n)+', ', ', personal_data.get('address', ''))
        form_data = {
            'PSPID': shop_id,
            'ORDERID': order_id,
            'AMOUNT': int(amount * 100),
            'CURRENCY': currency,
            'LANGUAGE': session.lang,
            'CN': unicode_to_ascii(remove_accents(registration.full_name[:35], False)),
            'EMAIL': registration.email[:50],
            'OWNERADDRESS': address[:35],
            'OWNERTELNO': personal_data.get('phone', '')[:30],
            'TP': template_page + '&hash=' + template_hash,
            'PM': method['type'],
            'BRAND': method['name'],
            'PARAMVAR': data['settings']['server_url_suffix'],
            'HOMEURL': url_for('event_registration.display_regform', locator, _external=True),
            'ACCEPTURL': url_for_plugin('payment_cern.success', locator, _external=True),
            'CANCELURL': url_for_plugin('payment_cern.cancel', locator, _external=True),
            'DECLINEURL': url_for_plugin('payment_cern.decline', locator, _external=True),
            'EXCEPTIONURL': url_for_plugin('payment_cern.uncertain', locator, _external=True),
            'BACKURL': url_for('payment.event_payment', locator, _external=True)
        }

        form_data['SHASIGN'] = create_hash(seed, form_data)
        return form_data