Facing Error with Stripe on Create session - javascript

I'm building an app with NODEJS and Express while I'm integrate with stripe but facing this type of error
Here is my code:
const session = await stripe.checkout.sessions.create({
payment_method_types: ['card'],
success_url: `${req.protocol}://${req.get('host')}/`,
cancel_url: `${req.protocol}://${req.get('host')}/tour/${tour.slug}`,
customer_email: req.user.email,
client_reference_id: req.params.tourId,
line_items: [
{
name: `${tour.name} Tour`,
description: tour.summary,
images: [`https://www.natours.dev/img/tours/${tour.imageCover}`],
amount: tour.price * 100,
currency: 'usd',
quantity: 1,
},
],
Error: You cannot use line_items.amount, line_items.currency, line_items.name, line_items.de line_items.imagesin this API version. Please useline_items.priceorline_items.price_data`.

Starting from v2022-08-01, the following parameters have been removed from create Checkout Session:
line_items[amount]
line_items[currency]
line_items[name]
line_items[description]
line_items[images]
You can use the price and price_data parameters instead.
Example
const checkout_session = stripe.checkout.sessions.create({
success_url: `${req.protocol}://${req.get('host')}/`,
cancel_url: `${req.protocol}://${req.get('host')}/tour/${tour.slug}`,
customer_email: req.user.email,
client_reference_id: req.params.tourId,
payment_method_types:["card"],
mode:"payment",
line_items:[
{
"price_data": {
"currency" : "usd",
"unit_amount" : tour.price * 100,
"product_data" : {
"name" : `${tour.name} Tour`,
"description" : tour.summary,
"images" : [`https://www.natours.dev/img/tours/${tour.imageCover}`],
}
},
"quantity": 1
}
]}
);

Related

How can I accept standalone blik payment using stripe

How can I accept payment via polish blik on stripe? According to the documentation, Blik payment should be a standalone payment option
const session = await stripe.checkout.sessions.create({
payment_method_types: ['card'],
payment_method_types: ['card', 'blik'],
line_items: [{
price_data: {
currency: 'usd',
// To accept `blik`, all line items must have currency: pln
currency: 'pln',
product_data: {
name: 'T-shirt',
},
unit_amount: 2000,
},
quantity: 1,
}],
mode: 'payment',
success_url: 'https://example.com/success',
cancel_url: 'https://example.com/cancel',
});
when I enter blik in the payment_method_types array I get a typescript error
Type '"blik"' is not assignable to type 'PaymentMethodType'.ts(2322)
Despite that, I tried to create a session as there was an option that silencing TS on one line would do the trick and the checkout session was created, but nothing has happened, no redirect whatsoever, and in the dashboard, I have a session with the status Incomplete and payment method none.
Thanks

Unable to fulfilling Stripe Connect representative requirement

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',
}
}

Is it possible to have user input come from a form input in this Stripe example?

Is it possible to modify this Stripe example so as to have the user input an amount in a text box. I am able to alter the amount on the server.js file and i know how to get the form working in the checkout.html but I don't know how to send the value forward when the button is clicked to that server.js can get it.
https://stripe.com/docs/checkout/integration-builder
server.js
app.post('/create-checkout-session', async (req, res) => {
const session = await stripe.checkout.sessions.create({
payment_method_types: ['card'],
line_items: [
{
price_data: {
currency: 'usd',
product_data: {
name: 'Stubborn Attachments',
images: ['https://i.imgur.com/EHyR2nP.png'],
},
unit_amount: 2000,
},
quantity: 1,
},
],
mode: 'payment',
success_url: `${YOUR_DOMAIN}/success.html`,
cancel_url: `${YOUR_DOMAIN}/cancel.html`,
});
checkout.html
You can, you just have to capture the amount in a form and then POST that data to your server before creating the Checkout Session.
For example:
app.post('/create-checkout-session', async (req, res) => {
const amount = parseInt(req.body.amount, 10) * 100;
const session = await stripe.checkout.sessions.create({
payment_method_types: ['card'],
line_items: [
{
price_data: {
currency: 'usd',
product_data: {
name: 'Stubborn Attachments',
images: ['https://i.imgur.com/EHyR2nP.png'],
},
unit_amount: amount,
},
quantity: 1,
},
],
mode: 'payment',
success_url: `${YOUR_DOMAIN}/success.html`,
cancel_url: `${YOUR_DOMAIN}/cancel.html`,
});
res.json(session.id);
});
Here's an example of how to do this in Glitch:
https://glitch.com/edit/#!/stripe-checkout-donate
End result looks like this:
https://stripe-checkout-donate.glitch.me/

Access to table user in sequelize

How can I get the information of 2 users when I request my friends table?
My table friends is formatted like this:
id X , UserId : 1 , idFriend : 3, ...
My table User is formatted like this:
id X , name , mail , ...
When I link model user in my query, I get only the information of UserID, but I don't get the information on idFriend
My request is
models.Friend.findAll({
where: {
$or: [{
idFriend: userFound.id
},
{
UserID: userFound.id
}],
status: "pending"
},
include: [
{ model: models.User },
]
})
How can I do that ?
1st Define association like this in your friend model :
Friend.belongsTo(User, { foreignKey : 'UserID', constraints: false});
Friend.belongsTo(User, { as: 'friend', foreignKey : 'idFriend' , constraints:false});
2nd thing is include model like this :
models.Friend.findAll({
where: {
$or: [{
idFriend: userFound.id
},
{
UserID: userFound.id
}],
status: "pending"
},
include: [
{
model: models.User ,
required : false,
where : { id : userFound.id }
},{
model: models.User ,
as : 'friend', // <--------- Magic is here
required : false,
where : { id : userFound.id }
}
]
})

paypal payment api doesn't work with property "payee"

I already took a look into the question that people keep saying this question is duplicated to, but I couldn't figure out how to deal with it with my code. I need an explanation. Thank you
I'm new to paypal APIs so I'm kind of confused right now. creating transaction only works when I don't specify payee property, but how would paypal know who to send the money when there's no payee specified?
Here's the code
$(function() {
paypal.Button.render({
env: 'sandbox', // Or 'sandbox'
client: {
sandbox: 'xxxxxx',
production: 'xxxxxx'
},
commit: false, // Show a 'Pay Now' button
payment: function(data, actions) {
return actions.payment.create({
payment: {
transactions: [
{
amount: { total: '5.00', currency: 'USD' },
description: "TEST",
payee: { email: "seller-inventory#gmail.com" }
}
]
}
});
},
onAuthorize: function(data, actions) {
return actions.payment.execute().then(function(payment) {
console.log("payment", payment)
});
}
}, '#paypal');
})
Error code:
In the transaction object you need to have the items list with the items you are trying to sell. The mail also needs to exist.
If you don't specify the mail paypal send the money to whom has generated the client id key.
Also the items sum and currenct needs to match with the amount sum and currency
Try this (change sandbox id and the payee email need to exist in paypal):
$(function() {
paypal.Button.render({
env: 'sandbox', // Or 'sandbox'
client: {
sandbox: 'yourclientid',
production: 'xxxxxx'
},
commit: false, // Show a 'Pay Now' button
payment: function(data, actions) {
return actions.payment.create({
payment: {
transactions: [
{
amount: { total: '5.00', currency: 'USD' },
payee: { email: "seller-inventory#gmail.com" },
item_list: {
items: [
{
name: "hat",
sku: "1",
price: "5.00",
currency: "USD",
quantity: "1",
description: "Brown hat."
}]}
}
]
}
});
},
onAuthorize: function(data, actions) {
return actions.payment.execute().then(function(payment) {
console.log("payment", payment)
});
}
}, '#paypal');
})

Categories

Resources