Beispiel #1
0
    def _get_weixin_signkey(self, acquirer):
        url = 'https://api.mch.weixin.qq.com/sandboxnew/pay/getsignkey'
        nonce_str = self.random_generator()
        data = {}
        data.update({'mch_id': acquirer.weixin_mch_id, 'nonce_str': nonce_str})

        _, prestr = util.params_filter(data)
        key = acquirer.weixin_key
        _logger.info("+++ prestr %s, Weixin Key %s" % (prestr, key))
        data['sign'] = util.build_mysign(prestr, key, 'MD5')

        data_xml = "<xml>" + self.json2xml(data) + "</xml>"

        request = urllib2.Request(url, data_xml)
        result = self._try_url(request, tries=3)

        _logger.info(
            "_______get_weixin_signkey_____ request to %s and the request data is %s, and request result is %s"
            % (url, data_xml, result)
        )
        return_xml = etree.fromstring(result)

        if return_xml.find('return_code').text == "SUCCESS" and return_xml.find(
            'sandbox_signkey'
        ).text != False:
            sandbox_signkey = return_xml.find('sandbox_signkey').text
        else:
            return_code = return_xml.find('return_code').text
            return_msg = return_xml.find('return_msg').text
            raise UserError("%s, %s" % (return_code, return_msg))

        return sandbox_signkey
Beispiel #2
0
    def tenpay_form_generate_values(self, cr, uid, id, partner_values, tx_values, context=None):
        base_url = self.pool["ir.config_parameter"].get_param(cr, SUPERUSER_ID, "web.base.url")
        acquirer = self.browse(cr, uid, id, context=context)
        amount = int(tx_values.get("total_fee", 0) * 100)

        tenpay_tx_values = dict(tx_values)
        tenpay_tx_values.update(
            {
                "total_fee": amount,
                "spbill_create_ip": acquirer._get_ipaddress(),
                "partner": acquirer.tenpay_partner_account,
                "out_trade_no": tx_values["reference"],
                "body": "%s: %s" % (acquirer.company_id.name, tx_values["reference"]),
                "bank_type": "DEFAULT",
                "fee_type": 1,
                "input_charset": "utf-8",
                "return_url": "%s" % urlparse.urljoin(base_url, TenpayController._return_url),
                "notify_url": "%s" % urlparse.urljoin(base_url, TenpayController._notify_url),
            }
        )

        to_sign = {}
        to_sign.update(
            {
                "total_fee": amount,
                "spbill_create_ip": acquirer._get_ipaddress(),
                "partner": acquirer.tenpay_partner_account,
                "out_trade_no": tx_values["reference"],
                "body": "%s: %s" % (acquirer.company_id.name, tx_values["reference"]),
                "bank_type": "DEFAULT",
                "fee_type": 1,
                "input_charset": "utf-8",
                "return_url": "%s" % urlparse.urljoin(base_url, TenpayController._return_url),
                "notify_url": "%s" % urlparse.urljoin(base_url, TenpayController._notify_url),
            }
        )

        _, prestr = util.params_filter(to_sign)
        tenpay_tx_values["sign"] = util.build_mysign(prestr, acquirer.tenpay_partner_key, "MD5")
        tenpay_tx_values["sign_type"] = "MD5"
        context = context
        context["_data_exchange"] = tenpay_tx_values

        return partner_values, tenpay_tx_values
Beispiel #3
0
    def tenpay_form_generate_values(self, cr, uid, id, partner_values, tx_values, context=None):
        base_url = self.pool['ir.config_parameter'].get_param(cr, SUPERUSER_ID, 'web.base.url')
        acquirer = self.browse(cr, uid, id, context=context)
        amount = int(tx_values.get('total_fee', 0) * 100)

        tenpay_tx_values = dict(tx_values)
        tenpay_tx_values.update({
            'total_fee': amount,
            'spbill_create_ip': acquirer._get_ipaddress(),
            'partner': acquirer.tenpay_partner_account,
            'out_trade_no': tx_values['reference'],
            'body': '%s: %s' % (acquirer.company_id.name, tx_values['reference']),
            'bank_type': 'DEFAULT',
            'fee_type': 1,
            'input_charset': 'utf-8',
            'return_url': '%s' % urlparse.urljoin(base_url, TenpayController._return_url),
            'notify_url': '%s' % urlparse.urljoin(base_url, TenpayController._notify_url),
        })

        to_sign = {}
        to_sign.update({
            'total_fee': amount,
            'spbill_create_ip': acquirer._get_ipaddress(),
            'partner': acquirer.tenpay_partner_account,
            'out_trade_no': tx_values['reference'],
            'body': '%s: %s' % (acquirer.company_id.name, tx_values['reference']),
            'bank_type': 'DEFAULT',
            'fee_type': 1,
            'input_charset': 'utf-8',
            'return_url': '%s' % urlparse.urljoin(base_url, TenpayController._return_url),
            'notify_url': '%s' % urlparse.urljoin(base_url, TenpayController._notify_url),
        })

        _,prestr = util.params_filter(to_sign)
        tenpay_tx_values['sign'] = util.build_mysign(prestr, acquirer.tenpay_partner_key, 'MD5')
        tenpay_tx_values['sign_type'] = 'MD5'
        context = context
        context['_data_exchange'] = tenpay_tx_values

        return partner_values, tenpay_tx_values
Beispiel #4
0
    def _gen_weixin_code_url(self, post_data):
        data = {}
        data.update(
            {
                'appid': post_data['appid'],
                'mch_id': post_data['mch_id'],
                'nonce_str': post_data['nonce_str'],
                'body': post_data['body'],
                'out_trade_no': post_data['out_trade_no'],
                'total_fee': post_data['total_fee'],
                'spbill_create_ip': post_data['spbill_create_ip'],
                'notify_url': post_data['notify_url'],
                'trade_type': post_data['trade_type'],
            }
        )

        acquirer = self.search([('weixin_appid', '=', post_data['appid'])])
        _logger.info("--- acquirer %s" % (acquirer))

        if acquirer.environment == 'prod':
            key = acquirer.weixin_key
        else:
            key = self._get_weixin_signkey(acquirer)

        _, prestr = util.params_filter(data)

        _logger.info("+++ prestr %s, Weixin Key %s" % (prestr, key))

        data['sign'] = util.build_mysign(prestr, key, 'MD5')

        data_xml = "<xml>" + self.json2xml(data) + "</xml>"

        url = acquirer._get_weixin_urls(acquirer.environment)['weixin_url']

        request = urllib2.Request(url, data_xml)
        result = self._try_url(request, tries=3)

        _logger.info(
            "________gen_weixin_code_url_____ request to %s and the request data is %s, and request result is %s"
            % (url, data_xml, result)
        )
        return_xml = etree.fromstring(result)

        data_json = {}

        for el in return_xml:
            data_json[el.tag] = el.text

        if data_json['return_code'] == "SUCCESS" and data_json.get(
            'code_url', False
        ):
            return data_json['code_url']

        else:
            return_code = data_json.get('return_code')
            return_msg = data_json.get('return_msg')

            msg = "[%s] %s " % (return_code, return_msg)

            _logger.info('+++ some error occurred %s' % msg)
            # raise UserError(msg)

        return False
Beispiel #5
0
    def weixin_form_generate_values(self, partner_values, tx_values):
        self.ensure_one()
        base_url = self.env['ir.config_parameter'].get_param('web.base.url')
        amount = int(tx_values.get('amount', 0) * 100)
        nonce_str = self.random_generator()

        weixin_tx_values = dict(tx_values)
        weixin_tx_values.update(
            {
                'appid': self.weixin_appid,
                'mch_id': self.weixin_mch_id,
                'nonce_str': nonce_str,
                'body': tx_values['reference'],
                'out_trade_no': tx_values['reference'],
                'total_fee': amount,
                'spbill_create_ip': self._get_ipaddress(),
                'notify_url': '%s' % urlparse.urljoin(base_url, WeixinController._notify_url),
                'trade_type': 'NATIVE',
                'product_id': tx_values['reference'],
            }
        )

        data_post = {}
        data_post.update(
            {
                'appid': self.weixin_appid,
                'mch_id': self.weixin_mch_id,
                'nonce_str': nonce_str,
                'body': tx_values['reference'],
                'out_trade_no': tx_values['reference'],
                'total_fee': amount,
                'spbill_create_ip': self._get_ipaddress(),
                'notify_url': '%s' % urlparse.urljoin(base_url, WeixinController._notify_url),
                'trade_type': 'NATIVE',
                'product_id': tx_values['reference'],
            }
        )

        _, prestr = util.params_filter(data_post)
        weixin_tx_values['sign'] = util.build_mysign(prestr, self.weixin_key, 'MD5')
        data_post['sign'] = weixin_tx_values['sign']

        data_xml = "<xml>" + self.json2xml(data_post) + "</xml>"

        url = self._get_weixin_urls(self.environment)['weixin_url']

        request = urllib2.Request(url, data_xml)
        result = self._try_url(request, tries=3)

        _logger.info("request to %s and the request data is %s, and request result is %s" % (url, data_xml, result))
        return_xml = etree.fromstring(result)

        if return_xml.find('return_code').text == "SUCCESS" and return_xml.find('code_url').text <> False:
            qrcode = return_xml.find('code_url').text
            weixin_tx_values['qrcode'] = qrcode
        else:
            return_code = return_xml.find('return_code').text
            return_msg = return_xml.find('return_msg').text
            raise ValidationError("%s, %s" % (return_code, return_msg))

        return partner_values, weixin_tx_values
Beispiel #6
0
    def alipay_form_generate_values(self, cr, uid, id, partner_values, tx_values, context=None):
        base_url = self.pool['ir.config_parameter'].get_param(cr, SUPERUSER_ID, 'web.base.url')
        acquirer = self.browse(cr, uid, id, context=context)

        alipay_tx_values = dict(tx_values)
        alipay_tx_values.update({
            'partner': acquirer.alipay_partner_account,
            'seller_email': acquirer.alipay_seller_email,
            'seller_id': acquirer.alipay_partner_account,
            '_input_charset': 'utf-8',
            'out_trade_no': tx_values['reference'],
            'subject': tx_values['reference'],
            'body': '%s: %s' % (acquirer.company_id.name, tx_values['reference']),
            'payment_type': '1',
            'return_url': '%s' % urlparse.urljoin(base_url, AlipayController._return_url),
            'notify_url': '%s' % urlparse.urljoin(base_url, AlipayController._notify_url),
        })

        to_sign = {}
        to_sign.update({
            'partner': acquirer.alipay_partner_account,
            'seller_email': acquirer.alipay_seller_email,
            'seller_id': acquirer.alipay_partner_account,
            '_input_charset': 'utf-8',
            'out_trade_no': tx_values['reference'],
            'subject': tx_values['reference'],
            'body': '%s: %s' % (acquirer.company_id.name, tx_values['reference']),
            'payment_type': '1',
            'return_url': '%s' % urlparse.urljoin(base_url, AlipayController._return_url),
            'notify_url': '%s' % urlparse.urljoin(base_url, AlipayController._notify_url),
        })

        payload_direct = {
            'service': 'create_direct_pay_by_user',
            'total_fee': tx_values['amount'],
        }

        payload_escow = {
            'service': 'create_partner_trade_by_buyer',
            'logistics_type': 'EXPRESS',
            'logistics_fee': 0,
            'logistics_payment': 'SELLER_PAY',
            'price': tx_values['amount'],
            'quantity': 1,
        }

        payload_dualfun = {
            'service': 'trade_create_by_buyer',
            'logistics_type': 'EXPRESS',
            'logistics_fee': 0,
            'logistics_payment': 'SELLER_PAY',
            'price': tx_values['amount'],
            'quantity': 1,
        }

        if acquirer.alipay_interface_type == 'create_direct_pay_by_user':
            to_sign.update(payload_direct)
            alipay_tx_values.update(payload_direct)

        if acquirer.alipay_interface_type == 'create_partner_trade_by_buyer':
            to_sign.update(payload_escow)
            alipay_tx_values.update(payload_direct)

        if acquirer.alipay_interface_type == 'trade_create_by_buyer':
            to_sign.update(payload_dualfun)
            alipay_tx_values.update(payload_direct)

        _, prestr = util.params_filter(to_sign)
        alipay_tx_values['sign'] = util.build_mysign(prestr, acquirer.alipay_partner_key, 'MD5')
        alipay_tx_values['sign_type'] = 'MD5'

        return partner_values, alipay_tx_values
Beispiel #7
0
    def alipay_form_generate_values(self, tx_values):
        base_url = self.env['ir.config_parameter'
                            ].sudo().get_param('web.base.url')

        alipay_tx_values = dict(tx_values)
        alipay_tx_values.update(
            {
                'partner':
                    self.alipay_partner_account,
                'seller_email':
                    self.alipay_seller_email,
                'seller_id':
                    self.alipay_partner_account,
                '_input_charset':
                    'UTF-8',
                'out_trade_no':
                    tx_values['reference'],
                'subject':
                    tx_values['reference'],
                'body':
                    tx_values['reference'],
                'payment_type':
                    '1',
                'return_url':
                    '%s' %
                    urlparse.urljoin(base_url, AlipayController._return_url),
                'notify_url':
                    '%s' %
                    urlparse.urljoin(base_url, AlipayController._notify_url),
            }
        )

        to_sign = {}
        to_sign.update(
            {
                'partner':
                    self.alipay_partner_account,
                'seller_email':
                    self.alipay_seller_email,
                'seller_id':
                    self.alipay_partner_account,
                '_input_charset':
                    'UTF-8',
                'out_trade_no':
                    tx_values['reference'],
                'subject':
                    tx_values['reference'],
                'body':
                    tx_values['reference'],
                'payment_type':
                    '1',
                'return_url':
                    '%s' %
                    urlparse.urljoin(base_url, AlipayController._return_url),
                'notify_url':
                    '%s' %
                    urlparse.urljoin(base_url, AlipayController._notify_url),
            }
        )

        payload_direct = {
            'service': 'create_direct_pay_by_user',
            'total_fee': tx_values['amount'],
        }

        payload_escow = {
            'service': 'create_partner_trade_by_buyer',
            'logistics_type': 'EXPRESS',
            'logistics_fee': 0,
            'logistics_payment': 'SELLER_PAY',
            'price': tx_values['amount'],
            'quantity': 1,
        }

        if self.alipay_interface_type == 'create_direct_pay_by_user':
            to_sign.update(payload_direct)
            alipay_tx_values.update(payload_direct)

        if self.alipay_interface_type == 'create_partner_trade_by_buyer':
            to_sign.update(payload_escow)
            alipay_tx_values.update(payload_escow)

        _, prestr = util.params_filter(to_sign)
        alipay_tx_values['sign'] = util.build_mysign(
            prestr, self.alipay_partner_key, 'MD5'
        )
        alipay_tx_values['sign_type'] = 'MD5'

        _logger.info('----alipay tx_values is %s' % alipay_tx_values)

        return alipay_tx_values