Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Taxcloud doesn't really support getTaxCodes yet * Ok, calm down * Taxcloud doesn't really provide taxCodes yet * Log Tax code errors to Logs collection rather than throwing a Meteor.Error * Add missing import * Use name from namespaced provides rather than name * Pulling tax codes from TaxCloud * Configure saving taxcloud taxes to db and displaying them
- Loading branch information
1 parent
a5c6008
commit 1f882b1
Showing
10 changed files
with
81 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
import "./publications"; | ||
import "./methods"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Meteor } from "meteor/meteor"; | ||
import { Logs } from "/lib/collections"; | ||
import { Reaction } from "/server/api"; | ||
|
||
export function writeToLog(logType, logLevel, logData, source = "client") { | ||
check(logType, String); | ||
check(logLevel, String); | ||
check(logData, Object); | ||
|
||
const logEntry = { | ||
logType: logType, | ||
shopId: Reaction.getShopId(), | ||
data: logData, | ||
level: logLevel, | ||
source: source | ||
}; | ||
Logs.insert(logEntry); | ||
} | ||
|
||
function logError(logType, logData) { | ||
check(logType, String); | ||
check(logData, Object); | ||
if (Roles.userIsInRole(this.userId, ["admin", "owner"])) { | ||
writeToLog(logType, "error", logData); | ||
} | ||
} | ||
|
||
function logWarning(logType, logData) { | ||
check(logType, String); | ||
check(logData, Object); | ||
if (Roles.userIsInRole(this.userId, ["admin", "owner"])) { | ||
writeToLog(logType, "warn", logData); | ||
} | ||
} | ||
|
||
Meteor.methods({ | ||
"logging/logError": logError, | ||
"logging/logWarning": logWarning | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
imports/plugins/included/taxes-taxcloud/server/methods/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import "./methods"; |
55 changes: 14 additions & 41 deletions
55
imports/plugins/included/taxes-taxcloud/server/methods/methods.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,31 @@ | ||
import { Meteor } from "meteor/meteor"; | ||
import { Match, check } from "meteor/check"; | ||
import { HTTP } from "meteor/http"; | ||
import { EJSON } from "meteor/ejson"; | ||
import { Logger } from "/server/api"; | ||
import Reaction from "../../core/taxes/server/api"; | ||
|
||
|
||
Meteor.methods({ | ||
/** | ||
* taxes/fetchTIC | ||
* Tax Code fixture data. | ||
* We're using https://taxcloud.net | ||
* just to get an intial import data set | ||
* this service doesn't require taxcloud id | ||
* but other services need authorization | ||
* use TAXCODE_SRC to override source url | ||
* @param {String} url alternate url to fetch TaxCodes from | ||
* @return {undefined} | ||
* @returns {Array} An array of Tax code objects | ||
*/ | ||
"taxcloud/getTaxCodes": function (url) { | ||
check(url, Match.Optional(String)); | ||
// check(url, Match.Optional(SimpleSchema.RegEx.Url)); | ||
|
||
// pretty info | ||
if (url) { | ||
Logger.debug("Fetching TaxCodes from source: ", url); | ||
} | ||
// allow for custom taxCodes from alternate sources | ||
const TAXCODE_SRC = url || "https://taxcloud.net/tic/?format=json"; | ||
"taxcloud/getTaxCodes": function () { | ||
const taxCodeArray = []; | ||
const TAXCODE_SRC = "https://taxcloud.net/tic/?format=json"; | ||
const taxCodes = HTTP.get(TAXCODE_SRC); | ||
|
||
if (taxCodes.data && Reaction.Import.taxCode) { | ||
for (json of taxCodes.data.tic_list) { | ||
// transform children and flatten | ||
// first level of tax children | ||
// TODO: is there a need to go further | ||
if (json.tic.children) { | ||
const children = json.tic.children; | ||
delete json.tic.children; // remove child levels for now | ||
// process chilren | ||
for (json of children) { | ||
delete json.tic.children; // remove child levels for now | ||
const taxCode = EJSON.stringify([json.tic]); | ||
Reaction.Import.process(taxCode, ["id", "label"], Reaction.Import.taxCode); | ||
} | ||
if (taxCodes) { | ||
taxCodes.data.tic_list.forEach(function (code) { | ||
if (code.tic.children) { | ||
code.tic.children.forEach(function (child) { | ||
taxCodeArray.push(child.tic); | ||
}); | ||
} | ||
// parent code process | ||
const taxCode = EJSON.stringify([json.tic]); | ||
Reaction.Import.process(taxCode, ["id", "label"], Reaction.Import.taxCode); | ||
} | ||
// commit tax records | ||
Reaction.Import.flush(); | ||
} else { | ||
throw new Meteor.error("unable to load taxcodes."); | ||
taxCodeArray.push(code.tic); | ||
}); | ||
return taxCodeArray; | ||
} | ||
throw new Meteor.Error("Error getting tax codes"); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters