Skip to main content

An extension on top of django-oscar-api providing a more flexible checkout API with a pluggable payment methods interface.

Project description

An extension on top of django-oscar-api providing a more flexible checkout API with a pluggable payment methods interface.

Compatible Payment Plugins

  • django-oscar-cybersource: Provides order payment using Cybersource Secure Acceptance Silent Order POST for PCI SAQ A-EP compliant credit card processing.

Installation

  1. Install django-oscar-api using the documentation.

  2. Install the django-oscar-api-checkout package.:

    $ pip install django-oscar-api-checkout
  3. Add oscarapicheckout to your INSTALLED_APPS:

    # myproject/settings.py
    ...
    INSTALLED_APPS = [
        ...
        'oscarapicheckout',
    ] + get_core_apps([])
    ...
  4. Configure Oscar’s order status pipeline.:

    # myproject/settings.py
    ...
    # Needed by oscarapicheckout
    ORDER_STATUS_PENDING = 'Pending'
    ORDER_STATUS_PAYMENT_DECLINED = 'Payment Declined'
    ORDER_STATUS_AUTHORIZED = 'Authorized'
    
    # Other statuses
    ORDER_STATUS_SHIPPED = 'Shipped'
    ORDER_STATUS_CANCELED = 'Canceled'
    
    # Pipeline Config
    OSCAR_INITIAL_ORDER_STATUS = ORDER_STATUS_PENDING
    OSCARAPI_INITIAL_ORDER_STATUS = ORDER_STATUS_PENDING
    OSCAR_ORDER_STATUS_PIPELINE = {
        ORDER_STATUS_PENDING: (ORDER_STATUS_PAYMENT_DECLINED, ORDER_STATUS_AUTHORIZED, ORDER_STATUS_CANCELED),
        ORDER_STATUS_PAYMENT_DECLINED: (ORDER_STATUS_AUTHORIZED, ORDER_STATUS_CANCELED),
        ORDER_STATUS_AUTHORIZED: (ORDER_STATUS_SHIPPED, ORDER_STATUS_CANCELED),
        ORDER_STATUS_SHIPPED: (),
        ORDER_STATUS_CANCELED: (),
    }
    
    OSCAR_INITIAL_LINE_STATUS = ORDER_STATUS_PENDING
    OSCAR_LINE_STATUS_PIPELINE = {
        ORDER_STATUS_PENDING: (ORDER_STATUS_SHIPPED, ORDER_STATUS_CANCELED),
        ORDER_STATUS_SHIPPED: (),
        ORDER_STATUS_CANCELED: (),
    }
  5. Configure what payment methods are enabled and who can use them.:

    # myproject/settings.py
    ...
    API_ENABLED_PAYMENT_METHODS = [
        {
            'method': 'oscarapicheckout.methods.Cash',
            'permission': 'oscarapicheckout.permissions.StaffOnly',
        },
        {
            'method': 'some.other.methods.CreditCard',
            'permission': 'oscarapicheckout.permissions.Public',
        },
    ]
  6. Add oscarapicheckout to your root URL configuration directly before oscarapi.:

    # myproject/urls.py
    ...
    from oscarapi.app import application as oscar_api
    from oscarapicheckout.app import application as oscar_api_checkout
    
    urlpatterns = patterns('',
        ...
        url(r'^api/', include(oscar_api_checkout.urls)), # Must be before oscar_api.urls
        url(r'^api/', include(oscar_api.urls)),
        ...
    )

Usage

These are the basic steps to add an item to the basket and checkout using the API.

  1. Add an item to the basket.:

    POST /api/basket/add-product/
    
    {
        "url": "/api/products/1/",
        "quantity": 1
    }
  2. List the payment methods available to the current user.:

    GET /api/checkout/payment-methods/
  3. Submit the order, specifying which payment method(s) to use.:

    POST /api/checkout/
    
    {
        "guest_email": "joe@example.com",
        "basket": "/api/baskets/1/",
        "shipping_address": {
            "first_name": "Joe",
            "last_name": "Schmoe",
            "line1": "234 5th Ave",
            "line4": "Manhattan",
            "postcode": "10001",
            "state": "NY",
            "country": "/api/countries/US/",
            "phone_number": "+1 (717) 467-1111",
        },
        "billing_address": {
            "first_name": "Joe",
            "last_name": "Schmoe",
            "line1": "234 5th Ave",
            "line4": "Manhattan",
            "postcode": "10001",
            "state": "NY",
            "country": "/api/countries/US/",
            "phone_number": "+1 (717) 467-1111",
        },
        "payment": {
            "cash": {
                "enabled": true,
                "amount": "10.00",
            },
            "creditcard": {
                "enabled": true,
                "pay_balance": true,
            }
        }
    }
  4. Check the status of each enabled payment option.:

    GET /api/checkout/payment-states/

Changelog

0.4.0

  • Improved split-pay support by allowing multiple payments of the same type. E.g. two credit cards, etc.
    • [Important] To accomplish this, the payment provider plug-in interface changed slightly. Plugins must be updated to support the new interface. The REST API front-end added parameters, but retained backwards compatibility with 0.3.x.

0.3.4

  • Fix Django 2.0 Deprecation warnings.

0.3.3

  • Add validation to checkout API to prevent placing an order for an item that went out of stock after the item was added to the customer’s basket.

0.3.2

  • Fix issue in Python 3 when OrderCreator.place_order raises a ValueError exception.

  • Fix bug occurring in Oscar 1.5 when vouchers can be used by the user placing an order, but not by the order owner.

0.3.1

  • Add support for Django 1.11 and Oscar 1.5

0.3.0

  • Add helper classes for caching structured data during a multi-step checkout process.
    • See oscarapicheckout.cache module for details.

    • Doesn’t yet include API views for editing or view such data.

    • Currently includes classes for storing email address, shipping address, billing address, and shipping method.

    • Required [Django Cache](https://docs.djangoproject.com/en/dev/topics/cache/) framework to be configured.

0.2.7

  • [Important] Fix bug introduced in r0.2.6 with multi-step payment methods when retrying a payment decline.

0.2.6

  • [Important] Fix bug causing mismatch between Order.user and Basket.owner when, during placement, the order ownership calculator assigns the order to a user other than the basket owner. Now, after creating the order model, the owner of the basket associated with the order is updated to match the order’s owner.

  • Make it possible to set the ORDER_OWNERSHIP_CALCULATOR to a callable or a string instead of just a string.

0.2.5

  • Improve testing by using tox in the CI runner.

0.2.4

  • Upgrade dependencies.

0.2.3

  • Make the order in which signals are sent during checkout consistent for synchronous and asynchronous payment methods.
    • Previously a synchronous payment method resulted in sending order_payment_authorized before sending order_placed, but an asynchronous payment method would trigger order_placed first followed by order_payment_authorized (on a subsequent HTTP request). They are still different in terms of synchronous payment methods firing both signals on the same request and asynchronous payment methods triggering them on different request, but at least now they are always fired in the same order: order_placed first followed by order_payment_authorized.

0.2.2

  • Require an email address during checkout

0.2.1

  • Explicitly dis-allow cache on API views

0.2.0

  • Add setting to allow configuring how many payment types may be used on an order

  • Add hook for setting the ownership information on an order during placement

  • Prevent PaymentEvent.reference from ever being None

0.1.5

  • Fix bug where order number wouldn’t be recycled for a declined order

0.1.4

  • Add context to payment method serializers

0.1.3

  • Simplify dependencies

0.1.2

  • Allow PaymentMethods to handle 0.00-amount transactions

0.1.1

  • Send confirmation message upon order authorization

  • Add pep8 linting

0.1.0

  • Initial release.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-oscar-api-checkout-0.4.0b1.tar.gz (27.9 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file django-oscar-api-checkout-0.4.0b1.tar.gz.

File metadata

File hashes

Hashes for django-oscar-api-checkout-0.4.0b1.tar.gz
Algorithm Hash digest
SHA256 6970ed7c7e84980a70bc00958cde5c06b176e54f8701a4718e3d0dc951cae7fb
MD5 ae5d1ca00b5635f425f43ada50a94880
BLAKE2b-256 376ed64309cab61f5a941e4a0acf573a49a155b76e61324620544527901aa946

See more details on using hashes here.

Provenance

File details

Details for the file django_oscar_api_checkout-0.4.0b1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_oscar_api_checkout-0.4.0b1-py3-none-any.whl
Algorithm Hash digest
SHA256 c7833efd49a3d30d9886736a1ef56bacb2f09b63c95ed6bdf0736c6b9f8a46cc
MD5 6fe35f86ea7c2f3ab856167487c1fba1
BLAKE2b-256 27f71e9929fc58cd4f2210625865794d2341cb9e20180f1507026cdba609d969

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page