I am getting this error:
Result: TypeError: Object [object Object] has no method '_each'
at request (stripe.js:58:11)
at post (stripe.js:117:12)
at Object.module.exports.Customers.create (stripe.js:239:16)
at main.js:13:22
This is my swift function call:
let userId = PFUser.currentUser()?.objectId
let userEmail = PFUser.currentUser()?.email
PFCloud.callFunctionInBackground("createCustomer", withParameters: ["email": userEmail!, "objectId": userId!])
This is my cloud code for that specific function:
var Stripe = require('stripe');
Stripe.initialize('sk_test_***************');
Parse.Cloud.define("createCustomer", function(request, response) {
Stripe.Customers.create({
email: request.params.email,
description: 'new Gyro user',
metadata: {
//name: request.params.name,
userId: request.params.objectId, // e.g PFUser object ID
createWithCard: false
}
}, {
success: function(httpResponse) {
response.success(customerId); // return customerId
},
error: function(httpResponse) {
console.log(httpResponse);
response.error("Cannot create a new customer.");
}
});
});
I'm not sure where and why I am getting this error. Any help would be appreciated.
Related
I am trying to create a contact using "create or update api" from here: https://developers.activecampaign.com/reference#create-or-update-contact-new
I tried calling the cURL command which gives a proper response but while doing it from axios it gives error.
API: https://deskera4783.api-us1.com/api/3/contact/sync
Method: POST
Code:
var axios = require("axios");
var data = ({
contact: {
email: "jondoe#example.com",
firstName: "John",
lastName: "Doe",
phone: "7223224241",
fieldValues: [
{ field: "1", value: "The Value for First Field" },
{ field: "6", value: "2008-01-20" },
],
},
});
var config = {
method: "post",
url: "https://deskera4783.api-us1.com/api/3/contact/sync",
headers: {
"Api-Token":
"XXX",
"Content-Type": "application/json",
Cookie:
"cmp800513081=0c7070adc5cdc923a8922c47e98dbe77; PHPSESSID=d3e534f9b1a3f61316cd2cf89b41f164; em_acp_globalauth_cookie=caea42ae-d440-4491-9c08-d920b3378638",
},
data,
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});
Also, in the network tab request params are not seen neither the response is received.
Console error is:
enter image description here
My code looks like this. Its a post action in Restivus.
'subs' is a mongoDB collection.
post: {
authRequired: false,
action: function () {
var tmp = subs.insert(this.bodyParams);
if(tmp){
return tmp;
}
return {
statusCode: 400,
body: {status: 'fail', message: 'Unable to CREATE subscriber!'}
};
}
}
When I send some JSON data in the body, for example:
{
_id: 1,
name: "John",
lastname: "Smith"
}
In the mongoDB a new document is created, but with just some random (default notation) string and without the data I sent. So I guess the data is not parsed right.
Does anyone know why this happens? Should I do some function to format the JSON before passing it to mongoDB from the body?
Try this ... insert {status: 'success', data: tmp};.
post: {
authRequired: false,
action: function () {
var tmp = subs.insert(this.bodyParams);
if(tmp){
return {status: 'success', data: tmp};
}
return {
statusCode: 400,
body: {status: 'fail', message: 'Unable to CREATE subscriber!'}
};
}
}
The problem was with sending requests from Postman (Google Chrome addon). When I used curl it worked!
So I am having an issue migrating away from Mailgun and start using Mandrill. I followed the Parse Purchase application tutorial and have a very similar code base. Here is what it currently is and successfully runs.
return Mailgun.sendEmail({
to: currentUser.get('email'),
from: hostEmail,
subject: 'Your ticket(s) purchase for ' + eventObject.get('title') + ' was successful!',
text: body
}).then(null, function(error) {
return Parse.Promise.error('Your purchase was successful, but we were not able to send you an email.');
});
So this runs successfully, no errors are thrown.
So heres the Mandrill equivalent,
return Mandrill.sendEmail({
message: {
text: body,
subject: 'Your ticket(s) purchase for ' + eventObject.get('title') + ' was successful!',
from_email: hostEmail,
from_name: appname,
to: [{
email: currentUser.get('email'),
name: currentUser.get('displayName')
}]
},
async: true
}).then(null, function(error) {
console.log('Sending email failed. Error: ' + error);
return Parse.Promise.error('Your purchase was successful, but we were not able to send you an email.');
});
Apparently, this is not working.
The error log shows:
Error: TypeError: Cannot read property 'success' of undefined
at Object.exports.sendEmail (mandrill.js:55:21)
at main.js:115:25
at e (Parse.js:2:6670)
at Parse.js:2:6119
at Array.forEach (native)
at Object.x.each.x.forEach [as _arrayEach] (Parse.js:1:661)
at c.extend.resolve (Parse.js:2:6070)
at Parse.js:2:6749
at e (Parse.js:2:6670)
at Parse.js:2:6119 (Code: 141, Version: 1.6.0)
So I think Mandrill successfully sends the email because its searching for the 'success' property, but the Promise is always failing and returns an error response back to the iOS app.
Any help will be appreciated!
Thanks again
Found the problem. Apparently you have to actually declare a promise variable and send it the success/failure callbacks.
The gist link I posted in the comments is what helped megist Link
Heres what I do now,
Parse.Cloud.define('purchase', function(request, response) {
...
...
...
var message = {
text: body,
subject: 'Your ticket(s) purchase for ' + eventObject.get('title') + ' was successful!',
from_email: hostEmail,
from_name: appname,
to: [{
email: currentUser.get('email'),
name: currentUser.get('displayName'),
}]
};
return sendMandrillEmailPromise(message).then(null, function(error) {
console.log('Sending email failed. Error: ' + error);
return Parse.Promise.error('Your purchase was successful, but we not able to send you an email');
...
...
...
});
var sendMandrillEmailPromise = function(message){
var promise = new Parse.Promise();
Mandrill.sendEmail({
message: message,
async: true,
},{
success: function(httpResponse) {
promise.resolve(httpResponse);
},
error: function(error) {
promise.error(error);
}
});
return promise;
}
Works as expected and I got an AWESOME email! Thanks guys for your input!
New to coding and never used Cloud Code before.
I need to send a confirmation email when someone submits their email in a form on my webpage with Parse Cloud Code but I can't get it to work. I'm using the Mandrill Cloud Module to send the emails.
My questions are -
a) Am I calling the Cloud Function correctly?
b) The only variable that changes is the persons email address. Am I passing that variable correctly?
Example code would really help.
Thanks
Here's my Cloud Code:
Parse.Cloud.define("introEmail", function(request, response) {
var Mandrill = require('mandrill');
Mandrill.initialize('*************');
mandrill.sendEmail({
message: {
text: "Hello!",
subject: "Thanks for Signing Up!",
from_email: "Test#Test.com",
from_name: "Chad",
to: [
{
email: request.params.Address,
name: ""
}
]
},
async: true
}, {
success: function(httpResponse) { response.success("Email sent!"); },
error: function(httpResponse) { response.error("Uh oh, something went wrong"); }
});
});
Here's my JS code:
$(".input-group-btn").click(function() {
console.log("Notify Me");
var Address = $(".form-control").val();
var Email = Parse.Object.extend("Email");
var email = new Email();
email.set("Address", Address);
console.log(Address);
email.save(null, {
success: function(email) {
console.log('New object created with objectId: ' + email.id);
Parse.Cloud.run(introEmail,Address)
},
error: function(email, error) {
alert('Could not accept email address: ' + error.message);
}
});
});
a) Call the Cloud function with Parse.Cloud.run(), however, you must pass name, data, options. These are 'introEmail' (the name of the cloud function), the variable which is {Address: $(".form-control").val()} and the success/error handlers.
b)See a
Parse.Cloud.define("introEmail", function(request, response) {
var mandrill = require("mandrill");
mandrill.initialize('*************');
mandrill.sendEmail({
message: {
text: "Hello!",
subject: "Thanks for Signing Up!",
from_email: "Test#Test.com",
from_name: "Test",
to: [
{
email: request.params.Address,
name: ""
}
]
},
async: true
}, {
success: function(httpResponse) { response.success("Email sent!"); },
error: function(httpResponse) { response.error("Uh oh, something went wrong"); }
});
});
Here's the JS for the client-side:
$(".input-group-btn").click(function() {
console.log("Notify Me");
var Address = $(".form-control").val();
var Email = Parse.Object.extend("Email");
var email = new Email();
email.set("Address", Address);
console.log(Address);
email.save(null, {
success: function(email) {
// Execute any logic that should take place after the object is saved.
console.log('New object created with objectId: ' + email.id);
// Invoke our cloud function, using the phone number in the text field
Parse.Cloud.run('introEmail', {
Address: $(".form-control").val()
}, {
// Success handler
success: function(message) {
alert('Success: ' + message);
},
// Error handler
error: function(message) {
alert('Error: ' + message);
}
});
}
});
});
i am new to the webservice and try to call a webservice from html page which give me following error "Hit error fn![object Object]" and cannot sending mail to the desired email address. kindly tell me that whats the error?
function test() {
var firstname=$('#txtName').val();
var lastname =$('#txtMessage').val();
var Email=$('#txtEmail').val();
$.ajax({ url: "http://localhost/ZeroDebt/WsZeroDebtApp.asmx/SendEmailToClient",
data: { _fromAddress: JSON.stringify(Email),_Subject:JSON.stringify("Zero Debt App Invitation Request"),_body:JSON.stringify(firstname +' '+lastname), clientName: JSON.stringify('Dr. Hanoi'), clientEmail: JSON.stringify('abc#xyz.net') },
dataType: "jsonp",
success: function(data) {
alert(data);
},
error: function(error) {
alert("Hit error fn!" + error);
}
});
}
May I suggest to rewrite as such? (Please test yourself)
var SENDMAIL_URL = "http://localhost/ZeroDebt/WsZeroDebtApp.asmx/SendEmailToClient"
function test() {
var firstname = $('#txtName').val(),
lastname = $('#txtMessage').val(),
email = $('#txtEmail').val();
var data = JSON.stringify({
_fromAddress: email,
_Subject: "Zero Debt App Invitation Request",
_body: firstname + ' ' + lastname,
_clientName: 'Dr. Hanoi',
clientEmail: 'abc#xyz.net'
});
function notify( args ) {
console.log( args );
}
function onSuccess( data ) {
notify( data );
}
function onError( error ) {
notify( "Hit error fn!" ); // Important to seperate string from Object
notify( error );
}
$.ajax({
url: SENDMAIL_URL,
data: data,
dataType: "jsonp",
success: onSuccess,
error: onError
});
}
Furthermore it would be maintainable to make your URL a constant string and keep urls together (easier configurable than scrolling through code).
At last, i found a solution. the only thing i need to do is to give email at client email parameter that would not be in string format. write abc#xyz.com instead of "abc#xyz.com".
the correct scenario is:
data: { _fromAddress: JSON.stringify(Email),_Subject:JSON.stringify("Zero Debt App Invitation Request"),_body:JSON.stringify(firstname +' '+lastname), clientName: JSON.stringify('Dr. Hanoi'), clientEmail: abc#xyz.net }