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

conedevelopment / bazar / 14116302579

27 Mar 2025 08:41PM UTC coverage: 63.48% (-0.2%) from 63.724%
14116302579

push

github

iamgergo
wip

1 of 17 new or added lines in 3 files covered. (5.88%)

996 of 1569 relevant lines covered (63.48%)

15.65 hits per line

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

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

3
namespace Cone\Bazar\Gateway;
4

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

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

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

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

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

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

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

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

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

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

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

90
            $this->checkout($request, $order);
3✔
91

92
            CheckoutProcessed::dispatch($this->name, $order);
2✔
93

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

98
            $order->markAs(Order::FAILED);
1✔
99

100
            CheckoutFailed::dispatch($this->name, $order);
1✔
101

102
            $url = $this->getFailureUrl($order);
1✔
103
        }
104

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

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

115
        return $order;
2✔
116
    }
117

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

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

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

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

150
            $order->cart?->delete();
×
151

152
            PaymentCaptured::dispatch($this->name, $order);
×
153

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

158
            PaymentCaptureFailed::dispatch($this->name, $order);
×
159

160
            $order->markAs(Order::FAILED);
×
161

162
            $url = $this->getFailureUrl($order);
×
163
        }
164

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

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

175
        $order->markAs(Order::ON_HOLD);
×
176

177
        return $order;
×
178
    }
179

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

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