-
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.
- Loading branch information
1 parent
e61b17c
commit c2077b4
Showing
21 changed files
with
677 additions
and
21 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
40 changes: 40 additions & 0 deletions
40
src/MerchantCapture/Capture/Action/AbstractPaymentCaptureAction.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,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Mollie\WooCommerce\MerchantCapture\Capture\Action; | ||
|
||
use Mollie\WooCommerce\SDK\Api; | ||
use Mollie\WooCommerce\Settings\Settings; | ||
use Psr\Log\LoggerInterface; | ||
|
||
class AbstractPaymentCaptureAction | ||
{ | ||
protected $apiHelper; | ||
protected $settingsHelper; | ||
protected $apiKey; | ||
protected $order; | ||
protected $logger; | ||
protected $pluginId; | ||
|
||
public function __construct( | ||
int $orderId, | ||
Api $apiHelper, | ||
Settings $settingsHelper, | ||
LoggerInterface $logger, | ||
string $pluginId | ||
) { | ||
|
||
$this->apiHelper = $apiHelper; | ||
$this->settingsHelper = $settingsHelper; | ||
$this->order = wc_get_order($orderId); | ||
$this->logger = $logger; | ||
$this->pluginId = $pluginId; | ||
$this->setApiKey(); | ||
} | ||
|
||
protected function setApiKey() | ||
{ | ||
$this->apiKey = $this->settingsHelper->getApiKey(); | ||
} | ||
} |
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,65 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Mollie\WooCommerce\MerchantCapture\Capture\Action; | ||
|
||
use Mollie\Api\Exceptions\ApiException; | ||
use Mollie\WooCommerce\MerchantCapture\ManualCaptureStatus; | ||
use Mollie\WooCommerce\MerchantCapture\MerchantCaptureModule; | ||
|
||
class CapturePayment extends AbstractPaymentCaptureAction | ||
{ | ||
public function __invoke() | ||
{ | ||
try { | ||
$paymentId = $this->order->get_meta('_mollie_payment_id'); | ||
|
||
if (!$paymentId) { | ||
$this->logger->error('Missing Mollie payment ID in order ' . $this->order->get_id()); | ||
$this->order->add_order_note( | ||
__( | ||
'The Mollie payment ID is missing, and we are unable to capture the funds.', | ||
'mollie-payments-for-woocommerce' | ||
) | ||
); | ||
return; | ||
} | ||
|
||
$paymentCapturesApi = $this->apiHelper->getApiClient($this->apiKey)->paymentCaptures; | ||
$captureData = [ | ||
'amount' => [ | ||
'currency' => $this->order->get_currency(), | ||
'value' => $this->order->get_total(), | ||
], | ||
]; | ||
$this->logger->debug( | ||
'SEND AN ORDER CAPTURE, orderId: ' . $this->order->get_id( | ||
) . ' transactionId: ' . $paymentId . 'Capture data: ' . json_encode($captureData) | ||
); | ||
$paymentCapturesApi->createForId($paymentId, $captureData); | ||
$this->order->update_meta_data( | ||
MerchantCaptureModule::ORDER_PAYMENT_STATUS_META_KEY, | ||
ManualCaptureStatus::STATUS_WAITING | ||
); | ||
$this->order->add_order_note( | ||
sprintf( | ||
__( | ||
'The payment capture of %s has been sent successfully, and we are currently awaiting confirmation.', | ||
'mollie-payments-for-woocommerce' | ||
), | ||
wc_price($this->order->get_total()) | ||
) | ||
); | ||
$this->order->save(); | ||
} catch (ApiException $exception) { | ||
$this->logger->error($exception->getMessage()); | ||
$this->order->add_order_note( | ||
__( | ||
'Payment Capture Failed. We encountered an issue while processing the payment capture.', | ||
'mollie-payments-for-woocommerce' | ||
) | ||
); | ||
} | ||
} | ||
} |
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,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Mollie\WooCommerce\MerchantCapture\Capture\Action; | ||
|
||
use Mollie\Api\Exceptions\ApiException; | ||
use Mollie\WooCommerce\MerchantCapture\ManualCaptureStatus; | ||
use Mollie\WooCommerce\MerchantCapture\MerchantCaptureModule; | ||
|
||
class VoidPayment extends AbstractPaymentCaptureAction | ||
{ | ||
public function __invoke() | ||
{ | ||
$paymentId = $this->order->get_meta('_mollie_payment_id'); | ||
$paymentCapturesApi = $this->apiHelper->getApiClient($this->apiKey)->payments; | ||
try { | ||
$paymentCapturesApi->cancel($paymentId); | ||
$this->order->update_meta_data( | ||
MerchantCaptureModule::ORDER_PAYMENT_STATUS_META_KEY, | ||
ManualCaptureStatus::STATUS_VOIDED | ||
); | ||
$this->order->save(); | ||
} catch (ApiException $exception) { | ||
$this->logger->error($exception->getMessage()); | ||
$this->order->add_order_note( | ||
__( | ||
'Payment Void Failed. We encountered an issue while canceling the pre-authorized payment.', | ||
'mollie-payments-for-woocommerce' | ||
) | ||
); | ||
} | ||
} | ||
} |
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,51 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Mollie\WooCommerce\MerchantCapture\Capture\Type; | ||
|
||
use Mollie\WooCommerce\MerchantCapture\Capture\Action\CapturePayment; | ||
use Mollie\WooCommerce\Vendor\Psr\Container\ContainerInterface; | ||
|
||
class ManualCapture | ||
{ | ||
/** | ||
* @var ContainerInterface $container | ||
*/ | ||
protected $container; | ||
protected const MOLLIE_MANUAL_CAPTURE_ACTION = 'mollie_capture_authorized_payment'; | ||
|
||
public function __construct(ContainerInterface $container) | ||
{ | ||
$this->container = $container; | ||
add_action('woocommerce_order_actions', [$this, 'enableOrderCaptureButton'], 10, 2); | ||
add_action('woocommerce_order_action_' . self::MOLLIE_MANUAL_CAPTURE_ACTION, [$this, 'manualCapture']); | ||
add_filter('woocommerce_mollie_wc_gateway_creditcard_args', [$this, 'sendManualCaptureMode']); | ||
} | ||
|
||
public function enableOrderCaptureButton(array $actions, \WC_Order $order): array | ||
{ | ||
if (!$this->container->get('merchant.manual_capture.can_capture_the_order')($order)) { | ||
return $actions; | ||
} | ||
$actions[self::MOLLIE_MANUAL_CAPTURE_ACTION] = __( | ||
'Capture authorized Mollie payment', | ||
'mollie-payments-for-woocommerce' | ||
); | ||
return $actions; | ||
} | ||
|
||
public function sendManualCaptureMode(array $paymentData): array | ||
{ | ||
if ($this->container->get('merchant.manual_capture.enabled')) { | ||
$paymentData['captureMode'] = 'manual'; | ||
} | ||
return $paymentData; | ||
} | ||
|
||
public function manualCapture(\WC_Order $order) | ||
{ | ||
|
||
($this->container->get(CapturePayment::class))($order->get_id()); | ||
} | ||
} |
Oops, something went wrong.