Skip to content

Commit

Permalink
Disable stopping prepaid recurrent payments for users and admins
Browse files Browse the repository at this point in the history
remp/crm#1504
  • Loading branch information
Matefko committed Oct 26, 2020
1 parent 51cb230 commit 3584c92
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/AppleAppstoreModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
Expand All @@ -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
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Crm\AppleAppstoreModule\Components;

use Crm\AppleAppstoreModule\Gateways\AppleAppstoreGateway;
use Crm\ApplicationModule\Widget\BaseWidget;
use Crm\ApplicationModule\Widget\WidgetManager;

class StopRecurrentPaymentInfoWidget extends BaseWidget
{
private $templateName = 'stop_recurrent_payment_info_widget.latte';


public function __construct(
WidgetManager $widgetManager
) {
parent::__construct($widgetManager);
}

public function identifier()
{
return 'stopapplerecurrentpaymentbuttonwidget';
}

public function render($recurrentPayment)
{
if ($recurrentPayment->payment_gateway->code !== AppleAppstoreGateway::GATEWAY_CODE) {
return;
}
$this->template->setFile(__DIR__ . DIRECTORY_SEPARATOR . $this->templateName);
$this->template->render();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<a class="small" data-toggle="modal" data-target="#infoModal" style="display: block; padding-top: 4%; color: #b00c28; cursor: pointer">
<i class="fa fa-info-circle fa-wh"></i> {_"apple_appstore.frontend.stop_recurrent_payment_info_widget.info_button"}
</a>

<style>
.modal-title {
font-weight: bold;
font-size: 125%;
}
</style>

<!-- Modal -->
<div class="modal fade" id="infoModal" tabindex="-1" role="dialog" aria-labelledby="infoModalLabel"
aria-hidden="true" style="top: 48px">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="infoModalLabel"
id="exampleModalLabel">{_"apple_appstore.frontend.stop_recurrent_payment_info_widget.modal_title"}</h5>
</div>
<div class="modal-body">
<p>{control snippet 'apple-stop-recurrent-info-widget-text'}</p>
<p>{_"apple_appstore.frontend.stop_recurrent_payment_info_widget.modal_text_manual"|noescape}</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">{_"apple_appstore.frontend.stop_recurrent_payment_info_widget.close"}</button>
</div>
</div>
</div>
</div>
2 changes: 2 additions & 0 deletions src/config/config.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,3 +22,4 @@ services:
- Crm\AppleAppstoreModule\Repository\AppleAppstoreTransactionDeviceTokensRepository
- Crm\AppleAppstoreModule\Seeders\ConfigsSeeder
- Crm\AppleAppstoreModule\Seeders\PaymentGatewaysSeeder
- Crm\AppleAppstoreModule\Seeders\SnippetsSeeder
7 changes: 7 additions & 0 deletions src/lang/apple_appstore.cs_CZ.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a class="link" href="https://support.apple.com/cz-cz/HT202039" target="_blank" style="font-weight: bold; color: #b00c28;">návod</a>, jak zastavit platbu v Apple AppStore.'
close: Zavřít
7 changes: 7 additions & 0 deletions src/lang/apple_appstore.en_US.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a class="link" href="https://support.apple.com/en-us/HT202039" target="_blank" style="font-weight: bold; color: #b00c28;">instructions</a> how to stop recurrent payment in Apple AppStore.'
close: Close
7 changes: 7 additions & 0 deletions src/lang/apple_appstore.sk_SK.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a class="link" href="https://support.apple.com/sk-sk/HT202039" target="_blank" style="font-weight: bold; color: #b00c28;">návod</a>, ako zastaviť platbu v Apple AppStore.'
close: Zatvoriť
39 changes: 39 additions & 0 deletions src/seeders/SnippetsSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Crm\AppleAppstoreModule\Seeders;

use Crm\ApplicationModule\Seeders\ISeeder;
use Crm\ApplicationModule\Snippet\Repository\SnippetsRepository;
use Symfony\Component\Console\Output\OutputInterface;

class SnippetsSeeder implements ISeeder
{
private $snippetsRepository;

public function __construct(SnippetsRepository $snippetsRepository)
{
$this->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(' <comment>* snippet <info>' . $key . '</info> created</comment>');
} elseif ($snippet->has_default_value && $snippet->html !== $value) {
$this->snippetsRepository->update($snippet, ['html' => $value, 'has_default_value' => true]);
$output->writeln(' <comment>* snippet <info>' . $key . '</info> updated</comment>');
} else {
$output->writeln(' * snippet <info>' . $key . '</info> exists');
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit 3584c92

Please sign in to comment.