| 1 |
<?php |
| 2 |
/** |
| 3 |
* Payment View Template |
| 4 |
* |
| 5 |
* @package Easy_Invoice |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace EasyInvoice\Templates\Payments; |
| 9 |
|
| 10 |
use EasyInvoice\Models\Payment; |
| 11 |
use EasyInvoice\Models\Invoice; |
| 12 |
|
| 13 |
if (!isset($payment) || !($payment instanceof Payment)) { |
| 14 |
wp_die(__('Invalid payment', 'easy-invoice')); |
| 15 |
} |
| 16 |
|
| 17 |
$invoice_post = get_post($payment->getInvoiceId()); |
| 18 |
$invoice = $invoice_post ? new Invoice($invoice_post) : null; |
| 19 |
|
| 20 |
|
| 21 |
?> |
| 22 |
|
| 23 |
<div class="p-8"> |
| 24 |
<div class="flex justify-between items-center mb-6"> |
| 25 |
<h1 class="text-2xl font-bold text-gray-900"> |
| 26 |
<?php printf(__('Payment #%s', 'easy-invoice'), $payment->getId()); ?> |
| 27 |
</h1> |
| 28 |
<a href="<?php echo admin_url('admin.php?page=easy-invoice-payments'); ?>" |
| 29 |
class="inline-flex items-center px-4 py-2 border border-transparent text-sm font-medium rounded-md shadow-sm text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500"> |
| 30 |
<?php _e('Back to Payments', 'easy-invoice'); ?> |
| 31 |
</a> |
| 32 |
</div> |
| 33 |
|
| 34 |
<div class="bg-white shadow overflow-hidden sm:rounded-lg"> |
| 35 |
<!-- Payment Information --> |
| 36 |
<div class="px-4 py-5 sm:px-6 border-b border-gray-200"> |
| 37 |
<h2 class="text-lg font-medium text-gray-900"><?php _e('Payment Information', 'easy-invoice'); ?></h2> |
| 38 |
</div> |
| 39 |
<div class="border-t border-gray-200"> |
| 40 |
<dl> |
| 41 |
<div class="bg-gray-50 px-4 py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6"> |
| 42 |
<dt class="text-sm font-medium text-gray-500"><?php _e('Payment ID', 'easy-invoice'); ?></dt> |
| 43 |
<dd class="mt-1 text-sm text-gray-900 sm:mt-0 sm:col-span-2">#<?php echo $payment->getId(); ?></dd> |
| 44 |
</div> |
| 45 |
<div class="bg-white px-4 py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6"> |
| 46 |
<dt class="text-sm font-medium text-gray-500"><?php _e('Invoice', 'easy-invoice'); ?></dt> |
| 47 |
<dd class="mt-1 text-sm text-gray-900 sm:mt-0 sm:col-span-2"> |
| 48 |
<?php if ($invoice): ?> |
| 49 |
<a href="<?php echo admin_url('admin.php?page=easy-invoice&action=edit&id=' . $invoice->getId()); ?>" |
| 50 |
class="text-indigo-600 hover:text-indigo-900"> |
| 51 |
<?php echo $invoice->getNumber(); ?> |
| 52 |
</a> |
| 53 |
<?php else: ?> |
| 54 |
<span class="text-gray-400"><?php _e('Invoice not found', 'easy-invoice'); ?></span> |
| 55 |
<?php endif; ?> |
| 56 |
</dd> |
| 57 |
</div> |
| 58 |
<div class="bg-gray-50 px-4 py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6"> |
| 59 |
<dt class="text-sm font-medium text-gray-500"><?php _e('Amount', 'easy-invoice'); ?></dt> |
| 60 |
<dd class="mt-1 text-sm text-gray-900 sm:mt-0 sm:col-span-2"> |
| 61 |
<?php echo $payment->getCurrencySymbol() . number_format($payment->getAmount(), 2); ?> |
| 62 |
</dd> |
| 63 |
</div> |
| 64 |
<div class="bg-white px-4 py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6"> |
| 65 |
<dt class="text-sm font-medium text-gray-500"><?php _e('Payment Method', 'easy-invoice'); ?></dt> |
| 66 |
<dd class="mt-1 text-sm text-gray-900 sm:mt-0 sm:col-span-2"> |
| 67 |
<?php |
| 68 |
$payment_method = $payment->getPaymentMethod(); |
| 69 |
if (empty($payment_method)) { |
| 70 |
// Try direct property access |
| 71 |
$payment_method = $payment->payment_method; |
| 72 |
} |
| 73 |
if (empty($payment_method)) { |
| 74 |
// Try direct meta access |
| 75 |
$payment_method = get_post_meta($payment->getId(), '_payment_method', true); |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
echo ucfirst($payment_method ?: __('Not specified', 'easy-invoice')); |
| 81 |
?> |
| 82 |
</dd> |
| 83 |
</div> |
| 84 |
<div class="bg-gray-50 px-4 py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6"> |
| 85 |
<dt class="text-sm font-medium text-gray-500"><?php _e('Status', 'easy-invoice'); ?></dt> |
| 86 |
<dd class="mt-1 text-sm sm:mt-0 sm:col-span-2"> |
| 87 |
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full |
| 88 |
<?php |
| 89 |
switch ($payment->getStatus()) { |
| 90 |
case 'completed': |
| 91 |
echo 'bg-green-100 text-green-800'; |
| 92 |
break; |
| 93 |
case 'pending': |
| 94 |
echo 'bg-yellow-100 text-yellow-800'; |
| 95 |
break; |
| 96 |
case 'failed': |
| 97 |
echo 'bg-red-100 text-red-800'; |
| 98 |
break; |
| 99 |
default: |
| 100 |
echo 'bg-gray-100 text-gray-800'; |
| 101 |
} |
| 102 |
?>"> |
| 103 |
<?php echo ucfirst($payment->getStatus()); ?> |
| 104 |
</span> |
| 105 |
</dd> |
| 106 |
</div> |
| 107 |
<div class="bg-white px-4 py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6"> |
| 108 |
<dt class="text-sm font-medium text-gray-500"><?php _e('Date', 'easy-invoice'); ?></dt> |
| 109 |
<dd class="mt-1 text-sm text-gray-900 sm:mt-0 sm:col-span-2"> |
| 110 |
<?php echo date_i18n(get_option('date_format'), strtotime($payment->getPaymentDate())); ?> |
| 111 |
</dd> |
| 112 |
</div> |
| 113 |
<div class="bg-gray-50 px-4 py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6"> |
| 114 |
<dt class="text-sm font-medium text-gray-500"><?php _e('Type', 'easy-invoice'); ?></dt> |
| 115 |
<dd class="mt-1 text-sm text-gray-900 sm:mt-0 sm:col-span-2"> |
| 116 |
<?php echo ucfirst($payment->getPaymentType()); ?> |
| 117 |
</dd> |
| 118 |
</div> |
| 119 |
<?php if ($payment->getRecurringId()) : ?> |
| 120 |
<div class="bg-white px-4 py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6"> |
| 121 |
<dt class="text-sm font-medium text-gray-500"><?php _e('Recurring ID', 'easy-invoice'); ?></dt> |
| 122 |
<dd class="mt-1 text-sm text-gray-900 sm:mt-0 sm:col-span-2"> |
| 123 |
<?php echo $payment->getRecurringId(); ?> |
| 124 |
</dd> |
| 125 |
</div> |
| 126 |
<?php endif; ?> |
| 127 |
<?php if ($payment->getParentPaymentId()) : ?> |
| 128 |
<div class="bg-gray-50 px-4 py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6"> |
| 129 |
<dt class="text-sm font-medium text-gray-500"><?php _e('Parent Payment', 'easy-invoice'); ?></dt> |
| 130 |
<dd class="mt-1 text-sm text-gray-900 sm:mt-0 sm:col-span-2"> |
| 131 |
<a href="<?php echo admin_url('admin.php?page=easy-invoice-payments&action=view&id=' . $payment->getParentPaymentId()); ?>" |
| 132 |
class="text-indigo-600 hover:text-indigo-900"> |
| 133 |
#<?php echo $payment->getParentPaymentId(); ?> |
| 134 |
</a> |
| 135 |
</dd> |
| 136 |
</div> |
| 137 |
<?php endif; ?> |
| 138 |
<?php if ($payment->getNotes()) : ?> |
| 139 |
<div class="bg-white px-4 py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6"> |
| 140 |
<dt class="text-sm font-medium text-gray-500"><?php _e('Notes', 'easy-invoice'); ?></dt> |
| 141 |
<dd class="mt-1 text-sm text-gray-900 sm:mt-0 sm:col-span-2"> |
| 142 |
<?php echo nl2br(esc_html($payment->getNotes())); ?> |
| 143 |
</dd> |
| 144 |
</div> |
| 145 |
<?php endif; ?> |
| 146 |
</dl> |
| 147 |
</div> |
| 148 |
|
| 149 |
<?php |
| 150 |
$gateway_response_raw = $payment->getGatewayResponse(); |
| 151 |
$gateway_response = null; |
| 152 |
|
| 153 |
if ($gateway_response_raw) { |
| 154 |
// Try to decode JSON if it's a string |
| 155 |
if (is_string($gateway_response_raw)) { |
| 156 |
$gateway_response = json_decode($gateway_response_raw, true); |
| 157 |
} elseif (is_array($gateway_response_raw)) { |
| 158 |
$gateway_response = $gateway_response_raw; |
| 159 |
} |
| 160 |
} |
| 161 |
|
| 162 |
if ($gateway_response && is_array($gateway_response)) : |
| 163 |
?> |
| 164 |
<!-- Gateway Response --> |
| 165 |
<div class="px-4 py-5 sm:px-6 border-t border-gray-200"> |
| 166 |
<h2 class="text-lg font-medium text-gray-900"><?php _e('Gateway Response', 'easy-invoice'); ?></h2> |
| 167 |
</div> |
| 168 |
<div class="border-t border-gray-200"> |
| 169 |
<dl> |
| 170 |
<?php |
| 171 |
$loop = 0; |
| 172 |
foreach ($gateway_response as $key => $value) : |
| 173 |
$loop++; |
| 174 |
?> |
| 175 |
<div class="<?php echo $loop % 2 === 0 ? 'bg-white' : 'bg-gray-50'; ?> px-4 py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6"> |
| 176 |
<dt class="text-sm font-medium text-gray-500"><?php echo ucwords(str_replace('_', ' ', $key)); ?></dt> |
| 177 |
<dd class="mt-1 text-sm text-gray-900 sm:mt-0 sm:col-span-2"> |
| 178 |
<?php |
| 179 |
if (is_array($value)) { |
| 180 |
echo '<pre class="text-xs bg-gray-100 p-2 rounded overflow-x-auto">' . esc_html(json_encode($value, JSON_PRETTY_PRINT)) . '</pre>'; |
| 181 |
} elseif (is_bool($value)) { |
| 182 |
echo $value ? 'Yes' : 'No'; |
| 183 |
} elseif (is_null($value)) { |
| 184 |
echo '<em>null</em>'; |
| 185 |
} else { |
| 186 |
echo esc_html($value); |
| 187 |
} |
| 188 |
?> |
| 189 |
</dd> |
| 190 |
</div> |
| 191 |
<?php endforeach; ?> |
| 192 |
</dl> |
| 193 |
</div> |
| 194 |
<?php endif; ?> |
| 195 |
</div> |
| 196 |
</div> |