Skip to content
This repository has been archived by the owner on Jan 25, 2024. It is now read-only.

Fix order status handling #75

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Controller/Transaction/CommitWebpayM22.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class CommitWebpayM22 extends \Magento\Framework\App\Action\Action
"S2" => "2 cuotas sin interés",
"NC" => "N cuotas sin interés",
];
protected $configProvider;

public function __construct(
\Magento\Framework\App\Action\Context $context, \Magento\Checkout\Model\Cart $cart,
Expand Down Expand Up @@ -49,7 +50,7 @@ public function __construct(
public function execute()
{
$config = $this->configProvider->getPluginConfig();
$orderStatusCanceled = $config['error_pay'];
$orderStatusCanceled = $this->configProvider->getOrderErrorStatus();
$transactionResult = [];
try {
$tokenWs = isset($_POST['token_ws']) ? $_POST['token_ws'] : null;
Expand Down Expand Up @@ -82,7 +83,7 @@ public function execute()
$payment->setTransactionId($authorizationCode);
$payment->setAdditionalInformation([\Magento\Sales\Model\Order\Payment\Transaction::RAW_DETAILS => (array)$transactionResult]);

$orderStatus = $config['sucefully_pay'];
$orderStatus = $this->configProvider->getOrderSuccessStatus();
$order->setState($orderStatus)->setStatus($orderStatus);
$order->addStatusToHistory($order->getStatus(), json_encode($transactionResult));
$order->save();
Expand Down Expand Up @@ -273,7 +274,7 @@ private function errorOnConfirmation(\Exception $e, $order, $orderStatusCanceled
$this->log->logError($message);
$this->checkoutSession->restoreQuote();
$this->messageManager->addError(__($message));
if ($order != null) {
if ($order != null && $order->getState() != Order::STATE_PROCESSING) {
$order->cancel();
$order->save();
$order->setStatus($orderStatusCanceled);
Expand Down
15 changes: 7 additions & 8 deletions Controller/Transaction/CreateWebpayM22.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
*/
class CreateWebpayM22 extends \Magento\Framework\App\Action\Action
{

protected $configProvider;

/**
* CreateWebpayM22 constructor.
*
Expand Down Expand Up @@ -53,17 +54,16 @@ public function __construct(
*/
public function execute()
{

$response = null;
$order = null;
$config = $this->configProvider->getPluginConfig();
$orderStatusCanceled = $config['error_pay'];
$orderStatusCanceled = $this->configProvider->getOrderErrorStatus();
$orderStatusPendingPayment = $this->configProvider->getOrderPendingStatus();

try {

$guestEmail = isset($_GET['guestEmail']) ? $_GET['guestEmail'] : null;

$config = $this->configProvider->getPluginConfig();
$orderStatusPendingPayment = $config['order_status'];

$tmpOrder = $this->getOrder();
$this->checkoutSession->restoreQuote();
Expand All @@ -74,8 +74,6 @@ public function execute()
$this->setQuoteData($quote, $guestEmail);
}

$quoteData = $quote->getData();

$quote->getPayment()->importData(['method' => Webpay::CODE]);
$quote->collectTotals()->save();
$order = $tmpOrder;
Expand Down Expand Up @@ -106,6 +104,7 @@ public function execute()

if (isset($response['token_ws'])) {
$webpayOrderData = $this->saveWebpayData($response['token_ws'], WebpayOrderData::PAYMENT_STATUS_WATING, $orderId, $quoteId);
$order->setStatus($orderStatusPendingPayment);
} else {
$webpayOrderData = $this->saveWebpayData('', WebpayOrderData::PAYMENT_STATUS_ERROR, $orderId, $quoteId);
$order->cancel();
Expand Down Expand Up @@ -152,7 +151,7 @@ protected function getOrder()
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

return $objectManager->create('\Magento\Sales\Model\Order')->load($orderId);
} catch (Exception $e) {
} catch (\Exception $e) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aquí claramente se está arreglando un bug de namespace

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

return null;
}
}
Expand Down
30 changes: 21 additions & 9 deletions Model/Config/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Transbank\Webpay\Model\Config;

class ConfigProvider implements \Magento\Checkout\Model\ConfigProviderInterface {
const CONFIG_ROUTE = 'payment/transbank_webpay/security_parameters/';

public function __construct(\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfigInterface) {

Expand All @@ -18,20 +19,31 @@ public function getConfig() {
}

public function getPluginConfig() {
$conf = 'payment/transbank_webpay/security_parameters/';
$config = array(
'MODO' => $this->scopeConfigInterface->getValue($conf.'environment'),
'PRIVATE_KEY' => $this->scopeConfigInterface->getValue($conf.'private_key'),
'PUBLIC_CERT' => $this->scopeConfigInterface->getValue($conf.'public_cert'),
'WEBPAY_CERT' => $this->scopeConfigInterface->getValue($conf.'webpay_cert'),
'COMMERCE_CODE' => $this->scopeConfigInterface->getValue($conf.'commerce_code'),
'MODO' => $this->scopeConfigInterface->getValue(self::CONFIG_ROUTE.'environment'),
'PRIVATE_KEY' => $this->scopeConfigInterface->getValue(self::CONFIG_ROUTE.'private_key'),
'PUBLIC_CERT' => $this->scopeConfigInterface->getValue(self::CONFIG_ROUTE.'public_cert'),
'WEBPAY_CERT' => $this->scopeConfigInterface->getValue(self::CONFIG_ROUTE.'webpay_cert'),
'COMMERCE_CODE' => $this->scopeConfigInterface->getValue(self::CONFIG_ROUTE.'commerce_code'),
'URL_RETURN' => 'checkout/transaction/commitwebpay',
'URL_FINAL' => 'checkout/transaction/commitwebpay',
'ECOMMERCE' => 'magento',
'order_status' => $this->scopeConfigInterface->getValue($conf.'order_status'),
'sucefully_pay' => $this->scopeConfigInterface->getValue($conf.'sucefully_pay'),
'error_pay' => $this->scopeConfigInterface->getValue($conf.'error_pay')
'order_status' => $this->getOrderPendingStatus(),
'sucefully_pay' => $this->getOrderSuccessStatus(),
'error_pay' => $this->getOrderErrorStatus(),
);
return $config;
}

public function getOrderPendingStatus() {
return $this->scopeConfigInterface->getValue(self::CONFIG_ROUTE.'order_status');
}

public function getOrderSuccessStatus() {
return $this->scopeConfigInterface->getValue(self::CONFIG_ROUTE.'sucefully_pay');
}

public function getOrderErrorStatus() {
return $this->scopeConfigInterface->getValue(self::CONFIG_ROUTE.'error_pay');
}
}