karni-commerce
One cart, checkout and order path for anything a Karni project sells. Experimental.
A project's apps sell different things: a product, a booking, a course seat.
They share one path. A cart line names a kind and an item. Checkout turns
the cart into an order with its lines copied and every line held.
karni-payments takes the money, and the
settlement and refunds move the order. Each kind is an adapter the selling
app registers in its own sellables.py. Commerce calls the adapter and
never imports the app.
pip install karni-commerce
karni add payments
karni add commerce
Or in karni.yaml:
modules:
payments:
provider: stripe
currency: eur
checkout_validator: karni_commerce.payments.checkout_validator
commerce: {}
What it gives
CartandCartLine: a signed-in person's cart, or a visitor's, found by a token and merged at sign-in.Order,OrderLine,OrderPaymentandOrderRefund: an order with a readable number, the buyer's person (karni.people), user (or none), email and name, the addresses, lines with the name, SKU and price copied at checkout, several payments (a deposit and its balance, a retry) and refunds by line or by amount.karni_commerce.services:set_line,merge,checkout,place_order,open_payment,settle,cancel,refund,settle_refundandrelease_expired, each in one transaction.- The API:
/api/carts/current/(andlines/,merge/,checkout/),/api/orders/(andlookup/,pay/,{id}/cancel/,{id}/refund/),/api/order-lines/,/api/order-payments/,/api/order-refunds/. - Signals in
karni_commerce.events:order_placed,order_paid,order_part_paid,order_failed,order_cancelled,order_refunded,cart_mergedandorders_claimed, and the family eventscommerce.order.*on the buyer's timeline. - The person facts
orders,total_spent,last_orderandfirst_order, andkarni_commerce.testing.assert_sellablefor a selling part's tests. - Emails through
karni.mail, each with a kind:commerce.order_paid,commerce.new_order,commerce.order_cancelled,commerce.order_refunded,commerce.order_note,commerce.payment_requestandcommerce.balance_due. Withkarni.notifyinstalled each lands in the recipient's inbox too. @karni/commerce-ui: the cart page, the mini cart, checkout, an order's page and the person's orders.
Selling something
# shop/sellables.py
from karni.capacity import release, reserve
from karni_commerce.sellables import Price, Sellable, register
from shop.models import Product
@register
class ProductSellable(Sellable):
kind = "product"
model = Product
def price(self, item, options, buyer):
return Price(unit=item.current_price(), compare_at=item.price)
def needs_shipping(self, item, options):
return True
def available(self, item, options):
return item.available
def hold(self, line):
reserve(Product.objects.get(pk=line.item), line.quantity)
def release(self, line):
release(Product.objects.get(pk=line.item), line.quantity)
An order's status holds the money only: pending, paid, part_paid,
failed, cancelled, refunded and part_refunded. What happens to the
goods (shipped, delivered, a seat confirmed) stays in the selling app's own
records, which point at karni_commerce.Order.
The full guide is docs/commerce.md.
License
Apache-2.0.
Metadata
Release files for karni-commerce 0.7.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| karni_commerce-0.7.0.tar.gz | 87.1 kB | Without provenance | Details for karni_commerce-0.7.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| karni_commerce-0.7.0-py3-none-any.whl | Python 3 | none | any | Details for karni_commerce-0.7.0-py3-none-any.whl |
Total release size: 200.0 kB
Release files / karni_commerce-0.7.0.tar.gz
| Download URL | karni_commerce-0.7.0.tar.gz |
|---|---|
| Size | 87.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
195b18a400c87da14617094bb097c0dd9437e8ec85129e28a35a22d122c5ccd9
|
|
BLAKE2b-256 checksum How to use checksums |
6203edc07cf461e26dbf6e520c8fb80c2bdcbf2ba19eadb66033473f0fc05ee5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / karni_commerce-0.7.0-py3-none-any.whl
| Download URL | karni_commerce-0.7.0-py3-none-any.whl |
|---|---|
| Size | 112.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0fd59c22f24f0a2a70018175b33b789d4617becd555a32bae5945229f705fc2c
|
|
BLAKE2b-256 checksum How to use checksums |
8436a42895c316d1607836719d3aba88355b2322ca29272135a0d32a96069f07
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Security for karni-commerce 0.7.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.