I could do with some pointers on how this is meant to work.

For instance, if I want to create a subscription product that grants a license, would the Product Variation Type have *both* the purchasable_entity_subscription and the commerce_license traits?

But the purchasing that product would grant the license first time around.

Is it instead the case that there is only the purchasable_entity_subscription trait? Is it then up to the License CommerceSubscriptionType plugin to reference itself the license type plugin & its settings?

Comments

joachim created an issue. See original summary.

bojanz’s picture

Like this: https://github.com/bojanz/commerce_recurring/blob/8.x-2.x/src/Plugin/Com...

For instance, if I want to create a subscription product that grants a license, would the Product Variation Type have *both* the purchasable_entity_subscription and the commerce_license traits?

Yes.

But the purchasing that product would grant the license first time around.

Yes. The subscription type can skip activating a license if it's already active.

We can't use just a single trait because we still need commerce_license to support doing its own thing (collecting info, doing remote activation, etc).

joachim’s picture

> We can't use just a single trait because we still need commerce_license to support doing its own thing (collecting info, doing remote activation, etc).

Thanks for clarifying!

I wasn't sure if a subscription product wasn't a separate thing that somehow wrapped the license product...

Next question.... the License trait for PVs currently has the period settings provided by a plugin, which means that the period for your license is baked into each Product Variation.

Meanwhile, the period for a subscription is set in the Billing Schedule config entity...

I remember a mention on Slack a while ago about how on D7 there was double entry of the periods between the license and the subscription. With one setting in config and one in content, that's not very good UX.

What about if License provides a Billing Schedule type which reads its config from the Product Variation?

bojanz’s picture

We said that a license that's handled by a subscription should have Unlimited expiration.

So, it's probably simplest to have a form alter that forces the license expiration to "Unlimited" if a subscription type field is found.

joachim’s picture

> We said that a license that's handled by a subscription should have Unlimited expiration.

That seems to mean that if a store admin wants to give customers to option of buying a license either as a one-off, or with renewal, they need to create 2 different product variations.

bojanz’s picture

That seems to mean that if a store admin wants to give customers to option of buying a license either as a one-off, or with renewal, they need to create 2 different product variations.

We've made that impossible by making the subscription_type/billing_schedule fields required, no?

joachim’s picture

Assigned: Unassigned » joachim

Working on this...

joachim’s picture

Status: Active » Needs review
StatusFileSize
new18.4 KB

Status: Needs review » Needs work

The last submitted patch, 8: 2924300-8.commerce_license.add-a-CommerceSubscriptionType-plugin-for-licenses.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

bojanz’s picture

+class LicenseSubscription extends SubscriptionTypeBase {

This should be called just License, to follow the naming convention.

+      // Create a new license.
+      $license = $this->licenseStorage->createFromOrderItem($order_item);

It is a big code smell that this plugin is creating licenses. That should never be its job.

+    // TODO: check whether this is the correct state to move the license to.
+    // The License class will handle deactivating the license type plugin.
+    $transition = $license->getState()->getWorkflow()->getTransition('expire');

I'd expect the license to have a canceled state of its own. (equivalent to "revoked" in D7)

joachim’s picture

Status: Needs work » Needs review
StatusFileSize
new23.96 KB

> This should be called just License, to follow the naming convention.

I don't want to have two classes in the module called License -- it's confusing.

> It is a big code smell that this plugin is creating licenses. That should never be its job.

Where else should the license be created? We need it to exist at this point in order to set it on the subscription.

I can't act in onSubscriptionActivate(), as that gets the recurring order rather than the original order. So at that point, I can't get the license that's been created for the original order's order item.

> I'd expect the license to have a canceled state of its own. (equivalent to "revoked" in D7)

It does have a canceled state, but that appears to be only for use during the early stages of the lifecycle, as its only transition is from pending -> canceled. The workflow states were defined by @kazanir and I'm don't completely understand what all of them are for.

Here's a new patch with more testing & fixes that the tests showed up.

Status: Needs review » Needs work

The last submitted patch, 11: 2924300-11.commerce_license.add-a-CommerceSubscriptionType-plugin-for-licenses.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

joachim’s picture

Fixing tests, hopefully...

joachim’s picture

> It does have a canceled state, but that appears to be only for use during the early stages of the lifecycle, as its only transition is from pending -> canceled. The workflow states were defined by @kazanir and I'm don't completely understand what all of them are for.

Going to rename this in #2928281: rename 'canceled' state to 'failed'.

joachim’s picture

> It is a big code smell that this plugin is creating licenses. That should never be its job.

Fixed this.

Here's the final patch.

  • joachim committed 4b0d207 on 8.x-2.x
    Issue #2924300 by joachim, bojanz: Added a Commerce Recurring...
joachim’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.