django-shop icon indicating copy to clipboard operation
django-shop copied to clipboard

Payment workflow for Releases/0.12.x

Open maltitco opened this issue 6 years ago • 1 comments

I need to do a workflow that will change the status of the order depending on the address from which the client will return from the PSP. They all look like this:

class TestPayment(PaymentProvider):
    namespace = 'test-payment'

    def get_urls(self):
        urlpatterns = [
            url(r'^pending', self.pending_view, name='pending'),
        ]
        return urlpatterns

    def get_payment_request(self, cart, request):
        order = OrderModel.objects.create_from_cart(cart, request)
        order.populate_from_cart(cart, request)
        order_number = order.get_or_assign_number()

this part contains everything that I need to send to the PSP

    order.awaiting_payment()
    order.save()
    js_expression = 'window.location.href="{}";'.format(url)
    return js_expression

@classmethod
@csrf_exempt
def pending_view(cls):
    thank_you_url = OrderModel.objects.get_latest_url()
    return HttpResponseRedirect(thank_you_url)
 class TestPaymentOrderWorkflowMixin(object):
     TRANSITION_TARGETS = {
         'declined': _("Declined"),
         'pending': _("Pending"),
         'approved': _("Approved"),
     }


    @csrf_exempt
    @transition(field='status', source=['awaiting_payment'], target='pending')
    def pending(self):
        """
        Signals that the current Order awaits a payment.
        Invoked by ForwardFundPayment.get_payment_request.
        ""

What should be included in the pending_view?

maltitco avatar Dec 12 '17 13:12 maltitco

For me it's impossible to figure out, what you intend to do with your PSP.

A good point to start with, is to draw a timing-diagram where you show the exact flow of requests between the browser, django-SHOP and your PSP.

With that I might be able to help you better.

jrief avatar Dec 13 '17 14:12 jrief