#votsircp-subscription
1 messages · Page 1 of 1 (latest)
You can try to expand and get the information from
subscription.latest_invoice.payment_intent.charges
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Payment_intent and charge only exists when the charge is attempted
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]
however, by default laste_invoice is just an ID but you can expand it https://stripe.com/docs/api/expanding_objects?lang=curl
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
var sub = stripe.subscriptions.create(...., {expand: [latest_invoice.payment_intent.charges]})
let charge = sub.latest_invoice.payment_intent.charges [0]
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] })
@misty coyote try
let sub = stripe.subscriptions.create({
customer: data.customerId,
items: [
{
plan: data.planId
}
]},{
expand: [latest_invoice
.payment_intent.charges]
});
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
?
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?
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
You can take a look at the guide here https://stripe.com/docs/billing/subscriptions/elements#create-subscription
Learn how to offer multiple pricing options to your customers and charge them a fixed amount each month.
const subscription = await stripe.subscriptions.create({
customer: customerId,
items: [{
price: priceId,
}],
payment_behavior: 'default_incomplete',
expand: ['latest_invoice.payment_intent'],
});
i am using Stripe Elements to collect card information
wrap the expand parameter in quote
let charge = sub.latest_invoice.payment_intent.charges [0]
seems like sub.latest_invoice.payment_intent.charges is an object
did you mean
sub.latest_invoice.payment_intent.charges.data[0] ?
yup, sorry, should be more accurate. on that.