Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Documents/ReceiptTest.php
<?php | <?php | ||||
namespace Tests\Feature\Documents; | namespace Tests\Feature\Documents; | ||||
use App\Documents\Receipt; | use App\Documents\Receipt; | ||||
use App\Payment; | use App\Payment; | ||||
use App\Providers\PaymentProvider; | |||||
use App\User; | use App\User; | ||||
use App\Wallet; | use App\Wallet; | ||||
use App\VatRate; | use App\VatRate; | ||||
use Carbon\Carbon; | use Carbon\Carbon; | ||||
use Illuminate\Support\Facades\Bus; | use Illuminate\Support\Facades\Bus; | ||||
use Tests\TestCase; | use Tests\TestCase; | ||||
class ReceiptTest extends TestCase | class ReceiptTest extends TestCase | ||||
▲ Show 20 Lines • Show All 206 Lines • ▼ Show 20 Lines | protected function getTestData(string $country = null): Wallet | ||||
} | } | ||||
// Create two payments out of the 2020-05 period | // Create two payments out of the 2020-05 period | ||||
// and three in it, plus one in the period but unpaid, | // and three in it, plus one in the period but unpaid, | ||||
// and one with amount 0, and an extra refund and chanrgeback | // and one with amount 0, and an extra refund and chanrgeback | ||||
$payment = Payment::create([ | $payment = Payment::create([ | ||||
'id' => 'AAA1', | 'id' => 'AAA1', | ||||
'status' => PaymentProvider::STATUS_PAID, | 'status' => Payment::STATUS_PAID, | ||||
'type' => PaymentProvider::TYPE_ONEOFF, | 'type' => Payment::TYPE_ONEOFF, | ||||
'description' => 'Paid in April', | 'description' => 'Paid in April', | ||||
'wallet_id' => $wallet->id, | 'wallet_id' => $wallet->id, | ||||
'provider' => 'stripe', | 'provider' => 'stripe', | ||||
'amount' => 1111, | 'amount' => 1111, | ||||
'credit_amount' => 1111, | 'credit_amount' => 1111, | ||||
'vat_rate_id' => $vat, | 'vat_rate_id' => $vat, | ||||
'currency' => 'CHF', | 'currency' => 'CHF', | ||||
'currency_amount' => 1111, | 'currency_amount' => 1111, | ||||
]); | ]); | ||||
$payment->updated_at = Carbon::create(2020, 4, 30, 12, 0, 0); | $payment->updated_at = Carbon::create(2020, 4, 30, 12, 0, 0); | ||||
$payment->save(); | $payment->save(); | ||||
$payment = Payment::create([ | $payment = Payment::create([ | ||||
'id' => 'AAA2', | 'id' => 'AAA2', | ||||
'status' => PaymentProvider::STATUS_PAID, | 'status' => Payment::STATUS_PAID, | ||||
'type' => PaymentProvider::TYPE_ONEOFF, | 'type' => Payment::TYPE_ONEOFF, | ||||
'description' => 'Paid in June', | 'description' => 'Paid in June', | ||||
'wallet_id' => $wallet->id, | 'wallet_id' => $wallet->id, | ||||
'provider' => 'stripe', | 'provider' => 'stripe', | ||||
'amount' => 2222, | 'amount' => 2222, | ||||
'credit_amount' => 2222, | 'credit_amount' => 2222, | ||||
'vat_rate_id' => $vat, | 'vat_rate_id' => $vat, | ||||
'currency' => 'CHF', | 'currency' => 'CHF', | ||||
'currency_amount' => 2222, | 'currency_amount' => 2222, | ||||
]); | ]); | ||||
$payment->updated_at = Carbon::create(2020, 6, 1, 0, 0, 0); | $payment->updated_at = Carbon::create(2020, 6, 1, 0, 0, 0); | ||||
$payment->save(); | $payment->save(); | ||||
$payment = Payment::create([ | $payment = Payment::create([ | ||||
'id' => 'AAA3', | 'id' => 'AAA3', | ||||
'status' => PaymentProvider::STATUS_PAID, | 'status' => Payment::STATUS_PAID, | ||||
'type' => PaymentProvider::TYPE_ONEOFF, | 'type' => Payment::TYPE_ONEOFF, | ||||
'description' => 'Auto-Payment Setup', | 'description' => 'Auto-Payment Setup', | ||||
'wallet_id' => $wallet->id, | 'wallet_id' => $wallet->id, | ||||
'provider' => 'stripe', | 'provider' => 'stripe', | ||||
'amount' => 0, | 'amount' => 0, | ||||
'credit_amount' => 0, | 'credit_amount' => 0, | ||||
'vat_rate_id' => $vat, | 'vat_rate_id' => $vat, | ||||
'currency' => 'CHF', | 'currency' => 'CHF', | ||||
'currency_amount' => 0, | 'currency_amount' => 0, | ||||
]); | ]); | ||||
$payment->updated_at = Carbon::create(2020, 5, 1, 0, 0, 0); | $payment->updated_at = Carbon::create(2020, 5, 1, 0, 0, 0); | ||||
$payment->save(); | $payment->save(); | ||||
$payment = Payment::create([ | $payment = Payment::create([ | ||||
'id' => 'AAA4', | 'id' => 'AAA4', | ||||
'status' => PaymentProvider::STATUS_OPEN, | 'status' => Payment::STATUS_OPEN, | ||||
'type' => PaymentProvider::TYPE_ONEOFF, | 'type' => Payment::TYPE_ONEOFF, | ||||
'description' => 'Payment not yet paid', | 'description' => 'Payment not yet paid', | ||||
'wallet_id' => $wallet->id, | 'wallet_id' => $wallet->id, | ||||
'provider' => 'stripe', | 'provider' => 'stripe', | ||||
'amount' => 990, | 'amount' => 990, | ||||
'credit_amount' => 990, | 'credit_amount' => 990, | ||||
'vat_rate_id' => $vat, | 'vat_rate_id' => $vat, | ||||
'currency' => 'CHF', | 'currency' => 'CHF', | ||||
'currency_amount' => 990, | 'currency_amount' => 990, | ||||
]); | ]); | ||||
$payment->updated_at = Carbon::create(2020, 5, 1, 0, 0, 0); | $payment->updated_at = Carbon::create(2020, 5, 1, 0, 0, 0); | ||||
$payment->save(); | $payment->save(); | ||||
// ... so we expect the five three on the receipt | // ... so we expect the five three on the receipt | ||||
$payment = Payment::create([ | $payment = Payment::create([ | ||||
'id' => 'AAA5', | 'id' => 'AAA5', | ||||
'status' => PaymentProvider::STATUS_PAID, | 'status' => Payment::STATUS_PAID, | ||||
'type' => PaymentProvider::TYPE_ONEOFF, | 'type' => Payment::TYPE_ONEOFF, | ||||
'description' => 'Payment OK', | 'description' => 'Payment OK', | ||||
'wallet_id' => $wallet->id, | 'wallet_id' => $wallet->id, | ||||
'provider' => 'stripe', | 'provider' => 'stripe', | ||||
'amount' => 1234, | 'amount' => 1234, | ||||
'credit_amount' => 1234, | 'credit_amount' => 1234, | ||||
'vat_rate_id' => $vat, | 'vat_rate_id' => $vat, | ||||
'currency' => 'CHF', | 'currency' => 'CHF', | ||||
'currency_amount' => 1234, | 'currency_amount' => 1234, | ||||
]); | ]); | ||||
$payment->updated_at = Carbon::create(2020, 5, 1, 0, 0, 0); | $payment->updated_at = Carbon::create(2020, 5, 1, 0, 0, 0); | ||||
$payment->save(); | $payment->save(); | ||||
$payment = Payment::create([ | $payment = Payment::create([ | ||||
'id' => 'AAA6', | 'id' => 'AAA6', | ||||
'status' => PaymentProvider::STATUS_PAID, | 'status' => Payment::STATUS_PAID, | ||||
'type' => PaymentProvider::TYPE_ONEOFF, | 'type' => Payment::TYPE_ONEOFF, | ||||
'description' => 'Payment OK', | 'description' => 'Payment OK', | ||||
'wallet_id' => $wallet->id, | 'wallet_id' => $wallet->id, | ||||
'provider' => 'stripe', | 'provider' => 'stripe', | ||||
'amount' => 1, | 'amount' => 1, | ||||
'credit_amount' => 1, | 'credit_amount' => 1, | ||||
'vat_rate_id' => $vat, | 'vat_rate_id' => $vat, | ||||
'currency' => 'CHF', | 'currency' => 'CHF', | ||||
'currency_amount' => 1, | 'currency_amount' => 1, | ||||
]); | ]); | ||||
$payment->updated_at = Carbon::create(2020, 5, 10, 0, 0, 0); | $payment->updated_at = Carbon::create(2020, 5, 10, 0, 0, 0); | ||||
$payment->save(); | $payment->save(); | ||||
$payment = Payment::create([ | $payment = Payment::create([ | ||||
'id' => 'AAA7', | 'id' => 'AAA7', | ||||
'status' => PaymentProvider::STATUS_PAID, | 'status' => Payment::STATUS_PAID, | ||||
'type' => PaymentProvider::TYPE_RECURRING, | 'type' => Payment::TYPE_RECURRING, | ||||
'description' => 'Payment OK', | 'description' => 'Payment OK', | ||||
'wallet_id' => $wallet->id, | 'wallet_id' => $wallet->id, | ||||
'provider' => 'stripe', | 'provider' => 'stripe', | ||||
'amount' => 100, | 'amount' => 100, | ||||
'credit_amount' => 100, | 'credit_amount' => 100, | ||||
'vat_rate_id' => $vat, | 'vat_rate_id' => $vat, | ||||
'currency' => 'CHF', | 'currency' => 'CHF', | ||||
'currency_amount' => 100, | 'currency_amount' => 100, | ||||
]); | ]); | ||||
$payment->updated_at = Carbon::create(2020, 5, 21, 23, 59, 0); | $payment->updated_at = Carbon::create(2020, 5, 21, 23, 59, 0); | ||||
$payment->save(); | $payment->save(); | ||||
$payment = Payment::create([ | $payment = Payment::create([ | ||||
'id' => 'ref1', | 'id' => 'ref1', | ||||
'status' => PaymentProvider::STATUS_PAID, | 'status' => Payment::STATUS_PAID, | ||||
'type' => PaymentProvider::TYPE_REFUND, | 'type' => Payment::TYPE_REFUND, | ||||
'description' => 'refund desc', | 'description' => 'refund desc', | ||||
'wallet_id' => $wallet->id, | 'wallet_id' => $wallet->id, | ||||
'provider' => 'stripe', | 'provider' => 'stripe', | ||||
'amount' => -100, | 'amount' => -100, | ||||
'credit_amount' => -100, | 'credit_amount' => -100, | ||||
'vat_rate_id' => $vat, | 'vat_rate_id' => $vat, | ||||
'currency' => 'CHF', | 'currency' => 'CHF', | ||||
'currency_amount' => -100, | 'currency_amount' => -100, | ||||
]); | ]); | ||||
$payment->updated_at = Carbon::create(2020, 5, 30, 23, 59, 0); | $payment->updated_at = Carbon::create(2020, 5, 30, 23, 59, 0); | ||||
$payment->save(); | $payment->save(); | ||||
$payment = Payment::create([ | $payment = Payment::create([ | ||||
'id' => 'chback1', | 'id' => 'chback1', | ||||
'status' => PaymentProvider::STATUS_PAID, | 'status' => Payment::STATUS_PAID, | ||||
'type' => PaymentProvider::TYPE_CHARGEBACK, | 'type' => Payment::TYPE_CHARGEBACK, | ||||
'description' => '', | 'description' => '', | ||||
'wallet_id' => $wallet->id, | 'wallet_id' => $wallet->id, | ||||
'provider' => 'stripe', | 'provider' => 'stripe', | ||||
'amount' => -10, | 'amount' => -10, | ||||
'credit_amount' => -10, | 'credit_amount' => -10, | ||||
'vat_rate_id' => $vat, | 'vat_rate_id' => $vat, | ||||
'currency' => 'CHF', | 'currency' => 'CHF', | ||||
'currency_amount' => -10, | 'currency_amount' => -10, | ||||
▲ Show 20 Lines • Show All 42 Lines • Show Last 20 Lines |