From 3584c9270aeeca618e7221f46fd885078b459efd Mon Sep 17 00:00:00 2001 From: Matus Kalafut Date: Mon, 26 Oct 2020 13:10:58 +0000 Subject: [PATCH] Disable stopping prepaid recurrent payments for users and admins remp/crm#1504 --- src/AppleAppstoreModule.php | 16 ++++++++ .../StopRecurrentPaymentInfoWidget.php | 33 ++++++++++++++++ .../stop_recurrent_payment_info_widget.latte | 30 ++++++++++++++ src/config/config.neon | 2 + src/lang/apple_appstore.cs_CZ.neon | 7 ++++ src/lang/apple_appstore.en_US.neon | 7 ++++ src/lang/apple_appstore.sk_SK.neon | 7 ++++ src/seeders/SnippetsSeeder.php | 39 +++++++++++++++++++ ...apple-stop-recurrent-info-widget-text.html | 1 + 9 files changed, 142 insertions(+) create mode 100644 src/components/StopRecurrentPaymentInfoWidget/StopRecurrentPaymentInfoWidget.php create mode 100644 src/components/StopRecurrentPaymentInfoWidget/stop_recurrent_payment_info_widget.latte create mode 100644 src/seeders/SnippetsSeeder.php create mode 100644 src/seeders/snippets/apple-stop-recurrent-info-widget-text.html diff --git a/src/AppleAppstoreModule.php b/src/AppleAppstoreModule.php index ffd8c35..534795e 100644 --- a/src/AppleAppstoreModule.php +++ b/src/AppleAppstoreModule.php @@ -9,6 +9,7 @@ use Crm\ApplicationModule\CrmModule; use Crm\ApplicationModule\DataProvider\DataProviderManager; use Crm\ApplicationModule\SeederManager; +use Crm\ApplicationModule\Widget\WidgetManagerInterface; use Crm\UsersModule\Auth\UserTokenAuthorization; use League\Event\Emitter; @@ -45,6 +46,7 @@ public function registerSeeders(SeederManager $seederManager) { $seederManager->addSeeder($this->getInstance(\Crm\AppleAppstoreModule\Seeders\ConfigsSeeder::class)); $seederManager->addSeeder($this->getInstance(\Crm\AppleAppstoreModule\Seeders\PaymentGatewaysSeeder::class)); + $seederManager->addSeeder($this->getInstance(\Crm\AppleAppstoreModule\Seeders\SnippetsSeeder::class), 100); } public function registerEventHandlers(Emitter $emitter) @@ -66,4 +68,18 @@ public function registerDataProviders(DataProviderManager $dataProviderManager) $this->getInstance(\Crm\AppleAppstoreModule\DataProviders\AccessTokenDataProvider::class) ); } + + public function registerWidgets(WidgetManagerInterface $widgetManager) + { + $widgetManager->registerWidget( + 'frontend.payments.listing.recurrent', + $this->getInstance(\Crm\AppleAppstoreModule\Components\StopRecurrentPaymentInfoWidget::class), + 100 + ); + $widgetManager->registerWidget( + 'payments.user_payments.listing.recurrent', + $this->getInstance(\Crm\AppleAppstoreModule\Components\StopRecurrentPaymentInfoWidget::class), + 100 + ); + } } diff --git a/src/components/StopRecurrentPaymentInfoWidget/StopRecurrentPaymentInfoWidget.php b/src/components/StopRecurrentPaymentInfoWidget/StopRecurrentPaymentInfoWidget.php new file mode 100644 index 0000000..e525c0e --- /dev/null +++ b/src/components/StopRecurrentPaymentInfoWidget/StopRecurrentPaymentInfoWidget.php @@ -0,0 +1,33 @@ +payment_gateway->code !== AppleAppstoreGateway::GATEWAY_CODE) { + return; + } + $this->template->setFile(__DIR__ . DIRECTORY_SEPARATOR . $this->templateName); + $this->template->render(); + } +} diff --git a/src/components/StopRecurrentPaymentInfoWidget/stop_recurrent_payment_info_widget.latte b/src/components/StopRecurrentPaymentInfoWidget/stop_recurrent_payment_info_widget.latte new file mode 100644 index 0000000..5598eea --- /dev/null +++ b/src/components/StopRecurrentPaymentInfoWidget/stop_recurrent_payment_info_widget.latte @@ -0,0 +1,30 @@ + + {_"apple_appstore.frontend.stop_recurrent_payment_info_widget.info_button"} + + + + + + diff --git a/src/config/config.neon b/src/config/config.neon index b9dbc9e..42c7abb 100644 --- a/src/config/config.neon +++ b/src/config/config.neon @@ -10,6 +10,7 @@ services: serverToServerNotificationProcessor: Crm\AppleAppstoreModule\Model\ServerToServerNotificationProcessor - Crm\AppleAppstoreModule\Api\ServerToServerNotificationWebhookApiHandler(@serverToServerNotificationProcessor) - Crm\AppleAppstoreModule\Api\VerifyPurchaseApiHandler + - Crm\AppleAppstoreModule\Components\StopRecurrentPaymentInfoWidget - Crm\AppleAppstoreModule\DataProviders\AccessTokenDataProvider - Crm\AppleAppstoreModule\Events\PairDeviceAccessTokensEventHandler - Crm\AppleAppstoreModule\Events\RemovedAccessTokenEventHandler @@ -21,3 +22,4 @@ services: - Crm\AppleAppstoreModule\Repository\AppleAppstoreTransactionDeviceTokensRepository - Crm\AppleAppstoreModule\Seeders\ConfigsSeeder - Crm\AppleAppstoreModule\Seeders\PaymentGatewaysSeeder + - Crm\AppleAppstoreModule\Seeders\SnippetsSeeder diff --git a/src/lang/apple_appstore.cs_CZ.neon b/src/lang/apple_appstore.cs_CZ.neon index 5cd29b0..18191a5 100644 --- a/src/lang/apple_appstore.cs_CZ.neon +++ b/src/lang/apple_appstore.cs_CZ.neon @@ -5,3 +5,10 @@ config: gateway_mode: name: Apple ITunes gateway mode description: 'Přepínač pro "test" (sandbox) mód nebo "live" (production) mód' + +frontend: + stop_recurrent_payment_info_widget: + info_button: Jak zastavit opakování + modal_title: Zastavit opakování platby + modal_text_manual: 'Viz návod, jak zastavit platbu v Apple AppStore.' + close: Zavřít diff --git a/src/lang/apple_appstore.en_US.neon b/src/lang/apple_appstore.en_US.neon index 3710d3d..42b185a 100644 --- a/src/lang/apple_appstore.en_US.neon +++ b/src/lang/apple_appstore.en_US.neon @@ -5,3 +5,10 @@ config: gateway_mode: name: Apple ITunes gateway mode description: 'Switch for "test" (sandbox) mode or "live" (production) mode' + +frontend: + stop_recurrent_payment_info_widget: + info_button: How to stop recurrent + modal_title: Stop recurrent payment + modal_text_manual: 'See instructions how to stop recurrent payment in Apple AppStore.' + close: Close diff --git a/src/lang/apple_appstore.sk_SK.neon b/src/lang/apple_appstore.sk_SK.neon index a1b43c5..1a982c1 100644 --- a/src/lang/apple_appstore.sk_SK.neon +++ b/src/lang/apple_appstore.sk_SK.neon @@ -5,3 +5,10 @@ config: gateway_mode: name: Apple ITunes gateway mode description: 'Prepínač pre "test" (sandbox) mód alebo "live" (production) mód' + +frontend: + stop_recurrent_payment_info_widget: + info_button: Ako zastaviť opakovanie + modal_title: Zastaviť opakovanie platby + modal_text_manual: 'Pozrite si návod, ako zastaviť platbu v Apple AppStore.' + close: Zatvoriť diff --git a/src/seeders/SnippetsSeeder.php b/src/seeders/SnippetsSeeder.php new file mode 100644 index 0000000..955ef65 --- /dev/null +++ b/src/seeders/SnippetsSeeder.php @@ -0,0 +1,39 @@ +snippetsRepository = $snippetsRepository; + } + + public function seed(OutputInterface $output) + { + $sorting = 1100; + foreach (glob(__DIR__ . '/snippets/*.html') as $filename) { + $info = pathinfo($filename); + $key = $info['filename']; + + $snippet = $this->snippetsRepository->findBy('identifier', $key); + $value = file_get_contents($filename); + + if (!$snippet) { + $this->snippetsRepository->add($key, $key, $value, $sorting++, true, true); + $output->writeln(' * snippet ' . $key . ' created'); + } elseif ($snippet->has_default_value && $snippet->html !== $value) { + $this->snippetsRepository->update($snippet, ['html' => $value, 'has_default_value' => true]); + $output->writeln(' * snippet ' . $key . ' updated'); + } else { + $output->writeln(' * snippet ' . $key . ' exists'); + } + } + } +} diff --git a/src/seeders/snippets/apple-stop-recurrent-info-widget-text.html b/src/seeders/snippets/apple-stop-recurrent-info-widget-text.html new file mode 100644 index 0000000..84803c5 --- /dev/null +++ b/src/seeders/snippets/apple-stop-recurrent-info-widget-text.html @@ -0,0 +1 @@ +Unfortunately we are unable to cancel your auto-renewing subscription at this site because you purchased it on your mobile device, not on our site.