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 shashign (%s)' % (reference, pay_id, shasign) _logger.error(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.error(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.error(error_msg) raise ValidationError(error_msg) return tx
def _alipay_form_get_tx_from_data(self, cr, uid, data, context=None): """ Given a data dict coming from alipay, verify it and find the related transaction record. """ reference = data.get('out_trade_no') if not reference: error_msg = 'Alipay: received data with missing reference (%s)' % reference _logger.error(error_msg) raise ValidationError(error_msg) tx_ids = self.pool['payment.transaction'].search(cr, uid, [('reference', '=', reference)], context=context) if not tx_ids or len(tx_ids) > 1: error_msg = 'Alipay: 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) tx = self.pool['payment.transaction'].browse(cr, uid, tx_ids[0], context=context) sign_check = self.pool['payment.acquirer']._alipay_generate_md5_sign(tx.acquirer_id, 'out', data) if sign_check != data.get('sign'): error_msg = 'alipay: invalid md5str, received %s, computed %s' % (data.get('sign'), sign_check) _logger.warning(error_msg) raise ValidationError(error_msg) return tx
def _allpay_form_get_tx_from_data(self, cr, uid, data, context=None): reference, txn_id = data.get('MerchantTradeNo'), data.get('TradeNo') if not reference or not txn_id: error_msg = 'allPay: received data with missing reference (%s) or txn_id (%s)' % ( reference, txn_id) _logger.error(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 = 'allPay: 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) tx = self.browse(cr, uid, tx_ids[0], context=context) acquirer = tx.acquirer_id _logger.info('acquirer id: %s' % acquirer.id) CheckMacValue_result = self.pool['payment.acquirer'].checkout_feedback( cr, uid, acquirer.id, data, context=context) if CheckMacValue_result: return tx else: error_msg = 'allPay: invalid CheckMacValue, received %s, computed %s' % ( data.get('CheckMacValue'), CheckMacValue_result) _logger.warning(error_msg) raise ValidationError(error_msg)
def _consale_form_validate(self, tx, data): _logger.info( "Validate payment transaction data for consale (tx ID %s)" % tx.id) # Check required fields required = [ 'acquirer_reference', 'consale_state', 'consale_transaction_date', 'consale_provider_name', 'consale_method', 'consale_method_brand', 'consale_amount', 'consale_currency' ] missing_fields = tuple(f for f in required if not data.get(f, False)) if missing_fields: raise ValidationError("Fields missing: %s" % missing_fields) if data.get('consale_method', '') == 'other' and not data.get( 'consale_method_other', ''): raise ValidationError("Field 'consale_method_other' is empty!") # Use the consale state as the payment transaction state vals = data vals['state'] = data.get('consale_state') # Update the payment transaction and return the boolean results res = tx.write(vals) return True if res and tx.state in ('done', 'pending') else False
def _redsys_form_get_tx_from_data(self, data): """ Given a data dict coming from redsys, verify it and find the related transaction record. """ reference = data.get('Ds_Order', '') pay_id = data.get('Ds_AuthorisationCode') shasign = data.get('Ds_Signature') if not reference or not pay_id or not shasign: error_msg = 'Redsys: received data with missing reference' \ ' (%s) or pay_id (%s) or shashign (%s)' % (reference, pay_id, shasign) _logger.error(error_msg) raise ValidationError(error_msg) tx = self.search([('reference', '=', reference)]) if not tx or len(tx) > 1: error_msg = 'Redsys: 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) # verify shasign acquirer = self.env['payment.acquirer'] shasign_check = acquirer._redsys_generate_digital_sign( tx.acquirer_id, 'out', data) if shasign_check.upper() != shasign.upper(): error_msg = 'Redsys: invalid shasign, received %s, computed %s,' \ ' for data %s' % (shasign, shasign_check, data) _logger.error(error_msg) raise ValidationError(error_msg) return tx
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 if len(tx.acquirer_id.adyen_skin_hmac_key) == 64: shasign_check = self.pool['payment.acquirer']._adyen_generate_merchant_sig_sha256(tx.acquirer_id, 'out', data) else: 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
def _consale_form_get_tx_from_data(self, data): reference = data.get('reference') tx = self.search([('reference', '=', reference)]) if not tx: raise ValidationError( 'No payment transaction found for reference %s' % reference) elif len(tx) > 1: raise ValidationError( 'Multiple payment transaction found for reference %s' % reference) return tx
def _remita_form_get_tx_from_data(self, cr, uid, data, context=None): """ Given a data dict coming from remita, verify it and find the related transaction record. """ #Use transaction_id to pull in more info from Remita transaction_id = data.get('transaction_id') #transaction_id = '559f55426a93a' response = urllib2.urlopen( 'https://remita.com/?v_transaction_id=%s&type=json' % (transaction_id)) myTx = json.load(response) # reference, pay_id, shasign = data.get('memo'), data.get('transaction_id'), data.get('merchant_ref') reference, pay_id, shasign = myTx['memo'], data.get( 'transaction_id'), myTx['merchant_ref'] if not reference or not pay_id or not shasign: # if not reference: error_msg = 'Remita: received data with missing reference (%s) or pay_id (%s) or shashign (%s)' % ( reference, pay_id, shasign) _logger.error(error_msg) raise ValidationError(error_msg) # tx_ids = self.search(cr, uid, [('reference', '=', reference)], context=context) if not pay_id: error_msg = 'Remita: 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) tx = self.pool['payment.transaction'].browse(cr, uid, tx_ids[0], context=context) #verify shasign # shasign_check = self.pool['payment.acquirer']._remita_generate_digital_sign(tx.acquirer_id, 'out' ,data) # if shasign_check.upper() != shasign.upper(): # error_msg = 'Remita: invalid shasign, received %s, computed %s, for data %s' % (shasign, shasign_check, data) # _logger.error(error_msg) # raise ValidationError(error_msg) return tx
def _payerse_form_get_tx_from_data(self, data): _logger.debug('get tx from data') reference = data[0].get('order_id', False) if reference: # Search for sale order name instead of reference, to avoid bugs in payment module so = self.env['sale.order'].search([('name', '=', reference)]) tx = self.env['payment.transaction'].search([('sale_order_id', '=', so.id)]) if len(tx) != 1: error_msg = 'Payer: callback referenced non-existing transaction: %s' % reference _logger.warning(error_msg) raise ValidationError(error_msg) return tx else: error_msg = 'Payer: callback did not contain a tx reference.' _logger.warning(error_msg) raise ValidationError(error_msg)
def _payson_form_get_tx_from_data(self, data): _logger.debug('get tx from data') #Required token Guid The token obtained when creating the payment. token = data.get('token', False) if token: tx = self.env['payment.transaction'].search([('acquirer_reference', '=', token)]) if len(tx) != 1: error_msg = 'Payson: callback referenced non-existing transaction: %s' % token _logger.warning(error_msg) raise ValidationError(error_msg) return tx else: error_msg = 'Payson: callback did not contain a token.' _logger.warning(error_msg) raise ValidationError(error_msg)
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.write({'payment_method_id': ref}) return tx
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.error(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.error(error_msg) raise ValidationError(error_msg) return self.browse(cr, uid, tx_ids[0], context=context)
def _payfort_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('merchant_reference'), data.get('fort_id'), data.get('signature') if not reference or not trans_id or not fingerprint: error_msg = 'payfort: 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]
def _redsys_form_get_tx_from_data(self, data): """ Given a data dict coming from redsys, verify it and find the related transaction record. Session object for tests purpose. """ parameters = data.get('Ds_MerchantParameters', '') parameters_dic = json.loads(base64.b64decode(parameters)) reference = urllib.unquote(parameters_dic.get('Ds_Order', '')) pay_id = parameters_dic.get('Ds_AuthorisationCode') shasign = data.get( 'Ds_Signature', '').replace('_', '/').replace('-', '+') test_env = http.request.session.get('test_enable', False) if not reference or not pay_id or not shasign: error_msg = 'Redsys: received data with missing reference' \ ' (%s) or pay_id (%s) or shashign (%s)' % (reference, pay_id, shasign) if not test_env: _logger.error(error_msg) raise ValidationError(error_msg) http.OpenERPSession.tx_error = True tx = self.search([('reference', '=', reference)]) if not tx or len(tx) > 1: error_msg = 'Redsys: received data for reference %s' % (reference) if not tx: error_msg += '; no order found' else: error_msg += '; multiple order found' if not test_env: _logger.error(error_msg) raise ValidationError(error_msg) else: http.OpenERPSession.tx_error = True if tx and not test_env: # verify shasign shasign_check = tx.acquirer_id.sign_parameters( tx.acquirer_id.redsys_secret_key, parameters) if shasign_check != shasign: error_msg = ( 'Redsys: invalid shasign, received %s, computed %s, ' 'for data %s' % (shasign, shasign_check, data) ) _logger.error(error_msg) raise ValidationError(error_msg) return tx
def _weixin_form_get_tx_from_data(self, data): 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) # find tx -> @TDENOTE use txn_id ? tx_ids = self.search([('reference', '=', reference)]) 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 tx_ids[0]
def _todopago_form_get_tx_from_data(self, data): Answer = data.get('Answer') reference = data.get('OPERATIONID') if not Answer or not reference: error_msg = ( 'TodoPago: received data with missing reference (%s) or ' 'collection_id (%s)' % (Answer, reference)) _logger.error(error_msg) raise ValidationError(error_msg) transaction = self.search([('reference', '=', reference)], limit=1) if not transaction: error_msg = ( 'TodoPago: received data for reference %s; no order found' % (reference)) _logger.error(error_msg) raise ValidationError(error_msg) transaction.todopago_Answer = Answer return transaction
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. """ reference, pay_id, shasign = data.get('orderID'), data.get( 'PAYID'), data.get('SHASIGN') if not reference or not pay_id or not shasign: error_msg = _( 'Ogone: received data with missing reference (%s) or pay_id (%s) or shashign (%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) return tx
def _alipay_form_get_tx_from_data(self, data): reference, txn_id = data.get('out_trade_no'), data.get('trade_no') if not reference or not txn_id: error_msg = _( 'Alipay: 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 ? txs = self.env['payment.transaction'].search([('reference', '=', reference)]) if not txs or len(txs) > 1: error_msg = 'Alipay: 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 _moneta_form_get_tx_from_data(self, data): """ Given a data dict coming from moneta, 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') reference, trans_id, fingerprint = data.get( 'MNT_TRANSACTION_ID'), data.get('MNT_OPERATION_ID'), data.get( 'MNT_SIGNATURE') if not reference or not trans_id or not fingerprint: error_msg = 'moneta: 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 = 'moneta: 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]
def _faircoin_form_get_tx_from_data(self, cr, uid, data, context=None): _logger.debug( 'Begin faircoin_form_get_tx_from_data. Data received %s' % data) reference = data.get('item_number') if not reference: error_msg = 'Faircoin: received data with missing reference (%s)' % reference _logger.error(error_msg) raise ValidationError(error_msg) return tx_ids = self.pool['payment.transaction'].search( cr, uid, [('reference', '=', reference)], context=context) if not tx_ids or len(tx_ids) > 1: error_msg = 'Faircoin: 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) _logger.debug('End faircoin_form_get_tx_from_data') return self.browse(cr, uid, tx_ids[0], context=context)
def _wcpay_form_get_tx_from_data(self, data): """ Given a data dict coming from wcpay, verify it and find the related transaction record. """ reference = data.get('out_trade_no') if not reference: error_msg = 'Wcpay: received data with missing reference (%s)' % ( reference) _logger.error(error_msg) raise ValidationError(error_msg) tx_ids = self.pool['payment.transaction'].search([('reference', '=', reference)]) if not tx_ids or len(tx_ids) > 1: error_msg = 'wcpay: 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) tx = self.pool['payment.transaction'].browse(tx_ids[0]) return tx
def _conekta_oxxo_form_get_tx_from_data(self, data): reference = data['reference_id'] payment_tx = self.search([('reference', '=', reference)]) if not payment_tx or len(payment_tx) > 1: error_msg = _( 'Conekta: 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
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 _mollie_form_get_tx_from_data(self, cr, uid, data, context=None): reference = data.get('reference') tx_ids = self.pool['payment.transaction'].search( cr, uid, [('reference', '=', reference)], context=context) if not tx_ids or len(tx_ids) > 1: error_msg = 'Mollie: 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)
def _getfaircoin_form_get_tx_from_data(self, cr, uid, data, context=None): """ Given a data dict coming from getfaircoin, verify it and find the related transaction record. """ data = normalize_keys_upper(data) logging.info("BEGIN getfaircoin_form_get_tx_data : %s" % data) reference, pay_id = data.get('ITEM_NUMBER'), data.get('PAYMENT_STATUS') if not reference: error_msg = 'Getfaircoin: received data with missing reference (%s) ' % ( reference) _logger.error(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 = 'Getfaircoin: 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) tx = self.pool['payment.transaction'].browse(cr, uid, tx_ids[0], context=context) #verify shasign #shasign_check = self.pool['payment.acquirer']._getfaircoin_generate_digital_sign(tx.acquirer_id, 'out', origin_data) #if shasign_check.upper() != shasign.upper(): # error_msg = 'Getfaircoin: invalid shasign, received %s, computed %s, for data %s' % (shasign, shasign_check, data) # _logger.error(error_msg) # raise ValidationError(error_msg) return tx
def _redsys_form_get_tx_from_data(self, data): """ Given a data dict coming from redsys, verify it and find the related transaction record. """ parameters = data.get('Ds_MerchantParameters', '') parameters_dic = json.loads(base64.b64decode(parameters)) reference = parameters_dic.get('Ds_Order', '') pay_id = parameters_dic.get('Ds_AuthorisationCode') shasign = data.get('Ds_Signature', '').replace('_', '/').replace('-', '+') if not reference or not pay_id or not shasign: error_msg = 'Redsys: received data with missing reference' \ ' (%s) or pay_id (%s) or shashign (%s)' % (reference, pay_id, shasign) _logger.error(error_msg) raise ValidationError(error_msg) tx = self.search([('reference', '=', reference)]) if not tx or len(tx) > 1: error_msg = 'Redsys: 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) # verify shasign shasign_check = tx.acquirer_id.sign_parameters( tx.acquirer_id.redsys_secret_key, parameters) if shasign_check != shasign: error_msg = 'Redsys: invalid shasign, received %s, computed %s,' \ ' for data %s' % (shasign, shasign_check, data) _logger.error(error_msg) raise ValidationError(error_msg) return tx
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 _bitcoin_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.error(error_msg) raise ValidationError(error_msg) return self.browse(cr, uid, tx_ids[0], context=context)
def sips_form_generate_values(self, partner_values, tx_values): self.ensure_one() base_url = self.env['ir.config_parameter'].sudo().get_param( 'web.base.url') currency = self.env['res.currency'].sudo().browse( tx_values['currency_id']) currency_code = CURRENCY_CODES.get(currency.name, False) if not currency_code: raise ValidationError(_('Currency not supported by Wordline')) amount = int(tx_values.get('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(tx_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|' % tx_values['reference'] + u'statementReference=%s|' % tx_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 partner_values, sips_tx_values
def _postfinance_form_get_tx_from_data(self, cr, uid, data, context=None): # the current sales order is stored in reference reference = data.get('reference') # search for transactions linked to this sales order tx_ids = self.search(cr, uid, [('reference', '=', reference),], context=context) if not tx_ids or len(tx_ids) > 1: error_msg = 'ESR Payment Transaction: received data for reference %s' % (pprint.pformat(reference)) if not tx_ids: error_msg += '; no Transaction found' else: error_msg += '; multiple Transactions found' _logger.error(error_msg) raise ValidationError(error_msg) # return the payment.transaction object return self.browse(cr, uid, tx_ids[0], context=context)