| Current Path : /home/rtorresani/www/vendor/stripe/module-payments/Helper/ |
| Current File : //home/rtorresani/www/vendor/stripe/module-payments/Helper/Order.php |
<?php
namespace StripeIntegration\Payments\Helper;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\CouldNotSaveException;
use StripeIntegration\Payments\Model\Config;
use Psr\Log\LoggerInterface;
use Magento\Framework\Validator\Exception;
use StripeIntegration\Payments\Helper\Logger;
class Order
{
private $config;
private $paymentIntentModel;
private $paymentsHelper;
public function __construct(
\StripeIntegration\Payments\Helper\Generic $paymentsHelper,
\StripeIntegration\Payments\Model\Config $config,
\StripeIntegration\Payments\Model\PaymentIntent $paymentIntentModel
)
{
$this->paymentsHelper = $paymentsHelper;
$this->config = $config;
$this->paymentIntentModel = $paymentIntentModel;
}
public function onMultishippingChargeSucceeded($order, $object)
{
// DO NOT call saveOrder() in here. A 3DS may still be happening which will record transactions and save the order elsewhere
$this->paymentsHelper->sendNewOrderEmailFor($order);
}
public function onTransaction($order, $object, $transactionId)
{
$action = __("Collected");
if ($object["captured"] == false)
{
if ($order->getState() != "pending" && $order->getPayment()->getAdditionalInformation("server_side_transaction_id") == $transactionId)
{
// This transaction does not need to be recorded, it was already created when the order was placed.
return;
}
$action = __("Authorized");
$transactionType = \Magento\Sales\Model\Order\Payment\Transaction::TYPE_AUTH;
$transactionAmount = $this->paymentsHelper->convertStripeAmountToOrderAmount($object['amount'], $object['currency'], $order);
}
else
{
if ($order->getTotalPaid() >= $order->getGrandTotal() && $order->getPayment()->getAdditionalInformation("server_side_transaction_id") == $transactionId)
{
// This transaction does not need to be recorded, it was already created when the order was placed.
return;
}
$action = __("Captured");
$transactionType = \Magento\Sales\Model\Order\Payment\Transaction::TYPE_CAPTURE;
$transactionAmount = $this->paymentsHelper->convertStripeAmountToOrderAmount($object['amount_captured'], $object['currency'], $order);
}
$transaction = $order->getPayment()->addTransaction($transactionType, null, false);
$transaction->setAdditionalInformation("amount", $transactionAmount);
$transaction->setAdditionalInformation("currency", $object['currency']);
$transaction->save();
$state = \Magento\Sales\Model\Order::STATE_PROCESSING;
$status = $order->getConfig()->getStateDefaultStatus($state);
$humanReadableAmount = $this->paymentsHelper->addCurrencySymbol($transactionAmount, $object['currency']);
$comment = __("%1 amount of %2 via Stripe. Transaction ID: %3", $action, $humanReadableAmount, $transactionId);
$order->setState($state)->addStatusToHistory($status, $comment, $isCustomerNotified = false);
}
}