Meteor-Dwolla Bulk create customer accounts - meteor

Requirement here is I wants to add number of customers on dwolla in one shot. By running dwolla create customer in loop. But things is some customer addition is failing with error,
Error: {“code”:“ServerError”,“message”:“A server error occurred. Error ID: 6188070b-8a1b-4d94-90a5-eb1333d3cd9e.”}
Code:
const client = new dwolla.Client({
key : dwollaCredentials.appKey,
secret : dwollaCredentials.appSecret,
environment : 'sandbox' // optional - defaults to production
});
client.auth.client().then(Meteor.bindEnvironment(function(appToken) {
var spaceProviders = getListofSpaceProvidersWithNoDwollaAcc();
console.log(spaceProviders.length);
for (var i = 0 ; i<spaceProviders.length ; i++) {
var spaceProviderId = spaceProviders[i].id;
var routingNumberUser = spaceProviders[i].routingNo;
var accountNumberUser = spaceProviders[i].accountNumber;
var bankName = spaceProviders[i].firstName+' '+spaceProviders[i].lastName+' Bank';
if (spaceProviders[i]) {
var requestBody = {
firstName : spaceProviders[i].firstName,
lastName : spaceProviders[i].lastName,
email : spaceProviders[i].email
};
console.log('requestBody: ',requestBody);
appToken
.post('customers', requestBody)
.then((res)=> {
var dwollaLocation = res.headers.get('location');
return Promise.resolve(dwollaLocation);
})
.then(Meteor.bindEnvironment((dloc) => {
console.log("dloc"+i+' '+dloc);
return Promise.resolve(dloc);
}))
.catch(error => console.log("Handled Exceptions user",i+' - '+error));
}
}//i
})
);

Somehow bulk customers account creation is failing, may be this is creating continues calls at dwolla and it is unable to handle this much big number, may be one request starts processing and another one is reaching like wise, so finally I am settling for individual "ADD" button for each customer and calling create dwolla customer api on click event.

Related

Issues DocumentMerge in Google AppMaker

As I would like to create documents by merging the entries in a list into a Google Docs template. I have therefore integrated the DocumentMerge method from my previous question into a printButton in a list widget.
Clicking on the printButton should produce a document that merges the contents of the current row into the document template. But when I click on the printButton the method fails due to a circular reference. How can I fix that? The print method goes like this ...
function printReview(widget) {
var review = app.models.Review.getRecord(widget.datasource.item._key);
var templateId = 'templateId';
var filename = 'Review for ...' + new Date();
var copyFile = DriveApp.getFileById(templateId).makeCopy(filename);
var copyDoc = DocumentApp.openById(copyFile.getId());
var copyBody = copyDoc.getBody();
var fields = app.metadata.models.Review.fields;
for (var i in fields) {
var text = '$$' + fields[i].name + '$$';
var data = review[fields[i].name];
copyBody.replaceText(text, data);
}
copyDoc.saveAndClose();
}
As Morfinismo noticed you are getting the error because you are trying to pass complex object from client to server and serializer fails to handle it. In order to fix that you need to adjust your code:
// onClick button's event handler (client script)
function onPrintClick(button) {
var reviewKey = button.datasource.item._key;
google.script.run
.withSuccessHandler(function() { /* TODO */ })
.withFailureHandler(function() { /* TODO */ })
.printReview(reviewKey);
}
// server script
function printReview(reviewKey) {
var review = app.models.Review.getRecord(reviewKey);
...
}

Getting "The service method is not found error" in Bing Maps

We are using geocoding service to get geocodeAddress (latitude/longitude) but we are getting the "The service method is not found" error. Below are my code.
public static double[] GeocodeAddress(string address, string virtualearthKey)
{
net.virtualearth.dev.GeocodeRequest geocodeRequest = new net.virtualearth.dev.GeocodeRequest
{
// Set the credentials using a valid Bing Maps key
Credentials = new net.virtualearth.dev.Credentials { ApplicationId = virtualearthKey },
// Set the full address query
Query = address
};
// Set the options to only return high confidence results
net.virtualearth.dev.ConfidenceFilter[] filters = new net.virtualearth.dev.ConfidenceFilter[1];
filters[0] = new net.virtualearth.dev.ConfidenceFilter
{
MinimumConfidence = net.virtualearth.dev.Confidence.High
};
// Add the filters to the options
net.virtualearth.dev.GeocodeOptions geocodeOptions = new net.virtualearth.dev.GeocodeOptions { Filters = filters };
geocodeRequest.Options = geocodeOptions;
// Make the geocode request
net.virtualearth.dev.GeocodeService geocodeService = new net.virtualearth.dev.GeocodeService();
net.virtualearth.dev.GeocodeResponse geocodeResponse = geocodeService.Geocode(geocodeRequest);
if (geocodeResponse.Results.Length > 0)
{
return new[] { geocodeResponse.Results[0].Locations[0].Latitude, geocodeResponse.Results[0].Locations[0].Longitude };
}
return new double[] { };
} // GeocodeAddress
Key is used for URL for bing map geocode service in we.config
<add key="net.virtualearth.dev.GeocodeService" value="http://dev.virtualearth.net/webservices/v1/geocodeservice/GeocodeService.svc" />
Looks like you are trying to use the old Virtual Earth SOAP Services which were deprecated and shut down last year. These were replaced by the Bing Maps REST services 7 or 8 years ago. Since you are working in .NET, take a look at the Bing Maps .NET REST Toolkit. It makes it easy to use the REST services in .NET. There is a NuGet package available as well. You can find details here: https://github.com/Microsoft/BingMapsRESTToolkit
Once you have the NuGet package added to your project, you can geocode like this:
//Create a request.
var request = new GeocodeRequest()
{
Query = "New York, NY",
IncludeIso2 = true,
IncludeNeighborhood = true,
MaxResults = 25,
BingMapsKey = "YOUR_BING_MAPS_KEY"
};
//Execute the request.
var response = await request.Execute();
if(response != null &&
response.ResourceSets != null &&
response.ResourceSets.Length > 0 &&
response.ResourceSets[0].Resources != null &&
response.ResourceSets[0].Resources.Length > 0)
{
var result = response.ResourceSets[0].Resources[0] as BingMapsRESTToolkit.Location;
//Do something with the result.
}

Saving data to child in Firebase

I have a small application where users can upvote or downvote players based on their recent performance in various sports.
When the upvote button is currently clicked, the UID of the voter (logged in via Google) is supposed to get pushed into the database of the corresponding player who was voted on. Like this:
However, instead, it's currently doing this:
Here is the code which is doing the Firebase work. I believe it is one of these lines that I have wrong.
this.database.child(playerId).transaction
or
ref = firebase.database().ref('players/voters');
The code:
this.database = firebase.database().ref().child('players');
upvotePlayer(playerId) {
this.state.user ?
this.database.child(playerId).transaction(function (player) {
if (player) {
console.log("UID: " + uid)
var ref = firebase.database().ref('players/voters');
ref.child(uid).set(1);
}
return player;
})
:
console.log("Must be logged in to vote.")
}
you're storing the votes in this path players/voters while it should be in this path players/$playerId/voters
checkout this
this.database = firebase.database().ref().child('players');
upvotePlayer(playerId) {
this.state.user ?
this.database.child(playerId).transaction(function (player) {
if (player) {
console.log("UID: " + uid)
var ref = firebase.database().ref('players/' + playerId + '/voters');
ref.child(uid).set(1);
}
return player;
})
:
console.log("Must be logged in to vote.")
}
transaction method have transactionUpdate function as argument which should return the new value and you didn't return any , also I think better solution is not use transaction
Edit : solution without transaction
upvotePlayer(playerId)
{
if(this.state.user)
{
let ref = firebase.database().ref('players/' + playerId + '/voters');
ref.child(uid).set(1);
}
else
{
console.log("Must be logged in to vote.")
}
}
The problem is because of this:
var ref = firebase.database().ref('players/voters');
it is adding the voters under the players node and not under the push id node.
So you have to retrieve the pushid from the database and then do this:
var ref=firebase.database().ref().child('players').child(playerId).child('voters');
so the voters will become one of the pushid child.
For Future Viewers:
It is better to use transactions since:
Using a transaction prevents upvote counts from being incorrect if multiple users upvote the same post at the same time or the client had stale data
Actually you are pushing the value to payers node with player id. you have push the data to child node of players id voters. Try this code:-
this.database = firebase.database().ref().child('players');
upvotePlayer(playerId) {
this.state.user ?
this.database.child(playerId).transaction(function (player) {
if (player) {
console.log("UID: " + uid)
player.ref.child(voters).push(uid);
}
return player;
})
console.log("Must be logged in to vote.")
}
Problem is your are actually taking the reference of players node and creating new node at same level of playerid named voters. Below line just create a new node voters at same level to playerid.
var ref = firebase.database().ref('players/voters');
ref.child(uid).set(1);
as you can see there is no node named voters in players root node. But you are setting the value so it is been created with new data using set() function

How to know if client is in sync with server in Meteor?

I am trying to implement a feature where I want the user to see if all requests to the server have been handled, i.e. that the client is in sync with the server so that the user can be confident that all his changes are saved.
My idea was to override Meteor.call and keep a counter for each call and then when a reply/error is returned I decrease the counter. I will then on the client show a message saying "Synced" if the counter is zero otherwise I will show "Unsynced".
Basically my question is if there is any "built-in" feature in Meteor which already handles this, keeping track of outgoing Meteor calls, or if I should proceed as I have started?
This is what my code looks at this moment:
var originalMeteorCall = Meteor.call;
var counter = 0;
Meteor.call = function() {
if (this.isClient) {
if (arguments && arguments.length > 1) {
counter++;
var returnFunc = arguments[arguments.length - 1];
var newReturnFunc = function (err, result) {
counter--;
return returnFunc(err, result);
}
arguments[arguments.length - 1] = newReturnFunc;
}
}
var result = originalMeteorCall.apply(this, arguments);
return result;
}

New Relic not logging custom parameters on transactions

I have a ASP.NET app that I'm trying to log custom parameters from to NewRelic. The code for logging looks like this:
this.searchResults = performanceMonitor.RecordQuery(() => searchManager.DoQuery(this.searchRequest));
The performanceMonitor is just an object that does this:
public TSearchResult RecordQuery<TSearchResult>(Func<TSearchResult> query) where TSearchResult : SearchResult
{
var stopwatch = Stopwatch.StartNew();
var result = query();
stopwatch.Stop();
var externalTime = stopwatch.ElapsedMilliseconds;
var internalTime = ToMilliseconds(result.ExecutionTicks);
NewRelicHelper.AddAttributeToTransaction("QueryExternalTime", externalTime);
NewRelicHelper.AddAttributeToTransaction("QueryInternalTime", internalTime);
return result;
}
All the line with NewRelicHelper does is call NewRelic.Api.Agent.NewRelic.AddCustomParameter with "QueryExternalTime" and externalTime.
Yet after executing this code on machines with NewRelic agents, when I run a NewRelic query, I cannot see either QueryExternalTime or QueryInternalTime with their respective values on any transactions.

Resources