Exemplo n.º 1
0
    def post(self, request):
        """
        """
        allpay = provider_factory('allpay')
        data = request.data

        cashFlowLog = CashFlowLog.objects.create(
            json_res=json.dumps(data),
            source_device=request.META['HTTP_USER_AGENT'],
            source_ip=get_ip(request),
        )

        tradeNo = data['MerchantTradeNo']
        payment = Payment.objects.filter(tradeNo=tradeNo).first()
        payment.logs = cashFlowLog.pk
        payment.save()

        data = json.loads(json.dumps(data))

        if allpay.verify_macValue(**data):

            return HttpResponseRedirect('/profile/orderList/')

        else:
            return HttpResponseRedirect('/')
Exemplo n.º 2
0
    def post(self, request):
        """
        """

        allpay = provider_factory('allpay')
        data = request.data

        cash_flow_log = CashFlowLog.objects.create(
            json_res=json.dumps(data),
            source_device=request.META['HTTP_USER_AGENT'],
            source_ip=get_ip(request),
        )

        data = json.loads(json.dumps(data))

        if allpay.verify_macValue(**data):

            RtnCode = int(data['RtnCode'])

            if RtnCode in [1, 800]:
                tradeNo = data['MerchantTradeNo']
                payment = Payment.objects.filter(tradeNo=tradeNo).first()
                payment.logs = cash_flow_log.pk
                payment.attrs.PaymentDate = data['PaymentDate']

                payment.change_status('confirmed')
            else:
                return HttpResponse('0|ErrorMessage')

            return HttpResponse('1|OK')
        else:

            return HttpResponse('0|ErrorMessage')
Exemplo n.º 3
0
 def _addLogForCashFlow(self, payment, data):
     """
     """
     cashFlowLog = CashFlowLog.objects.create(
         json_res=json.dumps(data),
         source_device=self.request.META['HTTP_USER_AGENT'],
         source_ip=get_ip(self.request),
     )
     payment.logs = cashFlowLog.pk
     payment.save()
Exemplo n.º 4
0
    def get(self, request):
        """grab query params and create payment

        accept url like. /../payment_process?token=jfeifjeifje&method=allpay
        """

        data = request.query_params

        if data['token'] is not None:
            order = Order.objects.filter(token=data['token']).first()
            # start to check order total number is consistent with sum of all items
            price_consistent = True

            if not price_consistent:

                return HttpResponse('price is not consistent')
        else:
            return HttpResponse('could not find order')

        # start to create a payment
        billing = order.billing_address
        total = order.get_total()
        variant = data['method']

        defaults = {
            'total': total.gross,
            'tax': total.tax,
            'currency': total.currency,
            'delivery': order.get_delivery_total().gross,
            'billing_first_name': billing.first_name,
            'billing_last_name': billing.last_name,
            'billing_city': billing.city,
            'billing_country_code': billing.country,
            'billing_email': order.get_user_email(),
            'description': 'test description',
            'billing_country_area': billing.country_area,
            'customer_ip_address': get_ip(request)
        }

        if not variant in [v for v, n in settings.CHECKOUT_PAYMENT_CHOICES]:
            raise Http404('{} is not a valid payment variant'.format(variant))

        with transaction.atomic():
            order.change_status('payment-pending')
            payment, _created = Payment.objects.get_or_create(
                variant=variant,
                status='waiting',
                order=order,
                defaults=defaults
            )


        # I think I should redirect with a payment token
        return redirect('cnpayments:direct_to_pay', token=payment.token)
Exemplo n.º 5
0
    def get(self, request, payment_token):
        """
        we will get something like this
        <QueryDict: {'token': ['EC-4P809628KK1823013'], 'PayerID': ['MBKAY3Q6GMASN']}>

        PayerID is need for capture payment
        """
        data = request.query_params
        paypal = provider_factory('paypal')

        # import pdb
        # pdb.set_trace()

        _params = {
            'TOKEN': data['token'],
        }

        cashFlowLog = CashFlowLog.objects.create(
            json_res=json.dumps(data),
            source_device=request.META['HTTP_USER_AGENT'],
            source_ip=get_ip(request),
        )

        payment = Payment.objects.filter(token=payment_token).first()
        payment.logs = cashFlowLog.pk
        payment.save()


        # call GetExpressCheckoutDetail api
        url = paypal.getExpressCheckoutDetails(**_params)
        res = paypal.get_nvp_response(url)
        self._addLogForCashFlow(payment, res)

        if res['ACK'][0] == 'Failure':
            return HttpResponseRedirect('/')
        else:
            # go on DoExpressCheckoutPayment..
            # auto confirm?
            doExpress_data = {
                'TOKEN': res['TOKEN'][0],
                'PAYERID': res['PAYERID'][0],
                'PAYMENTREQUEST_0_PAYMENTACTION': 'Sale',
                'PAYMENTREQUEST_0_AMT': payment.get_total_price().gross,
            }

            url = paypal.doExpressCheckoutPayment(**doExpress_data)
            res = paypal.get_nvp_response(url)
            self._addLogForCashFlow(payment, res)

            if res['ACK'][0] == 'Failure':
                return HttpResponseRedirect('/')
            else:
                # start to change payment status
                # change order status, note Order model line 45
                # it will automatically check whether order is full paid or not
                # and then change order status when I change the payment status

                payment.change_status('confirmed')


        return HttpResponseRedirect('/profile/orderList/')