Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add allowSubscriptionWithoutPaymentMethod setting #108

Open
wants to merge 1 commit into
base: 5.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ For subscriptions with automatic payments, Stripe creates an invoice 1-2 hours b

This setting affect all Stripe gateways on your Commerce installation.

### The `allowSubscriptionWithoutPaymentMethod` setting

Normally, this plugin will not allow a subscription to be created if the customer has no payment methods in Stripe. By setting this to true in your `commerce-stripe.php` config file, a customer can create a subscription without any payment information. This is useful for trial subscription flows where you do not wish to take payment information up front.

This setting affect all Stripe gateways on your Commerce installation.

## Subscriptions

### Creating a subscription plan
Expand Down
2 changes: 1 addition & 1 deletion src/gateways/PaymentIntents.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ public function subscribe(User $user, BasePlan $plan, BaseSubscriptionForm $para
$customer = StripePlugin::getInstance()->getCustomers()->getCustomer($this->id, $user);
$paymentMethods = PaymentMethod::all(['customer' => $customer->reference, 'type' => 'card']);

if (\count($paymentMethods->data) === 0) {
if (!StripePlugin::getInstance()->getSettings()->allowSubscriptionWithoutPaymentMethod && \count($paymentMethods->data) === 0) {
throw new PaymentSourceException(Craft::t('commerce-stripe', 'No payment sources are saved to use for subscriptions.'));
}

Expand Down
5 changes: 5 additions & 0 deletions src/models/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,9 @@ class Settings extends Model
* @var bool Whether to attempt to charge any created invoice immediately instead of waiting 1-2 hours.
*/
public $chargeInvoicesImmediately = false;

/**
* @var bool Whether to allow creation of a subscription for customers without any payment methods, useful for trials without taking payment up-front
*/
public $allowSubscriptionWithoutPaymentMethod = false;
}