Beispiel #1
0
class CreditCardDetail(models.Model):
    """
    Stores an encrypted CC number, its information, and its
    displayable number.
    """
    orderpayment = models.ForeignKey(OrderPayment,
                                     unique=True,
                                     edit_inline=True,
                                     num_in_admin=1,
                                     max_num_in_admin=1,
                                     related_name="creditcards")
    creditType = models.CharField(_("Credit Card Type"),
                                  max_length=16,
                                  choices=credit_choices())
    displayCC = models.CharField(_("CC Number (Last 4 digits)"),
                                 max_length=4,
                                 core=True)
    encryptedCC = models.CharField(_("Encrypted Credit Card"),
                                   max_length=40,
                                   blank=True,
                                   null=True,
                                   editable=False)
    expireMonth = models.IntegerField(_("Expiration Month"))
    expireYear = models.IntegerField(_("Expiration Year"))
    ccv = models.IntegerField(_("CCV"), blank=True, null=True)

    def storeCC(self, ccnum):
        # Take as input a valid cc, encrypt it and store the last 4 digits in a visible form
        # Must remember to save it after calling!
        secret_key = settings.SECRET_KEY
        encryption_object = Blowfish.new(secret_key)
        # block cipher length must be a multiple of 8
        padding = ''
        if (len(ccnum) % 8) <> 0:
            padding = 'X' * (8 - (len(ccnum) % 8))
        self.encryptedCC = base64.b64encode(
            encryption_object.encrypt(ccnum + padding))
        self.displayCC = ccnum[-4:]

    def _decryptCC(self):
        secret_key = settings.SECRET_KEY
        encryption_object = Blowfish.new(secret_key)
        # strip padding from decrypted credit card number
        ccnum = encryption_object.decrypt(base64.b64decode(
            self.encryptedCC)).rstrip('X')
        return (ccnum)

    decryptedCC = property(_decryptCC)

    def _expireDate(self):
        return (str(self.expireMonth) + "/" + str(self.expireYear))

    expirationDate = property(_expireDate)

    class Meta:
        verbose_name = _("Credit Card")
        verbose_name_plural = _("Credit Cards")
Beispiel #2
0
def product_feed(
    request,
    category=None,
    template="feeds/googlebase_atom.xml",
    mimetype="application/atom+xml",
):
    """Build a feed of all active products.
    """
    shop_config = Config.objects.get_current()
    if category:
        try:
            cat = Category.objects.get(slug=category)
            products = cat.active_products()
        except Category.DoesNotExist:
            raise Http404(_("Bad Category: %s" % category))
    else:
        cat = None
        products = Product.objects.active()

    products = [
        product
        for product in products
        if "ConfigurableProduct" not in product.get_subtypes()
    ]

    params = {}
    view = "satchmo_atom_feed"
    if category:
        params["category"] = category
        view = "satchmo_atom_category_feed"

    url = shop_config.base_url + reverse(view, None, params)

    payment_choices = [c[1] for c in credit_choices(None, True)]

    return render_to_response(
        template,
        {
            "products": products,
            "category": cat,
            "url": url,
            "shop": shop_config,
            "payments": payment_choices,
            "date": datetime.datetime.now(),
        },
        mimetype=mimetype,
    )
Beispiel #3
0
def product_feed(
    request,
    category=None,
    template="feeds/googlebase_atom.xml",
    mimetype="application/atom+xml",
):
    """Build a feed of all active products.
    """
    shop_config = Config.objects.get_current()
    if category:
        try:
            cat = Category.objects.get(slug=category)
            products = cat.active_products()
        except Category.DoesNotExist:
            raise Http404(_("Bad Category: %s" % category))
    else:
        cat = None
        products = Product.objects.active_by_site()

    products = [
        product
        for product in products
        if "ConfigurableProduct" not in product.get_subtypes()
    ]

    params = {}
    view = "satchmo_atom_feed"
    if category:
        params["category"] = category
        view = "satchmo_atom_category_feed"

    url = shop_config.base_url + reverse(view, None, params)

    payment_choices = [c[1] for c in credit_choices(None, True)]

    return render_to_response(
        template,
        {
            "products": products,
            "category": cat,
            "url": url,
            "shop": shop_config,
            "payments": payment_choices,
            "date": datetime.datetime.now(),
        },
        mimetype=mimetype,
    )
Beispiel #4
0
def product_feed(request,
                 category=None,
                 template="feeds/googlebase_atom.xml",
                 mimetype="application/atom+xml"):
    """Build a feed of all active products.
    """
    shop_config = Config.objects.get_current()
    if category:
        try:
            cat = Category.objects.get(slug=category)
            products = cat.active_products()
        except Category.DoesNotExist:
            raise Http404(_("Bad Category: %s" % category))
    else:
        cat = None
        products = Product.objects.active_by_site()

    products = filter(
        lambda product: "ConfigurableProduct" not in product.get_subtypes(),
        products)

    params = {}
    view = 'satchmo_atom_feed'
    if category:
        params['category'] = category
        view = 'satchmo_atom_category_feed'

    url = shop_config.base_url + urlresolvers.reverse(view, None, params)

    payment_choices = [c[1] for c in credit_choices(None, True)]

    return render_to_response(template, {
        'products': products,
        'category': cat,
        'url': url,
        'shop': shop_config,
        'payments': payment_choices,
        'date': datetime.datetime.now(),
    },
                              mimetype=mimetype)
Beispiel #5
0
def product_feed(request, category=None, template="feeds/googlebase_atom.xml", mimetype="application/atom+xml"):
    """Build a feed of all active products.
    """
    shop_config = Config.objects.get_current()
    if category:
        try:
            cat = Category.objects.get(slug=category)
            products = cat.active_products()
        except Category.DoesNotExist:
            raise Http404(_("Bad Category: %s" % category))
    else:
        cat = None
        products = Product.objects.active_by_site()

    products = filter(lambda product: "ConfigurableProduct" not in product.get_subtypes(), products)

    params = {}
    view = 'satchmo_atom_feed'
    if category:
        params['category'] = category
        view = 'satchmo_atom_category_feed'

    url = shop_config.base_url + urlresolvers.reverse(view, None, params)

    payment_choices = [c[1] for c in credit_choices(None, True)]

    return render_to_response(template, {
        'products': products,
        'category': cat,
        'url': url,
        'shop': shop_config,
        'payments': payment_choices,
        'date': datetime.datetime.now(),
    },
        mimetype=mimetype
    )
Beispiel #6
0
    def __init__(self, choices="__DYNAMIC__", *args, **kwargs):
        if choices == "__DYNAMIC__":
            kwargs["choices"] = credit_choices()

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