Skip to content

Commit b95dec6

Browse files
Feature: V3 support
1 parent 19d29f7 commit b95dec6

20 files changed

Lines changed: 430 additions & 463 deletions

.github/workflows/integration-test.yml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@ jobs:
77
fail-fast: false
88
matrix:
99
include:
10-
- PHP_VERSION: php73-fpm
11-
MAGENTO_VERSION: 2.3.7-p3
12-
- PHP_VERSION: php74-fpm
13-
MAGENTO_VERSION: 2.4.4
10+
- PHP_VERSION: php81-fpm
11+
MAGENTO_VERSION: 2.4.6-p4
1412
- PHP_VERSION: php84-fpm
15-
MAGENTO_VERSION: 2.4.8
13+
MAGENTO_VERSION: 2.4.8-p3
1614
runs-on: ubuntu-latest
1715
steps:
1816
- uses: actions/checkout@v3
@@ -23,8 +21,14 @@ jobs:
2321
- name: Upload the code into the docker container
2422
run: docker cp $(pwd)/. magento-project-community-edition:/data/extensions/mollie-magento2-subscriptions/
2523

24+
- name: Set stability
25+
run: docker exec magento-project-community-edition composer config minimum-stability dev
26+
2627
- name: Install Mollie and Mollie Subscription extensions
27-
run: docker exec magento-project-community-edition ./install-composer-package mollie/magento2 mollie/magento2-subscriptions:@dev
28+
run: |
29+
docker exec magento-project-community-edition ./install-composer-package mollie/magento2-subscriptions:@dev
30+
docker exec magento-project-community-edition rm -rf vendor/mollie/magento2
31+
docker exec magento-project-community-edition composer install --prefer-source
2832
2933
- name: Enable modules
3034
run: docker exec magento-project-community-edition bash -c "php bin/magento module:enable Mollie_Payment Mollie_Subscriptions && php bin/magento setup:upgrade"

.github/workflows/linting.yml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,6 @@ name: Lint PHP files
22
on: [push, pull_request]
33

44
jobs:
5-
php-73:
6-
runs-on: ubuntu-latest
7-
steps:
8-
- uses: prestashop/github-action-php-lint/7.3@v2.3.1
9-
10-
php-74:
11-
runs-on: ubuntu-latest
12-
steps:
13-
- uses: prestashop/github-action-php-lint/7.4@v2.3.1
14-
155
php-81:
166
runs-on: ubuntu-latest
177
steps:

.github/workflows/phpstan.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@ jobs:
66
strategy:
77
matrix:
88
include:
9-
- PHP_VERSION: php73-fpm
10-
MAGENTO_VERSION: 2.3.7-p3
11-
- PHP_VERSION: php74-fpm
12-
MAGENTO_VERSION: 2.4.4
13-
- PHP_VERSION: php84-fpm
14-
MAGENTO_VERSION: 2.4.8
9+
- PHP_VERSION: php81-fpm
10+
MAGENTO_VERSION: 2.4.6-p4
11+
- PHP_VERSION: php84-fpm
12+
MAGENTO_VERSION: 2.4.8-p3
1513
runs-on: ubuntu-latest
1614
steps:
1715
- uses: actions/checkout@v3
@@ -22,8 +20,11 @@ jobs:
2220
- name: Upload the code into the docker container
2321
run: docker cp $(pwd)/. magento-project-community-edition:/data/extensions/mollie-magento2-subscriptions/
2422

23+
- name: Set stability
24+
run: docker exec magento-project-community-edition composer config minimum-stability dev
25+
2526
- name: Install Mollie and Mollie Subscription extensions
26-
run: docker exec magento-project-community-edition ./install-composer-package mollie/magento2 mollie/magento2-subscriptions:@dev
27+
run: docker exec magento-project-community-edition ./install-composer-package mollie/magento2-subscriptions:@dev
2728

2829
- name: Install Mollie and Mollie Subscription extensions and run setup:di:compile
2930
run: |

.github/workflows/setup-di-compile.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@ jobs:
66
strategy:
77
matrix:
88
include:
9-
- PHP_VERSION: php73-fpm
10-
MAGENTO_VERSION: 2.3.7-p3
11-
- PHP_VERSION: php74-fpm
12-
MAGENTO_VERSION: 2.4.4
13-
- PHP_VERSION: php84-fpm
14-
MAGENTO_VERSION: 2.4.8
9+
- PHP_VERSION: php81-fpm
10+
MAGENTO_VERSION: 2.4.6-p4
11+
- PHP_VERSION: php84-fpm
12+
MAGENTO_VERSION: 2.4.8-p3
1513
runs-on: ubuntu-latest
1614
steps:
1715
- uses: actions/checkout@v3
@@ -22,8 +20,11 @@ jobs:
2220
- name: Upload the code into the docker container
2321
run: docker cp $(pwd)/. magento-project-community-edition:/data/extensions/mollie-magento2-subscriptions/
2422

23+
- name: Set stability
24+
run: docker exec magento-project-community-edition composer config minimum-stability dev
25+
2526
- name: Install Mollie and Mollie Subscription extensions
26-
run: docker exec magento-project-community-edition ./install-composer-package mollie/magento2 mollie/magento2-subscriptions:@dev
27+
run: docker exec magento-project-community-edition ./install-composer-package mollie/magento2-subscriptions:@dev
2728

2829
- name: Run setup:di:compile
2930
run: docker exec magento-project-community-edition ./retry "php bin/magento setup:di:compile"

Block/Frontend/Customer/Account/ActiveSubscriptions.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ public function __construct(
4848
$this->priceCurrency = $priceCurrency;
4949
}
5050

51+
/**
52+
* @param float $amount
53+
* @return string
54+
*/
55+
public function formatPrice(float $amount): string
56+
{
57+
return $this->priceCurrency->convertAndFormat($amount);
58+
}
59+
5160
/**
5261
* @return SubscriptionResponse[]
5362
*/
@@ -64,7 +73,7 @@ public function getSubscriptions(): array
6473
}
6574

6675
$api = $this->mollieSubscriptionApi->loadByStore($customer->getStoreId());
67-
$subscriptions = $api->subscriptions->listForId($extensionAttributes->getMollieCustomerId());
76+
$subscriptions = $api->subscriptions->pageForId($extensionAttributes->getMollieCustomerId());
6877

6978
$this->subscriptions = array_map(function ($subscription) use ($customer) {
7079
return new SubscriptionResponse($subscription, $customer);
@@ -83,13 +92,4 @@ public function hasParent(string $subscriptionId): bool
8392

8493
return false;
8594
}
86-
87-
/**
88-
* @param float $amount
89-
* @return string
90-
*/
91-
public function formatPrice(float $amount): string
92-
{
93-
return $this->priceCurrency->convertAndFormat($amount);
94-
}
9595
}

Controller/Index/Restart.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
namespace Mollie\Subscriptions\Controller\Index;
88

9+
use Exception;
910
use Magento\Catalog\Model\Product;
1011
use Magento\Customer\Helper\Session\CurrentCustomer;
1112
use Magento\Customer\Model\Session;
@@ -22,6 +23,7 @@
2223
use Mollie\Subscriptions\Api\SubscriptionToProductRepositoryInterface;
2324
use Mollie\Subscriptions\Service\Email\SendNotificationEmail;
2425
use Mollie\Subscriptions\Service\Mollie\MollieSubscriptionApi;
26+
use stdClass;
2527

2628
class Restart extends Action implements HttpPostActionInterface
2729
{
@@ -147,7 +149,7 @@ public function execute()
147149
]);
148150

149151
$this->saveSubscriptionResult($subscription);
150-
} catch (\Exception $exception) {
152+
} catch (Exception $exception) {
151153
$this->messageManager->addErrorMessage(__('We are unable to restart the subscription'));
152154

153155
$this->config->addToLog('error', [
@@ -164,16 +166,16 @@ public function execute()
164166
return $this->_redirect('*/*/index');
165167
}
166168

167-
private function getMetadata(Subscription $canceledSubscription)
169+
private function getMetadata(Subscription $canceledSubscription): ?array
168170
{
169-
if ($canceledSubscription->metadata instanceof \stdClass) {
170-
$metadata = $canceledSubscription->metadata;
171-
$metadata->parent_id = $canceledSubscription->id;
171+
if ($canceledSubscription->metadata instanceof stdClass) {
172+
$metadata = json_decode(json_encode($canceledSubscription->metadata), true);
173+
$metadata['parent_id'] = $canceledSubscription->id;
172174

173175
return $metadata;
174176
}
175177

176-
return [];
178+
return null;
177179
}
178180

179181
private function saveSubscriptionResult(Subscription $subscription)

Model/MollieSubscriptionsListing.php

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
namespace Mollie\Subscriptions\Model;
88

9+
use DateInterval;
10+
use DateTimeImmutable;
911
use Magento\Customer\Api\CustomerRepositoryInterface;
1012
use Magento\Customer\Api\Data\CustomerInterface;
1113
use Magento\Customer\Api\Data\CustomerInterfaceFactory;
@@ -93,12 +95,16 @@ public function getDataSourceData()
9395
$api = $this->mollieSubscriptionApi->loadByStore($storeId);
9496
$paging = $this->getContext()->getRequestParam('paging');
9597

96-
$pageSize = $paging['pageSize'] ?? 20;
98+
$pageSize = $paging['pageSize'] ?? null;
9799
if ($pageSize > 250) {
98100
$pageSize = 250;
99101
}
100102

101-
$result = $api->subscriptions->page(
103+
if (!$this->getContext()->getRequestParam('offsetID')) {
104+
$pageSize = null;
105+
}
106+
107+
$result = $api->subscriptions->allFor(
102108
$this->getContext()->getRequestParam('offsetID'),
103109
$pageSize
104110
);
@@ -110,8 +116,8 @@ public function getDataSourceData()
110116
$items = array_map(function (Subscription $subscription) use ($daysBeforeReminder) {
111117
$prePaymentReminder = null;
112118
if ($subscription->nextPaymentDate) {
113-
$prePaymentReminder = new \DateTimeImmutable($subscription->nextPaymentDate);
114-
$prePaymentReminder = $prePaymentReminder->sub(new \DateInterval('P' . $daysBeforeReminder . 'D'));
119+
$prePaymentReminder = new DateTimeImmutable($subscription->nextPaymentDate);
120+
$prePaymentReminder = $prePaymentReminder->sub(new DateInterval('P' . $daysBeforeReminder . 'D'));
115121
}
116122

117123
$response = new SubscriptionResponse(
@@ -132,23 +138,6 @@ public function getDataSourceData()
132138
];
133139
}
134140

135-
private function preloadCustomers(array $result)
136-
{
137-
$mollieCustomerIds = array_column($result, 'customerId');
138-
139-
$searchCriteria = $this->searchCriteriaBuilderFactory->create();
140-
$searchCriteria->addFilter('mollie_customer_id', $mollieCustomerIds, 'in');
141-
$result = $this->mollieCustomerRepository->getList($searchCriteria->create());
142-
143-
$customerIds = array_map(function (MollieCustomerInterface $customerInfo) {
144-
return $customerInfo->getCustomerId();
145-
}, $result->getItems());
146-
147-
$searchCriteria = $this->searchCriteriaBuilderFactory->create();
148-
$searchCriteria->addFilter('entity_id', $customerIds, 'in');
149-
$this->customers = $this->customerRepository->getList($searchCriteria->create())->getItems();
150-
}
151-
152141
private function getCustomerMollieCustomerById(string $customerId)
153142
{
154143
foreach ($this->customers as $customer) {
@@ -160,6 +149,14 @@ private function getCustomerMollieCustomerById(string $customerId)
160149
return $this->customerFactory->create();
161150
}
162151

152+
private function parseLink(string $link): string
153+
{
154+
$query = parse_url($link, PHP_URL_QUERY);
155+
parse_str($query, $parts);
156+
157+
return $parts['from'];
158+
}
159+
163160
private function parsePreviousNext(SubscriptionCollection $result)
164161
{
165162
if ($result->hasNext()) {
@@ -171,11 +168,20 @@ private function parsePreviousNext(SubscriptionCollection $result)
171168
}
172169
}
173170

174-
private function parseLink(string $link): string
171+
private function preloadCustomers(array $result)
175172
{
176-
$query = parse_url($link, PHP_URL_QUERY);
177-
parse_str($query, $parts);
173+
$mollieCustomerIds = array_column($result, 'customerId');
178174

179-
return $parts['from'];
175+
$searchCriteria = $this->searchCriteriaBuilderFactory->create();
176+
$searchCriteria->addFilter('mollie_customer_id', $mollieCustomerIds, 'in');
177+
$result = $this->mollieCustomerRepository->getList($searchCriteria->create());
178+
179+
$customerIds = array_map(function (MollieCustomerInterface $customerInfo) {
180+
return $customerInfo->getCustomerId();
181+
}, $result->getItems());
182+
183+
$searchCriteria = $this->searchCriteriaBuilderFactory->create();
184+
$searchCriteria->addFilter('entity_id', $customerIds, 'in');
185+
$this->customers = $this->customerRepository->getList($searchCriteria->create())->getItems();
180186
}
181187
}

Observer/MollieProcessTransactionEnd/CreateSubscriptions.php

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Mollie\Subscriptions\Service\Mollie\MollieSubscriptionApi;
2323
use Mollie\Subscriptions\Service\Mollie\SubscriptionOptions;
2424
use Mollie\Subscriptions\Service\Order\OrderContainsSubscriptionProduct;
25+
use Throwable;
2526

2627
class CreateSubscriptions implements ObserverInterface
2728
{
@@ -131,6 +132,38 @@ public function execute(Observer $observer)
131132
$this->orderRepository->save($order);
132133
}
133134

135+
private function createSubscription(string $customerId, SubscriptionOption $subscriptionOptions)
136+
{
137+
try {
138+
$this->config->addToLog('request', ['customerId' => $customerId, 'options' => $subscriptionOptions->toArray()]);
139+
$subscription = $this->mollieApi->subscriptions->createForId($customerId, $subscriptionOptions->toArray());
140+
141+
/** @var SubscriptionToProductInterface $model */
142+
$model = $this->subscriptionToProductFactory->create();
143+
$model->setCustomerId($subscription->customerId);
144+
$model->setSubscriptionId($subscription->id);
145+
$model->setProductId($subscriptionOptions->getProductId());
146+
$model->setStoreId($subscriptionOptions->getStoreId());
147+
$model->setNextPaymentDate($subscription->nextPaymentDate);
148+
149+
$model = $this->subscriptionToProductRepository->save($model);
150+
151+
$this->eventManager->dispatch('mollie_subscription_created', ['subscription' => $model]);
152+
153+
$this->sendAdminNotificationEmail->execute($model);
154+
$this->sendCustomerNotificationEmail->execute($model);
155+
} catch (Throwable $exception) {
156+
$this->config->addToLog('error', [
157+
'message' => 'Error while trying to create subscription for order',
158+
'subscription_options' => $subscriptionOptions->toArray(),
159+
'exception' => $exception->getMessage(),
160+
'trace' => $exception->getTraceAsString(),
161+
]);
162+
163+
throw $exception;
164+
}
165+
}
166+
134167
private function getPayment(OrderInterface $order)
135168
{
136169
$transactionId = $order->getPayment()->getAdditionalInformation()['mollie_id'];
@@ -142,25 +175,4 @@ private function getPayment(OrderInterface $order)
142175

143176
return $this->mollieApi->payments->get($transactionId);
144177
}
145-
146-
private function createSubscription(string $customerId, SubscriptionOption $subscriptionOptions)
147-
{
148-
$this->config->addToLog('request', ['customerId' => $customerId, 'options' => $subscriptionOptions->toArray()]);
149-
$subscription = $this->mollieApi->subscriptions->createForId($customerId, $subscriptionOptions->toArray());
150-
151-
/** @var SubscriptionToProductInterface $model */
152-
$model = $this->subscriptionToProductFactory->create();
153-
$model->setCustomerId($subscription->customerId);
154-
$model->setSubscriptionId($subscription->id);
155-
$model->setProductId($subscriptionOptions->getProductId());
156-
$model->setStoreId($subscriptionOptions->getStoreId());
157-
$model->setNextPaymentDate($subscription->nextPaymentDate);
158-
159-
$model = $this->subscriptionToProductRepository->save($model);
160-
161-
$this->eventManager->dispatch('mollie_subscription_created', ['subscription' => $model]);
162-
163-
$this->sendAdminNotificationEmail->execute($model);
164-
$this->sendCustomerNotificationEmail->execute($model);
165-
}
166178
}

0 commit comments

Comments
 (0)