I’m new to Craft Commerce and am really having trouble getting started with subscriptions.
I used the example from the docs and nothing happened. When reloading the cp though, it kept telling me "Unable to start the subscription. Please check your payment details." I learned from the docs that "Subscribing a user to a plan requires that the user have a stored payment source." So I added the getPaymentFormHtml
bit. Without any success. Not to mention error messages of any kind.
This is my template so far:
<ul>
{% for item in craft.session.getFlashes() %}
<li>{{item}}</li>
{% endfor %}
</ul>
{% set plans = craft.commerce.getPlans().getAllPlans() %}
<form method="POST">
<input type="hidden" name="action" value="commerce/subscriptions/subscribe">
{{ csrfInput() }}
<div>
{% for plan in plans %}
<input type="hidden" name="planUid" value="{{ plan.uid|hash }}"/>
{# Display only if the user does not have a payment soure saved #}
{{ plan.getGateway().getPaymentFormHtml({})|raw }}
{% endfor %}
</div>
<button type="submit">{{ "Subscribe"|t('commerce') }}</button>
</form>
I’ve set up a subscription in the cp, added store information and tried a valid testing card from the stripe docs. But even then it keeps giving me the above flash notice.
Could anybody shed some light here? Am I missing anything obvious?