Skip to content

Commit

Permalink
Merge pull request awesto#142 from per42/13ddf80ef69789a2433c8e4d1302…
Browse files Browse the repository at this point in the history
…2a68421ad90e

Updates order status after shipping and payment
  • Loading branch information
chrisglass committed Feb 22, 2012
2 parents 2bb2cde + 13ddf80 commit 1a08812
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
24 changes: 21 additions & 3 deletions shop/payment/api.py
@@ -1,15 +1,17 @@
# -*- coding: utf-8 -*-

"""
This file defines the interafces one should implement when either creating a
This file defines the interfaces one should implement when either creating a
new payment module or willing to use modules with another shop system.
"""
from decimal import Decimal
from shop.models.ordermodel import OrderPayment
from shop.models.ordermodel import Order
from shop.models.cartmodel import Cart
from shop.shop_api import ShopAPI
from shop.order_signals import completed
from django.core.urlresolvers import reverse


class PaymentAPI(ShopAPI):
"""
This object's purpose is to expose an API to the shop system.
Expand Down Expand Up @@ -41,7 +43,18 @@ def confirm_payment(self, order, amount, transaction_id, payment_method,
amount=Decimal(amount),
transaction_id=transaction_id,
payment_method=payment_method)
# Save is not used in the particular case.

if save and self.is_order_payed(order):
# Set the order status:
order.status = Order.COMPLETED
order.save()
completed.send(sender=self, order=order)

# Empty the customers basket, to reflect that the purchase was
# completed
cart_object = Cart.objects.get(user=order.user)
cart_object.empty()


#==========================================================================
# URLS
Expand All @@ -52,6 +65,11 @@ def get_finished_url(self):
A helper for backends, so that they can call this when their job
is finished i.e. The payment has been processed from a user perspective
This will redirect to the "Thanks for your order" page.
To confirm the payment, call confirm_payment before this function.
For example, for PayPal IPN, the payment is confirmed upon receipt
of an Instant Payment Notification, and later this function is called
when the user is directed back from PayPal.
"""
return reverse('thank_you_for_your_order')

Expand Down
3 changes: 3 additions & 0 deletions shop/shipping/api.py
Expand Up @@ -2,6 +2,7 @@
from shop.shop_api import ShopAPI
from shop.order_signals import payment_selection
from shop.models.ordermodel import ExtraOrderPriceField
from shop.models.ordermodel import Order
from django.shortcuts import redirect


Expand Down Expand Up @@ -58,6 +59,8 @@ def finished(self, order):
is finished i.e. shipping costs are added to the order.
This will redirect to the "select a payment method" page.
"""
order.status = Order.CONFIRMED
order.save()
# Emit the signal to say we're now selecting payment
payment_selection.send(self, order=order)
return redirect('checkout_payment')

0 comments on commit 1a08812

Please sign in to comment.