#user1352-question

1 messages ยท Page 1 of 1 (latest)

shadow bear
#

@inner trench Hello! I'm sorry I don't understand your question

inner trench
#

Hi thank for your repl

#

Reply

#

I have value total in card.js

#

And Iโ€™m trying to send the total server to make test recharge

shadow bear
#

Okay so that's not really a Stripe question in that case. You'd do this the same way you send any value to your server really

#

usually you do a POST request to your server to get the amount and create a PI

inner trench
#

What type of post , xhttp request or app.get(Pos)

shadow bear
#

that's really up to you. That's your own code in the sense that you send the value the same way you do a login form or any kind of submission in your app

inner trench
#

Look to this code

#

I try to use app get inside the server

#

To get the value total

#

I running the server is said to defined

shadow bear
#

I'm sorry I don't understand, it's just a picture of code with no context

#

that's your server-side code getting a total? But it's really just your own code, there's no Stripe code there

inner trench
#

I see

shadow bear
#

what's blocking you exactly?

inner trench
#

app.post('/create-payment-intent', async (req, res) => {
const {paymentMethodType, currency} = req.body;

// Each payment method type has support for different currencies. In order to
// support many payment method types and several currencies, this server
// endpoint accepts both the payment method type and the currency as
// parameters.
//
// Some example payment method types include card, ideal, and alipay.
const params = {
payment_method_types: [paymentMethodType],
amount: 1999,
currency: currency,
}

// If this is for an ACSS payment, we add payment_method_options to create
// the Mandate.
if(paymentMethodType === 'acss_debit') {
params.payment_method_options = {
acss_debit: {
mandate_options: {
payment_schedule: 'sporadic',
transaction_type: 'personal',
},
},
}
}

// Create a PaymentIntent with the amount, currency, and a payment method type.
//
// See the documentation [0] for the full list of supported parameters.
//
// [0] https://stripe.com/docs/api/payment_intents/create
try {
const paymentIntent = await stripe.paymentIntents.create(params);

// Send publishable key and PaymentIntent details to client
res.send({
  clientSecret: paymentIntent.client_secret,
});

} catch (e) {
return res.status(400).send({
error: {
message: e.message,
},
});
}
});

shadow bear
#

you're just copy-pasting code at this point unfortunately and mixing ACSS and stuff

#

just ignore all of Stripe for a few hours since you are working on how to handle basic form/post submission in JS

inner trench
#

`
app.post('/create-payment-intent', async (req, res) => {
const {paymentMethodType, currency} = req.body;

// Each payment method type has support for different currencies. In order to
// support many payment method types and several currencies, this server
// endpoint accepts both the payment method type and the currency as
// parameters.
//
// Some example payment method types include card, ideal, and alipay.
const params = {
payment_method_types: [paymentMethodType],
amount: 1999,
currency: currency,
}

// If this is for an ACSS payment, we add payment_method_options to create
// the Mandate.
if(paymentMethodType === 'acss_debit') {
params.payment_method_options = {
acss_debit: {
mandate_options: {
payment_schedule: 'sporadic',
transaction_type: 'personal',
},
},
}
}

// Create a PaymentIntent with the amount, currency, and a payment method type.
//
// See the documentation [0] for the full list of supported parameters.
//
// [0] https://stripe.com/docs/api/payment_intents/create
try {
const paymentIntent = await stripe.paymentIntents.create(params);

// Send publishable key and PaymentIntent details to client
res.send({
  clientSecret: paymentIntent.client_secret,
});

} catch (e) {
return res.status(400).send({
error: {
message: e.message,
},
});
}
});
`

shadow bear
#

you just did the same and reposted the whole code again ๐Ÿ˜…

inner trench
#

๐Ÿ‘

#

This inside server

shadow bear
#

But I see you're trying to send the amount from your client-side JS to your server-side code to create the PI

#

but you still haven't said what's blocking you

#

and really ignoring Stripe for a few hours and learning to do this in basic/vanilla JS is the best next step

#

it's not Stripe specific, it's the same as any input text you'd have in your website anywhere

inner trench
#

This it been send to client card .js

shadow bear
#

then what's the problem? I'm sorry I keep repeating this but you really need to explain the code and error in a lot more words, right now you just say it doesn't work

inner trench
#

I used app.get() as you can see in the photo and the server in the terminal said it Defined

#

The total

#

Not defined

#

I change the amount = total,

amount: total

#

It the same not defined

shadow bear
#

I'm sorry I barely understand what you are describing ๐Ÿ˜ฆ

#

you never parsed the request body, nor extracted the amount, you just use a variable named amount that's never defined, that's unfortunately not how basic JS works