change CoinifyRedirectView to a RedirectView with SingleObjectMixin

This commit is contained in:
Thomas Steen Rasmussen 2016-05-29 11:52:20 +02:00
parent ca3dd850b0
commit 490b01a4df

View file

@ -316,18 +316,13 @@ class BankTransferView(LoginRequiredMixin, EnsureUserOwnsOrderMixin, EnsureUnpai
template_name = 'bank_transfer.html' template_name = 'bank_transfer.html'
class CoinifyRedirectView(LoginRequiredMixin, EnsureUserOwnsOrderMixin, EnsureUnpaidOrderMixin, EnsureClosedOrderMixin, EnsureOrderHasProductsMixin, DetailView): class CoinifyRedirectView(LoginRequiredMixin, EnsureUserOwnsOrderMixin, EnsureUnpaidOrderMixin, EnsureClosedOrderMixin, EnsureOrderHasProductsMixin, SingleObjectMixin, RedirectView):
model = Order model = Order
template_name = 'coinify_redirect.html'
def get_context_data(self, **kwargs): def dispatch(self, **kwargs):
order = self.get_object() order = self.get_object()
context = super(CoinifyRedirectView, self).get_context_data(**kwargs)
if hasattr(order, 'coinifyapiinvoice'): if not hasattr(order, 'coinifyapiinvoice'):
# we already have an invoice for this order, just redirect
context['redirecturl'] == order.coinifyapiinvoice.payload['data']['payment_url']
else:
# Initiate coinify API and create invoice # Initiate coinify API and create invoice
coinifyapi = CoinifyAPI( coinifyapi = CoinifyAPI(
settings.COINIFY_API_KEY, settings.COINIFY_API_KEY,
@ -361,8 +356,9 @@ class CoinifyRedirectView(LoginRequiredMixin, EnsureUserOwnsOrderMixin, EnsureUn
invoicejson = response['data'], invoicejson = response['data'],
order = order, order = order,
) )
context['redirecturl'] == response['data']['payment_url']
return context def get_redirect_url(self, *args, **kwargs):):
return self.get_object().coinifyapiinvoice.payload['data']['payment_url']
class CoinifyCallbackView(SingleObjectMixin, View): class CoinifyCallbackView(SingleObjectMixin, View):