553cfafa49
CI / Tests (PHP 8.1) (pull_request) Successful in 51s
CI / Coding Standards (pull_request) Successful in 1m1s
CI / Tests (PHP 8.2) (pull_request) Successful in 58s
CI / No Debug Code (pull_request) Successful in 4s
CI / PHPStan (pull_request) Successful in 1m16s
CI / Tests (PHP 8.3) (pull_request) Successful in 45s
CI / Build Plugin Zip (pull_request) Has been skipped
Studio Settings gains a default HST rate; the rate is frozen onto each payment at booking and computed against the pre-tax subtotal, with the total billed as subtotal + tax. The rate is overridable per booking on My Lessons while unpaid (recomputing the tax amount), comped registrations are never taxed, and receipts break out subtotal/HST/total. Builds the payments report (roadmap #8) from us_payments: a monthly per-instructor view with subtotal, HST collected, and grand-total aggregation, plus a nonce-protected CSV export via admin-post. Studio admins see all instructors and can filter; instructors are scoped to their own rows. The Payment Report menu is gated on export_payments so instructors (who lack manage_billing) can reach it. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
83 lines
3.0 KiB
PHP
83 lines
3.0 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Unsupervised\Schedular\Tests\Unit\Payment;
|
|
|
|
use Unsupervised\Schedular\Payment\Payment;
|
|
use Unsupervised\Schedular\Tests\Unit\TestCase;
|
|
|
|
class PaymentTest extends TestCase
|
|
{
|
|
public function testDefaults(): void
|
|
{
|
|
$payment = new Payment(5, 3, Payment::REG_LESSON, 12, 35.00);
|
|
|
|
self::assertSame('CAD', $payment->currency);
|
|
self::assertSame(Payment::METHOD_ETRANSFER, $payment->method);
|
|
self::assertSame(Payment::STATUS_PENDING, $payment->status);
|
|
self::assertFalse($payment->isPaid());
|
|
self::assertNull($payment->id);
|
|
}
|
|
|
|
public function testConstants(): void
|
|
{
|
|
self::assertContains(Payment::METHOD_CARD, Payment::VALID_METHODS);
|
|
self::assertContains(Payment::METHOD_ETRANSFER, Payment::VALID_METHODS);
|
|
self::assertContains(Payment::METHOD_COMP, Payment::VALID_METHODS);
|
|
self::assertContains(Payment::STATUS_PAID, Payment::VALID_STATUSES);
|
|
}
|
|
|
|
public function testFromRowMapsCorrectly(): void
|
|
{
|
|
$payment = Payment::fromRow((object) [
|
|
'id' => '7',
|
|
'student_id' => '5',
|
|
'instructor_id' => '3',
|
|
'registration_type' => Payment::REG_ENROLLMENT,
|
|
'registration_id' => '12',
|
|
'amount' => '120.00',
|
|
'currency' => 'CAD',
|
|
'method' => Payment::METHOD_COMP,
|
|
'status' => Payment::STATUS_PAID,
|
|
'tax_rate' => '13.00',
|
|
'tax_amount' => '15.60',
|
|
'etransfer_email' => null,
|
|
'stripe_payment_intent_id' => null,
|
|
'receipt_number' => 'USC-7',
|
|
'receipt_sent_at' => null,
|
|
'paid_at' => '2026-06-08 10:00:00',
|
|
]);
|
|
|
|
self::assertSame(7, $payment->id);
|
|
self::assertSame(120.00, $payment->amount);
|
|
self::assertSame(13.00, $payment->taxRate);
|
|
self::assertSame(15.60, $payment->taxAmount);
|
|
self::assertSame(Payment::METHOD_COMP, $payment->method);
|
|
self::assertTrue($payment->isPaid());
|
|
self::assertSame('USC-7', $payment->receiptNumber);
|
|
}
|
|
|
|
public function testTotalAddsTaxToAmount(): void
|
|
{
|
|
$payment = new Payment(5, 3, Payment::REG_LESSON, 12, 100.00, taxRate: 13.0, taxAmount: 13.00);
|
|
|
|
self::assertSame(113.00, $payment->total());
|
|
}
|
|
|
|
public function testTotalEqualsAmountWhenUntaxed(): void
|
|
{
|
|
$payment = new Payment(5, 3, Payment::REG_LESSON, 12, 100.00);
|
|
|
|
self::assertSame(100.00, $payment->total());
|
|
}
|
|
|
|
public function testToArrayContainsExpectedKeys(): void
|
|
{
|
|
$arr = (new Payment(5, 3, Payment::REG_LESSON, 12, 35.00, id: 7))->toArray();
|
|
|
|
foreach (['id', 'student_id', 'amount', 'tax_rate', 'tax_amount', 'total', 'currency', 'method', 'status', 'receipt_number'] as $key) {
|
|
self::assertArrayHasKey($key, $arr);
|
|
}
|
|
}
|
|
}
|