• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

conedevelopment / bazar / 20305175558

17 Dec 2025 01:53PM UTC coverage: 64.063% (+0.6%) from 63.48%
20305175558

Pull #235

github

web-flow
Merge 3b257a314 into 090ff8496
Pull Request #235: Coupons & Discounts

199 of 261 new or added lines in 23 files covered. (76.25%)

8 existing lines in 1 file now uncovered.

1091 of 1703 relevant lines covered (64.06%)

17.14 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

66.67
/src/Fields/Transactions.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Cone\Bazar\Fields;
6

7
use Closure;
8
use Cone\Bazar\Gateway\Driver;
9
use Cone\Bazar\Models\Transaction;
10
use Cone\Bazar\Rules\TransactionAmount;
11
use Cone\Bazar\Support\Facades\Gateway;
12
use Cone\Root\Fields\Date;
13
use Cone\Root\Fields\HasMany;
14
use Cone\Root\Fields\Number;
15
use Cone\Root\Fields\Select;
16
use Cone\Root\Fields\Text;
17
use Cone\Root\Fields\URL;
18
use Illuminate\Database\Eloquent\Model;
19
use Illuminate\Http\Request;
20

21
class Transactions extends HasMany
22
{
23
    /**
24
     * The relations to eager load on every query.
25
     */
26
    protected array $with = [
27
        'order',
28
    ];
29

30
    /**
31
     * Create a new relation field instance.
32
     */
33
    public function __construct(?string $label = null, Closure|string|null $modelAttribute = null, Closure|string|null $relation = null)
34
    {
35
        parent::__construct($label ?: __('Transactions'), $modelAttribute ?: 'transactions', $relation);
67✔
36

37
        $this->asSubResource();
67✔
38
    }
39

40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function fields(Request $request): array
44
    {
45
        return [
67✔
46
            Select::make(__('Type'), 'type')
67✔
47
                ->options([
67✔
48
                    Transaction::PAYMENT => __('Payment'),
67✔
49
                    Transaction::REFUND => __('Refund'),
67✔
50
                ]),
67✔
51

52
            Number::make(__('Amount'), 'amount')
67✔
53
                ->min(0)
67✔
54
                ->required()
67✔
55
                ->format(static function (Request $request, Transaction $transaction, ?float $value): string {
67✔
NEW
56
                    return $transaction->order->getCurrency()->format($value ?: 0);
×
57
                })
67✔
58
                ->rules(static function (Request $request, Transaction $transaction): array {
67✔
59
                    return [
×
60
                        'required',
×
61
                        'numeric',
×
62
                        'gt:0',
×
63
                        new TransactionAmount($transaction->fill(['type' => $request->input('type')])),
×
64
                    ];
×
65
                }),
67✔
66

67
            Select::make(__('Driver'), 'driver')
67✔
68
                ->options(static function (Request $request, Transaction $transaction): array {
67✔
69
                    return array_map(static function (Driver $driver): string {
×
70
                        return $driver->getName();
×
71
                    }, Gateway::getAvailableDrivers($transaction->order));
×
72
                }),
67✔
73

74
            Text::make(__('Key'), 'key')
67✔
75
                ->searchable()
67✔
76
                ->sortable(),
67✔
77

78
            URL::make(__('URL'), static function (Request $request, Transaction $transaction): ?string {
67✔
79
                return $transaction->url;
×
80
            }),
67✔
81

82
            Date::make(__('Completed At'), 'completed_at')
67✔
83
                ->withTime(),
67✔
84
        ];
67✔
85
    }
86

87
    /**
88
     * {@inheritdoc}
89
     */
90
    public function saved(Request $request, Model $model): void
91
    {
92
        if ($model->wasRecentlyCreated) {
×
93
            Gateway::driver($model->driver)->handleManualTransaction($model);
×
94
        }
95
    }
96
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc