Skip to content

Commit

Permalink
Netsuite message parse (#382)
Browse files Browse the repository at this point in the history
* Netsuite message parsed

* Netsuite message parsed

* Netsuite message parsed

* Netsuite message parsed

* Netsuite message parsed

* Comments resolved

* Comments resolved

* Comments resolved

* Comments resolved

* Comments resolved

* Comments resolved

* Comments resolved
  • Loading branch information
ruuushhh authored May 5, 2023
1 parent 5853daa commit e36d728
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions apps/netsuite/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,18 @@ def __decode_project_or_customer_name(name):

@staticmethod
def get_message_and_code(raw_response):
response = eval(raw_response.text)
logger.info('Charge Card Error - %s', response)
code = response['error']['code']
message = json.loads(response['error']['message'])['message']

try:
response = eval(raw_response.text)
logger.info('Charge Card Error - %s', response)
code = response['error']['code']
message = json.loads(response['error']['message'])['message']
except Exception:
parsed_response = json.loads((eval(raw_response.text)).replace('"{', '{').replace('}"', '}').replace('\\', '').replace('"https://', "'https://").replace('.html"', ".html'"))
message = parsed_response['error']['message']['message']
code = parsed_response['error']['code']
return code, message



@staticmethod
def get_tax_code_name(item_id, tax_type, rate):
Expand Down Expand Up @@ -1300,8 +1306,10 @@ def post_credit_card_charge(self, credit_card_charge: CreditCardCharge,

elif configuration.change_accounting_period:
logger.info('Charge Card Error - %s', raw_response.text)

error_message = json.loads(eval(raw_response.text)['error']['message'])['message']
try:
error_message = json.loads((eval(raw_response.text)))['error']['message']['message']
except Exception:
error_message = json.loads((eval(raw_response.text)).replace('"{', '{').replace('}"', '}').replace('\\', '').replace('"https://', "'https://").replace('.html"', ".html'"))['error']['message']['message']
if error_message == 'The transaction date you specified is not within the date range of your accounting period.':
first_day_of_month = datetime.today().date().replace(day=1)
credit_card_charges_payload['tranDate'] = first_day_of_month.strftime('%m/%d/%Y')
Expand Down

0 comments on commit e36d728

Please sign in to comment.