finish refund

This commit is contained in:
2024-08-22 14:33:36 +02:00
parent 7635a9826f
commit 059638f3a7
6 changed files with 89 additions and 35 deletions

View File

@ -1,4 +1,4 @@
import {formatCurrency} from "./common.js"
import { formatCurrency } from "./common.js"
export function showTable(api) {
let token = localStorage.getItem("token");
@ -17,26 +17,32 @@ export function showTable(api) {
.then(response => response.json())
.then(function (data) {
if (data) {
data.forEach(function (i) {
let newRow = tbody.insertRow();
let newCell = newRow.insertCell();
data.forEach(function (i) {
let newRow = tbody.insertRow();
let newCell = newRow.insertCell();
newCell.innerHTML = `<a href="/admin/sales/${i.id}">Order ${i.id}</a>`;
newCell.innerHTML = `<a href="/admin/sales/${i.id}">Order ${i.id}</a>`;
newCell = newRow.insertCell();
let item = document.createTextNode(i.customer.last_name + ", " + i.customer.first_name);
newCell.appendChild(item)
newCell = newRow.insertCell();
let item = document.createTextNode(i.customer.last_name + ", " + i.customer.first_name);
newCell.appendChild(item)
newCell = newRow.insertCell();
item = document.createTextNode(i.widget.name);
newCell.appendChild(item)
newCell = newRow.insertCell();
item = document.createTextNode(i.widget.name);
newCell.appendChild(item)
let cur = formatCurrency(i.transaction.amount)
newCell = newRow.insertCell();
item = document.createTextNode(cur);
newCell.appendChild(item)
let cur = formatCurrency(i.transaction.amount)
newCell = newRow.insertCell();
item = document.createTextNode(cur);
newCell.appendChild(item)
});
newCell = newRow.insertCell();
if (i.status_id != 1) {
newCell.innerHTML = `<span class="badge bg-danger">Refunded</span>`
} else {
newCell.innerHTML = `<span class="badge bg-success">Charged</span>`
}
});
} else {
let newRow = tbody.insertRow();
let newCell = newRow.insertCell();

View File

@ -1,4 +1,4 @@
import { formatCurrency } from "./common.js"
import { formatCurrency, showError, showSuccess } from "./common.js"
const id = window.location.pathname.split("/").pop();
const token = localStorage.getItem("token");
@ -26,6 +26,15 @@ export function showInfo(api) {
document.getElementById("pi").value = data.transaction.payment_intent;
document.getElementById("charge-amount").value = data.transaction.amount;
document.getElementById("currency").value = data.transaction.currency;
if (data.status_id === 1) {
document.getElementById("refund-btn").classList.remove("d-none");
document.getElementById("refunded").classList.add("d-none");
document.getElementById("charged").classList.remove("d-none");
} else {
document.getElementById("refund-btn").classList.add("d-none");
document.getElementById("refunded").classList.remove("d-none");
document.getElementById("charged").classList.add("d-none");
}
}
});
}
@ -61,6 +70,15 @@ export function refund(api) {
.then(response => response.json())
.then(function (data) {
console.log(data);
if (!data.ok) {
showError(data.message)
} else {
showSuccess("messages", "Refunded!")
document.getElementById("refund-btn").classList.add("d-none");
document.getElementById("refunded").classList.remove("d-none");
document.getElementById("charged").classList.add("d-none");
}
});
}
});