#formigueiro

1 messages · Page 1 of 1 (latest)

proper ledgeBOT
#

Hello! We'll be with you shortly. Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

pale blaze
#

Hello

#

You can't list for both of those in one request, you would make two requests -- one with each desired status

#

But yes, this is possible

rain rose
#

In short, my backend would have to handle this for me so, right with the two calls

pale blaze
#

Yep that's correct

rain rose
#

by the way

#

is there an endpoint that brings me data from the card used in the purchase, for example **** **** **** 1234 ?

pale blaze
#

You can see the last4 by looking at the Card object, yes. Or looking at a Charge's payment_method_details

#

Mostly depends on what object you are working from to be able to see that

#

But yes it is available

rain rose
#

i was seeim this

#

is right?

#

just here or directly in the client endpoit? I didn't find this payment_method_details field in the response body

pale blaze
#

Are you working backward from a PaymentMethod ID?

rain rose
#

nice

#

If the user uses several cards in different subscriptions, will only one always be returned?

#

Another question, what would this value be?

pale blaze
#

If they use different cards in Subs then you would want to look at the PaymentMethod used for that Sub specifically

#

It is likely set as the default_payment_method

#

And then you can retrieve that for last4

rain rose
#

When bringing subscriptions, would it be best to bring their payment method so?

pale blaze
#

Not sure what you mean by that?

rain rose
#

I need to bring the client's subscriptions and bring their payment methods

pale blaze
#

You want to show a UI with all of a Customer's Subscriptions and PaymentMethods?

rain rose
#

yes some like this. And in the user interface the user will be able to update their payment method.

pale blaze
rain rose
#

perfect

pale blaze
#

In terms of updating the PaymentMethod, you'll likely want to render Payment Element using a SetupIntent

rain rose
#

stripe element do you mean?

pale blaze
#

Yep

#

You could also use Stripe Checkout

#

Totally up to you

rain rose
#

For payment I am using stripe checkout, but for editing I am not using

#

oh, i also could use some with await stripe.billingPortal.sessions.create({

#

to edit directly on stripe page, right?

pale blaze
#

To update the PaymentMethod for a Subscription you need to collect a new PaymentMethod for the Customer and then set that PaymentMethod as the new default_payment_method for the Subscription

#

Yes, this could also be fully handled by the Customer Portal if you want to use that

#

Basically everything you are doing right now can be done for you by Customer Portal

rain rose
rain rose
pale blaze
rain rose
#

I want to incorporate this case into my panel even without using the stripe flow.

pale blaze
#

So you create a SetupIntent on your backend, and then you render Payment Element in a form on your frontend

#

Take a read through that guide

rain rose
#

At the moment I don't understand why I would use this SetupIntent. Wouldn't there be a PaymentMethod.modify or PaymentMethod.update to update a payment method for a certain subscription?:

pale blaze
#

I thought you are trying to collect a new PaymentMethod

#

Are you only trying to switch what PaymentMethod would be charged based on previously-collected PaymentMethods?

rain rose
#

let me explai better: On my page, as I mentioned, I will bring all the subscriptions and all these payment methods for a user (the back will bring everything as needed). When listing payment methods (which have subscriptions), I will have the option to update the payment method or cancel. By clicking on change I will open a modal with also like this in the image. My question is how do I update this payment method that has a subscription attached?

pale blaze
#

You can't update PaymentMethods themselves (other than select information like the billing_details ) after they have been created.

#

You have to create a new PaymentMethod in that case.

#

To do that without charging it immediately, you use a SetupIntent

#

Like I showed you in the above guide.

#

That said, looks like you may be using Split Card Elements already based on your screenshot?

rain rose
#

But how will I create a new Payment Methods that has a signature attached. So will I cancel the current one and create a new subscription?

pale blaze
#

You don't have to cancel and create a new one. You use a SetupIntent and call confirmCardSetup() (https://stripe.com/docs/js/setup_intents/confirm_card_setup) on the frontend. This will create a new PaymentMethod and attach it to the Customer. Then you update the Subsription to set that new PaymentMehtod as the default_payment_method: https://stripe.com/docs/api/subscriptions/update#update_subscription-default_payment_method

rain rose
#

So my backend needs to create a SetupIntent and return the client_secret. So on the frontend side, before displaying the modal, I need to call the backend route to create a SetupIntent and get the client_secret. Is this necessary to configure the Stripe Elements modal.?

#

Im using vuejs so something like this? ```js
<template>
<div>
<form @submit.prevent="handleFormSubmit">
<div>
<label for="card-element">Credit card</label>
<div id="card-element"></div>
<div id="card-errors" role="alert"></div>
</div>
<button type="submit">Update</button>
</form>
</div>
</template>

<script>
export default {
setup() {
const stripe = ref(null);
const elements = ref(null);

onMounted(async () => {
  const stripePromise = await loadStripe('key');
  stripe.value = stripePromise;
  elements.value = stripePromise.elements();
});

const handleFormSubmit = async () => {
  try {
    const response = await fetch('/create_setup_intent', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        customer_id: 'client_id',
      }),
    });

    const data = await response.json();
    const { setupIntentClientSecret } = data;

    const cardElement = elements.value.create('card');
    await stripe.value.confirmCardSetup(setupIntentClientSecret, {
      payment_method: {
        card: cardElement,
      },
    });

    const updateSubscriptionResponse = await fetch('/update_subscription_payment', {
      method: 'PUT',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        subscription_id: 'id_subscription',
        new_payment_method_id: setupIntentClientSecret.payment_method,
      }),
    });

    const updateSubscriptionData = await updateSubscriptionResponse.json();
  } catch (error) {
    console.error(error);
  }
};

return {
  handleFormSubmit,
};

},
};
</script>```

pale blaze
#

Yep that looks good to me!

#

I'd test it out

rain rose
#

the /update_subscription_payment endpoint would do something like this? js stripe.Subscription.modify( subscription_id, default_payment_method=new_payment_method_id, )

pale blaze
#

Yep

rain rose
#

hm

#

you are awesome @pale blaze

#

ty my friend

pale blaze
#

Happy to help

rain rose
#

Sorry to bother you, just to finish

#

When bringing signatures, is it possible on my webpage to make the user download any file from the invoice?

proper ledgeBOT
rain rose
pale blaze
#

Not sure what you mean by that exactly

#

Cna you clarify?

rain rose
#

i would like to allow user download invoice about that subscription

#

as a PDF for example equal we have on stripe dashboard

formal abyss
#

Hi there

#

So you could either list invoices by subscription id or retrieve a specific invoice if you have its id

rain rose
#

So I can keep getting all these subscriptions and when I click on the download button, I pass this "latest_invoice": "in_1MowQWLkdIwHu7ixuzkSPfKd" to the back, and the back does the const invoice = await stripe.invoices.retrieve('in_1MtHbELkdIwHu7ixl4OzzPMv');

formal abyss
#

Yeah if that's the invoice you need

rain rose
#

So the back needs to generate this PDF?

#

from the object?

#

So can it be a personalized PDF?

formal abyss
#

No it's not personalizable

#

Stripe creates

#

You don't generate anything. We include it on the invoice object already

formal abyss
#

That's what I linked ^

rain rose
formal abyss
#

What I linked is the invoice_pdf param on the invoice object. The invoice object is what will be returned when you call retrieve

rain rose
#

um i think i found

#

You guys are too much. Thank you very much for your help, open my mind

#

@pale blaze and @formal abyss ty

formal abyss
#

Yeah that's the exact param I linked earlier

rain rose
#

hehe sorry

formal abyss
#

No problem