I was adding stripe payment in my project . I was using react-stripe-checkout and at backend was using node js with stripe installed.
At frontend I have inside render() :
const payNow= async token=>{
try{
const response = await axios({
url : `/mycardpay/${localStorage.getItem('slno')}`,
method : 'post',
data : {
amount : this.calculateTotalAmount(),
token,
}
});
if(response.data.message == 'Success'){
console.log(response.data)
}
}catch(err){
console.log(err)
}
}
than added :
<StripeCheckout
stripeKey="pk_stripekey..."
label='Pay Now'
name='Pay With Credit Card'
billingAddress
amount={this.calculateTotalAmount()*100}
description={`Your Total Amount $${this.calculateTotalAmount()}`}
token={payNow}
/>
AT my backend I have :
const Stripe = require('stripe')(process.env.Secret_Key);
async function paymentCard(req, res, next){
try{
const {usersl} = req.params;
const {token, amount} = req.body;
try{
console.log(amount)
console.log(token)
console.log(token.card.last4)
const customer = await Stripe.customers.create({
email: token.email, // Use the email from the token
source: token.id, // Use the token ID as the payment method source
});
await Stripe.paymentIntents.create({
amount: amount, // Amount in cents
currency: 'inr',
payment_method_types: ['card'],
payment_method: token.card.id, // Use the card ID from the token's card object
customer: customer.id,
confirm: true,
})
It is the portion of my code that handles stripe payment and take the api to stripe server .
I am getting perfectly fine token.
{
id: 'tok_1Ng5esSI10A4W78jlyIUAMLX',
object: 'token',
card: {
id: 'card_1Ng5erSI10A4W78j5WRiJWUm',
object: 'card',
address_city: 'dhaka',
address_country: 'Bangladesh',
address_line1: 'asdad',
address_line1_check: 'unchecked',
address_line2: null,
address_state: null,
address_zip: '1244',
address_zip_check: 'unchecked',
brand: 'Visa',
country: 'US',
cvc_check: 'unchecked',
dynamic_last4: null,
exp_month: 4,
exp_year: 2026,
funding: 'credit',
last4: '4242',
name: 'asdad asd',
tokenization_method: null,
wallet: null
},
client_ip: '103.110.161.4',
created: 1692276638,
email: '[email protected]',
livemode: false,
type: 'card',
used: false
}
Why in stripe website at payment i see it not succeded, I see it incomplete
I am expecting it to be completed.
2
Answers
Well, I just solved it finally. Latest stripe is way to secured and old methods in other tuts not work cause it sends require_action in backend after paymentIntents. So, we add another mode at frontend react js name @stripe/stripe-js.And add just few lines. At backend inside /payment (I used /mycardpay) rout :
Than at Frontend we similiarly use react-js-checkout at start to start the payment.But, inside token={payNow} we add the process to handle require_action.
And start the whole process with your method to call .
this.calculatetotalAmount()
is just my function that calculate all product data cost it's nothing much.Looking at this packages github source, it appears to be several years out of date and is an implementation of Legacy Checkout which Stripe deprecated several years ago.
Depending on what exactly you’re trying to achieve, you should either integrate using Stripe’s modern Checkout product, or look at leveraging
@stripe/react-stripe-js
to build a custom payment form (minimal example).