#juiceman

1 messages · Page 1 of 1 (latest)

tough raftBOT
untold tundra
#

Do you have the request ID from when you got that error? It sounds like you may be passing in the wrong kind of ID for that call, it may be expecting a token like tok_123

minor kiln
#

its not generating a log

untold tundra
#

Interesting. What is the code that you are running that you are getting this error from?

minor kiln
#

so let me give u the whole summary to get here

#

STEP 1:
I need to have the user save their bank information to deposit money into their account.

exports.createStripeBank = async (req, res, next) => {
console.log("createStripeBank() API HIT");
let customer = await getCustomer(req.userData)
if (customer == null) {
customer = await createCustomer(req.userData)
} else {
console.log('no customer created')
}
const account = await stripe.accounts.create({ type: 'express' });
createStripeBankAccount({ userId: req.userData.userId, stripeBankId: account.id })
const accountLink = await stripe.accountLinks.create({
account: account.id,
refresh_url: 'http://localhost:4200/settings',
return_url: 'http://localhost:4200/settings',
type: 'account_onboarding',
});
res.status(201).json({
url: accountLink.url
})
};
async function createStripeBankAccount(obj) {
// save the stripe info in a db
const stripeBank = new StripeBankAccount({
createdAt: Date.now(),
lastUpdate: Date.now(),
creator: obj.userId,
stripeBankId: obj.stripeBankId
});
stripeBank
.save()

untold tundra
#

Oh wait that screenshot does show that error

minor kiln
# untold tundra Oh wait that screenshot does show that error

STEP 2:
I need to have the user save their creditcard so that I can generate charges against it.

exports.createCardToken = async (req, res, next) => {
console.log("createCardToken() API HIT");
let customer = await getCustomer(req.userData)
if (customer == null) {
customer = await createCustomer(req.userData)
} else {
console.log('no customer created')
}

const session = await stripe.checkout.sessions.create({
payment_method_types: ['card'],
mode: 'setup',
customer: customer.id,
success_url: 'http://localhost:3000/api/stripe/saveCardToken/{CHECKOUT_SESSION_ID}__'+req.userData.userId,
cancel_url: 'https://example.com/cancel',
});

res.status(201).json({
url: session.url
})
};

exports.saveCardToken = async (req, res, next) => {
console.log('saveCardToken API')

const CHECKOUT_SESSION_ID = req.params.id.split('__')[0] ;
const session = await stripe.checkout.sessions.retrieve(
CHECKOUT_SESSION_ID, { expand: ['setup_intent'] }
);

const cardToken = new CardToken({
createdAt: Date.now(),
lastUpdate: Date.now(),
creator: req.params.id.split('')[1],
token: req.params.id.split('
')[0],
stripeUserId: session.customer
})

cardToken
.save()
.then(createdCardToken => {
console.log('CARD SAVED')
res.writeHead(301, {
Location: FRONTEND_URL+ 'settings'
}).end();
})
.catch(error => {
console.log('CARD NOT SAVED')

       res.status(500).json({
           message: "Creating a cardToken failed!"
       });
   });

}

#

STEP 3:

Once the customer has saved their banking information, i would like to generate a charge against them at some time later on.
This needs to be performed in a manner that does not require the customer to confirm the amount of the purchase (see diagram)

The following code should:
charge the buyer for the goods purchased
transfer the money to the companies account

// this first snip of code should be charging the buyer for the goods purchase. This should transfer money to the companies account
charge = await stripe.charges.create({
amount: amount*.20,
currency: "usd",
source: CHECKOUT_SESSION_ID, // this is the id that was generated when the buyer saved their credit card
description: Campaign id is${campaignId}. Campaign name is ${description}
});

// this second snip of code should be transferring money to the seller
const transfer = await stripe.transfers.create({
amount: amount*.80,
currency: "usd",
source_transaction: charge.id,
destination: sellerAccount.id,
});

untold tundra
#

So the Checkout Session ID can't be used to make payments

#

Checkout Sessions provide users a hosted page to input their details in to

#

After they finish you can use the PaymentMethod object that the Session creates to make payments

minor kiln
#

i dont understand sh*t of the docs to be honest

so once the user inputs their creditcard info, what data do i need to save, so that I can generate a charge against that card?

this is the session code that I think ur refering to:

const session = await stripe.checkout.sessions.retrieve(
CHECKOUT_SESSION_ID, { expand: ['setup_intent'] }
);

are you saying to save session.setup_intent, then charge against that?

untold tundra
#

Yeah I would recommend reading them more to get more of the concepts here. You should be saving the ID of the PaymentMethod that the setup intent creates, hence the second link. https://stripe.com/docs/api/setup_intents/object#setup_intent_object-payment_method

Setup intents are not things that can make payments, they help keep track of a user trying to save their payment method data. The PaymentMethod is what can actually make the payment here

#

Also is there a reason that you are trying to create a charge directly rather than using a payment intent to manage it?

minor kiln
#

i need u to be a bit more clear.

so from this code:

const session = await stripe.checkout.sessions.retrieve(
CHECKOUT_SESSION_ID, { expand: ['setup_intent'] }
);

save session.setup_intent.payment_method? and then create a charge agains that?

untold tundra
#

I believe so, yes

minor kiln
#

Error code is: StripeInvalidRequestError: You cannot create a charge with a PaymentMethod. Use the Payment Intents API instead.

versed galleon
#

Hi there 👋 taking over, as my colleague needs to step away

Give me a minute to get caught up.

#

Error code is: StripeInvalidRequestError: You cannot create a charge with a PaymentMethod. Use the Payment Intents API instead.
That error seems fairly self-explanatory. Do you have a question about it?

minor kiln
#

how do i fix it?

#

thats the session obj

#

i dont see anything about payment intents API

versed galleon
minor kiln
#

req_IduB3pjOJd75DD

#

let me show you my code and tell me if everything checks out. i feel like i been having the same issue for like a week here

#

nvm i already posted all my steps

#

is that the correct request id?

versed galleon
#

You posted an error for a request you made to create a Charge, which is entirely separate and unrelated to Stripe Checkout. The error is telling you exactly what is wrong.

minor kiln
#

ok let me summaries my code, the the goal and you can help me point out the issue

#

lets do section by section, there are only 3 sections

#

STEP 1:
I need to have the user save their bank information to deposit money into their account.
Does the following code save customers bank information (account.id) so that I can move funds from stripe to a bank?

exports.createStripeBank = async (req, res, next) => {
console.log("createStripeBank() API HIT");

const account = await stripe.accounts.create({ type: 'express' });

createStripeBankAccount({ userId: req.userData.userId, stripeBankId: account.id })

const accountLink = await stripe.accountLinks.create({
account: account.id,
refresh_url: 'http://localhost:4200/settings',
return_url: 'http://localhost:4200/settings',
type: 'account_onboarding',
});

res.status(201).json({
url: accountLink.url
})

};

#

?

#

STEP 2:
I need to have the user save their creditcard so that I can generate charges against it.
Does the following code save their creditcard (session.setup_intent.payment_method)so that I can generate charges against it?

exports.createCardToken = async (req, res, next) => {
console.log("createCardToken() API HIT");
let customer = await getCustomer(req.userData)
if (customer == null) {
customer = await createCustomer(req.userData)
} else {
console.log('no customer created')
}

const session = await stripe.checkout.sessions.create({
payment_method_types: ['card'],
mode: 'setup',
customer: customer.id,
success_url: 'http://localhost:3000/api/stripe/saveCardToken/{CHECKOUT_SESSION_ID}__'+req.userData.userId,
cancel_url: 'https://example.com/cancel',
});

res.status(201).json({
url: session.url
})
};

exports.saveCardToken = async (req, res, next) => {
console.log('saveCardToken API')
// console.log('params',req.params.id)

const CHECKOUT_SESSION_ID = req.params.id.split('__')[0] ;
const session = await stripe.checkout.sessions.retrieve(
CHECKOUT_SESSION_ID, { expand: ['setup_intent'] }
);

const cardToken = new CardToken({
createdAt: Date.now(),
lastUpdate: Date.now(),
creator: req.params.id.split('__')[1],
token: session.setup_intent.payment_method, // this is the id used to generate a charge against
stripeUserId: session.customer
})
cardToken
.save()
}

#

STEP 3 : Generate a charge against buyer, company takes 20%, goods seller gets 80%

Once the customer has saved their banking information, I would like to generate a charge against them at some time later on.
This needs to be performed in a manner that does not require the customer to confirm the amount of the purchase (see diagram)

The following code should:
charge the buyer for the goods purchased
transfer the money to the companies account
Transfer money to the seller

// this first snip of code should be charging the buyer for the goods purchase. This should transfer money to the companies account
charge = await stripe.charges.create({
amount: amount,
currency: "usd",
source: session.setup_intent.payment_method, // this is the id for the buyer.
description: Campaign id is${campaignId}. Campaign name is ${description}
});

// this second snip of code should be transferring money to the seller
const transfer = await stripe.transfers.create({
amount: amount*.80,
currency: "usd",
source_transaction: charge.id,
destination: sellerAccount.id,
});

#

i explicitly wrote as much as i could, let me know if it makes sense

versed galleon
#

You really need to be reading about how these different APIs interact. You have a bunch of different unrelated methods tangled together.

Regarding the steps above:
You should not be creating Card Tokens. You should be creating Payment Methods instead. So Step 2 needs Payment Methods in order for Stripe Checkout to work, but you're trying to give it a Card Token instead.

minor kiln
#

i was told to do that this morning

#

i literally added that whole thing

#

wtf

#

i liteally asked with code, if that was what i had to do and i was told yes

#

let me look into this payment method

versed galleon
#

My assumption is that, because you jump from one thing to another in rapid succession, that you presented problem X that we helped solve, but really you should have presented problem Y.

I was the one that helped you create Charges with Card Tokens yesterday and I literally said "you should use Payment Methods instead", so please be patient with us. We can only help you with what you ask us to help you with.

minor kiln
#

so u want me to create a payment method using this:

const paymentMethod = await stripe.paymentMethods.create({
type: 'card',
card: {
number: '4242424242424242',
exp_month: 8,
exp_year: 2023,
cvc: '314',
},
});

versed galleon
minor kiln
#

please

#

no more guides

#

i have tried to read them over the past week and have gotten nowhere

#

i just need the code snip

#

if thats not it, then can you give another hint

#

i was suppse to finish this project today

versed galleon
#

We cannot code your integration for you. We also do not have the bandwidth to cover everything our guides already cover. Please familiarize yourself with the docs and the APIs you are using before posting more questions here

minor kiln
#

i have tried for like a week

#

what part of the APIs are you refering too

#

can you please be more specifc with what parts you want me to go over

#

i am not asking to code the integration

#

i provided an example of what i though you were refering to and its not correct, please provide me the section of the doc

versed galleon
minor kiln
#

please

#

i am begging u

#

idk which method works best to do what i want

#

thats why i am telling what i want to do

#

as you said, the stripe checkout creates a payment method for me

#

so what am i doing wrong?

#

i want to use the stripe checkout

#

what do i need to do next? do i still need to change my step 2?

versed galleon
minor kiln
#

noo man

#

that does not work

#

please read over my goal

#

and the diagram

#

I need to save the users financial information to generate a charge against it a later time

#

the computer does the charge

#

please look at the diagram

#

there is no checkout

#

please tell me if you understand

versed galleon
#

I've looked at it. It's not helpful to me. I'm just taking you for your word when you say you want to use Checkout

minor kiln
#

please.

could you provide me with the code snip that allows me to save a users financial information so that I can generate a charge.
when there is a charge generate, the user does not need to confirm or do a checkout page, the charge should go straight through

#

If the code below does not do that, then please provide code snip.

exports.createCardToken = async (req, res, next) => {
console.log("createCardToken() API HIT");
let customer = await getCustomer(req.userData)
if (customer == null) {
customer = await createCustomer(req.userData)
} else {
console.log('no customer created')
}

const session = await stripe.checkout.sessions.create({
payment_method_types: ['card'],
mode: 'setup',
customer: customer.id,
success_url: 'http://localhost:3000/api/stripe/saveCardToken/{CHECKOUT_SESSION_ID}__'+req.userData.userId,
cancel_url: 'https://example.com/cancel',
});

res.status(201).json({
url: session.url
})
};

exports.saveCardToken = async (req, res, next) => {
console.log('saveCardToken API')
// console.log('params',req.params.id)

const CHECKOUT_SESSION_ID = req.params.id.split('__')[0] ;
const session = await stripe.checkout.sessions.retrieve(
CHECKOUT_SESSION_ID, { expand: ['setup_intent'] }
);

const cardToken = new CardToken({
createdAt: Date.now(),
lastUpdate: Date.now(),
creator: req.params.id.split('__')[1],
token: session.setup_intent.payment_method, // this is the id used to generate a charge against
stripeUserId: session.customer
})
cardToken
.save()
}

#

i was told to use this this morning. they told me to save the card so that I can generate the charge against it

versed galleon
#

I'm not going to write all the code snippets that build your integration for you. I would recommend reaching out to one of our partners who can help you build it instead: https://stripe.com/partners/directory

minor kiln
#

i am the person that got hired because the last engineer could not figure it out

#

i am not asking to get all the code snips. im asking to check my work

#

so please

#

can you please confirm if this is the code to save the users financial information so that I can charge them later?

const paymentMethod = await stripe.paymentMethods.create({
type: 'card',
card: {
number: '4242424242424242',
exp_month: 8,
exp_year: 2023,
cvc: '314',
},
});

#

I did the integration this way the first time, and i was told to user stripe connect

#

I remember that when I used the code sobr, i was told that THAT would not work because THAT is for a 1 time use charge. i need to generate multiple charges over time. so i was told to use stripe connect

#

like if you dont want to help me out anymore thats fine, i can connect with another person. but I been doing what i was told and things have not worked out, thats why i keep reaching out

#

so, if i re-implement the code above, can i generate multple charges against that?

versed galleon
#

When you run it, does it work?

minor kiln
#

it ran the first time, then it didnt work anymore because it was for a 1 time use

#

i need to save their data to make multiple charges over time

#

are you telling me, and you are 100% sure that if i use the code snip above, I can save the card info, to charge it multiple times?

#

I need to implement a very similar functionality as to how monthly subscritions work (such as spotify, apple tv), so that I can save a users financial information, and generate a charge against it. does the code snip you provide allow me to do that?

sacred pasture
#

If you follow our docs carefully then yes it will work

minor kiln
#

oki will re-implement that functionality

sacred pasture
#

@minor kiln At this point, you will need to consider hiring a professional. I know we told you that multiple timesand you keep saying you're the developer hired for this. But you unfortunately are quite lost with all of this and my team has been trying to help you all day for multiple days which is really unscalable at this point

minor kiln
#

i keep being told different things, please see the logs

sacred pasture
#

I mean you are not. We repeatedly keep explaining basic parts of our docs that are covered in details. You are just really lost unfortunately.

minor kiln
#

i am very lost. this is taking way too long

sacred pasture
#

agreed

#

I think at this point you need to take a step back and hire a professional to help you set this up or at least started in the right direction.
You should also talk to our support team directly. You can contact them at https://support.stripe.com/contact and you can have one "ticket/thread" with all your questions.
But Discord is really not working for you at this point and my team has collectively spent 20+ hours trying to help you

minor kiln
#

the support team told me to contact u guys

#

me and my coworker have been trying to figure this out since friday

#

the last person could not get it to work

#

i am literally level 3 dev trying to work this out

#

i done lots of integrations before

#

this is compliated because we cant confirm some logic details

#

so please

#

its frustating to your team

#

its frustating to my team

sacred pasture
#

I've explained our position. We're happy to answer clear and specific questions about your code. But we can't continue to do what's happening here. You need to figure out how to build this or pay someone to do this for you.