def perform_cash_management_operation(self, endpoint, data): data['merchantId'] = self.merchant_id data['interfaceVersion'] = 'CR_WS_2.3' data['keyVersion'] = self.key_version data['currencyCode'] = self.currency_code data['seal'] = self.get_seal_for_json_ws_data(data) url = self.WS_URL.get( self.platform) + '/rs-services/v2/cashManagement/%s' % endpoint self.logger.debug('posting %r to %s endpoint', data, endpoint) response = requests.post(url, data=json.dumps(data), headers={ 'content-type': 'application/json', 'accept': 'application/json' }) self.logger.debug('received %r', response.content) response.raise_for_status() json_response = response.json() if self.platform == 'prod': # test environment doesn't set seal if json_response.get('seal') != self.get_seal_for_json_ws_data( json_response): raise ResponseError('wrong signature on response') if json_response.get('responseCode') != '00': raise ResponseError('non-zero response code (%s)' % json_response) return json_response
def response(self, query_string, **kwargs): fields = urlparse.parse_qs(query_string, True) if not set(fields) >= set([SIGNATURE, VADS_CTX_MODE, VADS_AUTH_RESULT ]): raise ResponseError() for key, value in fields.iteritems(): fields[key] = value[0] copy = fields.copy() bank_status = [] if VADS_AUTH_RESULT in fields: v = copy[VADS_AUTH_RESULT] ctx = (v, AUTH_RESULT_MAP.get(v, 'Code inconnu')) copy[VADS_AUTH_RESULT] = '%s: %s' % ctx bank_status.append(copy[VADS_AUTH_RESULT]) if VADS_RESULT in copy: v = copy[VADS_RESULT] ctx = (v, RESULT_MAP.get(v, 'Code inconnu')) copy[VADS_RESULT] = '%s: %s' % ctx bank_status.append(copy[VADS_RESULT]) if v == '30': if VADS_EXTRA_RESULT in fields: v = fields[VADS_EXTRA_RESULT] if v.isdigit(): for parameter in PARAMETERS: if int(v) == parameter.code: s = 'erreur dans le champ %s' % parameter.name copy[VADS_EXTRA_RESULT] = s bank_status.append(copy[VADS_EXTRA_RESULT]) elif v in ('05', '00'): if VADS_EXTRA_RESULT in fields: v = fields[VADS_EXTRA_RESULT] extra_result_name = EXTRA_RESULT_MAP.get(v, 'Code inconnu') copy[VADS_EXTRA_RESULT] = '%s: %s' % (v, extra_result_name) bank_status.append(copy[VADS_EXTRA_RESULT]) self.logger.debug('checking systempay response on:') for key in sorted(fields.keys()): self.logger.debug(' %s: %s' % (key, copy[key])) signature = self.signature(fields) signature_result = signature == fields[SIGNATURE] self.logger.debug('signature check: %s <!> %s', signature, fields[SIGNATURE]) if not signature_result: bank_status.append('invalid signature') if fields[VADS_AUTH_RESULT] == '00': result = PAID else: result = ERROR test = fields[VADS_CTX_MODE] == 'TEST' transaction_id = '%s_%s' % (copy[VADS_TRANS_DATE], copy[VADS_TRANS_ID]) # the VADS_AUTH_NUMBER is the number to match payment in bank logs copy[self.BANK_ID] = copy.get(VADS_AUTH_NUMBER, '') response = PaymentResponse(result=result, signed=signature_result, bank_data=copy, order_id=transaction_id, transaction_id=copy.get(VADS_AUTH_NUMBER), bank_status=' - '.join(bank_status), test=test) return response
def response(self, query_string, logger=LOGGER, **kwargs): form = urlparse.parse_qs(query_string) if not set(form) >= set([REFERENCE, ETAT, REFSFP]): raise ResponseError() for key, value in form.iteritems(): form[key] = value[0] logger.debug('received query_string %s' % query_string) logger.debug('parsed as %s' % form) reference = form.get(REFERENCE) bank_status = [] signed = False form[self.BANK_ID] = form.get(REFSFP) etat = form.get('etat') status = '%s: %s' % (etat, SPPLUS_RESPONSE_CODES.get(etat, 'Unknown code')) logger.debug('status is %s', status) bank_status.append(status) if 'hmac' in form: try: signed_data, signature = query_string.rsplit('&', 1) _, hmac = signature.split('=', 1) logger.debug('got signature %s' % hmac) computed_hmac = sign_ntkey_query(self.cle, signed_data) logger.debug('computed signature %s' % computed_hmac) signed = hmac == computed_hmac if not signed: bank_status.append('invalid signature') except ValueError: bank_status.append('invalid signature') test = False if etat in PAID_STATE: result = PAID elif etat in ACCEPTED_STATE: result = ACCEPTED elif etat in VALID_STATE: result = RECEIVED elif etat in TEST_STATE: result = RECEIVED # what else ? test = True else: result = ERROR response = PaymentResponse(result=result, signed=signed, bank_data=form, order_id=reference, transaction_id=form[self.BANK_ID], bank_status=' - '.join(bank_status), return_content=SPCHECKOK, test=test) return response
def response(self, query_string, **kwargs): form = urlparse.parse_qs(query_string) if not DATA in form: raise ResponseError() params = {'message': form[DATA][0]} result = self.execute('response', params) d = dict(zip(RESPONSE_PARAMS, result)) # The reference identifier for the payment is the authorisation_id d[self.BANK_ID] = d.get(AUTHORISATION_ID) self.logger.debug('response contains fields %s' % d) response_result = d.get(RESPONSE_CODE) == '00' response_code_msg = CB_BANK_RESPONSE_CODES.get(d.get(RESPONSE_CODE)) response = PaymentResponse( result=response_result, signed=response_result, bank_data=d, order_id=d.get(ORDER_ID), transaction_id=d.get(AUTHORISATION_ID), bank_status=response_code_msg) return response
def response(self, query_string, **kwargs): params = urlparse.parse_qs(query_string, True) params = dict((key.upper(), params[key][0]) for key in params) if not set(params) >= set(['ORDERID', 'PAYID', 'STATUS', 'NCERROR']): raise ResponseError() # uniformize iso-8859-1 encoded values for key in params: params[key] = force_text(params[key], 'iso-8859-1') reference = params['ORDERID'] transaction_id = params['PAYID'] status = params['STATUS'] error = params['NCERROR'] signed = False if self.sha_in: signature = params.get('SHASIGN') expected_signature = self.sha_sign_out(params) signed = signature == expected_signature print 'signed', signature print 'expected', expected_signature if status == '1': result = CANCELLED elif status == '2': result = DENIED elif status == '5': result = ACCEPTED elif status == '9': result = PAID else: self.logger.error('response STATUS=%s NCERROR=%s NCERRORPLUS=%s', status, error, params.get('NCERRORPLUS', '')) result = ERROR # extract reference from received order id if ORDERID_TRANSACTION_SEPARATOR in reference: reference, transaction_id = reference.split( ORDERID_TRANSACTION_SEPARATOR, 1) return PaymentResponse(result=result, signed=signed, bank_data=params, order_id=reference, transaction_id=transaction_id)
def response(self, query_string, callback=False, **kwargs): d = urlparse.parse_qs(query_string, True, False) if not set(d) >= set(['erreur', 'reference']): raise ResponseError() signed = False if 'signature' in d: sig = d['signature'][0] sig = base64.b64decode(sig) data = [] if callback: for key in ('montant', 'reference', 'code_autorisation', 'erreur'): data.append('%s=%s' % (key, urllib.quote(d[key][0]))) else: for key, value in urlparse.parse_qsl(query_string, True, True): if key == 'signature': break data.append('%s=%s' % (key, urllib.quote(value))) data = '&'.join(data) signed = verify(data, sig) if d['erreur'][0] == '00000': result = PAID else: result = ERROR for l in (5, 3): prefix = d['erreur'][0][:l] suffix = 'x' * (5 - l) bank_status = PAYBOX_ERROR_CODES.get(prefix + suffix) if bank_status is not None: break orderid = d['reference'][0] # decode order id from returned reference if ORDERID_TRANSACTION_SEPARATOR in orderid: orderid, transaction_id = orderid.split( ORDERID_TRANSACTION_SEPARATOR, 1) return PaymentResponse(order_id=orderid, signed=signed, bank_data=d, result=result, bank_status=bank_status)
def response(self, query_string, **kwargs): fields = parse_qs(query_string, True) if not set(fields) >= set(['refdet', 'resultrans']): raise ResponseError() for key, value in fields.iteritems(): fields[key] = value[0] refdet = fields.get('refdet') if refdet is None: raise ValueError('refdet is missing') # if 'objet' in fields: # iso_now = fields['objet'][-20:] # else: # iso_now = isonow() transaction_id = fields['objet'][-20:] #'%s%s' % (iso_now, refdet) result = fields.get('resultrans') if result in ('P', 'V'): result = PAID bank_status = '' elif result == 'R': result = DENIED bank_status = 'refused' elif result == 'A': result = CANCELLED bank_status = 'canceled' else: bank_status = 'wrong return: %r' % result result = ERROR test = fields.get('saisie') == 'T' return PaymentResponse( result=result, bank_status=bank_status, signed=True, bank_data=fields, transaction_id=transaction_id, test=test)
def response(self, query_string, **kwargs): form = urlparse.parse_qs(query_string) if not set(form) >= set(['Data', 'Seal', 'InterfaceVersion']): raise ResponseError() self.logger.debug('received query string %r', form) data = self.decode_data(form['Data'][0]) seal = form['Seal'][0] self.logger.debug('parsed response %r seal %r', data, seal) signed = self.check_seal(data, seal) response_code = data['responseCode'] transaction_id = data.get('transactionReference') result = self.response_code_to_result.get(response_code, ERROR) merchant_id = data.get('merchantId') test = merchant_id == self.TEST_MERCHANT_ID return PaymentResponse(result=result, signed=signed, bank_data=data, order_id=transaction_id, transaction_id=data.get('authorisationId'), bank_status=self.RESPONSE_CODES.get( response_code, u'unknown code - ' + response_code), test=test)
def response(self, query_string, logger=LOGGER, **kwargs): form = parse_qs(query_string) if not 'transaction_id' in form: raise ResponseError() transaction_id = form.get('transaction_id', [''])[0] form[self.BANK_ID] = transaction_id signed = 'signed' in form if signed: content = 'signature ok' else: content = None signed = signed or self.consider_all_response_signed result = PAID if 'ok' in form else ERROR response = PaymentResponse(result=result, signed=signed, bank_data=form, return_content=content, order_id=transaction_id, transaction_id=transaction_id, bank_status=form.get('reason'), test=True) return response