Skip to content

Commit

Permalink
fix: Two pending status
Browse files Browse the repository at this point in the history
  • Loading branch information
brtkwr committed Oct 24, 2024
1 parent 8586d6d commit 9e419c9
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 17 deletions.
5 changes: 2 additions & 3 deletions Model/Two.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ class Two extends AbstractMethod

public const STATUS_NEW = 'two_new';
public const STATUS_FAILED = 'two_failed';
public const STATUS_APPROVED = 'APPROVED';
public const STATUS_TWO_PENDING = 'pending_two_payment';
public const STATUS_PENDING = 'pending_two_payment';
/**
* @var RequestInterface
*/
Expand Down Expand Up @@ -218,7 +217,7 @@ public function authorize(InfoInterface $payment, $amount)
throw new LocalizedException($error);
}

if ($response['status'] !== static::STATUS_APPROVED) {
if ($response['status'] !== 'APPROVED') {
$this->logRepository->addDebugLog(
sprintf('Order was not accepted by %s', $this->configRepository::PROVIDER),
$response
Expand Down
2 changes: 1 addition & 1 deletion Plugin/Model/Sales/AfterPlaceOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function afterPlace(Order $subject, Order $order)
{
if ($order->getPayment()->getMethod() == Two::CODE) {
$order->setState(Order::STATE_PENDING_PAYMENT);
$order->setStatus(Two::STATUS_TWO_PENDING);
$order->setStatus(Two::STATUS_PENDING);
$this->orderRepository->save($order);
}
return $order;
Expand Down
5 changes: 3 additions & 2 deletions Setup/Patch/Data/OrderStatuses.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class OrderStatuses implements DataPatchInterface
private $moduleDataSetup;

/**
* @param ConfigRepository $configRepository
* @param ModuleDataSetupInterface $moduleDataSetup
*/
public function __construct(
Expand All @@ -47,8 +48,8 @@ public function apply()

$data = [];
$statuses = [
Two::STATUS_NEW => __('%1 New Order', $this->configRepository::PROVIDER),
Two::STATUS_FAILED => __('%1 Failed', $this->configRepository::PROVIDER),
Two::STATUS_NEW => sprintf('%s New Order', $this->configRepository::PROVIDER),
Two::STATUS_FAILED => sprintf('%s Failed', $this->configRepository::PROVIDER),
];

foreach ($statuses as $code => $info) {
Expand Down
15 changes: 12 additions & 3 deletions Setup/Patch/Data/PendingPaymentStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,32 @@
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\DataPatchInterface;
use Two\Gateway\Model\Two;
use Two\Gateway\Api\Config\RepositoryInterface as ConfigRepository;

/**
* PendingPaymentStatus Data Patch
*/
class PendingPaymentStatus implements DataPatchInterface
{
/**
* @var ConfigRepository
*/
private $configRepository;

/**
* @var ModuleDataSetupInterface
*/
private $moduleDataSetup;

/**
* @param ConfigRepository $configRepository
* @param ModuleDataSetupInterface $moduleDataSetup
*/
public function __construct(
ConfigRepository $configRepository,
ModuleDataSetupInterface $moduleDataSetup
) {
$this->configRepository = $configRepository;
$this->moduleDataSetup = $moduleDataSetup;
}

Expand All @@ -44,13 +53,13 @@ public function apply()

$this->moduleDataSetup->getConnection()->insert(
$this->moduleDataSetup->getTable('sales_order_status'),
['status' => Two::STATUS_TWO_PENDING, 'label' => 'Two Pending']
['status' => Two::STATUS_PENDING, 'label' => sprintf('%s Pending', $this->configRepository::PROVIDER)]
);

$this->moduleDataSetup->getConnection()->insert(
$this->moduleDataSetup->getTable('sales_order_status_state'),
[
'status' => Two::STATUS_TWO_PENDING,
'status' => Two::STATUS_PENDING,
'state' => 'pending_payment',
'is_default' => 1,
'visible_on_front' => 0
Expand Down Expand Up @@ -87,7 +96,7 @@ private function isStatusAdded(): bool
$select = $this->moduleDataSetup->getConnection()->select()
->from($this->moduleDataSetup->getTable('sales_order_status'), 'status')
->where('status = :status');
$bind = [':status' => Two::STATUS_TWO_PENDING];
$bind = [':status' => Two::STATUS_PENDING];
return (bool)$this->moduleDataSetup->getConnection()->fetchOne($select, $bind);
}
}
2 changes: 0 additions & 2 deletions i18n/en_US.csv
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
"%1 Credit Note","%1 Credit Note"
"%1 Decline reason: %2","%1 Decline reason: %2"
"%1 Details","%1 Details"
"%1 Failed","%1 Failed"
"%1 Invoice","%1 Invoice"
"%1 New Order","%1 New Order"
"%1 Order ID","%1 Order ID"
"%1 [Trace ID: %2]","%1 [Trace ID: %2]"
"%1 order has been marked as cancelled","%1 order has been marked as cancelled"
Expand Down
2 changes: 0 additions & 2 deletions i18n/nb_NO.csv
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
"%1 Credit Note","%1 kreditnota"
"%1 Decline reason: %2","%1 Årsak til avvisning: %2"
"%1 Details","%1 Detaljer"
"%1 Failed","%1 Mislyktes"
"%1 Invoice","%1 Faktura"
"%1 New Order","%1 Ny ordre"
"%1 Order ID","%1 Bestillings-ID"
"%1 [Trace ID: %2]","%1 [Sporings-ID: %2]"
"%1 order has been marked as cancelled","%1 ordre er merket som kansellert"
Expand Down
2 changes: 0 additions & 2 deletions i18n/nl_NL.csv
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
"%1 Credit Note","%1 Creditnota"
"%1 Decline reason: %2","%1 Reden voor afwijzing: %2"
"%1 Details","%1 Gegevens"
"%1 Failed","%1 Mislukt"
"%1 Invoice","%1 Factuur"
"%1 New Order","%1 Nieuwe bestelling"
"%1 Order ID","%1 Bestelnummer"
"%1 [Trace ID: %2]","%1 [Trace-ID: %2]"
"%1 order has been marked as cancelled","%1 bestelling is gemarkeerd als geannuleerd"
Expand Down
2 changes: 0 additions & 2 deletions i18n/sv_SE.csv
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
"%1 Credit Note","%1 Kreditnota"
"%1 Decline reason: %2","%1 Orsak till avslag: %2"
"%1 Details","%1 Detaljer"
"%1 Failed","%1 Misslyckades"
"%1 Invoice","%1 Faktura"
"%1 New Order","%1 Ny beställning"
"%1 Order ID","%1 Beställnings-ID"
"%1 [Trace ID: %2]","%1 [Spår-ID: %2]"
"%1 order has been marked as cancelled","%1 beställning har markerats som avbruten"
Expand Down

0 comments on commit 9e419c9

Please sign in to comment.