cancel subscription
This commit is contained in:
		@ -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/subscriptions/${i.id}">Order ${i.id}</a>`;
 | 
			
		||||
                    newCell.innerHTML = `<a href="/admin/subscriptions/${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 + "/month");
 | 
			
		||||
                newCell.appendChild(item)
 | 
			
		||||
                    let cur = formatCurrency(i.transaction.amount)
 | 
			
		||||
                    newCell = newRow.insertCell();
 | 
			
		||||
                    item = document.createTextNode(cur + "/month");
 | 
			
		||||
                    newCell.appendChild(item)
 | 
			
		||||
 | 
			
		||||
            });
 | 
			
		||||
                    newCell = newRow.insertCell();
 | 
			
		||||
                    if (i.status_id != 1) {
 | 
			
		||||
                        newCell.innerHTML = `<span class="badge bg-danger">Cancelled</span>`
 | 
			
		||||
                    } else {
 | 
			
		||||
                        newCell.innerHTML = `<span class="badge bg-success">Charged</span>`
 | 
			
		||||
                    }
 | 
			
		||||
                });
 | 
			
		||||
            } else {
 | 
			
		||||
                let newRow = tbody.insertRow();
 | 
			
		||||
                let newCell = newRow.insertCell();
 | 
			
		||||
 | 
			
		||||
@ -39,7 +39,7 @@ export function showInfo(api) {
 | 
			
		||||
        });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function refund(api) {
 | 
			
		||||
export function refund(api, isRefund) {
 | 
			
		||||
    Swal.fire({
 | 
			
		||||
        title: "Are you sure?",
 | 
			
		||||
        text: "You won't be able to undo this!",
 | 
			
		||||
@ -47,7 +47,7 @@ export function refund(api) {
 | 
			
		||||
        showCancelButton: true,
 | 
			
		||||
        confirmButtonColor: "#3085d6",
 | 
			
		||||
        cancelButtonColor: "#d33",
 | 
			
		||||
        confirmButtonText: "Refund"
 | 
			
		||||
        confirmButtonText: isRefund === 1 ? "Refund" : "Cancel subscription"
 | 
			
		||||
    }).then((result) => {
 | 
			
		||||
        if (result.isConfirmed) {
 | 
			
		||||
            let payload = {
 | 
			
		||||
@ -66,15 +66,15 @@ export function refund(api) {
 | 
			
		||||
                body: JSON.stringify(payload),
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            fetch(api + "/api/admin/refund", requestOptions)
 | 
			
		||||
            fetch(api, requestOptions)
 | 
			
		||||
                .then(response => response.json())
 | 
			
		||||
                .then(function (data) {
 | 
			
		||||
                    console.log(data);
 | 
			
		||||
                    if (!data.ok) {
 | 
			
		||||
                        showError(data.message)
 | 
			
		||||
                        showError("messages", data.message)
 | 
			
		||||
 | 
			
		||||
                    } else {
 | 
			
		||||
                        showSuccess("messages", "Refunded!")
 | 
			
		||||
                        showSuccess("messages",  isRefund === 1 ? "Refunded" : "Subscription cancelled")
 | 
			
		||||
                        document.getElementById("refund-btn").classList.add("d-none");
 | 
			
		||||
                        document.getElementById("refunded").classList.remove("d-none");
 | 
			
		||||
                        document.getElementById("charged").classList.add("d-none");
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user