def get_hidden_fields(self, payment):
     #site = Site.objects.get_current()
     order_number = '%s%d' % (self.order_number_prefix, payment.pk)
     amount = str(int(payment.total * 100))  # price is in cents
     # switch to payment.get_total_price() at some point
     # returns a TaxedMoney from 'prices'
     # need the gross element of TaxedMoney
     # also switch to amount.quantize(CENTS, rounding=ROUND_HALF_UP)
     merchant_data = {
         "DS_MERCHANT_AMOUNT": amount,
         "DS_MERCHANT_ORDER": order_number,
         "DS_MERCHANT_MERCHANTCODE": self.merchant_code,
         "DS_MERCHANT_CURRENCY": self.currency,
         "DS_MERCHANT_TRANSACTIONTYPE": '0',
         "DS_MERCHANT_TERMINAL": self.terminal,
         "DS_MERCHANT_MERCHANTURL": self.get_return_url(payment),
         "DS_MERCHANT_URLOK": urljoin(get_base_url(),
                                      payment.get_success_url()),
         "DS_MERCHANT_URLKO": urljoin(get_base_url(),
                                      payment.get_failure_url()),
         "Ds_Merchant_ConsumerLanguage": '002',
     }
     json_data = json.dumps(merchant_data)
     b64_params = base64.b64encode(json_data.encode())
     signature = compute_signature(str(order_number), b64_params,
                                   self.shared_secret)
     data = {
         'Ds_SignatureVersion': self.signature_version,
         'Ds_MerchantParameters': b64_params.decode(),
         'Ds_Signature': signature.decode(),
     }
     return data
Beispiel #2
0
    def get_hidden_fields(self, payment):
        order_number = self.generate_order_number(payment)
        amount = str(int(payment.total * 100))  # price is in cents
        # switch to payment.get_total_price() at some point
        # returns a TaxedMoney from 'prices'
        # need the gross element of TaxedMoney
        # also switch to amount.quantize(CENTS, rounding=ROUND_HALF_UP)
        merchant_data = {
            "DS_MERCHANT_AMOUNT": amount,
            "DS_MERCHANT_ORDER": order_number,
            "DS_MERCHANT_MERCHANTCODE": self.merchant_code,
            "DS_MERCHANT_CURRENCY": self.currency,
            "DS_MERCHANT_TRANSACTIONTYPE": '0',
            "DS_MERCHANT_TERMINAL": self.terminal,
            "DS_MERCHANT_MERCHANTURL": self.get_return_url(payment),
            "DS_MERCHANT_URLOK": urljoin(get_base_url(),
                                         payment.get_success_url()),
            "DS_MERCHANT_URLKO": urljoin(get_base_url(),
                                         payment.get_failure_url()),
            "Ds_Merchant_ConsumerLanguage": '002',
        }

        if hasattr(
                payment,
                'transaction_type') and payment.transaction_type is not None:
            merchant_data.update(
                {'DS_MERCHANT_TRANSACTIONTYPE': payment.transaction_type})

        if hasattr(payment,
                   'payment_method') and payment.payment_method is not None:
            merchant_data.update(
                {'DS_MERCHANT_PAYMETHODS': payment.payment_method})

        if hasattr(payment, 'get_product_description'):
            merchant_data.update({
                'DS_MERCHANT_PRODUCT_DESCRIPTION':
                payment.get_product_description()
            })

        if hasattr(payment, 'get_merchant_data'):
            merchant_data.update(
                {'DS_MERCHANT_MERCHANTDATA': payment.get_merchant_data()})

        json_data = json.dumps(merchant_data)
        b64_params = base64.b64encode(json_data.encode())
        signature = compute_signature(str(order_number), b64_params,
                                      self.shared_secret)
        data = {
            'Ds_SignatureVersion': self.signature_version,
            'Ds_MerchantParameters': b64_params.decode(),
            'Ds_Signature': signature.decode(),
        }
        return data
 def auto_complete_recurring(self, payment):
     renew_token = payment.get_renew_token()
     url = self.process_widget(payment,
                               renew_token,
                               recurring="STANDARD",
                               auto_renew=True)
     if not url.startswith("http") and url != "success":
         url = urljoin(get_base_url(), url)
     return url
    def __init__(self, payu_base_url, script_params={}, *args, **kwargs):
        ret = super(WidgetPaymentForm, self).__init__(*args, **kwargs)
        inline_code = format_html(
            "<script "
            f"src='{payu_base_url}front/widget/js/payu-bootstrap.js' "
            "pay-button='#pay-button' {} >"
            "</script>",
            " ".join("%s=%s" % (k, v) for k, v in script_params.items()),
        )

        form_html = (inline_code + """
            <script>
                function cardSuccess($data) {
                    console.log('callback');
                    console.log($data);
                    $.post(
                        '%s',
                        $data,
                        function(data){ window.location.href=data; }
                    );
                }
                function cvvSuccess($data) {
                    console.log('cvv success');
                    console.log($data);
                    window.location.href="%s";
                }
            </script>
            <div id="payu-widget"></div>
            """ % (
            urljoin(
                get_base_url(),
                self.payment.get_process_url(),
            ),
            urljoin(
                get_base_url(),
                self.payment.get_success_url(),
            ),
        ))
        self.fields["script"].widget = HtmlOutputField(html=form_html)
        return ret
Beispiel #5
0
 def get_processor(self, payment):
     order = payment.get_purchased_items()
     notify_url = urljoin(get_base_url(), payment.get_process_url())
     processor = PaymentProcessor(
         order=order,
         notify_url=notify_url,
         currency=payment.currency,
         description=payment.description,
         customer_ip=payment.customer_ip_address,
         total=payment.total,
         tax=payment.tax,
     )
     processor.set_buyer_data(
         first_name=payment.get_user_first_name(),
         last_name=payment.get_user_last_name(),
         email=payment.get_user_email(),
         phone=None,
     )
     processor.external_id = payment.token
     processor.continueUrl = urljoin(get_base_url(),
                                     payment.get_success_url())
     return processor
Beispiel #6
0
 def test_callable_get_base_url(self, host):
     host.return_value = "example.com/callable"
     self.assertEqual(core.get_base_url(), "https://example.com/callable")
Beispiel #7
0
 def test_text_get_base_url(self, host):
     host.__str__ = lambda x: "example.com/string"
     self.assertEqual(core.get_base_url(), "https://example.com/string")
 def __init__(self, *args, **kwargs):
     ret = super(RenewPaymentForm, self).__init__(*args, **kwargs)
     self.action = urljoin(get_base_url(), self.payment.get_process_url())
     return ret
Beispiel #9
0
 def create_notification_url(self, payment: BasePayment) -> str:
     return urljoin(
         get_base_url(),
         reverse('process_payment', kwargs={"token": payment.token}))
Beispiel #10
0
 def test_callable_get_base_url(self, host):
     host.return_value = "example.com/callable"
     self.assertEqual(core.get_base_url(), "https://example.com/callable")
Beispiel #11
0
 def test_text_get_base_url(self, host):
     host.__str__ = lambda x: "example.com/string"
     self.assertEqual(core.get_base_url(), "https://example.com/string")