#Bassil-auth

1 messages ยท Page 1 of 1 (latest)

frail geyser
opaque brook
#

Sweet, from what im seeing, i wouldn't have to do much code changes, just need to add the parameter capture_method to my payment intent object

#

and then create a button that hits a backend endpoint to capture payment upon order confirmation

frail geyser
#

Yes, you are right ๐Ÿ™‚

opaque brook
#

Awesome! And in the situation customer cancels the order due to no stock, no fee will be taken if the payment wasnt captured right?

#

Would we have to manually cancel the hold or how would that work?

frail geyser
#

If you cancel the uncaptured payment intent, then yes there's no fee to be taken. However, if you do a partial capture, then it'll involve a fee.

opaque brook
#

Okay sweet that is awesome

#

Thank you so much you saved us so much $

frail geyser
#

Welcome ๐Ÿ™‚

opaque brook
#

Hey Jack I had a quick question

#

Do I have to add

payment_method_types=['card'],
``` to the payment intent?
#

It says:
"Before continuing to capture, attach a payment method with card details to the PaymentIntent, and authorize the card by confirming the PaymentIntent. You can do this by setting the payment_method and confirm fields on the PaymentIntent."

#

Kinda got confused on this step.
My code to create the initial payment intent is as follows:

#
   data = json.loads(request.body)
        intent = stripe.PaymentIntent.create(
            amount=calculate_order_amount(data['items']),
            currency='aed',
         
            capture_method='manual',
        )
frail geyser
#

OK, you should also add in the payment_method_types param since manual capture is only application to cards.

Did you attach a payment method to this payment intent before capturing it?

opaque brook
#

Okay so I changed my code when creating the payment intent to as follows

#
    try:
        data = json.loads(request.body)
        intent = stripe.PaymentIntent.create(
            amount=calculate_order_amount(data['items']),
            currency='aed',
            payment_method_types=['card'],
            capture_method='manual',
        )
        request.session['payment_intent'] = intent['id']

        return JsonResponse({
            'clientSecret': intent['client_secret']
        })
#

Now I have to attach payment intent when it is creating a payment method? I don't have this in my client.js

#

I have

var payWithCard = function (stripe, card, clientSecret) {
    loading(true);
    stripe
        .confirmCardPayment(clientSecret, {
            payment_method: {
                card: card
            }
        })
        .then(function (result) {
            if (result.error) {
                // Show error to your customer
                showError(result.error.message);
            } else {
                // The payment succeeded!
                orderComplete(result.paymentIntent.id);
                console.log(result)
            }
        });
};
#

(Using iframe for stripe on my site)

frail geyser
#

Yes, you still use stripe.confirmCardPayment to attach the payment method to the payment intent.

opaque brook
#

I see but I must use stripe.createPaymentMethod({?

frail geyser
#

you don't need

opaque brook
#

So My confirmCardpayment already seems to be attaching payment method?

frail geyser
#

Basically the integration flow is the same as capture_method=automatic, there is just one more step to capture the paymentIntent in your backend.

#

Yup, just need to use stripe.confirmCardPayment

opaque brook
#

I see okay so basically all that was different was me adding

        payment_method_types=['card'],
            capture_method='manual',
``` to my payment intent creation object
#

let me test this to see if it shows as a hold and not fully captured

#

then ill code in the capturing function ๐Ÿ˜„

opaque brook
#

Hmm

#

When checking out I got the following error:

#

This PaymentIntent's amount could not be updated because it has a status of requires_capture. You may only update the amount of a PaymentIntent with one of the following statuses: requires_payment_method,
requires_confirmation, requires_action.

frail geyser
#

From which API request did you receive this error?

opaque brook
#

Whats happening is I am updating the payment intent with the customer details when he clicks the pay now button

#
    stripe.PaymentIntent.modify(
                        payment_intent,
                        metadata={"full_name": customer_name, "email": email, 'cell_number': cell_number,
                                  'order_number': order_number,
                                  'invoice_number': invoice_number,
                                  'cart_items_list': cart_items_list,
                                  'cart_subtotal_in_aed_less_code': cart_subtotal_in_aed,
                                  'cart_cogs_in_aed': cart_cogs_in_aed, 'user_id': user_id, },
                    )
frail geyser
#

Why are you modifying the payment intent?

opaque brook
#

I am adding the customer name, number, etc that they fill out and attach it as meta data to the payment intent

#

so later I can access the info

#

This is the code for the update

#
   $(document).on('click', '.stripe-button', function () {
                $.ajax({
                    type: "POST",
                    url: '{% url 'store:update_payment_intent' %}',
                    data: $('#payment-form').serialize(),
                    success: function (response) {
                    }
                });
            });
frail geyser
#

You can also create a customer object and update your customer info on that object instead of on the payment Intent itself,

opaque brook
#

I see, that may require a lot of code change which I am up for but I want to see if I can keep my same system I built for now since we need this implemented asap. What I do is pass meta data to the payment intent so when the webhook hits my server it grabs that info and creates the order on my server

#

I need to somehow run the update payment intent code and when that succeeds, only then submit the form

#

i think whats happening is once the stripe button is being clicked there isnt enough time to update the payment intent since its charging right away

frail geyser
#

I'd recommend to use the Customer API to mange your customer info

opaque brook
#

Hmm so on clicking the pay button itll create a customer? and attach the payment intent ID to the customer object?

frail geyser
#

You can create a customer first, and attach the customer to the payment intent

opaque brook
#

Oh I think the payment intent update worked

#

its just saying you cant change the amount

#

the meta data seemed to attach to the payment intent

#

One quesiton Jack

frail geyser
#

Hi @opaque brook my shift is ending, my colleague @chilly hill will continue helping you.

opaque brook
#

If someone has unsufficient funds, will it automatically still show as insufficient funds?

#

Okay thank you so much Jack

#

You've been a great deal of help

#

appreciate it.

chilly hill
#

Hi!

opaque brook
#

Hi Soma ๐Ÿ™‚

chilly hill
#

If someone has unsufficient funds, will it automatically still show as insufficient funds?
Yes, placing a hold on a card is just like a regular card payment.

opaque brook
#

Okay awesome! I think im good now

#

I know what to do next

#

Ty for the help ๐Ÿ™‚

#

Need to code in capturing of the payment now

#

Because I was changing our system from auto capturing to manual capturing

#

to avoid loosing out on fees if the customer requests a refund due to no stock

#

Or if order has to be cancelled due to no stock