Skip to content

Commit

Permalink
Fix subscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaymo committed Jan 2, 2025
1 parent c5c8e59 commit 4e21d13
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 17 deletions.
15 changes: 8 additions & 7 deletions src/Payment/MollieSubscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ class MollieSubscription extends MollieObject
* Molliesubscription constructor.
*
*/
public function __construct($pluginId, Api $apiHelper, $settingsHelper, $dataHelper, $logger, $paymentMethod)
public function __construct($pluginId, Api $apiHelper, $settingsHelper, $dataHelper, $logger, $paymentMethod, $middleware)
{
$this->pluginId = $pluginId;
$this->apiHelper = $apiHelper;
$this->settingsHelper = $settingsHelper;
$this->dataHelper = $dataHelper;
$this->logger = $logger;
$this->paymentMethod = $paymentMethod;
$this->middleware = $middleware;
}
/**
* @param $order
Expand All @@ -46,11 +47,8 @@ public function getRecurringPaymentRequestData($order, $customerId, $initialPaym
$option = get_option($optionName);
$paymentDescription = $this->getRecurringPaymentDescription($order, $option, $initialPaymentUsedOrderAPI);
$selectedIssuer = $this->paymentMethod->getSelectedIssuer();
$returnUrl = $gateway->get_return_url($order);
$returnUrl = $this->getReturnUrl($order, $returnUrl);
$webhookUrl = $this->getWebhookUrl($order, $gatewayId);

return array_filter([
$requestData = array_filter([
'amount' => [
'currency' => $this->dataHelper->getOrderCurrency($order),
'value' => $this->dataHelper->formatCurrencyValue(
Expand All @@ -59,8 +57,6 @@ public function getRecurringPaymentRequestData($order, $customerId, $initialPaym
),
],
'description' => $paymentDescription,
'redirectUrl' => $returnUrl,
'webhookUrl' => $webhookUrl,
'method' => $methodId,
'issuer' => $selectedIssuer,
'locale' => $paymentLocale,
Expand All @@ -70,6 +66,11 @@ public function getRecurringPaymentRequestData($order, $customerId, $initialPaym
'sequenceType' => 'recurring',
'customerId' => $customerId,
]);
$context = 'payment';
foreach ($this->middleware as $field) {
$requestData = $field->decorate($requestData, $order, $context);
}
return $requestData;
}

protected function getRecurringPaymentDescription($order, $option, $initialPaymentUsedOrderAPI)
Expand Down
15 changes: 7 additions & 8 deletions src/Payment/Request/Decorators/StoreCustomerDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,15 @@ public function __construct(Settings $settingsHelper)
public function decorate(array $requestData, WC_Order $order, $context = null): array
{
$storeCustomer = $this->settingsHelper->shouldStoreCustomer();
$customerId = $order->get_meta('_mollie_customer_id');
if (!$storeCustomer || !$customerId) {
return $requestData;
}
if ($context === 'order') {
$requestData['payment']['customerId'] = $customerId;
} elseif ($context === 'payment') {
$requestData['customerId'] = $customerId;
if (!$storeCustomer) {
if ($context === 'order') {
unset($requestData['payment']['customerId']);
} elseif ($context === 'payment') {
unset($requestData['customerId']);
}
}


return $requestData;
}
}
4 changes: 3 additions & 1 deletion src/Payment/Request/Strategies/OrderRequestStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ public function createRequest(WC_Order $order, $customerId): array
]
),
'orderNumber' => $order->get_order_number(),
'payment' => []
'payment' => [
'customerId' => $customerId,
]
];

$context = 'order';
Expand Down
1 change: 1 addition & 0 deletions src/Payment/Request/Strategies/PaymentRequestStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public function createRequest(WC_Order $order, $customerId): array
'order_id' => $order->get_id(),
]
),
'customerId' => $customerId,
];

$context = 'payment';
Expand Down
4 changes: 3 additions & 1 deletion src/Subscription/MollieSubscriptionGatewayHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Mollie\WooCommerce\Payment\PaymentProcessor;
use Mollie\WooCommerce\Notice\NoticeInterface;
use Mollie\WooCommerce\Payment\MollieOrderService;
use Mollie\WooCommerce\Payment\Request\Decorators\UrlDecorator;
use Mollie\WooCommerce\PaymentMethods\InstructionStrategies\OrderInstructionsManager;
use Mollie\WooCommerce\PaymentMethods\PaymentMethodI;
use Mollie\WooCommerce\SDK\Api;
Expand All @@ -37,7 +38,7 @@ class MollieSubscriptionGatewayHandler extends MolliePaymentGatewayHandler
'mollie_wc_gateway_sofort', ];
protected const DIRECTDEBIT = Constants::DIRECTDEBIT;

protected $isSubscriptionPayment = false;
public $isSubscriptionPayment = false;
protected $apiHelper;
protected $settingsHelper;
/**
Expand Down Expand Up @@ -86,6 +87,7 @@ public function __construct(
$dataService,
$logger,
$paymentMethod,
new UrlDecorator($pluginId, $logger)
);
}

Expand Down

0 comments on commit 4e21d13

Please sign in to comment.