Skip to content

Commit

Permalink
Merge pull request #32 from craftcms/feature/subscriptions-field
Browse files Browse the repository at this point in the history
Add a subscriptions field
  • Loading branch information
i-just authored Oct 23, 2024
2 parents f5ea0e7 + 90fe9d6 commit 70d1430
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
- Webhook handler now listens for `customer.updated` events. ([#21](https://github.com/craftcms/stripe/pull/21))
- It’s now possible to manually sync Stripe customer data on Edit User pages. ([#21](https://github.com/craftcms/stripe/pull/21))
- Added support for selecting products in Link fields. ([#26](https://github.com/craftcms/stripe/pull/26))
- Added the “Stripe Subscriptions” field type. ([#32](https://github.com/craftcms/stripe/pull/32))
- It’s now possible to save custom field data against a new Subscription when using a checkout form. ([#25](https://github.com/craftcms/stripe/issues/25))
- Added `craft\stripe\events\StripeEvent`. ([#17](https://github.com/craftcms/stripe/issues/17))
- Added `craft\stripe\services\Webhooks::EVENT_STRIPE_EVENT`. ([#17](https://github.com/craftcms/stripe/issues/17))
- Added `craft\stripe\linktypes\Product`. ([#26](https://github.com/craftcms/stripe/pull/26))
- Added `craft\stripe\fields\Subscriptions`. ([#32](https://github.com/craftcms/stripe/pull/32))
- Fixed a SQL error that occurred when syncing a subscriptions that were missing a `latest_invoice` value. ([#21](https://github.com/craftcms/stripe/pull/21))
- Fixed links to stripe dashboard when in live mode. ([#21](https://github.com/craftcms/stripe/pull/21))
- Fixed an error that could occur when syncing Customer and Payment Method data. ([#29](https://github.com/craftcms/stripe/pull/29))
Expand Down
2 changes: 2 additions & 0 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
use craft\stripe\elements\Subscription;
use craft\stripe\fieldlayoutelements\PricesField;
use craft\stripe\fields\Products as ProductsField;
use craft\stripe\fields\Subscriptions as SubscriptionsField;
use craft\stripe\jobs\SyncData;
use craft\stripe\linktypes\Product as ProductLinkType;
use craft\stripe\models\Settings;
Expand Down Expand Up @@ -394,6 +395,7 @@ private function registerFieldTypes(): void
{
Event::on(Fields::class, Fields::EVENT_REGISTER_FIELD_TYPES, static function(RegisterComponentTypesEvent $event) {
$event->types[] = ProductsField::class;
$event->types[] = SubscriptionsField::class;
});
}

Expand Down
54 changes: 54 additions & 0 deletions src/fields/Subscriptions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
/**
* @link https://craftcms.com/
* @copyright Copyright (c) Pixel & Tonic, Inc.
* @license https://craftcms.github.io/license/
*/

namespace craft\stripe\fields;

use Craft;
use craft\fields\BaseRelationField;
use craft\stripe\elements\Subscription;

/**
* Class Stripe Subscriptions Field
*
* @author Pixel & Tonic, Inc. <[email protected]>
*
* @property-read array $contentGqlType
*/
class Subscriptions extends BaseRelationField
{
/**
* @inheritdoc
*/
public static function displayName(): string
{
return Craft::t('stripe', 'Stripe Subscriptions');
}

/**
* @inheritdoc
*/
public static function icon(): string
{
return 'clock-rotate-left';
}

/**
* @inheritdoc
*/
public static function defaultSelectionLabel(): string
{
return Craft::t('stripe', 'Add a subscription');
}

/**
* @inheritdoc
*/
public static function elementType(): string
{
return Subscription::class;
}
}

0 comments on commit 70d1430

Please sign in to comment.