Exemple #1
0
def exec_pay_signature(app_id, package, officalaccount):
    app_sercert = ""
    app_key = ""
    mch_id = ""
    if officalaccount:
        mch_id = officalaccount.wx_mch_id
        mch_key = officalaccount.wx_mch_secret
        app_sercert = officalaccount.wx_appsecret
        data_post = {}
        data_post.update({
            'package': "prepay_id=" + package,
            'timeStamp': str(int(time.time())),
            'nonceStr': util.random_generator(),
            'appId': app_id,
            'signType': "MD5"
        })
        _, prestr = util.params_filter(data_post)
        print prestr
        data_post['paySign'] = util.build_mysign(prestr, mch_key, 'MD5')
        result = json.dumps(data_post)
        print result
        return result
    else:
        msg = "服务号信息出错"
        raise ValidationError("%s,%s" % (msg, ""))
Exemple #2
0
    def _paypal_form_get_tx_from_data(self, cr, uid, data, context=None):
        reference, txn_id = data.get('item_number'), data.get('txn_id')
        if not reference or not txn_id:
            error_msg = _('Paypal: received data with missing reference (%s) or txn_id (%s)') % (reference, txn_id)
            _logger.info(error_msg)
            raise ValidationError(error_msg)

        # find tx -> @TDENOTE use txn_id ?
        tx_ids = self.pool['payment.transaction'].search(cr, uid, [('reference', '=', reference)], context=context)
        if not tx_ids or len(tx_ids) > 1:
            error_msg = 'Paypal: received data for reference %s' % (reference)
            if not tx_ids:
                error_msg += '; no order found'
            else:
                error_msg += '; multiple order found'
            _logger.info(error_msg)
            raise ValidationError(error_msg)
        return self.browse(cr, uid, tx_ids[0], context=context)
Exemple #3
0
 def _authorize_form_get_tx_from_data(self, data):
     """ Given a data dict coming from authorize, verify it and find the related
     transaction record. """
     reference, trans_id, fingerprint = data.get('x_invoice_num'), data.get('x_trans_id'), data.get('x_MD5_Hash')
     if not reference or not trans_id or not fingerprint:
         error_msg = 'Authorize: received data with missing reference (%s) or trans_id (%s) or fingerprint (%s)' % (reference, trans_id, fingerprint)
         _logger.error(error_msg)
         raise ValidationError(error_msg)
     tx = self.search([('reference', '=', reference)])
     if not tx or len(tx) > 1:
         error_msg = 'Authorize: received data for reference %s' % (reference)
         if not tx:
             error_msg += '; no order found'
         else:
             error_msg += '; multiple order found'
         _logger.error(error_msg)
         raise ValidationError(error_msg)
     return tx[0]
Exemple #4
0
 def _weixin_form_get_tx_from_data(self, cr, uid, data, context=None):
     reference, txn_id = data.get('out_trade_no'), data.get('out_trade_no')
     if not reference or not txn_id:
         error_msg = 'weixin: received data with missing reference (%s) or txn_id (%s)' % (
             reference, txn_id)
         _logger.error(error_msg)
         raise ValidationError(error_msg)
     tx_ids = self.pool['payment.transaction'].search(
         cr, uid, [('reference', '=', reference)], context=context)
     #tx_ids2 = self.search(cr, uid, [('reference', '=', reference)], context=context)
     if not tx_ids or len(tx_ids) > 1:
         error_msg = 'weixin: received data for reference %s' % (reference)
         if not tx_ids:
             error_msg += '; no order found'
         else:
             error_msg += '; multiple order found'
         _logger.error(error_msg)
         raise ValidationError(error_msg)
     return self.browse(cr, uid, tx_ids[0], context=context)
Exemple #5
0
    def _buckaroo_form_get_tx_from_data(self, cr, uid, data, context=None):
        """ Given a data dict coming from buckaroo, verify it and find the related
        transaction record. """
        reference, pay_id, shasign = data.get('BRQ_INVOICENUMBER'), data.get(
            'BRQ_PAYMENT'), data.get('BRQ_SIGNATURE')
        if not reference or not pay_id or not shasign:
            error_msg = _(
                'Buckaroo: received data with missing reference (%s) or pay_id (%s) or shasign (%s)'
            ) % (reference, pay_id, shasign)
            _logger.info(error_msg)
            raise ValidationError(error_msg)

        tx_ids = self.search(cr,
                             uid, [('reference', '=', reference)],
                             context=context)
        if not tx_ids or len(tx_ids) > 1:
            error_msg = _('Buckaroo: received data for reference %s') % (
                reference)
            if not tx_ids:
                error_msg += _('; no order found')
            else:
                error_msg += _('; multiple order found')
            _logger.info(error_msg)
            raise ValidationError(error_msg)
        tx = self.pool['payment.transaction'].browse(cr,
                                                     uid,
                                                     tx_ids[0],
                                                     context=context)

        #verify shasign
        shasign_check = self.pool[
            'payment.acquirer']._buckaroo_generate_digital_sign(
                tx.acquirer_id, 'out', data)
        if shasign_check.upper() != shasign.upper():
            error_msg = _(
                'Buckaroo: invalid shasign, received %s, computed %s, for data %s'
            ) % (shasign, shasign_check, data)
            _logger.info(error_msg)
            raise ValidationError(error_msg)

        return tx
Exemple #6
0
    def _adyen_form_get_tx_from_data(self, cr, uid, data, context=None):
        reference, pspReference = data.get('merchantReference'), data.get(
            'pspReference')
        if not reference or not pspReference:
            error_msg = _(
                'Adyen: received data with missing reference (%s) or missing pspReference (%s)'
            ) % (reference, pspReference)
            _logger.info(error_msg)
            raise ValidationError(error_msg)

        # find tx -> @TDENOTE use pspReference ?
        tx_ids = self.pool['payment.transaction'].search(
            cr, uid, [('reference', '=', reference)], context=context)
        if not tx_ids or len(tx_ids) > 1:
            error_msg = _('Adyen: received data for reference %s') % (
                reference)
            if not tx_ids:
                error_msg += _('; no order found')
            else:
                error_msg += _('; multiple order found')
            _logger.info(error_msg)
            raise ValidationError(error_msg)
        tx = self.pool['payment.transaction'].browse(cr,
                                                     uid,
                                                     tx_ids[0],
                                                     context=context)

        # verify shasign
        shasign_check = self.pool[
            'payment.acquirer']._adyen_generate_merchant_sig(
                tx.acquirer_id, 'out', data)
        if shasign_check != data.get('merchantSig'):
            error_msg = _(
                'Adyen: invalid merchantSig, received %s, computed %s') % (
                    data.get('merchantSig'), shasign_check)
            _logger.warning(error_msg)
            raise ValidationError(error_msg)

        return tx
Exemple #7
0
    def _sips_generate_shasign(self, values):
        """ Generate the shasign for incoming or outgoing communications.
        :param dict values: transaction values
        :return string: shasign
        """
        if self.provider != 'sips':
            raise ValidationError(_('Incorrect payment acquirer provider'))
        data = values['Data']

        # Test key provided by Worldine
        key = u'002001000000001_KEY1'

        if self.environment == 'prod':
            key = getattr(self, 'sips_secret')

        shasign = sha256(data + key)
        return shasign.hexdigest()
    def _transfer_form_get_tx_from_data(self, cr, uid, data, context=None):
        reference, amount, currency_name = data.get('reference'), data.get(
            'amount'), data.get('currency_name')
        tx_ids = self.search(cr,
                             uid, [
                                 ('reference', '=', reference),
                             ],
                             context=context)

        if not tx_ids or len(tx_ids) > 1:
            error_msg = _('received data for reference %s') % (
                pprint.pformat(reference))
            if not tx_ids:
                error_msg += _('; no order found')
            else:
                error_msg += _('; multiple order found')
            _logger.info(error_msg)
            raise ValidationError(error_msg)

        return self.browse(cr, uid, tx_ids[0], context=context)
Exemple #9
0
    def _sips_form_get_tx_from_data(self, data):
        """ Given a data dict coming from sips, verify it and find the related
        transaction record. """

        data = self._sips_data_to_object(data.get('Data'))
        reference = data.get('transactionReference')

        if not reference:
            custom = json.loads(data.pop('returnContext', False) or '{}')
            reference = custom.get('reference')

        payment_tx = self.search([('reference', '=', reference)])
        if not payment_tx or len(payment_tx) > 1:
            error_msg = _('Sips: received data for reference %s') % reference
            if not payment_tx:
                error_msg += _('; no order found')
            else:
                error_msg += _('; multiple order found')
            _logger.error(error_msg)
            raise ValidationError(error_msg)
        return payment_tx
Exemple #10
0
    def sips_form_generate_values(self, values):
        self.ensure_one()
        base_url = self.env['ir.config_parameter'].sudo().get_param('web.base.url')
        currency = self.env['res.currency'].sudo().browse(values['currency_id'])
        currency_code = CURRENCY_CODES.get(currency.name, False)
        if not currency_code:
            raise ValidationError(_('Currency not supported by Wordline'))
        amount = int(values['amount'] * 100)
        if self.environment == 'prod':
            # For production environment, key version 2 is required
            merchant_id = getattr(self, 'sips_merchant_id')
            key_version = '2'
        else:
            # Test key provided by Atos Wordline works only with version 1
            merchant_id = '002001000000001'
            key_version = '1'

        sips_tx_values = dict(values)
        sips_tx_values.update({
            'Data': u'amount=%s|' % amount +
                    u'currencyCode=%s|' % currency_code +
                    u'merchantId=%s|' % merchant_id +
                    u'normalReturnUrl=%s|' % urlparse.urljoin(base_url, SipsController._return_url) +
                    u'automaticResponseUrl=%s|' % urlparse.urljoin(base_url, SipsController._return_url) +
                    u'transactionReference=%s|' % values['reference'] +
                    u'statementReference=%s|' % values['reference'] +
                    u'keyVersion=%s' % key_version,
            'InterfaceVersion': 'HP_2.3',
        })

        return_context = {}
        if sips_tx_values.get('return_url'):
            return_context[u'return_url'] = u'%s' % sips_tx_values.pop('return_url')
        return_context[u'reference'] = u'%s' % sips_tx_values['reference']
        sips_tx_values['Data'] += u'|returnContext=%s' % (json.dumps(return_context))

        shasign = self._sips_generate_shasign(sips_tx_values)
        sips_tx_values['Seal'] = shasign
        return sips_tx_values
Exemple #11
0
    def _ogone_form_get_tx_from_data(self, cr, uid, data, context=None):
        """ Given a data dict coming from ogone, verify it and find the related
        transaction record. Create a payment method if an alias is returned."""
        reference, pay_id, shasign, alias = data.get('orderID'), data.get(
            'PAYID'), data.get('SHASIGN'), data.get('ALIAS')
        if not reference or not pay_id or not shasign:
            error_msg = _(
                'Ogone: received data with missing reference (%s) or pay_id (%s) or shasign (%s)'
            ) % (reference, pay_id, shasign)
            _logger.info(error_msg)
            raise ValidationError(error_msg)

        # find tx -> @TDENOTE use paytid ?
        tx_ids = self.search(cr,
                             uid, [('reference', '=', reference)],
                             context=context)
        if not tx_ids or len(tx_ids) > 1:
            error_msg = _('Ogone: received data for reference %s') % (
                reference)
            if not tx_ids:
                error_msg += _('; no order found')
            else:
                error_msg += _('; multiple order found')
            _logger.info(error_msg)
            raise ValidationError(error_msg)
        tx = self.pool['payment.transaction'].browse(cr,
                                                     uid,
                                                     tx_ids[0],
                                                     context=context)

        # verify shasign
        shasign_check = self.pool['payment.acquirer']._ogone_generate_shasign(
            tx.acquirer_id, 'out', data)
        if shasign_check.upper() != shasign.upper():
            error_msg = _(
                'Ogone: invalid shasign, received %s, computed %s, for data %s'
            ) % (shasign, shasign_check, data)
            _logger.info(error_msg)
            raise ValidationError(error_msg)

        if not tx.acquirer_reference:
            tx.acquirer_reference = pay_id

        # alias was created on ogone server, store it
        if alias:
            method_obj = self.pool['payment.method']
            domain = [('acquirer_ref', '=', alias)]
            cardholder = data.get('CN')
            if not method_obj.search_count(cr, uid, domain, context=context):
                _logger.info('Ogone: saving alias %s for partner %s' %
                             (data.get('CARDNO'), tx.partner_id))
                ref = method_obj.create(
                    cr, uid, {
                        'name':
                        data.get('CARDNO') +
                        (' - ' + cardholder if cardholder else ''),
                        'partner_id':
                        tx.partner_id.id,
                        'acquirer_id':
                        tx.acquirer_id.id,
                        'acquirer_ref':
                        alias
                    })
                tx.partner_reference = alias

        return tx
Exemple #12
0
 def process(self, **post):
     cr, uid, context = request.cr, request.uid, request.context
     parmsdata = request.params
     print parmsdata
     appid = parmsdata['appid']
     mch_id = parmsdata['mch_id']
     env = Environment(request.cr, SUPERUSER_ID, context)
     officialaccount = env['wx.officialaccount'].search([
         ('wx_appid', '=', appid), ('wx_mch_id', '=', mch_id)
     ])
     if officialaccount:
         appkey = officialaccount[0]['wx_mch_secret']
     else:
         appkey = ""
     nonce_str = parmsdata['noncestr']
     body = parmsdata['body']
     out_trade_no = parmsdata['out_trade_no'],
     total_fee = parmsdata['total_fee']
     spbill_create_ip = parmsdata['spbill_create_ip']
     notify_url = parmsdata['notify_url']
     trade_type = parmsdata['trade_type']
     product_id = parmsdata['product_id']
     process_url = parmsdata['process_url']
     notify_url_address = self._notify_url + "db:" + cr.dbname
     data_post = {}
     data_post.update({
         'appid':
         appid,
         'mch_id':
         mch_id,
         'nonce_str':
         nonce_str,
         'body':
         body,
         'out_trade_no':
         body,
         'total_fee':
         total_fee,
         'spbill_create_ip':
         spbill_create_ip,
         'notify_url':
         urlparse.urljoin(notify_url, notify_url_address),
         'trade_type':
         trade_type,
         'product_id':
         product_id,
     })
     if trade_type == "JSAPI":
         opendid = http.request.session['openid']
         print opendid
         data_post.update({'openid': opendid})
     _, prestr = util.params_filter(data_post)
     data_post['sign'] = util.build_mysign(prestr, appkey, 'MD5')
     print data_post
     data_xml = "<xml>" + util.json2xml(data_post) + "</xml>"
     print data_xml
     url = process_url
     requestdata = urllib2.Request(url, data_xml)
     result = util._try_url(requestdata, tries=3)
     weixin_tx_values = {}
     _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)
     print return_xml
     if return_xml.find('return_code').text == "SUCCESS":
         if return_xml.find('code_url') == None:
             if return_xml.find('prepay_id') == None:
                 err_code = return_xml.find('err_code').text
                 err_code_des = return_xml.find('err_code_des').text
             else:
                 urlinfo = "/shop/confirmation"
                 sale_order_id = request.session.get('sale_last_order_id')
                 if sale_order_id:
                     order = request.registry['sale.order'].browse(
                         cr, SUPERUSER_ID, sale_order_id, context=context)
                 else:
                     return request.redirect('/shop')
                 print order
                 data_info = {}
                 data_info.update({
                     "order":
                     order,
                     "test":
                     "",
                     "appid":
                     appid,
                     "prepay_id":
                     return_xml.find('prepay_id').text,
                     "trade_type":
                     trade_type
                 })
                 request.website.sale_reset(context=context)  # 清除
                 return request.website.render("website_sale.confirmation",
                                               data_info)
                 # raise ValidationError("%s, %s" % (err_code, err_code_des))
         elif return_xml.find('code_url').text == False:
             err_code = return_xml.find('err_code').text
             err_code_des = return_xml.find('err_code_des').text
         else:
             weixin_tx_values['data_xml'] = data_xml
             qrcode = return_xml.find('code_url').text
             weixin_tx_values['qrcode'] = qrcode
             urlinfo = "/shop/confirmation"
             sale_order_id = request.session.get('sale_last_order_id')
             _logger.info("sale_order_id:" + str(sale_order_id))
             if sale_order_id:
                 order = request.registry['sale.order'].browse(
                     cr, SUPERUSER_ID, sale_order_id, context=context)
             else:
                 return request.redirect('/shop')
             print order
             data_info = {}
             data_info.update({
                 "order": order,
                 "test": qrcode,
                 "appid": appid,
                 "prepay_id": return_xml.find('prepay_id').text,
                 "trade_type": trade_type
             })
             request.website.sale_reset(context=context)  # 清除
             return request.website.render("website_sale.confirmation",
                                           data_info)
     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))