-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #662 from mollie/release/2.28.0
Release/2.28.0
- Loading branch information
Showing
46 changed files
with
1,260 additions
and
98 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
|
||
namespace Mollie\Payment\Model\Client\Payments; | ||
|
||
use Magento\Sales\Api\Data\OrderInterface; | ||
use Magento\Sales\Api\Data\ShipmentInterface; | ||
use Magento\Sales\Api\OrderRepositoryInterface; | ||
use Magento\Sales\Model\Order\Email\Sender\InvoiceSender; | ||
use Mollie\Payment\Helper\General; | ||
use Mollie\Payment\Service\Mollie\MollieApiClient; | ||
use Mollie\Payment\Service\Order\Invoice\ShouldEmailInvoice; | ||
use Mollie\Payment\Service\Order\OrderCommentHistory; | ||
use Mollie\Payment\Service\Order\PartialInvoice; | ||
|
||
class CapturePayment | ||
{ | ||
/** | ||
* @var MollieApiClient | ||
*/ | ||
private $mollieApiClient; | ||
|
||
/** | ||
* @var PartialInvoice | ||
*/ | ||
private $partialInvoice; | ||
|
||
/** | ||
* @var General | ||
*/ | ||
private $mollieHelper; | ||
|
||
/** | ||
* @var OrderRepositoryInterface | ||
*/ | ||
private $orderRepository; | ||
|
||
/** | ||
* @var InvoiceSender | ||
*/ | ||
private $invoiceSender; | ||
|
||
/** | ||
* @var OrderCommentHistory | ||
*/ | ||
private $orderCommentHistory; | ||
/** | ||
* @var ShouldEmailInvoice | ||
*/ | ||
private $shouldEmailInvoice; | ||
|
||
public function __construct( | ||
MollieApiClient $mollieApiClient, | ||
PartialInvoice $partialInvoice, | ||
General $mollieHelper, | ||
OrderRepositoryInterface $orderRepository, | ||
InvoiceSender $invoiceSender, | ||
OrderCommentHistory $orderCommentHistory, | ||
ShouldEmailInvoice $shouldEmailInvoice | ||
) { | ||
$this->mollieApiClient = $mollieApiClient; | ||
$this->partialInvoice = $partialInvoice; | ||
$this->mollieHelper = $mollieHelper; | ||
$this->orderRepository = $orderRepository; | ||
$this->invoiceSender = $invoiceSender; | ||
$this->orderCommentHistory = $orderCommentHistory; | ||
$this->shouldEmailInvoice = $shouldEmailInvoice; | ||
} | ||
|
||
public function execute(ShipmentInterface $shipment, OrderInterface $order): void | ||
{ | ||
$payment = $order->getPayment(); | ||
$invoice = $this->partialInvoice->createFromShipment($shipment); | ||
if (!$invoice) { | ||
return; | ||
} | ||
|
||
$captureAmount = $invoice->getBaseGrandTotal(); | ||
|
||
$mollieTransactionId = $order->getMollieTransactionId(); | ||
$mollieApi = $this->mollieApiClient->loadByStore($order->getStoreId()); | ||
|
||
$data = []; | ||
if ($captureAmount != $order->getBaseGrandTotal()) { | ||
$data['amount'] = $this->mollieHelper->getAmountArray( | ||
$order->getOrderCurrencyCode(), | ||
$captureAmount | ||
); | ||
} | ||
|
||
$capture = $mollieApi->paymentCaptures->createForId($mollieTransactionId, $data); | ||
|
||
$payment->setTransactionId($capture->id); | ||
$payment->registerCaptureNotification($captureAmount, true); | ||
|
||
$this->orderRepository->save($order); | ||
|
||
$sendInvoice = $this->shouldEmailInvoice->execute($order->getStoreId(), $payment->getMethod()); | ||
if ($invoice && $invoice->getId() && !$invoice->getEmailSent() && $sendInvoice) { | ||
$this->invoiceSender->send($invoice); | ||
$message = __('Notified customer about invoice #%1', $invoice->getIncrementId()); | ||
$this->orderCommentHistory->add($order, $message, true); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.