Unable to fulfilling Stripe Connect representative requirement - javascript

im trying to create a company account via Stripe Connect. The problem is that whatever i do i always receive that there is missing representative. I'm attaching my JS code below.
Thanks in advance for the help people !
currently_due: [
"representative.address.city",
"representative.address.line1",
"representative.address.postal_code",
"representative.dob.day",
"representative.dob.month",
"representative.dob.year",
"representative.email",
"representative.first_name",
"representative.last_name",
"representative.phone",
"representative.relationship.executive",
"representative.relationship.title"
],
const account = await stripe.accounts.create({
country: payload.country,
type: 'custom',
capabilities: {
card_payments: {
requested: payload.capabilities.card_payments
},
transfers: {
requested: payload.capabilities.transfers
},
},
business_profile: payload.business_profile,
business_type: payload.business_type,
tos_acceptance: {
date: Math.round(+(new Date()) / 1000),
ip: ip
},
company: {
...payload.company,
directors_provided: true,
executives_provided: true,
owners_provided: true,
},
external_account: {
object: 'bank_account',
country: 'BG',
currency: 'BGN',
account_number: 'BG80BNBG96611020345678'
}
});
const person = await stripe.accounts.createPerson(
account.id,
{
...payload.representative
}
);
let updatedAccount = await stripe.accounts.retrieve(
account.id,
);
The person representative payload looks like this. All fields are filled according to documentation and the creation passes
representative: {
first_name: document.getElementById('representative.first_name').value,
last_name: document.getElementById('representative.last_name').value,
email: document.getElementById('representative.email').value,
phone: document.getElementById('representative.phone').value,
ssn_last_4: document.getElementById('representative.ssn_last_4').value,
dob: {
month: document.getElementById('representative.dob.month').value,
day: document.getElementById('representative.dob.day').value,
year: document.getElementById('representative.dob.year').value,
},
address: {
line1: document.getElementById('representative.address.line1').value,
postal_code: document.getElementById('representative.address.postal_code').value,
city: document.getElementById('representative.address.city').value,
state: document.getElementById('representative.address.state').value,
},
relationship: {
title: document.getElementById('representative.relationship.title').value,
executive: document.getElementById('representative.relationship.executive').value === 'true',
}
}

Related

How to search nested property in mongoose

hi I have mongodb document like below:
{
_id: ObjectId("63df40c651f1358f2b60f24a"),
origin: {
country: 'Usa',
state: 'Washington',
city: 'Washington',
type: 'Point',
coordinates: [ 12.555, 18.645 ]
},
destination: {
country: 'Usa',
state: 'Montana',
city: 'Yellowstone',
type: 'Point',
coordinates: [ 12.555, 20.645 ]
},
date: 'mon 2023-12-16',
seats: 4,
status: 'pending',
driver: {
firstName: 'sam',
lastName: 'johnson',
phoneNumber: '92823831736',
socialNumber: '1381222327',
driverId: '63d8f94202653dc3592a0aa4'
},
I use below url and code for finding location base on destination:
URL: "localhost:3000/api/v1/travel/?state=Montana&city=Yellowstone"
and my code is:
const Travel = require("../models/travel-model");
const getAllTravelsByDestination = async (req, res) => {
const { country, state, city } = req.query;
const queryObject = {};
if (country) {
queryObject.destination.country = country;
}
if (state) {
queryObject.destination.state= state;
}
if (city) {
queryObject.destination.city = city;
}
const travelList = await Travel.find({ destination:queryObject });
res.status(StatusCodes.OK).json({ status: "success", travelList });
};
I expect to get my document back but instead i get empty list as response:
{
"status": "success",
"travelList": []
}
please help me for this problam
You created a filter properly. But, instead of find({ destination: queryObject }), you should only do find(queryObject), since the queryObject already contains the destination property.
const travelList = await Travel.find(queryObject);
Check this line of your code:
const travelList = await Travel.find({ destination:queryObject });
You defined destination already in the queryObject. So you should just do
await Travel.find(queryObject);
Please note that queries are by default case-sensitive. So upper & lowercase matters.

How do i use Implicit relations for update in Prisma upsert

The following code should create a new id if id is not found, if id is found it should update.
for that i have used upsert function function.
in the model (prisma) i am using https://www.prisma.io/docs/guides/database/troubleshooting-orm/help-articles/working-with-many-to-many-relations my model has an Implicit relations.
how do i use update in Implicit relations
const data = await PRISMA.ref_types.upsert({
where: { id: id },
update: {
business_name: business_name,
business_logo: business_logo,
business_type: business_type,
timezone: timezone,
location_contact_details: { update: { contact: contact, email: email, } },
location_addresses: { update: { address: address, location_id: req.body.location_id, } },
languages: { create: { languages: languages } },
ref: headerData?.ref,
},
create: {
business_name: business_name,
business_logo: business_logo,
business_type: business_type,
timezone: timezone,
location_contact_details: { create: { contact: contact, email: email, } },
location_addresses: { create: { address: address, location_id: req.body.location_id, } },
languages: { create: { languages: languages } },
ref: headerData?.ref,
},
})

findoneandupdate mongodb for new field that not exist

so i try to udpdate new field that not exist on my mongodb models, i try to update it every time user login , but its not push any new fields on the mongodb, can someone tell me where did i do wrong here, here is mycode:
const userLog = await User.findOneAndUpdate(
{ NIK: req.body.NIK },
// { loginDate: { $exists: false } },
{ $push: { loginDate: toJSONLocal(date) } },
{ new: true }
);
console.log("====================================");
console.log(userLog);
console.log("====================================");
here is the response :
_id: new ObjectId("6368e40d1f58fd76efb27957"),
fullname: 'Ja lie',
password: '$2b$10$DEWgxY/hth/yYIVGOvZDt..RpxKCKm58NbrrDFQgITLB8.cHrHHvG',
NIK: 'MT220',
status: 'active',
department: 'Logistic',
position: 'Trainee',
Group_Shift: 'Non Shift',
role: 'admin',
createdAt: 1667818509,
updatedAt: 1669188767,
__v: 0
When you create your MongoDB model, you must create a model with the key loginDate

Push new Object inside a document array

I have this schema for my user
const userSchema = mongoose.Schema({
firstName: {
type: String,
},
notifications : [{
description: String,
status: {
type: String,
enum : ['read', 'unread'],
default: 'unread'
},
dateAdded:{
type: Date,
default: Date.now
}
}],
})
supposedly I want to find the user _id first then insert a new object inside the new notification array. and it should look like this
{
_id: ObjectId('123')
firstName: 'John Doe'
notifications:[
{
description: 'somedescription'
status: 'unread'
},
{
description: 'somedescription2'
status: 'unread'
}
]
}
How can I achieve this, assuming that the notification property is non existent in the user document first, i need to check if notification property is present else add the notification property and push the new object
User.updateOne(
{ _id: userId },
{ $push: { notifications: {description: 'new notifications'} } }
)
this code is not working for me
Use $addToSet operator to achieve that
User.updateOne(
{ _id: userId },
{ $addToSet: { notifications: {description: 'new notifications'} } }
)
If that doesn't work try to add the default value too, and then that must work
User.updateOne(
{ _id: userId },
{ $addToSet: { notifications: {description: 'new notifications',
'status': 'unread'} } }
)

What does this 'child' in my javascript array mean?

I keep getting these 'child' things in my Javascript collection after certain operations. The 'child' keyword is showing up in my terminal after logging the Javascript collection.
Whats strange is that I can't actually find good documentation anywhere online on what this means. Seems like it should be a basic concept.
When I do google it I just get a ton of results for 'child' in context of HTML and the DOM.
What does it mean in javascript? And how could I fix this collection to have these nested collections without the 'child' thing.
Gosh I wish I could speak about it with more sophistication :p
More Context on How This 'Bad' Collection is Generated
So I'm trying to populate JSON data from my Mongodb database and return it to the frontend. Essentially I have nested collections like so:
Institution
|
------------> memberOrganizations
|
---------------------> associatedVIPs
Where I'm originally grabbing Institutions I can populate collections one level down using built in populate functionality.
Doing like so:
Institution.find()
.populate('memberOrganizations')
.then(function (institutions) {
console.log("All institutions, memberOrganizations populated no problem.");
return res.json(institutions);
});
The problem is coming in when I try to go populate collections inside those member organizations, and replace existing memberOrganizations data with that.
Institution.find()
.populate('memberOrganizations')
.then(function (institutions) {
var populateOrganizationOrderManagers = _.map(institutions, function (institution) {
var masterInstitution = _.cloneDeep(institution);
return new Promise(function (resolve, reject) {
var ids = _.map(institution.memberOrganizations, 'id');
Organization.find(ids).populate('associatedVIPs').then(function (orgs) {
masterInstitution.memberOrganizations = orgs;
resolve(masterInstitution);
});
});
});
return Promise.all(populateOrganizationOrderManagers)
.then(function (institutionsWithOrderManagers) {
return res.json(institutionsWithOrderManagers);
});
})
Printouts of the JSON data using console.log to print to my terminal
(Simplified all data by a bit to make it easier to make a point)
What it looks like:
[ child {
memberOrganizations:
[ { associatedVIPs:
[ { firstName: 'Gregory',
lastName: 'Parker',
email: 'info#parker2018.com',
id: '5ab94183164475010026184b' } ],
institution: '5ab940b71644750100261845',
name: 'Greg Parker',
type: 'Student',
id: '5ab941401644750100261847' },
{ associatedVIPs:
[ { firstName: 'Irma',
lastName: 'Francisco',
email: 'irmaf#houstontransporter.com',
id: '5ae348da1ef63b245a74fe2d' } ],
institution: '5ab940b71644750100261845',
name: 'Transporter Inc',
type: 'Other',
id: '5ae3488d1ef63b2c8f74fe29' } ],
name: 'Corporate',
createdAt: 2018-03-26T18:49:27.955Z,
updatedAt: 2018-07-05T15:00:02.562Z,
id: '5ab940b71644750100261845' }
What I'd like it to look like:
{ memberOrganizations:
[ {
name: 'Tau Kappa Epsilon',
type: 'Greek - Fraternity',
institution: '5a3996d47bab3401001cc1bc',
id: '5a3ae7ebdfd69201001aa54d'
associatedVIPs:
[ { firstName: 'Irma',
lastName: 'Francisco',
email: 'irmaf#houstontransporter.com',
id: '5ae348da1ef63b245a74fe2d' },
{ firstName: 'Zach',
lastName: 'Cook',
email: 'zach#google.com',
id: '5ae348da1ef63b245a74f' } ]
},
{ name: 'Farmhouse',
type: 'Greek - Fraternity',
institution: '5a3996d47bab3401001cc1bc',
id: '5a4e71e806b97a01003bd313' } ],
name: 'Troy University',
createdAt: '2017-12-19T22:46:44.229Z',
updatedAt: '2018-07-05T15:18:03.182Z',
id: '5a3996d47bab3401001cc1bc' },
{ memberOrganizations:
[ { name: 'Alpha Epsilon Pi',
type: 'Greek - Fraternity',
institution: '5a4d534606b97a01003bd2f1',
id: '5a4f95c44ec7b6010025d2fb' },
{ name: 'Alpha Delta Chi',
type: 'Greek - Sorority',
institution: '5a4d534606b97a01003bd2f1',
id: '5a74a35e1981ef01001d0633' },
{ name: 'Phi Sigma Kappa',
type: 'Greek - Fraternity',
institution: '5a4d534606b97a01003bd2f1',
id: '5a7ba61821024e0100be67b7' } ],
name: 'University of Alabama',
createdAt: '2018-01-03T22:03:50.929Z',
updatedAt: '2018-07-05T15:18:03.182Z',
id: '5a4d534606b97a01003bd2f1' }

Categories

Resources