Skip to content

Commit

Permalink
Merge pull request #6 from starkbank/fix/error-warning
Browse files Browse the repository at this point in the history
Fix getBalance escope view
  • Loading branch information
luistarkbank authored Jun 28, 2024
2 parents 5fe5e0d + 5c2dba7 commit d1a738b
Show file tree
Hide file tree
Showing 16 changed files with 60 additions and 42 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
node_modules
src/.clasp.json
node_modules
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ Given a version number MAJOR.MINOR.PATCH, increment:

## [Unreleased]

## [0.6.5] - 2024-06-28
### Added
- idempotent session
### Fixed
- cardShop regex param
- error null alert
- getBalance dynamic request

## [0.6.4] - 2024-06-13
### Added
- new corporate card design
1 change: 1 addition & 0 deletions src/.clasp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"scriptId":"10XuhtMToOKv59YPboFbDYzYvBazsk2Odo1j9XAyZHZUXCg-HGeyF0Oex","rootDir":"/Users/luis.almeida/Documents/starkbank/google-sheets/src"}
2 changes: 1 addition & 1 deletion src/apiAuth.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function getUserInputCredential(email, workspace, password, environment) {
requestBody = {
expiration: 604800,
publicKey: publicKeyPem,
platform: "web"
platform: "spreadsheet"
}

var jsonString = JSON.stringify(requestBody)
Expand Down
2 changes: 1 addition & 1 deletion src/cartshop.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function cartShop() {
var displayName2 = removeDiacritics(sheet.getRange('B' + line.toString()).getValue().toString());
var displayName1 = removeDiacritics(sheet.getRange('C' + line.toString()).getValue().toString());
var holderName = removeDiacritics(sheet.getRange('C' + line.toString()).getValue().toString());
var shippingPhone = sheet.getRange('D' + line.toString()).getValue().toString();
var shippingPhone = removeDiacritics(sheet.getRange('D' + line.toString()).getValue().toString().replace(/\u202C/g, ''));
var shippingStreetLine1 = removeDiacritics(sheet.getRange('E' + line.toString()).getValue().toString());
var shippingStreetLine2 = removeDiacritics(sheet.getRange('F' + line.toString()).getValue().toString());
var shippingDistrict = removeDiacritics(sheet.getRange('G' + line.toString()).getValue().toString());
Expand Down
43 changes: 35 additions & 8 deletions src/sdkGetBalance.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,37 @@

function getBalance() {
function getBalance(getError=false) {
try{
let json = parseResponse(fetch("/balance", method = 'GET', null));
if (json[1] != 200) {
Browser.msgBox(json[0]["errors"][0]["message"])
throw new Error()
let [json, status] = parseResponse(fetch("/balance", method = 'GET', null));

if (status != 200 && getError) {
switch (status) {
case 500:
throw new Error(JSON.parse(json)["errors"]["message"]);
case 400:
let errors = Array.from(json["errors"]);
Logger.log(errors)
errors.forEach(error => {
if (error.code == "invalidCredentials") {
Browser.msgBox("Sessão expirada! \nFaça o login novamente");
return;
};
let errorMessage = error.message;
Browser.msgBox(errorMessage);
});
};
for(sheet of SpreadsheetApp.getActiveSpreadsheet().getSheets()) {
if(sheet.getSheetName().toLowerCase() != "credentials") {
sheet.getRange("A7").setValue(null);
}
}
return
}

if (status != 200 && !getError) {
return
}
jsonData = json[0]
let balance = parseInt(jsonData["balances"][0]["amount"]) / 100.0;

let balance = parseInt(json["balances"][0]["amount"]) / 100.0;
for(sheet of SpreadsheetApp.getActiveSpreadsheet().getSheets()) {
if(sheet.getSheetName().toLowerCase() != "credentials") {
sheet.getRange("A7").setValue("Saldo: R$ " + Number(balance).toLocaleString("PT"));
Expand All @@ -18,5 +42,8 @@ function getBalance() {
{
Browser.msgBox(e);
}

}

function viewBalance() {
getBalance(true)
}
10 changes: 0 additions & 10 deletions src/sdkSendOrder.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ function SendOrder(centerId) {
let payload = {requests: requests};
let responseApi = fetch("/payment-request", method = 'POST', payload, query);

if (parseResponse(responseApi)[1] != 200) {
Browser.msgBox(parseResponse(responseApi)[0]["errors"][0]["message"])
throw new Error()
}

let [json, status] = parseResponse(responseApi)
switch (status) {
case 500:
Expand Down Expand Up @@ -129,11 +124,6 @@ function getCenter(){
function checkLogin(){
let responseApi = fetch("/balance", method = 'GET', null, null);

if (parseResponse(responseApi)[1] != 200) {
Browser.msgBox(parseResponse(responseApi)[0]["errors"][0]["message"])
throw new Error()
}

let [json, status] = parseResponse(responseApi);
switch (status) {
case 500:
Expand Down
3 changes: 1 addition & 2 deletions src/sdkViewCharge.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ function ViewCharge(after, before, status) {
json = parseResponse(fetch("/boleto", method = 'GET', null, query));

if (json[1] != 200) {
Browser.msgBox(json[0]["errors"][0]["message"])
throw new Error()
throw new Error(json[0]["errors"][0]["message"])
}

json = json[0]
Expand Down
6 changes: 2 additions & 4 deletions src/sdkViewChargeEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ function viewChargeEvents(after, before, eventOption)
json = parseResponse(fetch("/boleto/log", method = 'GET', null, query));

if (json[1] != 200) {
Browser.msgBox(json[0]["errors"][0]["message"])
throw new Error()
throw new Error(json[0]["errors"][0]["message"])
}

elementsList = json[0]["logs"];
Expand Down Expand Up @@ -96,8 +95,7 @@ function getCreatedLogs(idsList, chargeIdLineAmountDict, sheet)
json = parseResponse(fetch("/boleto/log", method='GET', null, query));

if (json[1] != 200) {
Browser.msgBox(json[0]["errors"][0]["message"])
throw new Error()
throw new Error(json[0]["errors"][0]["message"])
}

elementsList = json[0]["logs"];
Expand Down
3 changes: 1 addition & 2 deletions src/sdkViewChargePayment.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ function ViewChargePayment(after, before, status = null) {
json = parseResponse(fetch("/boleto-payment", method = 'GET', null, query));

if (json[1] != 200) {
Browser.msgBox(json[0]["errors"][0]["message"])
throw new Error()
throw new Error(json[0]["errors"][0]["message"])
}

json = json[0]
Expand Down
3 changes: 1 addition & 2 deletions src/sdkViewCustomers.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ function fetchCustomers()
json = parseResponse(fetch("/boleto/customer", method = 'GET', null, query));

if (json[1] != 200) {
Browser.msgBox(json[0]["errors"][0]["message"])
throw new Error()
throw new Error(json[0]["errors"][0]["message"])
}

json = json[0]
Expand Down
3 changes: 1 addition & 2 deletions src/sdkViewInvoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ function ViewInvoice(after, before, status) {
json = parseResponse(fetch("/invoice", method = 'GET', null, query));

if (json[1] != 200) {
Browser.msgBox(json[0]["errors"][0]["message"])
throw new Error()
throw new Error(json[0]["errors"][0]["message"])
}
console.log(json)
json = json[0]
Expand Down
3 changes: 1 addition & 2 deletions src/sdkViewPaymentRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ function ViewPaymentRequest(after, before, status, centerId, type) {
json = parseResponse(fetch("/payment-request", method = 'GET', null, query));

if (json[1] != 200) {
Browser.msgBox(json[0]["errors"][0]["message"])
throw new Error()
throw new Error(json[0]["errors"][0]["message"])
}

json = json[0]
Expand Down
3 changes: 1 addition & 2 deletions src/sdkViewStatement.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ function ViewStatement(after, before) {
json = parseResponse(fetch("/transaction", method = 'GET', null, query));

if (json[1] != 200) {
Browser.msgBox(json[0]["errors"][0]["message"])
throw new Error()
throw new Error(json[0]["errors"][0]["message"])
}

json = json[0]
Expand Down
3 changes: 2 additions & 1 deletion src/utilsBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,13 @@ function formatHeader(sheet) {

function SetAllGreetings(){
user = new getDefaultUser();
getBalance();
for (sheet of SpreadsheetApp.getActiveSpreadsheet().getSheets()) {
if (sheet.getSheetName().toLowerCase() != "credentials") {
clearGreeting(sheet)
DisplayGreeting(user, sheet);
}
}
getBalance();
}


Expand Down
6 changes: 3 additions & 3 deletions src/utilsRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ function maskFetch(path, method='GET', payload=null, query=null, version="v2", e
let accessTime = Math.round((new Date()).getTime() / 1000).toString();
options['headers'] = {
'Access-Id': accessId,
'User-Agent': 'App-StarkBank-GSheets-v0.6.4b',
'User-Agent-Override': 'App-StarkBank-GSheets-v0.6.4b',
'User-Agent': 'App-StarkBank-GSheets-v0.6.5b',
'User-Agent-Override': 'App-StarkBank-GSheets-v0.6.5b',
'PlatFormId' : 'gsheets',
'PlatFormVersion' : '0.6.4',
'PlatFormVersion' : '0.6.5',
'Accept-Language': 'pt-BR',
'Content-Type': 'application/json',
'Access-Time': accessTime
Expand Down

0 comments on commit d1a738b

Please sign in to comment.