Currently working on server side info for Stripe connect and I'm having issues figuring out the correct parameters for creating a stripe connect account. I'm stuck on tax_id (ein) at the moment. Can someone please give me the correct abbreviation for this any others I may be missing on Node.js.
For example when it came to the name of the business Stripes API just say "name". Yet I kept getting the error 'Received unknown parameters: name'. But after some help looking online I saw that the correct way was to write out 'business_name' even through this was no where in the Stripe API.
here is my code: Hope this helps guide some people in the right direction as well (:
app.post('/newConnectCompanyAcct', (req, res) => {
// Creating New Connect Account...
//User
var company = req.body.business_name
var ein = req.body.business_tax_id
var first = req.body.first_name
var last = req.body.last_name
var email = req.body.email
var phone = req.body.phone
var birthDay = req.body.birthDay
var birthMonth = req.body.birthMonth
var birthYear = req.body.birthYear
var ssn = req.body.personal_id_number
var time = req.body.Time
var ip = req.body.iP
//Acct Type
var type = req.body.type
//Address
var line1 = req.body.line1
var line2 = req.body.line2
var zipcode = req.body.postal_code
var city = req.body.city
var state = req.body.state
var lastFour = req.body.lastFour
console.log('the email ' + email);
console.log('the phone ' + phone);
stripe.accounts.create({
type: "custom",
country: 'US',
requested_capabilities: ['card_payments','transfers'],
product_description: "example description",
mcc: "7299",
business_name: company,
tax_id: ein,
legal_entity: {
address: {
line1: line1,
line2: line2,
postal_code: zipcode,
city: city,
state: state
},
// relationship: {
// representative: true,
// title: "Manager"
// },
dob: {
day: birthDay,
month: birthMonth,
year: birthYear
},
first_name: first,
last_name: last,
type: type,
personal_phone_number: phone,
personal_email: email,
ssn_last_4: lastFour,
personal_id_number: ssn,
personal_address: {
line1: line1,
line2: line2,
postal_code: zipcode,
city: city,
state: state
}
},
tos_acceptance: {
date: Math.floor(Date.now() / 1000),
ip: ip
}
}).then((accounts) => {
console.log(accounts)
// Send customerId -> Save this for later use
return res.status(200).send(accounts.id)
}).catch((error) => {
console.log('error while creating new account' + error)
return res.status(500).send(JSON.stringify({ success: false, error: error }))
});
});
Related
app.get("/user/:id", (request, res)=>{
async function getToDoUser(){
const todoData = await fetch('https://jsonplaceholder.typicode.com/todos');
this api contains 200 entries
const response = await todoData.json();
const kuch = request.params.id;
const todoUserData = await fetch(`https://jsonplaceholder.typicode.com/users/${kuch}`);
this api will only give one entry
const userResponse = await todoUserData.json();
let responseArray = [];
var todos = {};
var target = {};
for(let i = 0; i<response.length;i++){
todos = new todoModel({
userId: response[i]["userId"],
id: response[i]["id"],
title: response[i]["title"],
completed: response[i]["completed"]
})
I have added the entries from 1st api
responseArray.push({userId: response[i]["userId"],
id: response[i]["id"],
title: response[i]["title"],
completed: response[i]["completed"]
})
}
const todoUser = new todoUserModel({
userid: userResponse["userid"],
name: userResponse["name"],
username: userResponse["username"],
email: userResponse["email"],
address: {
street: userResponse['address["street"]'],
suite: userResponse['address["suite"]'],
city: userResponse['address["city"]'],
zipcode: userResponse['addresss["zipcode"]'],
geo: {
lat:userResponse['address[geo["lat"]]'],
lng: userResponse['address[geo["lng"]]']
}
},
phone: userResponse["phone"],
website: userResponse["website"],
company: {
name: userResponse['company["nam"]'],
catchPhrase: userResponse['company["catchPhrase"]'],
bs: userResponse['company["bs"]']
},
till here 2nd api gives data and from here i want to add data from 1st api where the user id should be equal
todo: {
userId: response['0']['userid'],
userid in todo should be equal to userid in todoUser
all entries from todo with userid same as userid in todouser api
id: response['0']['id']
}
})
_.extend(target, todoUser);
// here i have merged data from todouser to new json object named target
res.send(target);
// here sending response
}
getToDoUser();
})
I am trying to pass the ID of the newly created address as a reference to the Tennent _addressMailing. The addressInstance is supposed to return this ID witch I use in my sequential object creation. I suspect it has something to do with the async handling.
Any help will be appreciated.
const address = new Address({
fullname: data.fullname,
street1: data.street,
street2: data.appartment,
city: data.city,
state: data.state,
zipcode: data.zipcode
})
const addressInstance = await address.save( (err, address) => {return address._id} );
const tennent = new Tennent({
name: data.company,
subdomain: 'test',
_addressMailing: addressInstance
})
const tennentInstance = await tennent.save();
console.log(addressInstance)
Console log output:
undefined
Database object for tennent:
_id: 5d508d8ff6ea5455f07e106f
name:"Digi"
subdomain:"test"
__v:0
all you need to get the _id of the new address saved then check if saved then pass it in the new Tennet.
const address = new Address({
fullname: data.fullname,
street1: data.street,
street2: data.appartment,
city: data.city,
state: data.state,
zipcode: data.zipcode
})
//
const newAddress = await address.save();
if(!newAddress)
return res.status(400).send({error:" can't create a new address"});
console.log(newAddress);
const tennent = new Tennent({
name: data.company,
subdomain: 'test',
_addressMailing: newAddress._id
})
const tennentInstance = await tennent.save();
I am trying to send an email using suitescript2 i am trying to attach the the Letter template programaticaly. Is there any way attach my custom letter template?
function templatemerge() {
var myMergeResult = render.mergeEmail({
templateId: 12,
entity: {
type: 'customer',
id: 31921
},
recipient: {
type: 'customer',
id: 31921
},
supportCaseId: 'NULL',
transactionId: 'NULL',
customRecord: 'custrecordid'
});
}
templatemerge();
function sendEmailWithAttachement() {
var newId = context.newRecord;
var emailbody = 'attachment';
var senderId = -5;
var recipientEmail = 'red#imi.com';
email.send({
author: senderId,
recipients: recipientEmail,
subject: 'Item Fulfillments',
body: emailbody
});
}
sendEmailWithAttachement();
If, by letter template, you mean email template. Here is a basic idea (I pulled that part from a larger script file that I am using) of how to do it.
var emailTemp4=nlapiLoadRecord('emailtemplate',emailTempID4);
var emailSubj4=emailTemp4.getFieldValue('subject');
var emailBody4=emailTemp4.getFieldValue('content');
var renderer4=nlapiCreateTemplateRenderer();
renderer4.setTemplate(emailSubj4);
renderSubj4=renderer4.renderToString();
renderer4.setTemplate(emailBody4);
renderBody4=renderer4.renderToString();
nlapiSendEmail(-4,'RecipientEmail#domain.com',renderSubj4,renderBody4,null,null);
I am trying to configure stripe.accounts.create({}) for Stripe custom. My goal here is to create everything in one form so the user fulfills all of the information requirements for their stripe account to transact after the form is compete. When testing the current code using the credit card number Stripe recommended, I am getting the error that is displayed after the following code block. I am wondering if there is a tokenization process that I am missing that isn't referenced in the stripe create account docs. This is my current post method
var knex = require("../models/knex"),
express = require('express'),
middleware = require("../middleware/index"),
stripe = require("stripe")("sk_test_VALUEOFMYTESTKEY"),
router = express.Router({mergeParams:true});
router.post("/formuser",function(req,res){
console.log(req.user[0].user_id);
knex("users.user").select("*").where("user_id",req.user[0].user_id)
.then((user) => {
var today = new Date(Date.now()).toLocaleString();
var accountType = String(req.body.accountType).toLowerCase();
var checkIfCard = accountType=="card";
console.log(req.body.accountType,checkIfCard,String(req.body.cardNumber));
var ip = req.headers['x-forwarded-for'] ||
req.connection.remoteAddress ||
req.socket.remoteAddress ||
req.connection.socket.remoteAddress;
console.log(ip);
if(!checkIfCard){
stripe.accounts.create({
email: user.email,
country: "US",
type: "custom",
//Required fields for Custom via... https://stripe.com/docs/connect/required-verification-information
metadata: {
"external_account": {
"object": "bank_account",
"exp_month": req.body.cardExpirationMonth,
"exp_year": req.body.cardExpirationYear,// : null,
"number": req.body.bankNumber,// : null,
}, //external account info... https://stripe.com/docs/api#account_create_bank_account
"city": req.body.city,
"legal_entity.adress.line1": req.body.streetAddress,
"legal_entity.address.postal_code": req.body.zipCode,
"legal_entity.address.state": req.body.state,
"legal_entity.dob.day": req.body.birthDay,
"legal_entity.dob.month": req.body.birthMonth,
"legal_entity.dob.year": req.body.birthYear,
"legal_entity.first_name": req.body.firstName,
"legal_entity.last_name": req.body.lastName,
"legal_entity.ssn_last_4": req.body.ssn_last_4,
"tos_acceptance.date": today,
"tos_acceptance.ip": ip,
}
}).then((acct) => {
res.redirect("/");
})
.catch((e) => {
console.log(e);
});
} else {
stripe.accounts.create({
email: user.email,
country: "US",
type: "custom",
//Required fields for Custom via... https://stripe.com/docs/connect/required-verification-information
metadata: {
"external_account": {
"object": "card", //bank account or cc or dc...
"card": req.body.cardNumber.toString(),
"cvc" : req.body.cvc.toString(),
"currency" : "usd",// : null
}, //external account info... https://stripe.com/docs/api#account_create_bank_account
"city": req.body.city,
"legal_entity.adress.line1": req.body.streetAddress,
"legal_entity.address.postal_code": req.body.zipCode,
"legal_entity.address.state": req.body.state,
"legal_entity.dob.day": req.body.birthDay,
"legal_entity.dob.month": req.body.birthMonth,
"legal_entity.dob.year": req.body.birthYear,
"legal_entity.first_name": req.body.firstName,
"legal_entity.last_name": req.body.lastName,
"legal_entity.ssn_last_4": req.body.ssn_last_4,
"tos_acceptance.date": today,
"tos_acceptance.ip": ip,
}
}).then((acct) => {
res.redirect("/");
})
.catch((e) => {
console.log(e);
});
}});
});
When I enter in the credit card information that Stripe recommends to test, I get the following error
{ [Error: Invalid val: {"object"=>"card", "card"=>"4242 4242 4242 4242", "cvc"=>"111", "currency"=>"usd"} must be a string under 500 characters]
type: 'StripeInvalidRequestError',
stack: 'Error: Invalid val: {"object"=>"card", "card"=>"4242 4242 4242 4242", "cvc"=>"111", "currency"=>"usd"} must be a string under 500 character
when I expected a user to be created.
EDIT: I removed some of the knex database code in this post to shorten it's length as it is not relevant to the current error. The current error is specifically from Stripe's promise.
Your code is trying to pass bank account details in external_account but also passing card data at the same time. This is unlikely to be what you want.
On top of this, you should not be passing this information server-side at all as it's sensitive. Instead, you should be creating a token client-side. For card data, you would use Elements and for bank account data you would build your own form and tokenize with Stripe.js. Once this is done, you get a card token tok_123 or a bank account token btok_123 and can then use this server-side in the external_account parameter.
Then, you should also pass the data as nested hashes. This means that you would not pass "legal_entity.adress.line1" but instead legal_entity[address][line1]. Your code should instead look something like this:
stripe.accounts.create(
{
type: 'custom',
country: 'US',
legal_entity : {
first_name : 'john',
last_name : 'doe',
type : 'individual',
address: {
line1: 'line1',
city: 'city',
state: 'state',
postal_code: '90210',
country: 'US'
}
},
external_account: 'tok_visa_debit',
}).then((acct) => {
console.log('account: ', JSON.stringify(acct));
}).catch((e) => {
console.log(e);
});
i want to fetch the price from the database to store in order model,
here is my code
newOrder: function(req,res){
var data = req.body;
const orderNo = data.orderNo;
const user = data.user;
const business = data.business;
const inventory = data.inventory;
const price = Inventory.find({id: data.inventory}).exec(function(err,record){ return record.price});
const address = data.address;
const quantity = data.quantity;
const contactNumber = data.contactNumber;
Order.create({
orderNo: orderNo,
user: user,
business: business,
inventory: inventory,
price: price,
address: address,
quantity: quantity,
contactNumber: contactNumber
}).then(function(result){
res.ok(result);
});
},
i know it is not correct , but i don't know how to do that,
the inner query is not returning anything,
i want to store the resulted data in variable for further use.
please Help
Here you go:
newOrder: function(req,res){
var data = req.body;
const orderNo = data.orderNo;
const user = data.user;
const business = data.business;
const inventory = data.inventory;
const address = data.address;
const quantity = data.quantity;
const contactNumber = data.contactNumber;
Inventory.findOne({id: data.inventory})
.then(function(record) {
// Price is available here as record.price,
// do whatever you want with it
return Order.create({
orderNo: orderNo,
user: user,
business: business,
inventory: inventory,
price: record.price,
address: address,
quantity: quantity,
contactNumber: contactNumber
});
})
.then(function(createdOrder) {
res.ok(createdOrder);
})
.catch(function(err) {
console.log("Error ar newOrder:", err);
return res.serverError(err);
})
}
basically just fetch the inventory record first, and then you can use it in the Order query. I also swapped Inventory.find to .findOne() since it seemed like that's how you intended to use it.