#Bernard Paulet

1 messages · Page 1 of 1 (latest)

fresh mortarBOT
teal yacht
#

Hi there!

#

Can you try to summarize your question here?

pliant furnace
#

Yes, thanks !
I am working with the Flutter Stripe package and I try to make a payment that is incomplete with status requires_payment_method. I don't see what's wrong with my code and how to go further. I use a PaymentSheet and do not see the further steps to perform.
Note that I am certainly not a professional developper.
My last try, I had the following payment intent : pi_3MhxlzF5SeCFLsdc1U8J5rxg successful.

teal yacht
#

I try to make a payment that is incomplete with status requires_payment_method
The PaymentIntent you shared has requires_payment_method status. So that's what you were looking for?

pliant furnace
#

No, sorry, my mistake...
I tried to say that I wanted to make a complete payment (in test mode) but when I try the status stays required_payment_method and I don't see what's wrong and how to make the payment complete.

teal yacht
#

It's a two step process:

  • Create the PaymentIntent on the backend, it will have status:requires_payment_method (that part is done)
  • Then collect the payment information on the frontend with the client secret of the PaymentIntent, and confirm the PaymentIntent (this part is missing)
pliant furnace
#

Yes it is what I was suspecting...
But in my code I (think that I) send the payment info and confirm them...

#

I made a question on StackOverflow with my code (client and server), I don't know whether I can ask you to take a look at it?

#

To see what part is missing/wrong...

#

I just tried again and receive the following error : PlatformException(Invalid Params,,,null)

teal yacht
#

Can you share your full code here and the full error message?

pliant furnace
#

Of course

#

Here is the Flutter function:
`Future<void> initPayment({required String email, required int montant, required String nomOrga}) async{
try{
//1. Crée un payment intent sur le serveur
final response = await http.post(
Uri.parse("https://us-central1-bonbon-7af2f.cloudfunctions.net/stripePaymentIntentRequest"),
body: {
"email":email,
"amount": (montant*100).toString(),
},
);
print("email : $email - montant : $montant - organisation : $nomOrga");

  final jsonResponse = jsonDecode(response.body);
  print(jsonResponse);

  //2. Initialise le payment sheet
  await Stripe.instance.initPaymentSheet(paymentSheetParameters: SetupPaymentSheetParameters(
    //paymentIntentClientSecret: jsonResponse["client_secret"],
    paymentIntentClientSecret: jsonResponse["paymentIntent"],
    merchantDisplayName: nomOrga,
    customerId: jsonResponse["customer"],
    //customerEphemeralKeySecret: jsonResponse["ephemeral_key"],
    customerEphemeralKeySecret: jsonResponse["ephemeralKey"],
    customFlow: true,
  )
  );

  //3. Présenter le paiement
  await Stripe.instance.presentPaymentSheet();
  print("on a présenté la paymentsheet");


  //4. Attacher la méthode de paiement au PaymentIntent et confirmer le paiement
  final paymentIntentResult = await Stripe.instance.confirmPayment(
      paymentIntentClientSecret: jsonResponse["paymentIntent"],
  );
  print("on a fini confirmpayment");
  //print(paymentIntentResult.status);
}
catch(error){
  if(error is StripeException){
    quickConfirm("Oups", "une erreur StripeException s'est produite\n${error.error.message}", context);
  }else{
    quickConfirm("Oups", "une erreur brol s'est produite\n${error}", context);
  }
}

}`

#

And on the server side :
`const functions = require("firebase-functions");
const stripe = require("stripe")("sk_test...");
require("firebase-functions/logger/compat");

exports.stripePaymentIntentRequest = functions.https.onRequest(async (req, res) => {
try{
let customerId;

    //Get the customer who's email matches the one sent by the client
    const customerList = await stripe.customers.list({
        email: req.body.email,
        limit: 1,
    });
    console.log(customerList);

    //Check if customer exists, if not create a new customer
    if(customerList.data.lenght !== 0){
        customerId = customerList.data[0].id;
    } else {
        const customer = await stripe.customers.create({
            email: req.body.email,
        });
        customerId = customers.id;
    }

    //Creates a temporarysecret key linked with the customer
    const ephemeralKey = await stripe.ephemeralKeys.create(
        {customer: customerId},
        {apiVersion: '2022-11-15'}
    );

    //Creates a new payment intent with amount passed from the client
    const paymentIntent = await stripe.paymentIntents.create({
        amount: parseInt(req.body.amount),
        currency: 'eur',
        customer: customerId,
        automatic_payment_methods: {
            enabled: true,
        },
    });
    console.log(res);
    res.send({
        paymentIntent: paymentIntent.client_secret,
        ephemeralKey: ephemeralKey.secret,
        customer: customerId,
        publishableKey:'pk_test_...',
        success: true,
    });
    console.log('on a fini 200');
    } catch(error) {
        console.log('il y a eu une erreur :', error.message);
        res.status(404).send({
            success: false,
            error: error.message,
        });
    }

});`

#

Note that if I comment the point4 of the Flutter function, I don't receive any error message but the payment stays incomplete with status require_payment_method

spare idol
#

Hi, I'm taking over my colleague.
Let me check the code.

#

Where exactly do you get the error message?

pliant furnace
#

Hi, Thanks for helping me !

#

My error in the flutter function arise with point 4

final paymentIntentResult = await Stripe.instance.confirmPayment( paymentIntentClientSecret: jsonResponse["paymentIntent"], );

#

Otherwise, if I comment this point I don't receive any error but the payment is still incomplete

spare idol
#

I see. You confirm the PaymentIntent right after presenting the Payment Sheet.

#

You should wait until the customer fills out their payment information before confirming

#

Do you see the Payment Sheet? Does it pop up?

pliant furnace
#

Yes, the payment sheet pops up and I fill it with the 4242 card

#

but it is like the info is never sent (I guess)

#

I suspect there might be a problem with my server code?

spare idol
#

Do you click to Submit your payment details?

pliant furnace
#

I check to be sure...

#

I click on a 'Continue' button

#

once the Payment Sheet is completed

spare idol
#

Basically, you don't need to confirm the PaymentIntent yourself if you use Payment Sheet.

pliant furnace
#

If I comment those lines (and don't confirm), nothing special happens but the payment stays incomplete

spare idol
#

When you click Continue the Payment Sheet closes?

#

Could you record a video please?

pliant furnace
#

I try (never done it)...

#

Yes, the payment sheet closes

spare idol
#

I see you use customFlow: true, in your initPaymentSheet(). Why? What happens if you remove that?

pliant furnace
#

I try to remove it

#

Yes, that was the error !

#

Now, the payment is successful !

#

Could you quickly explain what is the point with customFlow : true?

#

I thank you very much, very very, for your help !

spare idol
#

When customFlow is set to true, it separates out the payment method selection & confirmation steps. If true, you must call confirmPaymentSheetPayment on your own.

pliant furnace
#

OK, I see !

spare idol
#

Happy to help. Let me know if you have any other questions.

pliant furnace
#

And, since I am in Europe, I don't have to confirm the payment (don't remember the name of the protocol)?

spare idol
#

Not sure how is this related.

pliant furnace
#

Ok, don't worry, I will try as is and come back to you should I experience a problem !

#

Thanks once more for your kind help !

spare idol
#

You're welcome!