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')
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('/')
def direct_to_pay(request, token): """post to cash flow merchantdise with params needed - use token to get correspond payment model - all data needed are in payment - call process_data (a unify facade for transfering payment data to cash flow merchandise) """ context = { 'page': 'direct_to_pay' } if token is not None: payment = Payment.objects.filter(token=token).first() provider = provider_factory(payment.variant) form = provider.process_data(payment, request) context['form'] = form return render(request, 'payments_extend/direct_to_pay.html', context)
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/')