def _adyen_form_get_tx_from_data(self, data): 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 = self.env['payment.transaction'].search([('reference', '=', reference)]) if not tx or len(tx) > 1: error_msg = _('Adyen: received data for reference %s') % ( reference) if not tx: error_msg += _('; no order found') else: error_msg += _('; multiple order found') _logger.info(error_msg) raise ValidationError(error_msg) # verify shasign if len(tx.acquirer_id.adyen_skin_hmac_key) == 64: shasign_check = tx.acquirer_id._adyen_generate_merchant_sig_sha256( 'out', data) else: shasign_check = tx.acquirer_id._adyen_generate_merchant_sig( 'out', data) if to_native(shasign_check) != to_native(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
def razorpay_form_generate_values(self, values): self.ensure_one() currency = self.env['res.currency'].sudo().browse(values['currency_id']) if currency != self.env.ref('base.INR'): raise ValidationError(_('Currency not supported by Razorpay')) values.update({ 'key': self.razorpay_key_id, 'amount': float_repr(float_round(values.get('amount'), 2) * 100, 0), 'name': values.get('partner_name'), 'contact': values.get('partner_phone'), 'email': values.get('partner_email'), 'order_id': values.get('reference'), }) return values
def _payfast_form_get_tx_from_data(self, data): reference = data.get('custom_str1') tx_ids = self.env['payment.transaction'].search([('reference', '=', reference)]) if not tx_ids or len(tx_ids) > 1: error_msg = 'Payfast: 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 tx_ids[0]
def _chanpay_form_get_tx_from_data(self, data): reference = data.get('outer_trade_no') # find tx -> @TDENOTE use txn_id ? txs = self.env['payment.transaction'].search([('reference', '=', reference)]) if not txs or len(txs) > 1: error_msg = 'chanpay: received data for reference %s' % (reference) if not txs: error_msg += '; no order found' else: error_msg += '; multiple order found' _logger.info(error_msg) raise ValidationError(error_msg) return txs[0]
def _visanet_form_get_tx_from_data(self, data): """ Given a data dict coming from visanet, verify it and find the related transaction record. """ origin_data = dict(data) reference = data.get('req_reference_number') if not reference: error_msg = _('VisaNet: received data with missing reference (%s)' ) % (reference) _logger.info(error_msg) raise ValidationError(error_msg) tx = self.search([('reference', '=', reference)]) if not tx or len(tx) > 1: error_msg = _('VisaNet: received data for reference %s') % ( reference) if not tx: error_msg += _('; no order found') else: error_msg += _('; multiple order found') _logger.info(error_msg) raise ValidationError(error_msg) return tx
def _doku_form_get_tx_from_data(self, data): _logger.info('------ _doku_form_get_tx_from_data : %s' % data) reference = data.get('TRANSIDMERCHANT', '') if not reference: error_msg = _( 'Doku: received data with missing reference (%s) or missing pspReference (%s)' ) % (reference) _logger.info(error_msg) raise ValidationError(error_msg) # find tx tx = self.env['payment.transaction'].search([('reference', '=', reference)]) if not tx or len(tx) > 1: error_msg = _('Doku: received data for reference %s') % (reference) if not tx: error_msg += _('; no order found') else: error_msg += _('; multiple order found') _logger.info(error_msg) raise ValidationError(error_msg) return tx
def _webpay_form_get_tx_from_data(self, cr, uid, data, context=None): _logger.info('Webpay: entering form_get_tx with post data %s', pprint.pformat(data)) # debug reference, txn_id = data.get('item_number'), data.get('txn_id') if not reference or not txn_id: error_msg = _( 'Webpay: received data with missing reference (%s) or txn_id (%s)' ) % (reference, txn_id) _logger.warning(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 = 'Webpay: received data for reference %s' % (reference) if not tx_ids: error_msg += '; no order found' else: error_msg += '; multiple order found' _logger.warning(error_msg) raise ValidationError(error_msg) return self.browse(cr, uid, tx_ids[0], context=context)
def _mistertango_form_get_tx_from_data(self, data): '''Extracts the order ID from received data. Returns the corresponding transaction.''' # We use the plaintext data here as we do not yet know which acquirer # is being used. custom_data = json.loads(data['custom']) reference = custom_data.get('description') if not reference: msg = 'Order ID missing in callback data' _logger.error(msg) raise ValidationError(msg) txs = self.env['payment.transaction'].search([ ('reference', '=', reference), ]) if not txs or len(txs) > 1: raise ValidationError( # pylint: disable=translation-required 'Callback data received for reference ID: "%s", ' 'either zero or multiple order found' % reference) return txs[0]
def _credit_form_get_tx_from_data(self, data): reference, amount, currency_name = data.get('reference'), data.get('amount'), data.get('currency_name') tx = self.search([('reference', '=', reference)]) if not tx or len(tx) > 1: error_msg = _('received data for reference %s') % (pprint.pformat(reference)) if not tx: error_msg += _('; no order found') else: error_msg += _('; multiple order found') _logger.info(error_msg) raise ValidationError(error_msg) return tx
def _mercadopago_form_get_tx_from_data(self, data): reference = data.get('external_reference') collection_id = data.get('collection_id') if not reference or not collection_id: error_msg = ( 'MercadoPago: received data with missing reference (%s) or ' 'collection_id (%s)' % (reference, collection_id)) _logger.error(error_msg) raise ValidationError(error_msg) # find tx -> @TDENOTE use txn_id ? txs = self.env['payment.transaction'].search([('reference', '=', reference)]) if not txs or len(txs) > 1: error_msg = ('MercadoPago: received data for reference %s' % (reference)) if not txs: error_msg += '; no order found' else: error_msg += '; multiple order found' _logger.error(error_msg) raise ValidationError(error_msg) return txs[0]
def square_client(self): """ Method is used for create square client. """ self.ensure_one() client = False if self.sudo().square_access_token and self.sudo( ).square_access_token == 'dummy': raise ValidationError(_("Please configure square account.")) if self.sudo().square_access_token: client = Client( access_token=self.sudo().square_access_token, environment='sandbox' if self.state == 'test' else 'production', ) return client
def _payumoney_form_get_tx_from_data(self, data): """ Given a data dict coming from payumoney, verify it and find the related transaction record. """ reference = data.get('txnid') pay_id = data.get('mihpayid') shasign = data.get('hash') if not reference or not pay_id or not shasign: raise ValidationError(_('PayUmoney: received data with missing reference (%s) or pay_id (%s) or shashign (%s)') % (reference, pay_id, shasign)) transaction = self.search([('reference', '=', reference)]) if not transaction: error_msg = (_('PayUmoney: received data for reference %s; no order found') % (reference)) raise ValidationError(error_msg) elif len(transaction) > 1: error_msg = (_('PayUmoney: received data for reference %s; multiple orders found') % (reference)) raise ValidationError(error_msg) #verify shasign shasign_check = transaction.acquirer_id._payumoney_generate_sign('out', data) if shasign_check.upper() != shasign.upper(): raise ValidationError(_('PayUmoney: invalid shasign, received %s, computed %s, for data %s') % (shasign, shasign_check, data)) return transaction
def _flow_form_get_tx_from_data(self, data): reference, txn_id = data.transaction_id, data.payment_id if not reference or not txn_id: error_msg = _( 'Flow: received data with missing reference (%s) or txn_id (%s)' ) % (reference, txn_id) _logger.warning(error_msg) raise ValidationError(error_msg) # find tx -> @TDENOTE use txn_id ? txs = self.env['payment.transaction'].search([ ('reference', '=', reference), ('acquirer_id.provider', '=', 'flow') ]) if not txs or len(txs) > 1: error_msg = 'Flow: received data for reference %s' % (reference) if not txs: error_msg += '; no order found' else: error_msg += '; multiple order found' _logger.info(error_msg) raise ValidationError(error_msg) return txs[0]
def _moyasar_form_get_tx_from_data(self, data): print(data) reference, pspReference = data.get('merchantReference'), data.get( 'pspReference') if not reference or not pspReference: error_msg = _( 'Moyasar: 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 ? print(reference) tx = self.env['payment.transaction'].sudo().search([('reference', '=', reference)]) print(tx) if not tx or len(tx) > 1: error_msg = _('Moyasar: received data for reference %s') % ( reference) if not tx: error_msg += _('; no order found') else: error_msg += _('; multiple order found') _logger.info(error_msg) raise ValidationError(error_msg) # verify shasign # if len(tx.acquirer_id.Moyasar_scret_key) == 64: # shasign_check = tx.acquirer_id._moyasar_generate_merchant_sig_sha256('out', data) # else: # shasign_check = tx.acquirer_id._moyasar_generate_merchant_sig('out', data) # if to_text(shasign_check) != to_text(data.get('merchantSig')): # error_msg = _('Moyasar: invalid merchantSig, received %s, computed %s') % (data.get('merchantSig'), shasign_check) # _logger.warning(error_msg) # raise ValidationError(error_msg) print(tx) return tx
def _alipay_form_get_tx_from_data(self, data): reference, txn_id, sign = data.get('reference'), data.get( 'trade_no'), data.get('sign') if not reference or not txn_id: _logger.info( 'Alipay: received data with missing reference (%s) or txn_id (%s)' % (reference, txn_id)) raise ValidationError( _('Alipay: received data with missing reference (%s) or txn_id (%s)' ) % (reference, txn_id)) txs = self.env['payment.transaction'].search([('reference', '=', reference)]) if not txs or len(txs) > 1: error_msg = _('Alipay: received data for reference %s') % ( reference) logger_msg = 'Alipay: received data for reference %s' % (reference) if not txs: error_msg += _('; no order found') logger_msg += '; no order found' else: error_msg += _('; multiple order found') logger_msg += '; multiple order found' _logger.info(logger_msg) raise ValidationError(error_msg) # verify sign sign_check = txs.acquirer_id._build_sign(data) if sign != sign_check: _logger.info( 'Alipay: invalid sign, received %s, computed %s, for data %s' % (sign, sign_check, data)) raise ValidationError( _('Alipay: invalid sign, received %s, computed %s, for data %s' ) % (sign, sign_check, data)) return txs
def sips_form_generate_values(self, values): self.ensure_one() base_url = self.get_base_url() currency = self.env['res.currency'].sudo().browse( values['currency_id']) sips_currency = SIPS_SUPPORTED_CURRENCIES.get(currency.name) if not sips_currency: raise ValidationError( _('Currency not supported by Wordline: %s') % currency.name) # rounded to its smallest unit, depends on the currency amount = round(values['amount'] * (10**sips_currency.decimal)) sips_tx_values = dict(values) data = { 'amount': amount, 'currencyCode': sips_currency.iso_id, 'merchantId': self.sips_merchant_id, 'normalReturnUrl': urls.url_join(base_url, SipsController._return_url), 'automaticResponseUrl': urls.url_join(base_url, SipsController._notify_url), 'transactionReference': values['reference'], 'statementReference': values['reference'], 'keyVersion': self.sips_key_version, } sips_tx_values.update({ 'Data': '|'.join([f'{k}={v}' for k, v in data.items()]), 'InterfaceVersion': self.sips_version, }) return_context = {} if sips_tx_values.get('return_url'): return_context['return_url'] = urls.url_quote( sips_tx_values.get('return_url')) return_context['reference'] = sips_tx_values['reference'] sips_tx_values['Data'] += '|returnContext=%s' % ( json.dumps(return_context)) shasign = self._sips_generate_shasign(sips_tx_values) sips_tx_values['Seal'] = shasign return sips_tx_values
def _cardconnect_form_get_tx_from_data(self, data): _logger.info("********************form data=%r", data) reference, amount, currency, acquirer_reference = data.get( 'reference'), data.get('amount'), data.get('currency'), data.get( 'acquirer_reference') if not reference or not amount or not currency or not acquirer_reference: error_msg = 'CardConnect: received data with missing reference (%s) or acquirer_reference (%s) or Amount (%s)' % ( reference, acquirer_reference, amount) _logger.error(error_msg) raise ValidationError(error_msg) tx = self.search([('reference', '=', reference)]) if not tx or len(tx) > 1: error_msg = _('received data for reference %s') % ( pprint.pformat(reference)) if not tx: error_msg += _('; no order found') else: error_msg += _('; multiple order found') _logger.info(error_msg) raise ValidationError(error_msg) return tx
def _paymaya_form_get_tx_from_data(self, data): reference = data.get('requestReferenceNumber') # if not reference: # paymaya_error = data.get('error', {}).get('message', '') # _logger.error('Paymaya: invalid reply received from paymaya API, looks like ' # 'the transaction failed. (error: %s)', paymaya_error or 'n/a') # error_msg = _("We're sorry to report that the transaction has failed.") # if paymaya_error: # error_msg += " " + (_("Paymaya gave us the following info about the problem: '%s'") % # paymaya_error) # error_msg += " " + _("Perhaps the problem can be solved by double-checking your " # "credit card details, or contacting your bank?") # raise ValidationError(error_msg) tx = self.search([('reference', '=', reference)]) if not tx: error_msg = (_('Paymaya: no order found for reference %s') % reference) _logger.error(error_msg) raise ValidationError(error_msg) elif len(tx) > 1: error_msg = (_('Paymaya: %s orders found for reference %s') % (len(tx), reference)) _logger.error(error_msg) raise ValidationError(error_msg) return tx
def _bac_form_get_tx_from_data(self, data): """ Given a data dict coming from bac, verify it and find the related transaction record. """ origin_data = dict(data) reference = data.get('order_description') if not reference: error_msg = _('BAC: received data with missing reference (%s)') % ( reference) _logger.info(error_msg) raise ValidationError(error_msg) # order = reference.split('--')[0] order = reference tx = self.search([('reference', '=', order)]) if not tx or len(tx) > 1: error_msg = _('BAC: received data for reference %s') % (order) if not tx: error_msg += _('; no order found') else: error_msg += _('; multiple order found') _logger.info(error_msg) raise ValidationError(error_msg) return tx
def _payanyway_form_get_tx_from_data(self, data): _logger.info("_payanyway_form_get_tx_from_data\n" + pformat(data)) mnt_transaction_id = data.get('MNT_TRANSACTION_ID') order = self.env['payment.transaction'].search([('reference', '=', mnt_transaction_id)]) if not order or len(order) > 1: error_msg = 'PayAnyWay: received data for reference %s' % ( mnt_transaction_id) if not order: error_msg += '; no order found' else: error_msg += '; multiple order found' _logger.info(error_msg) raise ValidationError(error_msg) return order[0]
def _mollie_form_get_tx_from_data(self, data): reference = data.get("reference") payment_tx = self.search([("reference", "=", reference)]) if not payment_tx or len(payment_tx) > 1: error_msg = _("received data for reference %s") % ( pprint.pformat(reference)) if not payment_tx: error_msg += _("; no order found") else: error_msg += _("; multiple order found") _logger.info(error_msg) raise ValidationError(error_msg) return payment_tx
def unlink(self): """ Method is used for delete card from square side. """ for rec in self: if rec.acquirer_id and rec.acquirer_id.provider == 'square' and rec.acquirer_ref and rec.partner_id and rec.partner_id.square_customer_id: try: client = rec.acquirer_id.square_client() if client: result = client.customers.delete_customer_card( customer_id=rec.partner_id.square_customer_id, card_id=rec.acquirer_ref) if result.is_success(): return super(PaymentToken, self).unlink() except Exception as e: raise ValidationError(_("Square Error : %s !" % e)) return super(PaymentToken, self).unlink()
def _vnpay_form_get_tx_from_data(self, data): _logger.info('================_vnpay_form_get_tx_from_data') _logger.debug(data) reference = data.get('vnp_TxnRef') if not reference: error_msg = _('VNpay: received data with missing reference (%s)' ) % (reference) _logger.error(error_msg) raise ValidationError(error_msg) txs = self.env['payment.transaction'].search([('reference', '=', reference)]) if not txs or len(txs) > 1: error_msg = 'VNpay: received data for reference %s' % (reference) if not txs: error_msg += '; no order found' else: error_msg += '; multiple order found' _logger.error(error_msg) raise ValidationError(error_msg) return txs[0]
def _buckaroo_form_get_tx_from_data(self, data): """ Given a data dict coming from buckaroo, verify it and find the related transaction record. """ origin_data = dict(data) data = normalize_keys_upper(data) 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 = self.search([('reference', '=', reference)]) if not tx or len(tx) > 1: error_msg = _('Buckaroo: received data for reference %s') % ( reference) if not tx: error_msg += _('; no order found') else: error_msg += _('; multiple order found') _logger.info(error_msg) raise ValidationError(error_msg) # verify shasign shasign_check = tx.acquirer_id._buckaroo_generate_digital_sign( 'out', origin_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
def _check_alipay_configuration(self, vals): acquirer_id = int(vals.get('acquirer_id')) acquirer = self.env['payment.acquirer'].sudo().browse(acquirer_id) if acquirer and acquirer.provider == 'alipay' and acquirer.alipay_payment_method == 'express_checkout': currency_id = int(vals.get('currency_id')) if currency_id: currency = self.env['res.currency'].sudo().browse(currency_id) if currency and currency.name != 'CNY': _logger.info("Only CNY currency is allowed for Alipay Express Checkout") raise ValidationError(_(""" Only transactions in Chinese Yuan (CNY) are allowed for Alipay Express Checkout.\n If you wish to use another currency than CNY for your transactions, switch your configuration to a Cross-border account on the Alipay payment acquirer in Odoo. """)) return True
def _epayco_form_get_tx_from_data(self, data): """ Given a data dict coming from epayco, verify it and find the related transaction record. """ reference = data.get('x_extra1') signature = data.get('x_signature') if not reference or not pay_id or not shasign: raise ValidationError(_('Epayco: received data with missing reference (%s) or signature (%s)') % (reference, signature)) transaction = self.search([('reference', '=', reference)]) if not transaction: error_msg = (_('Epayco: received data for reference %s; no order found') % (reference)) raise ValidationError(error_msg) elif len(transaction) > 1: error_msg = (_('Epayco: received data for reference %s; multiple orders found') % (reference)) raise ValidationError(error_msg) #verify signature reference = data.get('x_extra1') signature = data.get('x_signature') shasign_check = transaction.acquirer_id._epayco_generate_sign(data) if shasign_check != signature: raise ValidationError(_('Epayco: invalid signature, received %s, computed %s, for data %s') % (signature, shasign_check, data)) return transaction
def _paytabs_form_get_tx_from_data(self, data): reference = data.get('reference_no') tx = self.env['payment.transaction'].sudo().search([('reference', '=', reference)]) if 'response_code' in data: if int(data['response_code']) == 0: tx.write({'state': 'cancel'}) if not tx or len(tx) > 1: error_msg = _('PayTabs: received data with missing reference (%s)' ) % (reference) if not tx.ids: error_msg += '; no order found' else: error_msg += '; multiple order found' raise ValidationError(error_msg) return tx
def _hyperpay_form_get_tx_from_data(self, data): reference = data.get('ndc') tx_id = data.get('tx_id') tx = tx_id and self.sudo().browse(int(tx_id)) if not tx or len(tx) > 1: error_msg = _('received data for reference %s') % ( pprint.pformat(reference)) if not tx: error_msg += _('; no order found') else: error_msg += _('; multiple order found') _logger.info(error_msg) raise ValidationError(error_msg) return tx
def _paymaya_request(self, url, data, method, key): # self.ensure_one() paymaya_url = self._get_paymaya_urls(self.environment)['paymaya_form_url'] url = urls.url_join(paymaya_url, url) resp = requests.request(method, url, data=json.dumps(data), headers=self.paymaya_get_headers(key)) try: if not resp.ok and not (400 <= resp.status_code < 500 and resp.json().get('error', {}).get('code')): try: resp.raise_for_status() except HTTPError: _logger.error(resp.text) paymaya_error = resp.json().get('error', {}).get('message', '') error_msg = " " + (_("Paymaya gave us the following info about the problem: '%s'") % paymaya_error) raise ValidationError(error_msg) except: pass return resp.json()
def action_returns_commit(self): # ================== # 确认退款操作 # ================== data = { 'appid', self.acquirer_id.appid, 'mch_id', self.acquirer_id.mch_id, 'nonce_str', random_generator(), 'out_refund_no', self.reference, 'refund_fee', int(self.amount * 100), 'total_fee', int(self.amount * 100), 'transaction_id', self.acquirer_reference, } _, prestr = util.params_filter(data) sign = util.build_mysign(prestr, self.acquirer_id.weixin_key, 'MD5') data.update({'sign': sign}) data_xml = "<xml>" + self.json2xml(data) + "</xml>" url = 'https://api.mch.weixin.qq.com/secapi/pay/refund' # print(data_xml) request_data = urllib.request.Request( url, data_xml.encode(encoding='utf-8')) result = urllib.request.urlopen(request_data).read() return_xml = etree.fromstring(result) if return_xml.find( 'return_code' ).text == "SUCCESS" and return_xml.find('sign').text != False: transaction_id = return_xml.find('transaction_id').text out_refund_no = return_xml.find('out_refund_no').text sign = return_xml.find('sign').text res = self.env['payment.transaction'].sudo().search([ ('acquirer_reference', '=', transaction_id), ('reference', '=', out_refund_no) ]) if res: super(TxWeixin, self).action_returns_commit() 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))