Skip to content

Commit

Permalink
Merge pull request #54 from two-inc/brtkwr-two/abn-43-magento-admin-p…
Browse files Browse the repository at this point in the history
…ortal-order-displayed-with-status-such-as-two

fix: Two pending status
  • Loading branch information
brtkwr authored Oct 24, 2024
2 parents c0d5d73 + 80d9af4 commit 14e5c81
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 38 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
8 changes: 2 additions & 6 deletions Model/Ui/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,8 @@ public function getConfig(): array
$provider = $this->configRepository::PROVIDER;
$tryAgainLater = __('Please try again later.');
$soleTraderaccountCouldNotBeVerified = __('Your sole trader account could not be verified.');
// Set isTermsAndConditionsEnabled based on provider
$paymentTerms = __("Payment Terms");
$paymentTermsLink = $this->configRepository::PAYMENT_TERMS_LINK;
// This check here is present to only enable the terms and conditions
$isTermsAndConditionsEnabled = !empty($paymentTermsLink);
$paymentTermsLink = $this->configRepository->getCheckoutPageUrl() . '/terms';

return [
'payment' => [
Expand All @@ -87,8 +84,7 @@ public function getConfig(): array
'isOrderNoteFieldEnabled' => $this->configRepository->isOrderNoteEnabled(),
'isPONumberFieldEnabled' => $this->configRepository->isPONumberEnabled(),
'isTwoLinkEnabled' => $this->configRepository->isTwoLinkEnabled(),
'isTermsAndConditionsEnabled' => $isTermsAndConditionsEnabled,
'paymentTermsLink' => $paymentTermsLink,
'isPaymentTermsEnabled' => true,
'redirectMessage' => __(
'You will be redirected to %1 when you place order.',
$provider
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: 1 addition & 1 deletion bumpver.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tool.bumpver]
current_version = "1.6.0"
current_version = "1.6.3"
version_pattern = "MAJOR.MINOR.PATCH[-TAGNUM]"
commit_message = "chore: Bump version {old_version} -> {new_version}"
commit = true
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "two-inc/magento2",
"description": "Two B2B BNPL payments extension",
"type": "magento2-module",
"version": "1.6.0",
"version": "1.6.3",
"license": [
"OSL-3.0",
"AFL-3.0"
Expand Down
2 changes: 1 addition & 1 deletion etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<payment>
<two_payment>
<active>1</active>
<version>1.6.0</version>
<version>1.6.3</version>
<title>Business invoice - 30 days</title>
<mode>sandbox</mode>
<invoice_type>FUNDED_INVOICE</invoice_type>
Expand Down
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
24 changes: 14 additions & 10 deletions view/frontend/web/js/view/payment/method-renderer/two_payment.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ define([
redirectMessage: config.redirectMessage,
paymentTermsMessage: config.paymentTermsMessage,
termsNotAcceptedMessage: config.termsNotAcceptedMessage,
isTermsAndConditionsEnabled: config.isTermsAndConditionsEnabled,
termsAccepted: ko.observable(false),
isPaymentTermsEnabled: config.isPaymentTermsEnabled,
isPaymentTermsAccepted: ko.observable(false),
orderIntentApprovedMessage: config.orderIntentApprovedMessage,
orderIntentDeclinedMessage: config.orderIntentDeclinedMessage,
generalErrorMessage: config.generalErrorMessage,
Expand Down Expand Up @@ -86,10 +86,11 @@ define([
this.configureFormValidation();
this.popupMessageListener();
},
checkTerms: function (data, event) {
// Update the termsAccepted observable based on the checkbox state
// And added logging
console.debug({ logger: 'checkTerms', termsAccepted: this.termsAccepted() });
logIsPaymentsAccepted: function (data, event) {
console.debug({
logger: 'logIsPaymentsAccepted',
isPaymentTermsAccepted: this.isPaymentTermsAccepted()
});
},
fillCompanyData: function ({ companyId, companyName }) {
console.debug({ logger: 'twoPayment.fillCompanyData', companyId, companyName });
Expand Down Expand Up @@ -207,17 +208,20 @@ define([
}
},
placeOrder: function (data, event) {
// Additional logging to check termsAccepted
console.debug({ logger: 'placeOrder', termsAccepted: this.termsAccepted() });
// Additional logging to check isPaymentTermsAccepted
console.debug({
logger: 'placeOrder',
isPaymentTermsAccepted: this.isPaymentTermsAccepted()
});
if (event) event.preventDefault();
if (this.isTermsAndConditionsEnabled && !this.termsAccepted()) {
if (this.isPaymentTermsEnabled && !this.isPaymentTermsAccepted()) {
this.processTermsNotAcceptedErrorResponse();
return;
}
if (
this.validate() &&
additionalValidators.validate() &&
this.termsAccepted() === true &&
this.isPaymentTermsAccepted() === true &&
this.isPlaceOrderActionAllowed() === true
)
this.placeOrderBackend();
Expand Down
4 changes: 2 additions & 2 deletions view/frontend/web/template/payment/two_payment.html
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,12 @@
/>
</div>
</div>
<!-- ko if: isTermsAndConditionsEnabled -->
<!-- ko if: isPaymentTermsEnabled -->
<div class="payment-method-content terms-container">
<input
type="checkbox"
name="terms-checkbox"
data-bind="checked: termsAccepted, event: { change: checkTerms }"
data-bind="checked: isPaymentTermsAccepted, event: { change: logIsPaymentsAccepted }"
/>
<span class="terms-text" data-bind="html: paymentTermsMessage"></span>
</div>
Expand Down

0 comments on commit 14e5c81

Please sign in to comment.