Example #1
0
    def test_correct_payment_request_with_minimal_options(self):
        cpr = '9052180'
        sender = '481166'
        format = '521'
        suffix = '002'
        reference_number = '8123456789'
        payment_limit_date = datetime.datetime.now()
        quantity = '1100'
        language = 'eu'
        return_url = 'http://localhost:8000'
        payment_modes = ['01']

        html, payment_code = make_payment_request(cpr,
                                                  sender,
                                                  format,
                                                  suffix,
                                                  reference_number,
                                                  payment_limit_date,
                                                  quantity,
                                                  language,
                                                  return_url,
                                                  payment_modes,
                                                  test_environment=True)

        self.assertTrue(html.find(payment_code) != -1)
        self.assertTrue(payment_code.isdigit())
Example #2
0
    def test_correct_payment_request_with_full_options(self):
        cpr = '9052180'
        sender = '481166'
        format = '521'
        suffix = '002'
        reference_number = '8123456789'
        payment_limit_date = datetime.datetime.now()
        quantity = '1100'
        language = 'eu'
        return_url = 'http://localhost:8000'
        payment_modes = ['01']

        extra = {
            'message_1': {
                'eu': 'Message: message_1 in Basque (eu)',
                'es': 'Message: message_1 in Spanish (es)'
            },
            'message_2': {
                'eu': 'Message: message_2 in Basque (eu)',
                'es': 'Message: message_2 in Spanish (es)'
            },
            'message_3': {
                'eu': 'Message: message_3 in Basque (eu)',
                'es': 'Message: message_3 in Spanish (es)'
            },
            'message_4': {
                'eu': 'Message: message_4 in Basque (eu)',
                'es': 'Message: message_4 in Spanish (es)'
            },
            'message_payment_title': {
                'eu': 'Message: message_payment_title in Basque (eu)',
                'es': 'Message: message_payment_title in Spanish (es)'
            },
            'mipago_payment_description': {
                'eu': 'Message: mipago_payment_description in Basque (eu)',
                'es': 'Message: mipago_payment_description in Spanish (es)'
            },
            'logo_1_url': '/data/this-is-a-demo-url-of-logo_1_url.gif',
            'logo_2_url': '/data/this-is-a-demo-url-of-logo_2_url.gif',
            'pdf_xslt_url': '/data/this-is-a-demo-url-of-pdf_xslt_url.xsl',
        }

        html, payment_code = make_payment_request(cpr,
                                                  sender,
                                                  format,
                                                  suffix,
                                                  reference_number,
                                                  payment_limit_date,
                                                  quantity,
                                                  language,
                                                  return_url,
                                                  payment_modes,
                                                  extra=extra,
                                                  test_environment=True)

        self.assertTrue(html.find(payment_code) != -1)
        self.assertTrue(payment_code.isdigit())
Example #3
0
    def test_invalid_formated_reference_number_raises_exception(self):
        cpr = '9052180'
        sender = '123456'
        format = '521'
        suffix = '002'
        reference_number = '12345678'
        payment_limit_date = datetime.datetime.now()
        quantity = '1100'
        language = 'eu'
        return_url = 'http://localhost:8000'
        payment_modes = ['01']

        with self.assertRaises(InvalidReferenceNumber):
            make_payment_request(cpr,
                                 sender,
                                 format,
                                 suffix,
                                 reference_number,
                                 payment_limit_date,
                                 quantity,
                                 language,
                                 return_url,
                                 payment_modes,
                                 test_environment=True)
    def onSuccess(self, fields, REQUEST=None):
        """ Called by form to invoke custom success processing.
            return None (or don't use "return" at all) if processing is
            error-free.

            Return a dictionary like {'field_id':'Error Message'}
            and PFG will stop processing action adapters and
            return back to the form to display your error messages
            for the matching field(s).

            You may also use Products.PloneFormGen.config.FORM_ERROR_MARKER
            as a marker for a message to replace the top-of-the-form error
            message.

            For example, to set a message for the whole form, but not an
            individual field:

            {FORM_ERROR_MARKER:'Yuck! You will need to submit again.'}

            For both a field and form error:

            {FORM_ERROR_MARKER:'Yuck! You will need to submit again.',
             'field_id':'Error Message for field.'}

            Messages may be string types or zope.i18nmessageid objects.
        """
        if self.getMipago_use_debug_environment():
            log.info('Payment requests are being sent to the TEST environment')

        amount = self.get_amount(REQUEST)
        cpr = self.getMipago_cpr_code()
        sender = self.getMipago_sender()
        format = self.getMipago_format()
        suffix = self.getMipago_suffix()
        reference_number = self.get_reference_number()
        language = self.getMipago_screen_language()
        return_url = self.absolute_url() + '/payment_end'
        payment_modes = self.getMipago_payment_modes()
        period_date = self.getMipago_payment_limit_date().asdatetime().date()
        extra = {}

        # Extra messages
        if self.getMessage_2_spanish():
            if 'message2' not in extra:
                extra['message2'] = {}
            extra['message2'].update({'es': self.getMessage_2_spanish()})
        if self.getMessage_2_basque():
            if 'message2' not in extra:
                extra['message2'] = {}

            extra['message2'].update({'eu': self.getMessage_2_spanish()})

        if self.getMessage_3_spanish():
            if 'message3' not in extra:
                extra['message3'] = {}
            extra['message3'].update({'es': self.getMessage_3_spanish()})
        if self.getMessage_3_basque():
            if 'message3' not in extra:
                extra['message3'] = {}

            extra['message3'].update({'eu': self.getMessage_3_spanish()})

        if self.getMessage_4_spanish():
            if 'message4' not in extra:
                extra['message4'] = {}
            extra['message4'].update({'es': self.getMessage_4_spanish()})
        if self.getMessage_4_basque():
            if 'message4' not in extra:
                extra['message4'] = {}

            extra['message4'].update({'eu': self.getMessage_4_spanish()})

        if self.getMessage_top_description_spanish():
            if 'message_payment_title' not in extra:
                extra['message_payment_title'] = {}

            extra['message_payment_title'].update(
                {'es': self.getMessage_top_description_spanish()})

        if self.getMessage_top_description_basque():
            if 'message_payment_title' not in extra:
                extra['message_payment_title'] = {}

            extra['message_payment_title'].update(
                {'eu': self.getMessage_top_description_basque()})

        # Citizen data
        if self.getCitizen_name() != '#NONE#':
            field_name = self.getCitizen_name()
            extra['citizen_name'] = REQUEST.get(field_name)
        if self.getCitizen_surname1() != '#NONE#':
            field_name = self.getCitizen_surname1()
            extra['citizen_surname_1'] = REQUEST.get(field_name)
        if self.getCitizen_surname2() != '#NONE#':
            field_name = self.getCitizen_surname2()
            extra['citizen_surname_2'] = REQUEST.get(field_name)
        if self.getCitizen_nif() != '#NONE#':
            field_name = self.getCitizen_nif()
            extra['citizen_nif'] = REQUEST.get(field_name)
        if self.getCitizen_address() != '#NONE#':
            field_name = self.getCitizen_address()
            extra['citizen_address'] = REQUEST.get(field_name)
        if self.getCitizen_city() != '#NONE#':
            field_name = self.getCitizen_city()
            extra['citizen_city'] = REQUEST.get(field_name)
        if self.getCitizen_postal_code() != '#NONE#':
            field_name = self.getCitizen_postal_code()
            extra['citizen_postal_code'] = REQUEST.get(field_name)
        if self.getCitizen_territory() != '#NONE#':
            field_name = self.getCitizen_territory()
            extra['citizen_territory'] = REQUEST.get(field_name)
        if self.getCitizen_country() != '#NONE#':
            field_name = self.getCitizen_country()
            extra['citizen_country'] = REQUEST.get(field_name)
        if self.getCitizen_phone() != '#NONE#':
            field_name = self.getCitizen_phone()
            extra['citizen_phone'] = REQUEST.get(field_name)
        if self.getCitizen_email() != '#NONE#':
            field_name = self.getCitizen_email()
            extra['citizen_email'] = REQUEST.get(field_name)

        # Payment concept / description
        if self.getMipago_payment_description_es() != '#NONE#':
            if 'mipago_payment_description' not in extra:
                extra['mipago_payment_description'] = {}

            extra['mipago_payment_description'].update(
                {'es': self.getMipago_payment_description_es()})

        if self.getMipago_payment_description_eu() != '#NONE#':
            if 'mipago_payment_description' not in extra:
                extra['mipago_payment_description'] = {}

            extra['mipago_payment_description'].update(
                {'eu': self.getMipago_payment_description_eu()})

        # Logo URLs
        if self.getImage_1_link():
            extra['logo_1_url'] = self.getImage_1_link()

        if self.getImage_2_link():
            extra['logo_2_url'] = self.getImage_2_link()

        # PDF Template
        if self.getPdf_generator_template():
            extra['pdf_xslt_url'] = self.getPdf_generator_template()

        try:
            html, code = make_payment_request(
                cpr, sender, format, suffix, reference_number, period_date,
                amount, language, return_url, payment_modes,
                self.getMipago_use_debug_environment(), extra)
            if REQUEST is not None:
                request = REQUEST
            else:
                request = self.REQUEST

            normalized_fields = self.normalize_fields(REQUEST, fields)
            self.register_payment(code, reference_number, amount,
                                  normalized_fields)

            request.SESSION[MIPAGO_HTML_KEY] = html
            request.SESSION[MIPAGO_PAYMENT_CODE] = code

            return request.response.redirect(self.absolute_url() +
                                             '/@@redirect',
                                             lock=1)

        except Exception, e:
            log.exception(e)

            return {
                FORM_ERROR_MARKER:
                _(u'There was an error processing the payment. Please try again'
                  )
            }