--
https://github.com/tangentlabs/django-oscar
http://django-oscar.readthedocs.org/en/latest/
https://twitter.com/django_oscar
---
You received this message because you are subscribed to the Google Groups "django-oscar" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-oscar...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-oscar.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-oscar/2e5b8e85-3915-4276-b9ad-0aea66d0632a%40googlegroups.com?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
--
https://github.com/tangentlabs/django-oscar
http://django-oscar.readthedocs.org/en/latest/
https://twitter.com/django_oscar
---
You received this message because you are subscribed to the Google Groups "django-oscar" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-oscar...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-oscar.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-oscar/1903648b-8776-41fc-a76e-1b22c6a47d18%40googlegroups.com.
class PaymentDetailsView(PaymentDetailsViewCore):
def post(self, request, *args, **kwargs):
# Posting to payment-details isn't the right thing to do. Form
# submissions should use the preview URL.
if not self.preview:
return http.HttpResponseBadRequest()
# We use a custom parameter to indicate if this is an attempt to place
# an order (normally from the preview page). Without this, we assume a
# payment form is being submitted from the payment details view. In
# this case, the form needs validating and the order preview shown.
if request.POST.get('action', '') == 'place_order':
if request.POST.get('wire-transfer', '') == 'on':
return self.handle_place_wire_submission(request)
elif request.POST.get('contrassegno', '') == 'on':
return self.handle_place_contrassegno_submission(request)
return self.handle_payment_details_submission(request)
And my handle_submission methods are:
def handle_place_wire_submission(self, request, *args, **kwargs):
kwargs['payment_kwargs'] = {'source': 'wire'}
return self.submit(**self.build_submission(**kwargs))
def handle_place_contrassegno_submission(self, request, *args, **kwargs):
kwargs['payment_kwargs'] = {'source': 'contrassegno'}
return self.submit(**self.build_submission(**kwargs))
def build_submission(self, **kwargs):
submission = super(PaymentDetailsViewCore, self).build_submission(**kwargs)
return submission
Then i found that PaymentDetailsView.submit calls oscar.apps.checkout.mixins.OrderPlacementMixin.handle_payment that
"... is designed to be overridden within your project. The
default is to do nothing as payment is domain-specific.
This method is responsible for handling payment and recording the
payment sources (using the add_payment_source method) and payment
events (using add_payment_event) so they can be
linked to the order when it is saved later on."
So i'm trying to override this method as follow:
# Any payment sources should be added to this list as part of the
# handle_payment method. If the order is placed successfully, then
# they will be persisted. We need to have the order instance before the
# payment sources can be saved.
_payment_sources = None
# Any payment events should be added to this list as part of the
# handle_payment method.
_payment_events = None
# Payment handling methods
# ------------------------
def handle_payment(self, order_number, total, **kwargs):
"""
Handle any payment processing and record payment sources and events.
This method is designed to be overridden within your project. The
default is to do nothing as payment is domain-specific.
This method is responsible for handling payment and recording the
payment sources (using the add_payment_source method) and payment
events (using add_payment_event) so they can be
linked to the order when it is saved later on.
"""
sourceType = None
source = None
if kwargs['source'] == 'wire':
sourceType = SourceType.objects.get(code='bonifico-bancario')
if kwargs['source'] == 'contrassegno':
sourceType = SourceType.objects.get(code='spedizione-in-contrassegno')
if sourceType:
basket = self.request.basket
source = Source.objects.create(
order_id=self.generate_order_number(basket),
source_type_id=sourceType,
amount_allocated=D('20.0'),
amount_debited=D('20'),
)
if source:
self.add_payment_source(source)
self.add_payment_event(
sourceType.code,
D('20'),
'Some Text'
)
But i'm getting this error: TransactionManagementError: An error occurred in the current transaction. You can't execute queries until the end of the 'atomic' block.
Probably i'm trying to save something in the wrong time, or getting wrong order number, or i don't know.
Am i doing payments handling in the wrong way?
Has please, anybody any suggestion?
Thanks in advance
Sergio Brero