예제 #1
0
    def obj_create(self, bundle, request=None, **kwargs):
        bundle = super(HiPaySubscription, self).obj_create(bundle, request, **kwargs)

        # Go on pay it for real
        response = subscriptionpayment(bundle.obj.subscription, sender_host=request.get_host(),
                                       secure=request.is_secure(), internal_transid=bundle.obj.pk)

        if response['status'] == 'Accepted':
            bundle.obj.redirect_url = response['message']
            bundle.obj.save()

        return bundle
예제 #2
0
def hipay_subscription(request, subscription_id):
    current_user = Users.objects.get(email=request.user.email)
    subscriptions = [c.subscription_set.all() for c in current_user.clients_set.all()]
    if not subscriptions:
        raise Http404

    qs  = reduce(operator.or_, subscriptions)
    subscription = get_object_or_404(qs, pk=subscription_id)
    tr = SubscriptionTransaction(subscription=subscription)
    tr.save()

    response = hipay.subscriptionpayment(subscription, sender_host=request.get_host(), secure=request.is_secure(), internal_transid=tr.pk)

    if response['status'] == 'Accepted':
        tr.redirect_url = response['message']
        tr.save()

        return redirect(response['message'])
    else:
        raise ValueError(response)