working on coinify payments

This commit is contained in:
Thomas Steen Rasmussen 2016-05-29 10:43:38 +02:00
parent 6016a6b605
commit 07d74878c5
3 changed files with 24 additions and 14 deletions

View file

@ -240,6 +240,7 @@ class CoinifyAPIInvoice(CreatedUpdatedModel):
class CoinifyCallback(CreatedUpdatedModel): class CoinifyCallback(CreatedUpdatedModel):
payload = JSONField() payload = JSONField()
order = models.ForeignKey('shop.Order')
def __str__(self): def __str__(self):
return 'callback at %s' % self.created return 'callback at %s' % self.created

View file

@ -0,0 +1,13 @@
{% extends 'shop_base.html' %}
{% load bootstrap3 %}
{% block shop_content %}
<h2>Thank you for your payment!</h2>
<p class="lead">
{% if order.paid %}
Thank you for your payment. Your order has been marked as paid.
{% else %}
Thank you for your payment. Your order will be marked as paid as soon as we register a callback from our payment provider.</p>
{% endif %}
</p>
{% endblock %}

View file

@ -306,20 +306,10 @@ class EpayCallbackView(View):
return HttpResponse('OK') return HttpResponse('OK')
class EpayThanksView(LoginRequiredMixin, EnsureUserOwnsOrderMixin, DetailView): class EpayThanksView(LoginRequiredMixin, EnsureUserOwnsOrderMixin, EnsureClosedOrderMixin, DetailView):
model = Order model = Order
template_name = 'epay_thanks.html' template_name = 'epay_thanks.html'
def dispatch(self, request, *args, **kwargs):
order = self.get_object()
if order.open:
### this order is open, what is the user doing here?
return HttpResponseRedirect(reverse_lazy('shop:order_detail', kwargs={'pk': order.pk}))
return super(EpayThanksView, self).dispatch(
request, *args, **kwargs
)
class BankTransferView(LoginRequiredMixin, EnsureUserOwnsOrderMixin, EnsureUnpaidOrderMixin, EnsureOrderHasProductsMixin, DetailView): class BankTransferView(LoginRequiredMixin, EnsureUserOwnsOrderMixin, EnsureUnpaidOrderMixin, EnsureOrderHasProductsMixin, DetailView):
model = Order model = Order
@ -375,9 +365,9 @@ class CoinifyRedirectView(LoginRequiredMixin, EnsureUserOwnsOrderMixin, EnsureUn
return context return context
class CoinifyCallbackView(View): class CoinifyCallbackView(SingleObjectMixin, View):
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
# Get the signature from the HTTP or email headers # Get the signature from the HTTP headers
signature = request.META['HTTP_X_COINIFY_CALLBACK_SIGNATURE'] signature = request.META['HTTP_X_COINIFY_CALLBACK_SIGNATURE']
sdk = CoinifyCallback( sdk = CoinifyCallback(
settings.COINIFY_API_KEY, settings.COINIFY_API_KEY,
@ -387,7 +377,8 @@ class CoinifyCallbackView(View):
if sdk.validate_callback(request.body, signature): if sdk.validate_callback(request.body, signature):
# callback is valid, save it to db # callback is valid, save it to db
callbackobject = CoinifyCallback.objects.create( callbackobject = CoinifyCallback.objects.create(
payload=request.body payload=request.body,
order=self.get_object()
) )
# parse json # parse json
@ -411,3 +402,8 @@ class CoinifyCallbackView(View):
else: else:
HttpResponseBadRequest('something is fucky') HttpResponseBadRequest('something is fucky')
class CoinifyThanksView(LoginRequiredMixin, EnsureUserOwnsOrderMixin, EnsureClosedOrderMixin, DetailView):
model = Order
template_name = 'coinify_thanks.html'