コード例 #1
0
    def __init__(self, request, order_form, *args, **kwargs):

        super(PayUSubmissionForm, self).__init__(*args, **kwargs)
        cart = request.cart
        self.order = self.get_or_create_order(request, order_form)
        form_value = lambda name, default: request.POST.get(\
                        'shipping_detail_%s' % name, default)

        shipping_type = request.session.get("shipping_type")
        shipping_total = request.session.get("shipping_total")

        tax_type = request.session.get("tax_type")
        tax_total = request.session.get("tax_total")

        cart_price = cart.total_price()
        ship_price = Decimal(str(shipping_total)).quantize(const.NEAREST_CENT)
        tax_price = Decimal(str(tax_total)).quantize(const.NEAREST_CENT)
        total_price = cart_price + \
            (ship_price if ship_price else Decimal('0')) + \
            (tax_price if tax_price else const.Decimal('0'))
        try:
            s_key = request.session.session_key
        except:
            # for Django 1.4 and above
            s_key = request.session._session_key

        #payu = get_backend_settings('payu')
        #payu specific fields
        pkey = settings.PAYU_MERCHANT_KEY
        self.fields['key'].initial = settings.PAYU_MERCHANT_KEY

        # cart order related fields
        ptxid = self.order.callback_uuid
        self.fields['txnid'].initial = self.order.callback_uuid
        pprice = str(total_price)
        self.fields['amount'].initial = total_price
        self.fields['productinfo'].initial = "Test Products"

        # buyer details
        pfirstname = self.order.billing_detail_first_name
        self.fields['firstname'].initial = pfirstname
        pemail = self.order.billing_detail_email
        self.fields['email'].initial = pemail

        # merchant's side related fields
        self.fields['surl'].initial = self.lambda_reverse(\
            settings.PAYU_SRETURN_URL, cart, self.order.callback_uuid, \
            order_form)
        self.fields['furl'].initial = self.lambda_reverse(\
            settings.PAYU_FRETURN_URL, cart, self.order.callback_uuid, \
            order_form)

        self.fields['udf1'].initial = ""
        self.fields['udf2'].initial = "SSA"
        self.fields['udf3'].initial = ""
        self.fields['udf4'].initial = "15"
        self.fields['udf5'].initial = ""
        self.fields['udf6'].initial = ""
        self.fields['udf7'].initial = ""
        self.fields['udf8'].initial = ""
        self.fields['udf9'].initial = ""
        self.fields['udf10'].initial = ""

        hashp = sha512(pkey.encode('utf-8'))
        hashp.update("|".encode('utf-8'))
        hashp.update(ptxid.encode('utf-8'))
        hashp.update("|".encode('utf-8'))
        hashp.update(pprice.encode('utf-8'))
        hashp.update("|".encode('utf-8'))
        hashp.update("Test Products".encode('utf-8'))
        hashp.update("|".encode('utf-8'))
        hashp.update(pfirstname.encode('utf-8'))
        hashp.update("|".encode('utf-8'))
        hashp.update(pemail.encode('utf-8'))
        hashp.update("|".encode('utf-8'))
        hashp.update("".encode('utf-8'))  #udf1
        hashp.update("|".encode('utf-8'))
        hashp.update("SSA".encode('utf-8'))  #udf2
        hashp.update("|".encode('utf-8'))
        hashp.update("".encode('utf-8'))  #udf3
        hashp.update("|".encode('utf-8'))
        hashp.update("15".encode('utf-8'))  #udf4
        hashp.update("|".encode('utf-8'))
        hashp.update("".encode('utf-8'))  #udf5
        hashp.update("|".encode('utf-8'))
        hashp.update("".encode('utf-8'))  #udf6
        hashp.update("|".encode('utf-8'))
        hashp.update("".encode('utf-8'))  #udf7
        hashp.update("|".encode('utf-8'))
        hashp.update("".encode('utf-8'))  #udf8
        hashp.update("|".encode('utf-8'))
        hashp.update("".encode('utf-8'))  #udf9
        hashp.update("|".encode('utf-8'))
        hashp.update("".encode('utf-8'))  #udf10
        hashp.update("|".encode('utf-8'))
        psalt = settings.PAYU_MERCHANT_SALT
        hashp.update(psalt.encode('utf-8'))
        self.fields['hash'].initial = hashp.hexdigest().lower()

        i = 1
        if cart.has_items():
            for item in cart.items.all():
                rounded = item.unit_price.quantize(const.NEAREST_CENT)
                qty = int(item.quantity)
                self.add_line_item(i, item.description, rounded, qty)
                i += 1

        # Add shipping as a line item
        if shipping_type and shipping_total:
            self.add_line_item(i, shipping_type, shipping_total, 1)
            i += 1

        # Add tax as a line item
        if tax_type and tax_total:
            self.add_line_item(i, tax_type, tax_total, 1)
            i += 1
コード例 #2
0
ファイル: paypal.py プロジェクト: jiejiang/cartridge-payments
    def __init__(self, request, order_form, *args, **kwargs):

        super(PaypalSubmissionForm, self).__init__(*args, **kwargs)

        cart = request.cart
        self.order = self.get_or_create_order(request, order_form)

        form_value = lambda name, default: request.POST.get(\
                        'shipping_detail_%s' % name, default)

        shipping_type = request.session.get("shipping_type")
        shipping_total = request.session.get("shipping_total")

        tax_type = request.session.get("tax_type")
        tax_total = request.session.get("tax_total")

        cart_price = cart.total_price()
        ship_price = Decimal(str(shipping_total)).quantize(const.NEAREST_CENT)
        tax_price = Decimal(str(tax_total)).quantize(const.NEAREST_CENT)
        total_price = cart_price + \
            (ship_price if ship_price else Decimal('0')) + \
            (tax_price if tax_price else const.Decimal('0'))
        try:
            s_key = request.session.session_key
        except:
            # for Django 1.4 and above
            s_key = request.session._session_key

        # a keyword, haha :)
        self.fields['return'] = forms.CharField(widget=forms.HiddenInput())
        #paypal = get_backend_settings('paypal')
        #customer = payment.get_customer_data()
        self.fields['invoice'].initial = self.order.callback_uuid
        self.fields['first_name'].initial = form_value('first_name', '')
        self.fields['last_name'].initial = form_value('last_name', '')
        self.fields['email'].initial = form_value('email', '')
        self.fields['city'].initial = form_value('city', '')
        self.fields['country'].initial = form_value('country_iso', '')
        self.fields['zip'].initial = form_value('postal_code', '')
        self.fields['amount'].initial = total_price
        self.fields['currency_code'].initial = settings.PAYPAL_CURRENCY
        self.fields['business'].initial = settings.PAYPAL_BUSINESS
        self.fields['custom'].initial = ','.join([s_key, str(request.cart.pk)])

        i = 1
        if cart.has_items():
            for item in cart.items.all():
                rounded = item.unit_price.quantize(const.NEAREST_CENT)
                qty = int(item.quantity)
                self.add_line_item(i, item.description, rounded, qty)
                i += 1

        # Add shipping as a line item
        if shipping_type and shipping_total:
            self.add_line_item(i, shipping_type, shipping_total, 1)
            i += 1

        # Add tax as a line item
        if tax_type and tax_total:
            self.add_line_item(i, tax_type, tax_total, 1)
            i += 1

        self.fields['return'].initial = self.lambda_reverse(\
            settings.PAYPAL_RETURN_URL, cart, self.order.callback_uuid, \
            order_form)

        self.fields['notify_url'].initial = self.lambda_reverse(\
            settings.PAYPAL_IPN_URL, cart, self.order.callback_uuid, order_form)