如何在Djangoscar 2.0中定义instore cashpaymentmethod

2024-06-09 14:27:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我想实施现金支付,其中客户拿起他的订单在商店,并支付相同的那里。稍后还会有一个选项供客户在交付订单时支付现金(注意:我知道有一个oscar货到付款应用程序,但无论如何我都会问)。在2.0版中,oscar推荐的定义现金支付方式的新方法是什么?你知道吗

以前(虽然我再也找不到文档),付款方式是通过扩展基本付款方式来定义的,如下所示:

# mystore/forked_apps/payment/methods.py

class Base(object):
    """
    Payment method base class
    """

    code = '__default__'
    name = 'Default payment'

    description = ''
    enabled = False
    default = False


class CashOnPickup(Base):
    code = 'cash_on_pickup'
    name = 'Cash on Pickup'
    description = 'Pay when you pick up your items'
    enabled = True
    default = True

然而,新的documentation提到了SourceTypeSourceTransaction模型的使用,我再也找不到以前关于定义上述方法的文档了。你知道吗

因此,在django oscar 2.0中定义店内现金支付方法的建议方式是什么?是在一个方法.py文件不再是路要走?我们应该改为SourceTypeSourceTransaction子类吗?或者,方法是简单地为它们创建新的数据库条目,如下面的代码所示?你知道吗

# https://github.com/django-oscar/django-oscar-datacash/blob/master/sandbox/apps/checkout/views.py
# django-oscar-datacash/sandbox/apps/checkout/views.py 

...
from oscar.apps.checkout.views import PaymentDetailsView as OscarPaymentDetailsView
...
from oscar.apps.payment.models import SourceType, Source
...

class PaymentDetailsView(OscarPaymentDetailsView):
    ...
    def handle_payment(self, order_number, total, **kwargs):
        ...
        source_type, _ = SourceType.objects.get_or_create(name='Datacash')
        source = Source(source_type=source_type,
                        currency=settings.DATACASH_CURRENCY,
                        amount_allocated=total.incl_tax,
                        reference=datacash_ref)
        self.add_payment_source(source)

        # Also record payment event
        self.add_payment_event('pre-auth', total.incl_tax)

此外,对于使用新模式的现金支付系统,建议采用什么方法?例如,SourceType是“Cash”吗,Source(或源代码引用)是“CashOnPickup”还是“CashOnDelivery”?最后,在现金支付中,Transaction模型适合哪里?AbstractTransaction类的代码注释指出,transactions have nothing to do with the lines of the order while payment events do,我对这一点的理解是,“交易”不一定是有资金流动的交易,但是像卡的预授权这样的非支付行为也被计算在内。但是现金支付呢?你知道吗


Tags: appsdjango方法namepydefaultsource定义