Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve information for transaction status #263

Merged
merged 19 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
c4130e5
refactor: improve code flow
mastudillot Nov 10, 2024
fd88140
refactor: split code for transaction status meta box
mastudillot Nov 11, 2024
b23df79
feat: update expired query status error message
mastudillot Nov 13, 2024
589fa9b
refactor: reduce code in catch block for status method
mastudillot Nov 13, 2024
a0ad2e6
feat: add specific error message in catch block for oneclick exception
mastudillot Nov 13, 2024
8c176df
feat: improve exception message for oneclick status
mastudillot Nov 13, 2024
5e0a6cd
refactor: use constants for exception message
mastudillot Nov 13, 2024
ca901d8
feat: add getCommonFieldsStatusFormatted method
mastudillot Nov 13, 2024
3f51149
feat: add getWebpayStatusFormattedResponse method
mastudillot Nov 13, 2024
b063b68
feat: add getOneclickStatusFormattedResponse method
mastudillot Nov 13, 2024
317b38f
feat: add variables for colors in global context
mastudillot Nov 13, 2024
5b973c2
feat: improve information in status meta box
mastudillot Nov 13, 2024
fd2709c
fix: typo in exception message
mastudillot Nov 13, 2024
43c5a55
feat: remove duplicated status error message
mastudillot Nov 13, 2024
4c5a646
feat: add ajax hooks in init event
mastudillot Nov 13, 2024
f85f4d9
feat: add log to status controller
mastudillot Nov 13, 2024
f6be020
feat: register hook add_meta_boxes in the correct order
mastudillot Nov 13, 2024
f384083
feat: use default status error message in api mismatch exception
mastudillot Nov 13, 2024
c522ae9
feat: add field key for status payload params in log
mastudillot Nov 13, 2024
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
103 changes: 101 additions & 2 deletions plugin/css/tbk.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
:root {
--tbk-red: #D5006C;
--tbk-red-2: #C00063;
--tbk-success: #28a745;
--tbk-info: #007bff;
--tbk-warning: #fd7e14;
--tbk-error: #dc3545;
--tbk-default: #6c757d:
}

.tbk_table_info {
width: 600px;
Expand Down Expand Up @@ -221,8 +230,6 @@
}

.tbk-box {
--tbk-red: #D5006C;
--tbk-red-2: #C00063;
background: #fff;
border-radius: 10px;
padding: 15px;
Expand Down Expand Up @@ -413,3 +420,95 @@
font-size: 18px;
font-weight: 500;
}

.tbk-field {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 8px;
font-size: 14px;
line-height: 1.4;
}

.tbk-field-name {
font-weight: bold;
margin-right: 8px;
}

.tbk-field-value {
text-align: right;
word-break: break-word;
}

.tbk-badge {
padding: 2px 6px;
border-radius: 4px;
font-size: 12px;
font-weight: bold;
color: white
}

.tbk-badge-success {
background-color: var(--tbk-success);
}

.tbk-badge-info {
background-color: var(--tbk-info);
}

.tbk-badge-warning {
background-color: var(--tbk-warning);
}

.tbk-badge-error {
background-color: var(--tbk-error);
}

.tbk-badge-default {
background-color: var(--tbk-default);
}

.tbk-status {
display: flex;
flex-direction: row;
align-items: center;
}

.tbk-status i {
width: 100px;
max-width: 24px;
text-align: center;
font-size: x-large;
}

.tbk-status p {
padding-left: 10px;
margin: 0px;
}

.tbk-status.tbk-status-info i {
color: var(--tbk-info);
}

.tbk-status.tbk-status-error i, .tbk-status.tbk-status-error p {
color: var(--tbk-error);
font-weight: bold;
}

.tbk-status-button {
display: flex;
justify-content: center;
margin-bottom: 10px;
}

.tbk-status-button .tbk-button-primary {
width: 100%;
text-align: center;
}

.tbk-separator {
width: 100%;
height: 1px;
background-color: #ccc;
margin: 10px 0;
}
124 changes: 98 additions & 26 deletions plugin/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ jQuery(function($) {
if ($(`.${btnName}`).data('sending') === true) {
return false;
}
$(`.${btnName}`).data('sending', true).html(msg);
const btn = $(`.${btnName}`);
btn.data('sending', true).html(`${msg} <i class="fa fa-spinner fa-spin"></i>`);

e.preventDefault();
mastudillot marked this conversation as resolved.
Show resolved Hide resolved
return true;
}
Expand Down Expand Up @@ -72,40 +74,113 @@ jQuery(function($) {
});

$('.get-transaction-status').on("click",function(e) {
if (!blockButton(e, 'get-transaction-status', 'Consultando al API REST...')){
e.preventDefault();
if (!blockButton(e, 'get-transaction-status', 'Consultando estado')){
return;
}

const container = document.getElementById('transaction_status_admin');
container.innerHTML = '';

const separator = document.createElement('div');
separator.className = 'tbk-separator';
separator.style.display = 'none';
container.appendChild(separator);

post('get_transaction_status', {
order_id: $('.get-transaction-status').data('order-id'),
buy_order: $('.get-transaction-status').data('buy-order'),
token: $('.get-transaction-status').data('token')
}, (resp) => {
mastudillot marked this conversation as resolved.
Show resolved Hide resolved
let $table = $('.transaction-status-response');
let statusData = resp.status;
if(resp.product == "webpay_plus"){
$("#tbk_wpp_vci").removeClass("tbk-hide");
$("#tbk_wpp_session_id").removeClass("tbk-hide");
}else{
$("#tbk_wpoc_commerce_code").removeClass("tbk-hide");
for (const [key, value] of Object.entries(resp)) {
const fieldName = document.createElement('span');
fieldName.className = 'tbk-field-name';
fieldName.textContent = getFieldName(key);

const fieldValue = document.createElement('span');
fieldValue.className = 'tbk-field-value';
fieldValue.textContent = value.toString();

if(key == 'status') {
fieldValue.classList.add('tbk-badge');
fieldValue.classList.add(getBadgeColorFromStatus(value.toString()));
}

if(key == 'cardNumber') {
fieldValue.style.width = '100%';
}

const field = document.createElement('div');
field.className = 'tbk-field';
field.appendChild(fieldName);
field.appendChild(fieldValue);

container.appendChild(field);
}
const statusDataKeys = Object.keys(statusData);
statusDataKeys.forEach(key => {
let value = statusData[key] ? statusData[key] : '-';
const tableRow = $table.find('.status-' + key);
tableRow.html(value);
});
$table.find('.status-product').html(resp.product);
let niceJson = JSON.stringify(resp.raw, null, 2)
$table.find('.status-raw').html(`<pre>${niceJson}</pre>`);
$table.show();
releaseButton('get-transaction-status','Consultar estado de la transacción');
separator.style.removeProperty('display');

releaseButton('get-transaction-status','Consultar Estado');
}, (error) => {
$('.error-status-raw').html(`<p>${error.responseJSON.message}</p>`);
$('.error-transaction-status-response').show();
releaseButton('get-transaction-status','Consultar estado de la transacción');
const errorContainer = createErrorContainer(error.responseJSON.message);
container.appendChild(errorContainer);
separator.style.removeProperty('display');

releaseButton('get-transaction-status','Consultar Estado');
});
});

function getBadgeColorFromStatus(status) {
const statusColorsDictionary = {
'Inicializada': 'tbk-badge-warning',
'Capturada': 'tbk-badge-success',
'Autorizada': 'tbk-badge-success',
'Fallida': 'tbk-badge-error',
'Anulada': 'tbk-badge-info',
'Parcialmente anulada': 'tbk-badge-info'
};

return statusColorsDictionary[status] ?? 'tbk-badge-default';
}

function getFieldName(fieldKey) {
const fieldNameDictionary = {
vci: 'VCI',
status: 'Estado',
responseCode: 'Código de respuesta',
amount: 'Monto',
authorizationCode: 'Código de autorización',
accountingDate: 'Fecha contable',
paymentType: 'Tipo de pago',
installmentType: 'Tipo de cuota',
installmentNumber: 'Número de cuotas',
installmentAmount: 'Monto cuota',
sessionId: 'ID de sesión',
buyOrder: 'Orden de compra',
buyOrderMall: 'Orden de compra mall',
buyOrderStore: 'Orden de compra tienda',
cardNumber: 'Número de tarjeta',
transactionDate: 'Fecha transacción',
transactionTime: 'Hora transacción',
balance: 'Balance'
};

return fieldNameDictionary[fieldKey] ?? fieldKey;
}

function createErrorContainer(errorMessage)
{
const errorContainer = document.createElement('div');
errorContainer.classList.add('tbk-status', 'tbk-status-error');
const icon = document.createElement('i');
icon.classList.add('fa', 'fa-times');
const paragraph = document.createElement('p');
paragraph.textContent = errorMessage;

errorContainer.appendChild(icon);
errorContainer.appendChild(paragraph);
return errorContainer;
}

$('#mainform').on('click', '.notice-dismiss', function() {
let noticeId = $(this).closest('.notice').attr('id');

Expand Down Expand Up @@ -169,7 +244,4 @@ jQuery(function($) {

});
});



})
Loading
Loading