示例#1
0
    def handle(self, *args, **options):
        current_site = get_domain()
        self.stdout.write('Login to Epay.dk configuration page and '
                          'setup following links:\n\n')

        success_name = 'getpaid-epaydk-success'
        path = reverse(success_name)
        self.stdout.write(' * accepturl URL: http://%s%s\n\thttps://%s%s\n\n' %
                          (current_site, path, current_site, path))

        failure_name = 'getpaid-epaydk-failure'
        path = reverse(failure_name)
        self.stdout.write(' * cancelurl URL: http://%s%s\n\thttps://%s%s\n\n' %
                          (current_site, path, current_site, path))

        path = reverse('getpaid-epaydk-online')
        self.stdout.write(
            ' * callbackurl  URL: http://%s%s\n\thttps://%s%s\n\n' % (
                current_site,
                path,
                current_site,
                path,
            ))

        self.stdout.write(
            'To change domain name please edit Sites settings.\n'
            'Don\'t forget to setup your web server to accept\nhttps connection in'
            ' order to use secure links.\n')
 def get_backlink_url(self, request, scheme):
     if 'get_backlink_url' in self.backend_settings:
         return self.backend_settings['get_backlink_url'](request, self.payment)
     return "{}://{}{}".format(
         scheme,
         get_domain(),
         self.payment.order.get_absolute_url())
示例#3
0
    def test_get_domain_site_old_django(self, patch_site):
        with patch.object(utils, 'django') as patch_django:
            patch_django.VERSION = (1, 6)
            domain = utils.get_domain()

        self.assertEquals(domain,
                          patch_site.objects.get_current.return_value.domain)
        patch_site.objects.get_current.assert_called_once_with()
示例#4
0
 def get_return_url(self, type, pk=None):
     kwargs = {'pk': pk} if pk else {}
     url = reverse('getpaid-paypal-%s' % type, kwargs=kwargs)
     domain = get_domain()
     if PaymentProcessor.get_backend_setting('force_ssl', False):
         return 'https://%s%s' % (domain, url)
     else:
         return 'http://%s%s' % (domain, url)
示例#5
0
    def get_gateway_url(self, request):
        """
        @see http://tech.epay.dk/en/payment-window-parameters
        @see http://tech.epay.dk/en/specification
        @see http://tech.epay.dk/en/payment-window-how-to-get-started

        `accepturl` - payment accepted for processing.
        `cancelurl` - user closed window before the payment is completed.
        `callbackurl` - is called instantly from the ePay server when
                        the payment is completed.
        """
        merchantnumber = unicode(self.get_backend_setting("merchantnumber", ""))
        if not merchantnumber:
            raise ImproperlyConfigured("epay.dk requires merchantnumber")

        # According to docs order ID should be a-Z 0-9. Max. 9 characters.
        # We use payment id here as we will have access to order from it.
        payment_id = unicode(self.payment.id)

        currency = unicode(PaymentProcessor.get_number_for_currency(self.payment.currency))

        # timeout in minutes
        timeout = unicode(self.get_backend_setting("timeout", "3"))
        instantcallback = unicode(self.get_backend_setting("instantcallback", "0"))

        params = OrderedDict(
            [
                (u"merchantnumber", merchantnumber),
                (u"orderid", payment_id),
                (u"currency", currency),
                (u"amount", PaymentProcessor.format_amount(self.payment.amount)),
                (u"windowstate", u"3"),  # 3 = Full screen
                (u"mobile", u"1"),  # 1 = autodetect
                (u"timeout", timeout),
                (u"instantcallback", instantcallback),
            ]
        )

        user_data = {u"email": None, u"lang": None}

        signals.user_data_query.send(sender=None, order=self.payment.order, user_data=user_data)

        prefered = user_data["lang"] or "en"
        params["language"] = self._get_language_id(request, prefered=prefered)

        url_data = {"domain": get_domain(request=request), "scheme": request.scheme}

        params["accepturl"] = build_absolute_uri("getpaid-epaydk-success", **url_data)

        if not PaymentProcessor.get_backend_setting("callback_secret_path", ""):
            params["callbackurl"] = build_absolute_uri("getpaid-epaydk-online", **url_data)

        params["cancelurl"] = build_absolute_uri("getpaid-epaydk-failure", **url_data)
        params["hash"] = PaymentProcessor.compute_hash(params)

        url = u"{}?{}".format(self.BACKEND_GATEWAY_BASE_URL, urlencode(params))
        return (url, "GET", {})
示例#6
0
    def get_gateway_url(self, request):
        """
        Routes a payment to Gateway, should return URL for redirection.

        """
        params = {
            'p24_id_sprzedawcy': PaymentProcessor.get_backend_setting('id'),
            'p24_opis': self.get_order_description(self.payment, self.payment.order),
            'p24_session_id': "%s:%s:%s" % (self.payment.pk, self.BACKEND, time.time()),
            'p24_kwota': int(self.payment.amount * 100),
            'p24_email': None,

        }

        user_data = {
            'email': None,
            'lang': None,
            'p24_klient': None,
            'p24_adres': None,
            'p24_kod': None,
            'p24_miasto': None,
            'p24_kraj': None,
        }
        signals.user_data_query.send(sender=None, order=self.payment.order, user_data=user_data)

        for key in ('p24_klient', 'p24_adres', 'p24_kod', 'p24_miasto', 'p24_kraj'):
            if user_data[key] is not None:
                params[key] = user_data[key]

        if user_data['email']:
            params['p24_email'] = user_data['email']

        if user_data['lang'] and user_data['lang'].lower() in PaymentProcessor._ACCEPTED_LANGS:
            params['p24_language'] = user_data['lang'].lower()
        elif PaymentProcessor.get_backend_setting('lang', False) and PaymentProcessor.get_backend_setting(
                'lang').lower() in PaymentProcessor._ACCEPTED_LANGS:
            params['p24_language'] = PaymentProcessor.get_backend_setting('lang').lower()

        params['p24_crc'] = self.compute_sig(params, self._REQUEST_SIG_FIELDS,
                                             PaymentProcessor.get_backend_setting('crc'))

        current_site = get_domain()
        use_ssl = PaymentProcessor.get_backend_setting('ssl_return', False)

        params['p24_return_url_ok'] = ('https://' if use_ssl else 'http://') + current_site + reverse(
            'getpaid:przelewy24:success', kwargs={'pk': self.payment.pk})
        params['p24_return_url_error'] = ('https://' if use_ssl else 'http://') + current_site + reverse(
            'getpaid:przelewy24:failure', kwargs={'pk': self.payment.pk})

        if params['p24_email'] is None:
            raise ImproperlyConfigured(
                '%s requires filling `email` field for payment '
                '(you need to handle `user_data_query` signal)' % self.BACKEND)

        return self._SANDBOX_GATEWAY_URL if PaymentProcessor.get_backend_setting(
            'sandbox', False) else self._GATEWAY_URL, 'POST', params
示例#7
0
    def handle(self, *args, **options):

        current_site = get_domain()

        self.stdout.write(
            'Login to PayU configuration page and setup following links:\n\n')
        self.stdout.write(
            ' * Success URL: http://%s%s\n                https://%s%s\n\n' % (
                current_site,
                reverse('getpaid:payu:success', kwargs={
                    'pk': 1234
                }).replace('1234', '%orderId%'),
                current_site,
                reverse('getpaid:payu:success', kwargs={
                    'pk': 1234
                }).replace('1234', '%orderId%'),
            ))

        self.stdout.write(
            ' * Failure URL: http://%s%s\n                https://%s%s\n\n' % (
                current_site,
                reverse('getpaid:payu:failure',
                        kwargs={
                            'pk': 1234,
                            'error': 9999
                        }).replace('1234', r'%orderId%').replace(
                            '9999', r'%error%'),
                current_site,
                reverse('getpaid:payu:failure',
                        kwargs={
                            'pk': 1234,
                            'error': 9999
                        }).replace('1234', r'%orderId%').replace(
                            '9999', r'%error%'),
            ))

        self.stdout.write(
            ' * Online  URL: http://%s%s\n                https://%s%s\n\n' % (
                current_site,
                reverse('getpaid:payu:online'),
                current_site,
                reverse('getpaid:payu:online'),
            ))

        self.stdout.write(
            'To change domain name please edit Sites settings. '
            'Don\'t forget to setup your web server to accept https connection in order to use secure links.\n'
        )
        if PaymentProcessor.get_backend_setting('testing', False):
            self.stdout.write(
                '\nTesting mode is ON\nPlease be sure that you enabled testing payments in PayU configuration page.\n'
            )
        if PaymentProcessor.get_backend_setting('signing', False):
            self.stdout.write(
                '\nRequest signing is ON\n * Please be sure that you enabled signing payments '
                'in PayU configuration page.\n')
示例#8
0
    def handle(self, *args, **options):
        current_site = get_domain()

        self.stdout.write(
            'Please contact with Przelewy24 ([email protected]) and provide them with the following URL: \n\n')

        self.stdout.write(
            ('https://' if PaymentProcessor.get_backend_setting('ssl_return', False) else 'http://') + '%s%s\n\n' % (
                current_site, reverse('getpaid-przelewy24-online'))
        )

        self.stdout.write(
            'This is an additional URL for accepting payment status updates.\n\n')

        self.stdout.write(
            'To change domain name please edit Sites settings. Don\'t forget to setup your web server to accept https connection in order to use secure links.\n')
        if PaymentProcessor.get_backend_setting('sandbox', False):
            self.stdout.write('\nSandbox mode is ON.\n')
    def handle(self, *args, **options):

        current_site = get_domain()

        self.stdout.write('Login to PayU configuration page and setup following links:\n\n')
        self.stdout.write(
            ' * Success URL: http://%s%s\n                https://%s%s\n\n' % (
                current_site,
                reverse('getpaid:payu:success', kwargs={'pk': 1234}).replace('1234', '%orderId%'),
                current_site,
                reverse('getpaid:payu:success', kwargs={'pk': 1234}).replace('1234', '%orderId%'),)
        )

        self.stdout.write(
            ' * Failure URL: http://%s%s\n                https://%s%s\n\n' % (
                current_site,
                reverse('getpaid:payu:failure', kwargs={'pk': 1234, 'error': 9999}).replace('1234',
                                                                                            r'%orderId%').replace(
                    '9999', r'%error%'),
                current_site,
                reverse('getpaid:payu:failure', kwargs={'pk': 1234, 'error': 9999}).replace('1234',
                                                                                            r'%orderId%').replace(
                    '9999', r'%error%'),)
        )

        self.stdout.write(
            ' * Online  URL: http://%s%s\n                https://%s%s\n\n' % (
                current_site,
                reverse('getpaid:payu:online'),
                current_site,
                reverse('getpaid:payu:online'),
            )
        )

        self.stdout.write(
            'To change domain name please edit Sites settings. '
            'Don\'t forget to setup your web server to accept https connection in order to use secure links.\n')
        if PaymentProcessor.get_backend_setting('testing', False):
            self.stdout.write(
                '\nTesting mode is ON\nPlease be sure that you enabled testing payments in PayU configuration page.\n')
        if PaymentProcessor.get_backend_setting('signing', False):
            self.stdout.write(
                '\nRequest signing is ON\n * Please be sure that you enabled signing payments '
                'in PayU configuration page.\n')
示例#10
0
    def _build_urls(self, params):
        domain = get_domain()
        online_domain = return_domain = "http"

        if self.get_backend_setting('force_ssl_online', False):
            online_domain = "https"
        if self.get_backend_setting('force_ssl_return', False):
            return_domain = "https"

        online_domain = "{}://{}".format(online_domain, domain)
        return_domain = "{}://{}".format(return_domain, domain)

        params['wyn_url'] = online_domain + reverse(
            'getpaid-transferuj-online')
        params['pow_url'] = return_domain + reverse(
            'getpaid-transferuj-success', kwargs={'pk': self.payment.pk})
        params['pow_url_blad'] = return_domain + reverse(
            'getpaid-transferuj-failure', kwargs={'pk': self.payment.pk})

        return params
示例#11
0
    def _build_urls(self, params):
        domain = get_domain()
        online_domain = return_domain = "http"

        if self.get_backend_setting('force_ssl_online', False):
            online_domain = "https"
        if self.get_backend_setting('force_ssl_return', False):
            return_domain = "https"

        online_domain = "{}://{}".format(online_domain, domain)
        return_domain = "{}://{}".format(return_domain, domain)

        params['wyn_url'] = online_domain + reverse(
            'getpaid:transferuj:online'
        )
        params['pow_url'] = return_domain + reverse(
            'getpaid:transferuj:success', kwargs={'pk': self.payment.pk}
        )
        params['pow_url_blad'] = return_domain + reverse(
            'getpaid:transferuj:failure', kwargs={'pk': self.payment.pk}
        )

        return params
    def handle(self, *args, **options):
        current_site = get_domain()
        self.stdout.write('Login to Epay.dk configuration page and '
                          'setup following links:\n\n')

        success_name = 'getpaid:epaydk:success'
        path = reverse(success_name)
        self.stdout.write(
            ' * accepturl URL: http://%s%s\n\thttps://%s%s\n\n' % (
                current_site,
                path,
                current_site,
                path)
        )

        failure_name = 'getpaid:epaydk:failure'
        path = reverse(failure_name)
        self.stdout.write(
            ' * cancelurl URL: http://%s%s\n\thttps://%s%s\n\n' % (
                current_site,
                path,
                current_site,
                path)
        )

        path = reverse('getpaid:epaydk:online')
        self.stdout.write(
            ' * callbackurl  URL: http://%s%s\n\thttps://%s%s\n\n' % (
                current_site,
                path,
                current_site,
                path,)
        )

        self.stdout.write('To change domain name please edit Sites settings.\n'
                          'Don\'t forget to setup your web server to accept\nhttps connection in'
                          ' order to use secure links.\n')
示例#13
0
    def get_gateway_url(self, request):
        """
        @see http://tech.epay.dk/en/payment-window-parameters
        @see http://tech.epay.dk/en/specification
        @see http://tech.epay.dk/en/payment-window-how-to-get-started

        `accepturl` - payment accepted for processing.
        `cancelurl` - user closed window before the payment is completed.
        `callbackurl` - is called instantly from the ePay server when
                        the payment is completed.
        """
        merchantnumber = unicode(
            self.get_backend_setting('merchantnumber', ''))
        if not merchantnumber:
            raise ImproperlyConfigured("epay.dk requires merchantnumber")

        # According to docs order ID should be a-Z 0-9. Max. 9 characters.
        # We use payment id here as we will have access to order from it.
        payment_id = unicode(self.payment.id)

        currency = unicode(PaymentProcessor.get_number_for_currency(
                           self.payment.currency))

        # timeout in minutes
        timeout = unicode(self.get_backend_setting('timeout', '3'))
        instantcallback = unicode(self.get_backend_setting('instantcallback',
                                                           '0'))

        params = OrderedDict([
            (u'merchantnumber', merchantnumber),
            (u'orderid', payment_id),
            (u'currency', currency),
            (u'amount', PaymentProcessor.format_amount(self.payment.amount)),
            (u'windowstate', u'3'),  # 3 = Full screen
            (u'mobile', u'1'),  # 1 = autodetect
            (u'timeout', timeout),
            (u'instantcallback', instantcallback),
        ])

        user_data = {
            u'email': None,
            u'lang': None,
        }

        signals.user_data_query.send(
            sender=None, order=self.payment.order, user_data=user_data)

        prefered = user_data['lang'] or 'en'
        params['language'] = self._get_language_id(request, prefered=prefered)

        url_data = {
            'domain': get_domain(request=request),
            'scheme': request.scheme
        }

        params['accepturl'] = build_absolute_uri('getpaid:epaydk:success',
                                                 **url_data)

        if not PaymentProcessor.get_backend_setting('callback_secret_path',
                                                    ''):
            params['callbackurl'] = build_absolute_uri(
                'getpaid:epaydk:online', **url_data
            )

        params['cancelurl'] = build_absolute_uri('getpaid:epaydk:failure',
                                                 **url_data)
        params['hash'] = PaymentProcessor.compute_hash(params)

        url = u"{}?{}".format(self.BACKEND_GATEWAY_BASE_URL, urlencode(params))
        return (url, 'GET', {})
示例#14
0
    def get_gateway_url(self, request):
        """
        @see http://tech.epay.dk/en/payment-window-parameters
        @see http://tech.epay.dk/en/specification
        @see http://tech.epay.dk/en/payment-window-how-to-get-started

        `accepturl` - payment accepted for processing.
        `cancelurl` - user closed window before the payment is completed.
        `callbackurl` - is called instantly from the ePay server when
                        the payment is completed.
        """
        merchantnumber = unicode(self.get_backend_setting(
            'merchantnumber', ''))
        if not merchantnumber:
            raise ImproperlyConfigured("epay.dk requires merchantnumber")

        # According to docs order ID should be a-Z 0-9. Max. 9 characters.
        # We use payment id here as we will have access to order from it.
        payment_id = unicode(self.payment.id)

        currency = unicode(
            PaymentProcessor.get_number_for_currency(self.payment.currency))

        # timeout in minutes
        timeout = unicode(self.get_backend_setting('timeout', '3'))
        instantcallback = unicode(
            self.get_backend_setting('instantcallback', '0'))

        params = OrderedDict([
            (u'merchantnumber', merchantnumber),
            (u'orderid', payment_id),
            (u'currency', currency),
            (u'amount', PaymentProcessor.format_amount(self.payment.amount)),
            (u'windowstate', u'3'),  # 3 = Full screen
            (u'mobile', u'1'),  # 1 = autodetect
            (u'timeout', timeout),
            (u'instantcallback', instantcallback),
        ])

        user_data = {
            u'email': None,
            u'lang': None,
        }

        signals.user_data_query.send(sender=None,
                                     order=self.payment.order,
                                     user_data=user_data)

        prefered = user_data['lang'] or 'en'
        params['language'] = self._get_language_id(request, prefered=prefered)

        url_data = {
            'domain': get_domain(request=request),
            'scheme': request.scheme
        }

        params['accepturl'] = build_absolute_uri('getpaid-epaydk-success',
                                                 **url_data)

        if not PaymentProcessor.get_backend_setting('callback_secret_path',
                                                    ''):
            params['callbackurl'] = build_absolute_uri('getpaid-epaydk-online',
                                                       **url_data)

        params['cancelurl'] = build_absolute_uri('getpaid-epaydk-failure',
                                                 **url_data)
        params['hash'] = PaymentProcessor.compute_hash(params)

        url = u"{}?{}".format(self.BACKEND_GATEWAY_BASE_URL, urlencode(params))
        return (url, 'GET', {})
示例#15
0
 def get_URL(self, pk):
     url = reverse('getpaid:dotpay:return', kwargs={'pk': pk})
     if PaymentProcessor.get_backend_setting('force_ssl', False):
         return u'https://%s%s' % (get_domain(), url)
     else:
         return u'http://%s%s' % (get_domain(), url)
示例#16
0
    def get_gateway_url(self, request):
        """
        Tricky process that requires to get auth key, send order via POST and
        then present final URL for redirection to finalize payment.
        """

        grant_type = self.get_backend_setting('grant_type', 'client_credentials')
        if grant_type == 'client_credentials':
            client_id = self.get_backend_setting('client_id')
            client_secret = self.get_backend_setting('client_secret')
            url = "{gateway_url}pl/standard/user/oauth/authorize?" \
                  "grant_type={grant_type}&" \
                  "client_id={client_id}&" \
                  "client_secret={client_secret}".format(gateway_url=self._GATEWAY_URL,
                                                         grant_type=grant_type, client_id=client_id,
                                                         client_secret=client_secret)
        elif grant_type == 'trusted_merchant':
            raise ImproperlyConfigured('grant_type not yet supported')
        else:
            raise ImproperlyConfigured('grant_type should be one of: "trusted_merchant", "client_credentials"')

        response = requests.get(url)
        assert response.status_code == 200

        response_data = response.json()
        access_token = response_data['access_token']
        token_type = response_data['token_type']

        headers = {"Authorization": "{token_type} {access_token}".format(
            token_type=token_type.title(), access_token=access_token)}

        pos_id = self.get_backend_setting('pos_id', None)

        user_data = {
            'email': None,
            'lang': None,
        }

        signals.user_data_query.send(
            sender=None, order=self.payment.order, user_data=user_data)

        if not user_data['email']:
            raise ImproperlyConfigured

        buyer_info = dict(  # dane kupującego
            email=user_data['email'],
        )

        if user_data['lang'] and user_data['lang'].lower() in self._ACCEPTED_LANGS:
            buyer_info['language'] = user_data['lang'].lower()
        elif self.get_backend_setting('lang', False
                                      ) and (self.get_backend_setting('lang').lower() in self._ACCEPTED_LANGS):
            buyer_info['language'] = six.text_type(self.get_backend_setting('lang').lower())

        customer_id = user_data.get('id', None)
        if customer_id:
            buyer_info['extCustomerId'] = customer_id

        customer_first_name = user_data.get('first_name', None)
        if customer_first_name:
            buyer_info['firstName'] = customer_first_name

        customer_last_name = user_data.get('last_name', None)
        if customer_last_name:
            buyer_info['last_Namme'] = customer_last_name

        customer_phone = user_data.get('phone', None)
        if customer_phone:
            buyer_info['phone'] = customer_phone

        current_site = getpaid_utils.get_domain(request)
        use_ssl = self.get_backend_setting('ssl_return', True)

        notify_url = "http{}://{}{}".format(
            's' if use_ssl else '',
            current_site,
            reverse('getpaid:payu_rest:confirm')
        )

        params = dict(
            customerIp=getpaid_utils.get_ip_address(request),
            merchantPosId=pos_id,
            description=self.get_order_description(self.payment, self.payment.order),
            currencyCode=self.payment.currency.upper(),
            totalAmount=str(int(self.payment.amount * 100)),
            buyer=buyer_info,
            products=[dict(
                name='Payment #{} from {}'.format(self.payment.pk, current_site),
                unitPrice=str(int(self.payment.amount * 100)),
                quantity="1",
                # ### optional:
                # virtual=True,
                # listingDate='',
            )],

            # ### optional:
            notifyUrl=notify_url,
            extOrderId=str(self.payment.pk),
            # validityTime='',
            # additionalDescription='',
            continueUrl='http://127.0.0.1:8000/',
            # payMethods=None,
        )

        order_url = "{gateway_url}api/v2_1/orders".format(gateway_url=self._GATEWAY_URL)

        order_register = requests.post(order_url, json=params, headers=headers, allow_redirects=False)
        order_register_data = order_register.json()
        status = order_register_data.get('status', {}).get('statusCode', '')
        if status != 'SUCCESS':
            logger.error('Houston, we have a problem with this payment trajectory: {}'.format(status))
            return reverse('getpaid:failure-fallback', kwargs=dict(pk=self.payment.pk)), 'GET', {}
        final_url = order_register_data.get('redirectUri')

        return final_url, 'GET', {}
示例#17
0
    def get_gateway_url(self, request):
        """
        Tricky process that requires to get auth key, send order via POST and
        then present final URL for redirection to finalize payment.
        """

        grant_type = self.get_backend_setting('grant_type',
                                              'client_credentials')
        if grant_type == 'client_credentials':
            client_id = self.get_backend_setting('client_id')
            client_secret = self.get_backend_setting('client_secret')
            url = "{gateway_url}pl/standard/user/oauth/authorize?" \
                  "grant_type={grant_type}&" \
                  "client_id={client_id}&" \
                  "client_secret={client_secret}".format(gateway_url=self._GATEWAY_URL,
                                                         grant_type=grant_type, client_id=client_id,
                                                         client_secret=client_secret)
        elif grant_type == 'trusted_merchant':
            raise ImproperlyConfigured('grant_type not yet supported')
        else:
            raise ImproperlyConfigured(
                'grant_type should be one of: "trusted_merchant", "client_credentials"'
            )

        response = requests.get(url)
        assert response.status_code == 200

        response_data = response.json()
        access_token = response_data['access_token']
        token_type = response_data['token_type']

        headers = {
            "Authorization":
            "{token_type} {access_token}".format(token_type=token_type.title(),
                                                 access_token=access_token)
        }

        pos_id = self.get_backend_setting('pos_id', None)

        user_data = {
            'email': None,
            'lang': None,
        }

        signals.user_data_query.send(sender=None,
                                     order=self.payment.order,
                                     user_data=user_data)

        if not user_data['email']:
            raise ImproperlyConfigured

        buyer_info = dict(  # dane kupującego
            email=user_data['email'], )

        if user_data['lang'] and user_data['lang'].lower(
        ) in self._ACCEPTED_LANGS:
            buyer_info['language'] = user_data['lang'].lower()
        elif self.get_backend_setting(
                'lang', False) and (self.get_backend_setting('lang').lower()
                                    in self._ACCEPTED_LANGS):
            buyer_info['language'] = six.text_type(
                self.get_backend_setting('lang').lower())

        customer_id = user_data.get('id', None)
        if customer_id:
            buyer_info['extCustomerId'] = customer_id

        customer_first_name = user_data.get('first_name', None)
        if customer_first_name:
            buyer_info['firstName'] = customer_first_name

        customer_last_name = user_data.get('last_name', None)
        if customer_last_name:
            buyer_info['last_Namme'] = customer_last_name

        customer_phone = user_data.get('phone', None)
        if customer_phone:
            buyer_info['phone'] = customer_phone

        current_site = getpaid_utils.get_domain(request)
        use_ssl = self.get_backend_setting('ssl_return', True)

        notify_url = "http{}://{}{}".format(
            's' if use_ssl else '', current_site,
            reverse('getpaid:payu_rest:confirm'))

        params = dict(
            customerIp=getpaid_utils.get_ip_address(request),
            merchantPosId=pos_id,
            description=self.get_order_description(self.payment,
                                                   self.payment.order),
            currencyCode=self.payment.currency.upper(),
            totalAmount=str(int(self.payment.amount * 100)),
            buyer=buyer_info,
            products=[
                dict(
                    name='Payment #{} from {}'.format(self.payment.pk,
                                                      current_site),
                    unitPrice=str(int(self.payment.amount * 100)),
                    quantity="1",
                    # ### optional:
                    # virtual=True,
                    # listingDate='',
                )
            ],

            # ### optional:
            notifyUrl=notify_url,
            extOrderId=str(self.payment.pk),
            # validityTime='',
            # additionalDescription='',
            continueUrl='http://127.0.0.1:8000/',
            # payMethods=None,
        )

        order_url = "{gateway_url}api/v2_1/orders".format(
            gateway_url=self._GATEWAY_URL)

        order_register = requests.post(order_url,
                                       json=params,
                                       headers=headers,
                                       allow_redirects=False)
        order_register_data = order_register.json()
        status = order_register_data.get('status', {}).get('statusCode', '')
        if status != 'SUCCESS':
            logger.error(
                'Houston, we have a problem with this payment trajectory: {}'.
                format(status))
            return reverse('getpaid:failure-fallback',
                           kwargs=dict(pk=self.payment.pk)), 'GET', {}
        final_url = order_register_data.get('redirectUri')

        return final_url, 'GET', {}
示例#18
0
 def get_URLC(self):
     urlc = reverse('getpaid:dotpay:online')
     if PaymentProcessor.get_backend_setting('force_ssl', False):
         return u'https://%s%s' % (get_domain(), urlc)
     else:
         return u'http://%s%s' % (get_domain(), urlc)
示例#19
0
 def get_URLC(self):
     urlc = reverse('getpaid:dotpay:online')
     if self.get_backend_setting('force_ssl', False):
         return u'https://%s%s' % (get_domain(), urlc)
     else:
         return u'http://%s%s' % (get_domain(), urlc)
示例#20
0
 def get_URL(self, pk):
     url = reverse('getpaid:dotpay:return', kwargs={'pk': pk})
     if self.get_backend_setting('force_ssl', False):
         return u'https://%s%s' % (get_domain(), url)
     else:
         return u'http://%s%s' % (get_domain(), url)
示例#21
0
 def get_URLC(self):
     urlc = reverse('getpaid-dotpay-online')
     if PaymentProcessor.get_backend_setting('force_ssl', False):
         return u'https://%s%s' % (get_domain(), urlc)
     else:
         return u'http://%s%s' % (get_domain(), urlc)
示例#22
0
 def get_backlink_url(self, request, scheme):
     if 'get_backlink_url' in self.backend_settings:
         return self.backend_settings['get_backlink_url'](request,
                                                          self.payment)
     return "{}://{}{}".format(scheme, get_domain(),
                               self.payment.order.get_absolute_url())
示例#23
0
 def test_get_domain_getpaid_const(self):
     self.assertEquals('example1.com', utils.get_domain())
示例#24
0
    def get_gateway_url(self, request):
        """
        Routes a payment to Gateway, should return URL for redirection.

        """
        params = {
            'p24_id_sprzedawcy':
            PaymentProcessor.get_backend_setting('id'),
            'p24_opis':
            self.get_order_description(self.payment, self.payment.order),
            'p24_session_id':
            "%s:%s:%s" % (self.payment.pk, self.BACKEND, time.time()),
            'p24_kwota':
            int(self.payment.amount * 100),
            'p24_email':
            None,
        }

        user_data = {
            'email': None,
            'lang': None,
            'p24_klient': None,
            'p24_adres': None,
            'p24_kod': None,
            'p24_miasto': None,
            'p24_kraj': None,
        }
        signals.user_data_query.send(sender=None,
                                     order=self.payment.order,
                                     user_data=user_data)

        for key in ('p24_klient', 'p24_adres', 'p24_kod', 'p24_miasto',
                    'p24_kraj'):
            if user_data[key] is not None:
                params[key] = user_data[key]

        if user_data['email']:
            params['p24_email'] = user_data['email']

        if user_data['lang'] and user_data['lang'].lower(
        ) in PaymentProcessor._ACCEPTED_LANGS:
            params['p24_language'] = user_data['lang'].lower()
        elif PaymentProcessor.get_backend_setting(
                'lang', False) and PaymentProcessor.get_backend_setting(
                    'lang').lower() in PaymentProcessor._ACCEPTED_LANGS:
            params['p24_language'] = PaymentProcessor.get_backend_setting(
                'lang').lower()

        params['p24_crc'] = self.compute_sig(
            params, self._REQUEST_SIG_FIELDS,
            PaymentProcessor.get_backend_setting('crc'))

        current_site = get_domain()
        use_ssl = PaymentProcessor.get_backend_setting('ssl_return', False)

        params['p24_return_url_ok'] = (
            'https://' if use_ssl else 'http://') + current_site + reverse(
                'getpaid:przelewy24:success', kwargs={'pk': self.payment.pk})
        params['p24_return_url_error'] = (
            'https://' if use_ssl else 'http://') + current_site + reverse(
                'getpaid:przelewy24:failure', kwargs={'pk': self.payment.pk})

        if params['p24_email'] is None:
            raise ImproperlyConfigured(
                '%s requires filling `email` field for payment '
                '(you need to handle `user_data_query` signal)' % self.BACKEND)

        return self._SANDBOX_GATEWAY_URL if PaymentProcessor.get_backend_setting(
            'sandbox', False) else self._GATEWAY_URL, 'POST', params
示例#25
0
    def get_gateway_url(self, request):
        """
        Routes a payment to Gateway, should return URL for redirection.

        """
        params = {
            "p24_id_sprzedawcy": PaymentProcessor.get_backend_setting("id"),
            "p24_opis": self.get_order_description(self.payment, self.payment.order),
            "p24_session_id": "%s:%s:%s" % (self.payment.pk, self.BACKEND, time.time()),
            "p24_kwota": int(self.payment.amount * 100),
            "p24_email": None,
        }

        user_data = {
            "email": None,
            "lang": None,
            "p24_klient": None,
            "p24_adres": None,
            "p24_kod": None,
            "p24_miasto": None,
            "p24_kraj": None,
        }
        signals.user_data_query.send(sender=None, order=self.payment.order, user_data=user_data)

        for key in ("p24_klient", "p24_adres", "p24_kod", "p24_miasto", "p24_kraj"):
            if user_data[key] is not None:
                params[key] = user_data[key]

        if user_data["email"]:
            params["p24_email"] = user_data["email"]

        if user_data["lang"] and user_data["lang"].lower() in PaymentProcessor._ACCEPTED_LANGS:
            params["p24_language"] = user_data["lang"].lower()
        elif (
            PaymentProcessor.get_backend_setting("lang", False)
            and PaymentProcessor.get_backend_setting("lang").lower() in PaymentProcessor._ACCEPTED_LANGS
        ):
            params["p24_language"] = PaymentProcessor.get_backend_setting("lang").lower()

        params["p24_crc"] = self.compute_sig(
            params, self._REQUEST_SIG_FIELDS, PaymentProcessor.get_backend_setting("crc")
        )

        current_site = get_domain()
        use_ssl = PaymentProcessor.get_backend_setting("ssl_return", False)

        params["p24_return_url_ok"] = (
            ("https://" if use_ssl else "http://")
            + current_site
            + reverse("getpaid-przelewy24-success", kwargs={"pk": self.payment.pk})
        )
        params["p24_return_url_error"] = (
            ("https://" if use_ssl else "http://")
            + current_site
            + reverse("getpaid-przelewy24-failure", kwargs={"pk": self.payment.pk})
        )

        if params["p24_email"] is None:
            raise ImproperlyConfigured(
                "%s requires filling `email` field for payment (you need to handle `user_data_query` signal)"
                % self.BACKEND
            )

        return (
            self._SANDBOX_GATEWAY_URL if PaymentProcessor.get_backend_setting("sandbox", False) else self._GATEWAY_URL,
            "POST",
            params,
        )
示例#26
0
    def get_gateway_url(self, request):
        """
        Routes a payment to Gateway, should return URL for redirection.

        """

        self.payment.external_id = self.generate_payment_id()
        params = {
            'ClientId': six.text_type(PaymentProcessor.get_backend_setting('client_id')),
            'Password': six.text_type(PaymentProcessor.get_backend_setting('password')),
            'OrderId': self.payment.external_id,
            'Total': self.payment.amount,
            'Currency': EServiceCurrency.get_by_name(self.payment.currency)
        }

        token = self.get_token(params)
        params.pop('Password')

        if token is None:
            # TODO Handle broken payment
            logger.error('No token could be retrieved for the payment')

        params['Token'] = six.text_type(token)

        user_data = {
            'lang': None,
        }

        signals.user_data_query.send(sender=None, order=self.payment.order, user_data=user_data)

        if user_data['lang'] and user_data['lang'].lower() in PaymentProcessor._ACCEPTED_LANGS:
            params['lang'] = user_data['lang'].lower()
        elif PaymentProcessor.get_backend_setting('lang', False) and \
                PaymentProcessor.get_backend_setting('lang').lower() in PaymentProcessor._ACCEPTED_LANGS:
            params['lang'] = six.text_type(PaymentProcessor.get_backend_setting('lang').lower())

        url_data = {
            'domain': get_domain(request=request),
            'scheme': request.scheme
        }
        params['okUrl'] = build_absolute_uri('getpaid-eservice-success',  **url_data)
        params['failUrl'] = build_absolute_uri('getpaid-eservice-failure', **url_data)
        params['pendingUrl'] = build_absolute_uri('getpaid-eservice-pending', **url_data)

        params['StoreType'] = PaymentProcessor.get_backend_setting('store_type')
        params['TranType'] = u'Auth'

        params['ConsumerName'] = user_data.get('first_name', u'')
        params['ConsumerSurname'] = user_data.get('last_name', u'')

        params['ShipToName'] = user_data.get('shipping_country', u'')
        params['ShipToPostalCode'] = user_data.get('shipping_zip_code', u'')
        params['ShipToStreet1'] = user_data.get('shipping_address', u'')
        params['ShipToCity'] = user_data.get('shipping_city', u'')
        params['ShipToCountry'] = u'PL'

        params['BillToName'] = user_data.get('name') or u'{} {}'.format(user_data.get('first_name', u''),
                                                                        user_data.get('last_name', u''))
        params['BillToPostalCode'] = user_data.get('adress_zip_code', u'')
        params['BillToStreet1'] = user_data.get('adress', u'')
        params['BillToCity'] = user_data.get('address_city', u'')
        params['BillToCountry'] = user_data.get('address_country', u'')

        logger.info(u'New payment using GET: %s' % params)
        for key in params.keys():
            params[key] = six.text_type(params[key]).encode('utf-8')
        return self.gateway_url + 'fim/eservicegate?' + urlencode(params), 'GET', {}
示例#27
0
    def get_gateway_url(self, request):
        """
        Routes a payment to Gateway, should return URL for redirection.

        """

        self.payment.external_id = self.generate_payment_id()
        params = {
            'ClientId':
            six.text_type(PaymentProcessor.get_backend_setting('client_id')),
            'Password':
            six.text_type(PaymentProcessor.get_backend_setting('password')),
            'OrderId':
            self.payment.external_id,
            'Total':
            self.payment.amount,
            'Currency':
            EServiceCurrency.get_by_name(self.payment.currency)
        }

        token = self.get_token(params)
        params.pop('Password')

        if token is None:
            # TODO Handle broken payment
            logger.error('No token could be retrieved for the payment')

        params['Token'] = six.text_type(token)

        user_data = {
            'lang': None,
        }

        signals.user_data_query.send(sender=None,
                                     order=self.payment.order,
                                     user_data=user_data)

        if user_data['lang'] and user_data['lang'].lower(
        ) in PaymentProcessor._ACCEPTED_LANGS:
            params['lang'] = user_data['lang'].lower()
        elif PaymentProcessor.get_backend_setting('lang', False) and \
                PaymentProcessor.get_backend_setting('lang').lower() in PaymentProcessor._ACCEPTED_LANGS:
            params['lang'] = six.text_type(
                PaymentProcessor.get_backend_setting('lang').lower())

        url_data = {
            'domain': get_domain(request=request),
            'scheme': request.scheme
        }
        params['okUrl'] = build_absolute_uri('getpaid-eservice-success',
                                             **url_data)
        params['failUrl'] = build_absolute_uri('getpaid-eservice-failure',
                                               **url_data)
        params['pendingUrl'] = build_absolute_uri('getpaid-eservice-pending',
                                                  **url_data)

        params['StoreType'] = PaymentProcessor.get_backend_setting(
            'store_type')
        params['TranType'] = u'Auth'

        params['ConsumerName'] = user_data.get('first_name', u'')
        params['ConsumerSurname'] = user_data.get('last_name', u'')

        params['ShipToName'] = user_data.get('shipping_country', u'')
        params['ShipToPostalCode'] = user_data.get('shipping_zip_code', u'')
        params['ShipToStreet1'] = user_data.get('shipping_address', u'')
        params['ShipToCity'] = user_data.get('shipping_city', u'')
        params['ShipToCountry'] = u'PL'

        params['BillToName'] = user_data.get('name') or u'{} {}'.format(
            user_data.get('first_name', u''), user_data.get('last_name', u''))
        params['BillToPostalCode'] = user_data.get('adress_zip_code', u'')
        params['BillToStreet1'] = user_data.get('adress', u'')
        params['BillToCity'] = user_data.get('address_city', u'')
        params['BillToCountry'] = user_data.get('address_country', u'')

        logger.info(u'New payment using GET: %s' % params)
        for key in params.keys():
            params[key] = six.text_type(params[key]).encode('utf-8')
        return self.gateway_url + 'fim/eservicegate?' + urlencode(
            params), 'GET', {}