#votsircp-subscription

1 messages · Page 1 of 1 (latest)

scenic kestrel
#

You can try to expand and get the information from

subscription.latest_invoice.payment_intent.charges

#

Payment_intent and charge only exists when the charge is attempted

misty coyote
#

not sure i get it

#

should i use a webhook instead?

scenic kestrel
#

no

#

it is a property of the subscription

#

you would get it like an ID of the subscription. e.g.

var sub = stripe.subscriptions.create 
// get id 
let id = sub.id
// Similarly, you can get 
let charge = sub.latest_invoice.payment_intent.charges [0] 
#
var sub = stripe.subscriptions.create(...., {expand: [latest_invoice.payment_intent.charges]}) 
let charge = sub.latest_invoice.payment_intent.charges [0] 
misty coyote
#

thank you, i will try this and get back to you if i'm unable!

#

not sure where the expand goes in the function

#

can you tell me if this is correct?

      let sub = stripe.subscriptions.create({
        customer: data.customerId,
        items: [
          {
            plan: data.planId
          }
        ]
      }, { expand: [latest_invoice.payment_intent.charges] })
vast marten
#

@misty coyote try

   let sub = stripe.subscriptions.create({
            customer: data.customerId,
            items: [
              {
                plan: data.planId
              }
            ]},{
            expand: [latest_invoice
.payment_intent.charges]
          });
misty coyote
#

thank you

#

it returned latest_invoice is not defined

#

here

let charge = sub.latest_invoice.payment_intent.charges [0]

you mean index 0 of array sub.latest_invoice.payment_intent.charges

?

scenic kestrel
#

As i mentioned, you will only get an invoice and payment if a payment is attempted

#

here you are only creating the subscription. Does your customer has a default payment_method that could be used for payment?

misty coyote
#

isn't that what subscriptions.create does?

#

the user inputs card information

#

i wasn't aware that after stripe.subscriptions.create i had to trigger a payment

scenic kestrel
#
    const subscription = await stripe.subscriptions.create({
      customer: customerId,
      items: [{
        price: priceId,
      }],
      payment_behavior: 'default_incomplete',
      expand: ['latest_invoice.payment_intent'],
    });

misty coyote
#

i am using Stripe Elements to collect card information

scenic kestrel
#

wrap the expand parameter in quote

misty coyote
scenic kestrel
#

yup, sorry, should be more accurate. on that.