1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- # -*- coding: utf-8 -*-
- # !/usr/bin/env python
- import logging
- from collections import OrderedDict
- from typing import TYPE_CHECKING, Optional
- import simplejson as json
- from apps.web.constant import AppPlatformType
- from apps.web.core import DlbMixin
- from apps.web.core.payment.base import PaymentGateway
- from library.dlb import DlbPay
- if TYPE_CHECKING:
- from apps.web.core.models import DlbPayApp
- logger = logging.getLogger(__name__)
- class DlbPaymentGateway(PaymentGateway, DlbMixin):
- def __init__(self, app, gateway_type): # type: (DlbPayApp, AppPlatformType)->None
- super(DlbPaymentGateway, self).__init__(app)
- self.__gateway_type__ = gateway_type
- def __repr__(self):
- return \
- '<DlbPaymentGateway(occupantId = %s, merchant_no = %s, shop_no = %s, debug = %s)>' % (
- str(self.occupantId), self.merchant_no, self.shop_no, self.debug)
- @property
- def __client__(self):
- # type: ()->DlbPay
- return DlbPay(self.merchant_no, self.shop_no, self.access_key, self.secret_key, self.machine_no, self.debug)
- def create_pay_url(self, order_no, money, notify_url, front_url = '', attach = None):
- return self.client.create_pay_url(
- requestNum = order_no,
- amount = str(money),
- notify_url = notify_url,
- front_url = front_url,
- extraInfo = json.dumps(attach, separators = (',', ':')) if attach else '')
- def api_trade_query(self, out_trade_no = None, trade_no = None):
- # type:(Optional[str], Optional[str])->dict
- """
- 查询订单
- :param out_trade_no: 商户订单号
- :param trade_no: 微信订单号
- :return:
- """
- assert out_trade_no or trade_no, 'must input out_trade_no or trade_no'
- return self.client.query_trade_result(trade_no = trade_no, out_trade_no = out_trade_no)
- def check(self, data, token):
- # type: (dict, str)->bool
- sign_data = OrderedDict()
- sign_data['secretKey'] = self.secret_key
- sign_data['timestamp'] = data['timestamp']
- re_token = self.client.token(sign_data)
- return re_token == token
|