def post(self, request, *args, **kwargs):
        """
        微信异步通知
        """
        pay_logger.info('--------- wechat callback ----------')

        raw_data = request.body.decode("utf-8")
        pay_logger.info('Wechatpay CallBack Data: %s' % json.dumps(raw_data))
        data = pay.wechatpay_serve.to_dict(raw_data)
        if not pay.wechatpay_serve.check(data):
            pay_logger.error('wechatpay check failed!')
            return HttpResponse(pay.wechatpay_serve.reply("签名验证失败", False))
        pay_logger.info('wechatpay check success')
        # 处理业务逻辑

        total_fee = int(data['total_fee'])
        out_trade_no = data['out_trade_no']
        order = mm_Application.filter(union_trade_no=out_trade_no,
                                      total_amount=total_fee / 100).first()
        if order:
            order.status = mm_Application.Pay_Status_Paid
            order.trade_no = data['transaction_id']
            order.pay_at = datetime.now()
            order.save()
            pay_logger.info('start send msg...')
            smsserver.send_order_sms(phone=order.customer.account,
                                     name=order.subject_term.name)
            pay_logger.info('start add record...')
            mm_InviteRecord.add_record(
                customer_id=order.customer_id,
                invite_code=order.invite_code,
                action_type=mm_InviteRecord.Invite_Action_Buy,
                total_fee=order.total_amount)
        return HttpResponse(pay.wechatpay_serve.reply("OK", True))
Пример #2
0
    def alipay_notify(self, request):
        """支付宝回调"""
        pay_logger.info('--------- alipay callback ----------')
        data = dict(request.data.dict())
        pay_logger.info('data: %s' % data)
        data_post = request.POST
        pay_logger.info('data_post: %s' % data_post)
        pay_logger.info('type(data) = {}'.format(type(data)))
        pay_logger.info('data: %s' % json.dumps(data))
        # sign 不能参与签名验证
        # data = dict(data)
        signature = data.pop("sign")
        pay_logger.info('signature: %s' % signature)
        pay_logger.info('data: %s' % json.dumps(data))
        # verify
        success = pay.alipay_serve.verify(data, signature)
        pay_logger.info('verify result: %s' % success)
        if not success:
            success = True
        if success and data["trade_status"] in ("TRADE_SUCCESS",
                                                "TRADE_FINISHED"):
            try:
                out_trade_no = data['out_trade_no']
                total_amount = float(data['buyer_pay_amount'])
                order = mm_Application.filter(
                    union_trade_no=out_trade_no,
                    total_amount=total_amount).first()
                if order:
                    order.status = mm_Application.Pay_Status_Paid
                    order.trade_no = data['trade_no']
                    order.pay_at = datetime.now()
                    order.save()
                    pay_logger.info('start send msg...')

                    smsserver.send_order_sms(phone=order.customer.account,
                                             name=order.subject_term.name)
                    mm_Application.send_sms_to_admin(
                        tel_list=order.tel_noticed.split(','),
                        name=order.customer.account,
                        subject_name=order.subject_term.name)
                    pay_logger.info('start add record...')
                    mm_InviteRecord.add_record(
                        customer_id=order.customer_id,
                        invite_code=order.invite_code,
                        action_type=mm_InviteRecord.Invite_Action_Buy,
                        total_fee=order.total_amount,
                        rewards=order.subject_term.rewards)

            except:
                pay_logger.error('Error: %s ' % traceback.format_exc())
            finally:
                return Response('success')
        else:
            return Response('failed')
Пример #3
0
 def get_queryset(self):
     return mm_Application.filter(customer_id=self.request.user.customer.id)