From c484568ab8f9f2d0e9fcedfce77739417e68ba6a Mon Sep 17 00:00:00 2001 From: Andre L Date: Thu, 2 Jun 2022 08:39:24 +0100 Subject: [PATCH 1/2] Adds Stripe Prices field type --- src/Stripe.php | 7 ++++- src/elements/Price.php | 23 +++++++++++++-- src/fields/StripePrices.php | 49 ++++++++++++++++++++++++++++++++ src/variables/StripeVariable.php | 23 +++++++++++++++ 4 files changed, 99 insertions(+), 3 deletions(-) create mode 100644 src/fields/StripePrices.php diff --git a/src/Stripe.php b/src/Stripe.php index fd7cd9d..9da4897 100644 --- a/src/Stripe.php +++ b/src/Stripe.php @@ -27,6 +27,7 @@ use enupal\stripe\events\AfterPopulatePaymentFormEvent; use enupal\stripe\events\OrderCompleteEvent; use enupal\stripe\events\WebhookEvent; +use enupal\stripe\fields\StripePrices; use enupal\stripe\fields\StripeProducts; use enupal\stripe\services\App; use enupal\stripe\services\Carts; @@ -116,7 +117,11 @@ function(Event $event) { Event::on(Fields::class, Fields::EVENT_REGISTER_FIELD_TYPES, function(RegisterComponentTypesEvent $event) { $event->types[] = StripePaymentFormsField::class; - $event->types[] = StripeProducts::class; + if (self::getInstance()->is(self::EDITION_PRO)) { + $event->types[] = StripeProducts::class; + $event->types[] = StripePrices::class; + } + }); Event::on(Elements::class, Elements::EVENT_AFTER_SAVE_ELEMENT, function(ElementEvent $event) { diff --git a/src/elements/Price.php b/src/elements/Price.php index 12c74bc..6cd56bb 100644 --- a/src/elements/Price.php +++ b/src/elements/Price.php @@ -96,7 +96,7 @@ public function getCpEditUrl(): ?string */ public function __toString(): string { - $name = $this->getUnitAmount() ?? $this->stripeId; + $name = $this->getLabel() ?? $this->stripeId; return (string)$name; } @@ -171,13 +171,15 @@ protected static function defineSortOptions(): array protected static function defineTableAttributes(): array { $attributes['stripeId'] = ['label' => StripePlugin::t('Stripe Id')]; + $attributes['unitAmount'] = ['label' => StripePlugin::t('Unit Amount')]; + $attributes['type'] = ['label' => StripePlugin::t('Type')]; return $attributes; } protected static function defineDefaultTableAttributes(string $source): array { - $attributes = ['stripeId', 'unitAmount']; + $attributes = ['stripeId', 'unitAmount', 'type']; return $attributes; } @@ -194,6 +196,10 @@ protected function tableAttributeHtml(string $attribute): string { return $this->getUnitAmount(); } + case 'type': + { + return $this->getType(); + } } return parent::tableAttributeHtml($attribute); @@ -243,6 +249,19 @@ public function getUnitAmount() return Craft::$app->getFormatter()->asCurrency($unitAmount, $this->getStripeObject()->currency); } + public function getType() + { + return $this->getStripeObject()->type ?? null; + } + + /** + * @return string|null + */ + private function getLabel() + { + return $this->getStripeObject()->nickname ?? null; + } + public function getStripeObject() { if (is_string($this->stripeObject)) { diff --git a/src/fields/StripePrices.php b/src/fields/StripePrices.php new file mode 100644 index 0000000..7d6625e --- /dev/null +++ b/src/fields/StripePrices.php @@ -0,0 +1,49 @@ +taxes; From 248286e362c9d5888b637ea0c700626236548570 Mon Sep 17 00:00:00 2001 From: Andre L Date: Thu, 2 Jun 2022 08:42:15 +0100 Subject: [PATCH 2/2] Adds v5.0.2 --- CHANGELOG.md | 8 ++++++++ composer.json | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 31ccf76..722df92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Stripe Payments Changelog +## 5.0.2 - 2022.06.02 +### Added +- Added the `craft.enupalStripe.app` service layer to twig variable ([#289]) +- Added the `Stripe Prices` field type ([#288]) + +[#288]: https://github.com/enupal/stripe/issues/288 +[#289]: https://github.com/enupal/stripe/issues/289 + ## 5.0.1 - 2022.05.28 ### Fixed - Fixed issue when creating a Stripe Products field type diff --git a/composer.json b/composer.json index 13ff8fd..5c2e762 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "enupal/stripe", "description": "Allows customers sign up for recurring and one-time payments with Stripe, perfect for orders, donations, subscriptions, and events. Create simple payment forms in seconds easily without coding. For Craft CMS 3.x", "type": "craft-plugin", - "version": "5.0.1", + "version": "5.0.2", "keywords": [ "craft", "cms",