Closed mandrasch closed 4 days ago
Hi, thanks for getting in touch!
Yes, you could store that info in the session and retrieve it when displaying the success page or pass it in the success URL (in the query string). You could also use custom_fields
which are available when creating a Stripe checkout session (when you use the checkout links or form, Stripe plugin creates a checkout session).
If your success (thank you) URL is configured to pass the session ID back to the page (that’s the ?session={CHECKOUT_SESSION_ID}
part), you could then retrieve the session by its id. It’ll have the data submitted to the custom fields (if you choose to use those) and the subscription ID (if it was a subscription that was created). You could then retrieve that session by id, grab the data you need (from custom fields, session or the URL) and process it as you wish.
You could also intercept the checkout.session.completed
event (which will have the submitted data and the subscription id if the purchased product was a recurring one) and process the data the way you want. Please note that until Stripe plugin 1.2 is released, you’d have to listen for that event on your own (more info here: https://github.com/craftcms/stripe/pull/20).
There are some caveats when using custom fields. You can specify a maximum of 3 custom fields, and they can only be text, number, or dropdown type.
Also I'm wondering how I get all current active subscriptions for a user?
You can do that via the element query, like so:
craft.stripeSubscriptions.user(currentUser).status('live').all()
Or, via behaviour attached to the user, like so:
currentUser.getStripeSubscriptions().where('stripeStatus', 'active').all()
I hope this clarifies things a bit.
I’ll close this now, but if you have any further questions or if anything above doesn’t make sense, feel free to reach out again!
Hi @i-just,
thanks very much for the detailed and quick response đź‘Ť (For the current project, we decided to stay with the current way / not use this new plugin - but your answer helped very much to evaluate both options. Much appreciated!)
I just wondered one thing about the new way:
I can add custom fields to subscriptions in the plugin settings, but these are just meant to be filled later via twig or PHP?
The challenge with that - as far as I can see - is that I need the stripe webhook to ping craftcms first in order to fill them? Before that the subscription does not exist in craft as far as I saw in my tests. Just as optional feedback.
(I guess that's what confused me, because in the old way (craft commerce subscriptions) these can be inserted via POST subscriptions/subscribe directly while subscribing and by seeing the custom field settings screen I assumed this will be the same here in the new plugin)
Hi @mandrasch,
Not a problem at all! I’m glad you found it helpful. We had a chat about the points you made, and we should make adding custom data to subscriptions easier.
We’ll have a look at a few options and see how we can improve this.
Stripe 1.2.0 is out with this improvement. Thanks again!
Description
Hi, this is more of a question rather than a bug (apologies, but discussions are not open here).
The native subscriptions in Craft Commerce have the ability to set custom fields in POST subscriptions/subscribe
fields[...]
Subscription custom field values, indexed by their handles.How can I achieve this with this new plugin?
I saw that custom field can be attached to subscriptions as well.
Because of the redirect to Hosted Checkout of Stripe, I assume I have to keep this in a session or submit the values I want to store in the thankYou-URL as GET parameter?
What would be the most robust place to do this - after a new subscription was sucessfully paid? 🤔
Use case: I want to store some additional fields to a subscription, e.g.
discountType
for a reduced membership likesenior
,student
, etc. (same product) + some uploaded files for verification. The user enters this information beforehand and pays -and I wanted to store the data and uploaded files within the subscription.Also I'm wondering how I get all current active subscriptions for a user? In craft commerce it was like this:
I'll dig into source code of this plugin, guess it's just not documented in README.md yet?
Thanks very much in advance!
Additional info