<p>Commerce needs an actual user for subscriptions but you can make onboarding pretty simple by doing a couple things:</p>
<ul>
<li>Uncheck &quot;Verify email addresses&quot; in the CP under Settings -&gt; Users -&gt; Settings.</li>
<li>Set <code>deferPublicRegistrationPassword</code> to true so you don't need the user to set a password</li>
<li>Set the <code>autoLoginAfterAccountActivation</code> config to true. This, along with skipping email verification, makes it possible to use the same session.</li>
<li>Set <code>useEmailAsUsername</code> to true. Does what it says; sets the username to the email address.</li>
</ul>
<pre><code>        'useEmailAsUsername' =&gt; true,
        'deferPublicRegistrationPassword' =&gt; true,
        'autoLoginAfterAccountActivation' =&gt; true
        
</code></pre>
<p>The user will be sent the &quot;activate your account&quot; email so you might want to customize that a bit to say something like &quot;Activate your account and set a password so you can login to manage your subscription.&quot;</p>
<p>If they don't set a password, they'll need to go through the motions of doing a password reset to manage their account.</p>
<p>That will allow you to simply grab the email email address on the form. You could do that via ajax on the same form (say after the users tabs off) or redirect back to the same form using something like:</p>
<pre><code>{% if not currentUser %}
   {# show the registration form #}
{% else %}
    {# show the plans #}
{%endif%}
</code></pre>

CC BY-SA 4.0
2020-09-07T16:49:28.687Z
2020-09-07T16:49:28.687Z
RitterKnight
<p>This can definitely be done, but I don't think it's possible to do it all in the same form without using a custom module to handle either creating the user programmatically and then submitting to the Commerce controller or vice versa.</p>
<p>Craft has support for creating a user account via a front-end form (see the <a href="https://craftcms.com/docs/3.x/dev/examples/user-registration-form.html" rel="nofollow noreferrer">User Registration Form</a> in the Craft docs) but you can't submit to that controller <em>and</em> also submit to the Commerce subscriptions controller as per the standard example template at the same time.</p>
<p>It might be possible to achieve something close to what you're looking for by showing a user registration form first, and then set the redirect input for that form to the payment page. However, if you want to have the user logged in directly after registration but before payment in order to save the user's payment details etc., you're going to need to do some custom development work to log the user in programmatically first since the default user registration controller just creates the account but doesn't log the user in.</p>
<p>I've done this sort of process where the user account is created, then logged in automatically, then they enter their billing address and payment details, but that was using Commerce Pro and a multi-step registration/payment form which is a bit more complex than your use case.</p>

CC BY-SA 4.0
2020-09-07T09:31:31.043Z
2020-09-07T09:31:31.043Z
Martin Spain
<p>I have just started using Craft Commerce (only Lite version currently) and I'm currently trying to get to grips with what is possible. My question is regarding subscriptions.</p>
<p>The site that I'm working on needs to support subscriptions. It has a single, flat rate plan which would charge users monthly. Not only that but it requires that once a user/guest has subscribed to a plan, they are then registered as Craft users. So far I have set up the plan in Stripe and in Craft using the standard template below.</p>
<pre><code>{% set plans = craft.commerce.getPlans().getAllPlans() %}

{% for plan in plans %}
&lt;form method=&quot;post&quot;&gt;
    &lt;input type=&quot;hidden&quot; name=&quot;action&quot; value=&quot;commerce/subscriptions/subscribe&quot;&gt;
    &lt;input type=&quot;hidden&quot; name=&quot;planUid&quot; value=&quot;{{ plan.uid|hash }}&quot;&gt;
    {{ csrfInput() }}

    &lt;h4&gt;{{ plan.name }}&lt;/h4&gt;

    {% set paymentSources = craft.commerce.
        getPaymentSources().
        getAllGatewayPaymentSourcesByUserId(
            plan.getGateway().id,
            currentUser.id ?? null
        )
    %}

    {# if we don’t have a saved payment soruce, collect details for the gateway #}
    {% if not paymentSources|length %}
        &lt;div class=&quot;paymentForm&quot;&gt;
            {{ plan.getGateway().getPaymentFormHtml({})|raw }}
        &lt;/div&gt;
    {% endif %}

    &lt;button type=&quot;submit&quot;&gt;{{ &quot;Subscribe&quot;|t }}&lt;/button&gt;
&lt;/form&gt;
{% endfor %}
</code></pre>
<p>When I try to submit this form it simply reloads the current page. Nothing is recorded in Stripe or Craft. Not too sure why this would be.</p>
<p>Ideally what I'd like is for a user to subscribe to a plan and simultaneously register themselves as a user on the site, so that they would be able to log in and out. Is Commerce able to support user registration when purchasing a subscription?</p>

<craft3><plugin-craftcommerce><users><plugin-commerce-stripe>
Guest user registration using Commerce 3
# Guest user registration using Commerce 3

(Asked by: username_0 on 2020-09-03)

I have just started using Craft Commerce (only Lite version currently) and I'm currently trying to get to grips with what is possible. My question is regarding subscriptions.
The site that I'm working on needs to support subscriptions. It has a single, flat rate plan which would charge users monthly. Not only that but it requires that once a user/guest has subscribed to a plan, they are then registered as Craft users. So far I have set up the plan in Stripe and in Craft using the standard template below.
{% set plans = craft.commerce.getPlans().getAllPlans() %}

{% for plan in plans %}

    
    
    {{ csrfInput() }}

    {{ plan.name }}

    {% set paymentSources = craft.commerce.
        getPaymentSources().
        getAllGatewayPaymentSourcesByUserId(
            plan.getGateway().id,
            currentUser.id ?? null
        )
    %}

    {# if we don’t have a saved payment soruce, collect details for the gateway #}
    {% if not paymentSources|length %}
        
            {{ plan.getGateway().getPaymentFormHtml({})|raw }}
        
    {% endif %}

    {{ "Subscribe"|t }}

{% endfor %}

When I try to submit this form it simply reloads the current page. Nothing is recorded in Stripe or Craft. Not too sure why this would be.
Ideally what I'd like is for a user to subscribe to a plan and simultaneously register themselves as a user on the site, so that they would be able to log in and out. Is Commerce able to support user registration when purchasing a subscription?

**Tags:** craft3, plugin-craftcommerce, users, plugin-commerce-stripe

---

## 2 answers

### Answer by username_1 on 2020-09-07. Score: 2

Commerce needs an actual user for subscriptions but you can make onboarding pretty simple by doing a couple things:

Uncheck "Verify email addresses" in the CP under Settings -> Users -> Settings.
Set deferPublicRegistrationPassword to true so you don't need the user to set a password
Set the autoLoginAfterAccountActivation config to true. This, along with skipping email verification, makes it possible to use the same session.
Set useEmailAsUsername to true. Does what it says; sets the username to the email address.

        'useEmailAsUsername' => true,
        'deferPublicRegistrationPassword' => true,
        'autoLoginAfterAccountActivation' => true
        

The user will be sent the "activate your account" email so you might want to customize that a bit to say something like "Activate your account and set a password so you can login to manage your subscription."
If they don't set a password, they'll need to go through the motions of doing a password reset to manage their account.
That will allow you to simply grab the email email address on the form. You could do that via ajax on the same form (say after the users tabs off) or redirect back to the same form using something like:
{% if not currentUser %}
   {# show the registration form #}
{% else %}
    {# show the plans #}
{%endif%}


---

### Answer by username_2 on 2020-09-07. Score: 1

This can definitely be done, but I don't think it's possible to do it all in the same form without using a custom module to handle either creating the user programmatically and then submitting to the Commerce controller or vice versa.

Craft has support for creating a user account via a front-end form (see the [User Registration Form](https://craftcms.com/docs/3.x/dev/examples/user-registration-form.html) in the Craft docs) but you can't submit to that controller *and* also submit to the Commerce subscriptions controller as per the standard example template at the same time.

It might be possible to achieve something close to what you're looking for by showing a user registration form first, and then set the redirect input for that form to the payment page. However, if you want to have the user logged in directly after registration but before payment in order to save the user's payment details etc., you're going to need to do some custom development work to log the user in programmatically first since the default user registration controller just creates the account but doesn't log the user in.

I've done this sort of process where the user account is created, then logged in automatically, then they enter their billing address and payment details, but that was using Commerce Pro and a multi-step registration/payment form which is a bit more complex than your use case.


---

