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

conedevelopment / bazar / 20694116184

04 Jan 2026 02:08PM UTC coverage: 68.615% (+4.5%) from 64.117%
20694116184

push

github

iamgergo
version

1679 of 2447 relevant lines covered (68.61%)

25.06 hits per line

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

48.28
/src/Gateway/Driver.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Cone\Bazar\Gateway;
6

7
use Cone\Bazar\Events\CheckoutFailed;
8
use Cone\Bazar\Events\CheckoutProcessed;
9
use Cone\Bazar\Events\CheckoutProcessing;
10
use Cone\Bazar\Events\PaymentCaptured;
11
use Cone\Bazar\Events\PaymentCaptureFailed;
12
use Cone\Bazar\Models\Order;
13
use Cone\Bazar\Models\Transaction;
14
use Cone\Bazar\Support\Driver as BaseDriver;
15
use Illuminate\Http\Request;
16
use Illuminate\Http\Response as HttpResponse;
17
use Illuminate\Support\Facades\Config;
18
use Illuminate\Support\Facades\URL;
19
use Illuminate\Support\Str;
20
use Throwable;
21

22
abstract class Driver extends BaseDriver
23
{
24
    /**
25
     * The driver name.
26
     */
27
    protected string $name;
28

29
    /**
30
     * Process the payment.
31
     */
32
    public function pay(Order $order, ?float $amount = null, array $attributes = []): Transaction
3✔
33
    {
34
        return $order->pay($amount, $this->name, array_merge(['key' => Str::random()], $attributes));
3✔
35
    }
36

37
    /**
38
     * Process the refund.
39
     */
40
    public function refund(Order $order, ?float $amount = null, array $attributes = []): Transaction
3✔
41
    {
42
        return $order->refund($amount, $this->name, array_merge(['key' => Str::random()], $attributes));
3✔
43
    }
44

45
    /**
46
     * Get the URL of the transaction.
47
     */
48
    public function getTransactionUrl(Transaction $transaction): ?string
3✔
49
    {
50
        return null;
3✔
51
    }
52

53
    /**
54
     * Get the URL for the payment capture.
55
     */
56
    public function getCaptureUrl(Order $order): string
2✔
57
    {
58
        return URL::route('bazar.gateway.capture', [
2✔
59
            'driver' => $this->name,
2✔
60
            'order' => $order->uuid,
2✔
61
        ]);
2✔
62
    }
63

64
    /**
65
     * Get the success URL.
66
     */
67
    public function getSuccessUrl(Order $order): string
×
68
    {
69
        $url = $this->config['success_url'] ?? Config::get('bazar.gateway.urls.success');
×
70

71
        return URL::to(str_replace(['{order}'], [$order->uuid], $url ?? '/'));
×
72
    }
73

74
    /**
75
     * Get the failure URL.
76
     */
77
    public function getFailureUrl(Order $order): string
1✔
78
    {
79
        $url = $this->config['failure_url'] ?? Config::get('bazar.gateway.urls.failure');
1✔
80

81
        return URL::to(str_replace(['{order}'], [$order->uuid], $url ?? '/'));
1✔
82
    }
83

84
    /**
85
     * Handle the checkout request.
86
     */
87
    public function handleCheckout(Request $request, Order $order): Response
3✔
88
    {
89
        try {
90
            CheckoutProcessing::dispatch($this->name, $order);
3✔
91

92
            $this->checkout($request, $order);
3✔
93

94
            CheckoutProcessed::dispatch($this->name, $order);
2✔
95

96
            $url = $this->getCaptureUrl($order);
2✔
97
        } catch (Throwable $exception) {
1✔
98
            report($exception);
1✔
99

100
            $order->markAs(Order::FAILED);
1✔
101

102
            CheckoutFailed::dispatch($this->name, $order);
1✔
103

104
            $url = $this->getFailureUrl($order);
1✔
105
        }
106

107
        return new Response($url, $order->toArray());
3✔
108
    }
109

110
    /**
111
     * Checkout the order.
112
     */
113
    public function checkout(Request $request, Order $order): Order
2✔
114
    {
115
        $order->markAs(Order::PENDING);
2✔
116

117
        return $order;
2✔
118
    }
119

120
    /**
121
     * Resolve the order by the given UUID.
122
     */
123
    public function resolveOrder(string $id): Order
×
124
    {
125
        return Order::proxy()->newQuery()->where('bazar_orders.uuid', $id)->firstOrFail();
×
126
    }
127

128
    /**
129
     * Resolve the order model for payment capture.
130
     */
131
    public function resolveOrderForCapture(Request $request): Order
×
132
    {
133
        return $this->resolveOrder($request->input('order', ''));
×
134
    }
135

136
    /**
137
     * Resolve the order model for notification.
138
     */
139
    public function resolveOrderForNotification(Request $request): Order
×
140
    {
141
        return $this->resolveOrder($request->input('order', ''));
×
142
    }
143

144
    /**
145
     * Handle the capture request.
146
     */
147
    public function handleCapture(Request $request, Order $order): Response
×
148
    {
149
        try {
150
            $this->capture($request, $order);
×
151

152
            $order->cart?->delete();
×
153

154
            PaymentCaptured::dispatch($this->name, $order);
×
155

156
            $url = $this->getSuccessUrl($order);
×
157
        } catch (Throwable $exception) {
×
158
            report($exception);
×
159

160
            PaymentCaptureFailed::dispatch($this->name, $order);
×
161

162
            $order->markAs(Order::FAILED);
×
163

164
            $url = $this->getFailureUrl($order);
×
165
        }
166

167
        return new Response($url, $order->toArray());
×
168
    }
169

170
    /**
171
     * Capture the payment.
172
     */
173
    public function capture(Request $request, Order $order): Order
×
174
    {
175
        $this->pay($order);
×
176

177
        $order->markAs(Order::ON_HOLD);
×
178

179
        return $order;
×
180
    }
181

182
    /**
183
     * Handle the notification request.
184
     */
185
    public function handleNotification(Request $request, Order $order): Response
×
186
    {
187
        return (new Response)->respondWith(static function (): HttpResponse {
×
188
            return new HttpResponse('', HttpResponse::HTTP_NO_CONTENT);
×
189
        });
×
190
    }
191

192
    /**
193
     * Handle the manual transaction creation.
194
     */
195
    public function handleManualTransaction(Transaction $transaction): void
×
196
    {
197
        //
198
    }
×
199
}
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