#sovie7ic

1 messages ยท Page 1 of 1 (latest)

sacred hornetBOT
hard hare
sullen mason
#

Hi river, super sorry

#

let elements = this.cc.current.props.elements
const {error: submitError} = await elements.submit();
if (submitError) {
// Show error to your customer
this.setState({
error: submitError.message,
loading: false,
});

        if (this.props.hasStripeErrors) {
            this.props.hasStripeErrors();
        }
        return;
    }
    
    const res = await axios.post(`/${this.props.org.url}/transaction/create_intent`, {
        contact_id: contact.id,
        client_id: contact.client_id,
        anonymous: formValues.anonymous,
        msg: formValues.msg,
        cur: this.state.cur,
        cmp_id: this.props.cmp.id,
        amount: this.state.amount,
        perk_id: this.state.perk.id,
    }).catch((error) => {
        notification.error({
            message: 'Error',
            description: 'Something went wrong. Please try again later.',
        });
        if (this.props.hasStripeErrors) {
            this.props.hasStripeErrors();
        }
    });
    // Use the clientSecret and Elements instance to confirm the setup
    const {error} = await this.cc.current.props.stripe.confirmPayment({
            elements,
            confirmParams: {
                return_url: `${window.location.origin}/${this.props.org.url}/thanks`,
                shipping: {
                    name: contact.name,
                    address: {
                      line1: contact.address,
                      city: contact.city,
                      postal_code: contact.postal,
                      state: contact.short_state,
                      country: contact.short_country,
                    },
                },
            },
    });
#

Thanks the react web code

#

Thats*

hard hare
#

Can you elaborate the issue you're facing?

sullen mason
#

I think im creating 2 payment intents

#

One on the front end

#

And one on the backend

#

But there should be only one

#

Is there a way of getting the PI on the front end?

hard hare
#

Frontend doesn't create payment intent unless your frontend make a request to your server to create another payment intent

sullen mason
#

const options = {
mode: 'payment',
amount: this.state.amount ? this.state.amount * 100 : 500,
currency: this.state.cur,
};

hard hare
#

Which guide are you following for your Payment Element integration?

sullen mason
#

Some elements from there

hard hare
sullen mason
#

Some from here

hard hare
#

I'd recommend following the guide above as your code is a mix and match of different payment integrations

#

The above doc should guide you the proper way to integrate Payment Element

sullen mason
#

Ok, I think I found the issue

#

When there is an error with stripe.confirmPayment

#

I re-run the function

#

So it reacrate a PI

#

Is it an OK behaviour

#

Or I should avoid doing this?

#

And how should I manage the future use of the credit card in this case?

hard hare
#

No, you shouldn't recreate a payment intent when there's an error of stripe.confirmPayment(). If the error is due to declines, then same payment intent should be re-used

sullen mason
#

Dont see any doc for that ๐Ÿ˜ฆ

#

So I should save the PI on front end?

hard hare
#

Payment intent can always be re-used as long as it's not completed or canceled

#

You should save the PI associated to the your internal order number. If the order has payment fails and requires a payment again, then your frontend will retrieve its associated payment intent to retry it again

sullen mason
#

So lets say I receive this error

#

On the confirm payment side, and I change few info... I should simply reuse the created PI correct?

hard hare
#

Yes, as long as the amount is the same. If the amount is updated, the Payment Intent should be updated to the new amount

sullen mason
#

$stripe = new \Stripe\StripeClient($org->getStripeSecretAttribute());
$amount = $request->input('amount') ?? 5;

        $data = [
            'metadata' => [
                'org_id' => $org->id,
            ],
            'automatic_payment_methods' => [
                'enabled' => true,
            ],
            'amount' => $amount * 100,
            'currency' => $org->cur
        ];

        if (empty($org->cc_desc)) {
            $data['statement_descriptor_suffix'] = $org->cc_desc;
        }
        
        if (!empty($request->input('pi'))) {
            $paymentIntent = $stripe->paymentIntents->retrieve(
                $request->input('pi'),
            );
            $paymentIntent->update($data);
        } else {
            $pi = $stripe->paymentIntents->create(
                $data,
            );
        }
#

Only element that can be updated is the Amount?

#

And also, how can I make sure I can reuse the credit card on file? To create a subscription etc?

#

Thanks for your help and sorry for the 109 questions ๐Ÿ™‚

#

How can I re-use a credit card in the future while creating a payment item with the automatic payment methods?

hard hare
#

Only element that can be updated is the Amount?
If the amount of an order is updated, you should update both payment intent at server and elements at client

sullen mason
#

I'm doing this:

#

$pi = $stripe->paymentIntents->retrieve(
$request->input('pi'),
);
$stripe->paymentIntents->update($request->input('pi'), [
'amount' => $amount * 100,
'currency' => $request->input('cur') ?? $org->cur,
]);

#

Just updaing the amount / currency on the PI

hard hare
#

And also, how can I make sure I can reuse the credit card on file? To create a subscription etc?
If the payment method has been saved with Stripe, the payment method (pm_xxx) can be set to default_payment_method: https://stripe.com/docs/api/subscriptions/create#create_subscription-default_payment_method

sullen mason
#

Getting this

#

You cannot confirm this PaymentIntent because it's missing a payment method. You can either update the PaymentIntent with a payment method and then confirm it again, or confirm it again directly with a payment method.

#

Its because of this: automatic_payment_methods - correct?

#

I want to simply be able to manually add a subscription in the future for a PI

#

From the dashbaord...

hard hare
#

Its because of this: automatic_payment_methods - correct?
No. A payment method should be collected when confirmPayment() is called, i.e. the elements should have payment method collected before making a confirm request

sullen mason
#

So in my case, I will need an extra call?

#

As I have

#

confirmParams: {
return_url: ${window.location.origin}/${this.props.org.url}/thanks,
shipping: {
name: contact.name,
address: {
line1: contact.address,
city: contact.city,
postal_code: contact.postal,
state: contact.short_state,
country: contact.short_country,
},
},
},

#

It goes to a thank you page

hard hare
#

The update should be before any gesture event listener, not right before confirm request. The amount should be updated as soon as the order number is changed

sullen mason
#

Ok but how can I save the payment method for later use?

hard hare
sacred hornetBOT
sullen mason
#

So just by putting setup_future_usage: 'off_session' it solve the issue?