-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add decorators and strategies for request
- Loading branch information
Showing
15 changed files
with
538 additions
and
243 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/Payment/Request/Decorators/AddSequenceTypeForSubscriptionsDecorator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Mollie\WooCommerce\Payment\Decorator; | ||
|
||
use Mollie\WooCommerce\Payment\Request\Decorators\RequestDecoratorInterface; | ||
use Mollie\WooCommerce\Shared\Data; | ||
use WC_Order; | ||
|
||
class AddSequenceTypeForSubscriptionsDecorator implements RequestDecoratorInterface | ||
{ | ||
private Data $dataHelper; | ||
private String $pluginId; | ||
|
||
public function __construct($dataHelper, $pluginId) | ||
{ | ||
$this->dataHelper = $dataHelper; | ||
$this->pluginId = $pluginId; | ||
} | ||
|
||
public function decorate(array $requestData, WC_Order $order, $context): array | ||
{ | ||
$gateway = wc_get_payment_gateway_by_order($order); | ||
if ($gateway) { | ||
$requestData = $this->addSequenceTypeForSubscriptionsFirstPayments($order->get_id(), $gateway, $requestData, $context); | ||
} | ||
return $requestData; | ||
} | ||
|
||
private function addSequenceTypeForSubscriptionsFirstPayments($orderId, $gateway, $requestData, $context): array | ||
{ | ||
if ($this->dataHelper->isSubscription($orderId) || $this->dataHelper->isWcSubscription($orderId)) { | ||
$disable_automatic_payments = apply_filters($this->pluginId . '_is_automatic_payment_disabled', false); | ||
$supports_subscriptions = $gateway->supports('subscriptions'); | ||
|
||
if ($supports_subscriptions == true && $disable_automatic_payments == false) { | ||
$requestData = $this->addSequenceTypeFirst($requestData, $context); | ||
} | ||
} | ||
return $requestData; | ||
} | ||
|
||
private function addSequenceTypeFirst($requestData, $context) | ||
{ | ||
if($context === 'order') { | ||
$requestData['payment']['sequenceType'] = 'first'; | ||
} elseif ($context === 'payment') { | ||
$requestData['sequenceType'] = 'first'; | ||
} | ||
return $requestData; | ||
} | ||
} |
Oops, something went wrong.