#Steven P
1 messages · Page 1 of 1 (latest)
hello! when you create the Checkout Session, you can actually create metadata on the Subscription too - https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-subscription_data-metadata
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
the events to look at for when a trial expires / subscription is cancelled is mentioned here : https://stripe.com/docs/billing/subscriptions/webhooks#state-changes
let session = try stripe.sessions.create(
cancelUrl: "http://localhost:4200/dashboard",
paymentMethodTypes: [.card],
successUrl: "http://localhost:4200/dashboard",
allowPromotionCodes: nil,
billingAddressCollection: .auto,
customerEmail: user.email,
lineItems: [[
"price": price,
"quantity": 1,
]],
metadata: [
"user_id": body.uid,
"type": body.type.rawValue
],
mode: .subscription).wait()
This creates metadata on the Checkout object, however I'd like to create metadata on the associated Subscription object. How would I do this?
you can pass in metadata for the subscription in this parameter when creating the checkout session - https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-subscription_data-metadata
let session = try stripe.sessions.create(
cancelUrl: "http://localhost:4200/dashboard",
paymentMethodTypes: [.card],
successUrl: "http://localhost:4200/dashboard",
allowPromotionCodes: nil,
billingAddressCollection: .auto,
customerEmail: user.email,
lineItems: [[
"price": price,
"quantity": 1,
]],
mode: .subscription,
subscriptionData: [
"meta_data": [
"user_id": body.uid,
"type": body.type.rawValue
]
]).wait()
this throws an error
subscriptionData: [
"meta_data": [
"user_id": body.uid,
"type": body.type.rawValue
]
]
``` is the faulty param
how should i structure this?
what's the error?
[ WARNING ] StripeKit.StripeError [request-id: FE87D409-52EA-4350-A808-5998DA5E7256]
Not descriptive :/
are you using a third party library (instead of the official Stripe SDKs)?
correct
if let subscriptionData = subscriptionData {
subscriptionData.forEach { body["subscription_data[\($0)]"] = $1 }
}```
here is where they set the value for this param
unfortunately, I can't help you if you're using a third party library. We don't have any insight / knowledge on how those libraries work so you'll need to reach out to them instead for guidance.