Roberto Santini hace 1 mes
padre
commit
81296b87e0

+ 6
- 1
app/Http/Controllers/AcquistoServizioPublicController.php Ver fichero

161
         } catch (\Throwable $e) {
161
         } catch (\Throwable $e) {
162
             report($e);
162
             report($e);
163
 
163
 
164
+            $msg = $e->getMessage();
165
+            if (str_contains($msg, 'Resolving timed out') || str_contains($msg, 'cURL error 28')) {
166
+                $msg = 'Timeout di rete verso il gateway di pagamento (DNS). Riprova tra poco o contatta il supporto.';
167
+            }
168
+
164
             return redirect()->route('shop.create', $prodotto->id)
169
             return redirect()->route('shop.create', $prodotto->id)
165
                 ->withInput()
170
                 ->withInput()
166
-                ->withErrors(['provider' => 'Errore avvio pagamento: '.$e->getMessage()]);
171
+                ->withErrors(['provider' => 'Errore avvio pagamento: '.$msg]);
167
         }
172
         }
168
 
173
 
169
         return redirect()->away($url);
174
         return redirect()->away($url);

+ 29
- 19
app/Services/AcquistoServizioPaymentService.php Ver fichero

97
         $token = $this->paypalAccessToken();
97
         $token = $this->paypalAccessToken();
98
         $base = $this->paypalBaseUrl();
98
         $base = $this->paypalBaseUrl();
99
 
99
 
100
-        $response = Http::withToken($token)->post($base.'/v2/checkout/orders', [
101
-            'intent' => 'CAPTURE',
102
-            'purchase_units' => [[
103
-                'reference_id' => (string) $acquisto->id,
104
-                'custom_id' => $acquisto->token,
105
-                'amount' => [
106
-                    'currency_code' => 'EUR',
107
-                    'value' => number_format((float) $acquisto->totale, 2, '.', ''),
100
+        $response = $this->paypalHttp()
101
+            ->withToken($token)
102
+            ->post($base.'/v2/checkout/orders', [
103
+                'intent' => 'CAPTURE',
104
+                'purchase_units' => [[
105
+                    'reference_id' => (string) $acquisto->id,
106
+                    'custom_id' => $acquisto->token,
107
+                    'amount' => [
108
+                        'currency_code' => 'EUR',
109
+                        'value' => number_format((float) $acquisto->totale, 2, '.', ''),
110
+                    ],
111
+                    'description' => $acquisto->prodotto?->nome ?: ('Servizio #'.$acquisto->id),
112
+                ]],
113
+                'application_context' => [
114
+                    'return_url' => route('shop.paypal.return', $acquisto->token),
115
+                    'cancel_url' => route('shop.cancel', $acquisto->token),
116
+                    'brand_name' => config('app.name'),
117
+                    'user_action' => 'PAY_NOW',
108
                 ],
118
                 ],
109
-                'description' => $acquisto->prodotto?->nome ?: ('Servizio #'.$acquisto->id),
110
-            ]],
111
-            'application_context' => [
112
-                'return_url' => route('shop.paypal.return', $acquisto->token),
113
-                'cancel_url' => route('shop.cancel', $acquisto->token),
114
-                'brand_name' => config('app.name'),
115
-                'user_action' => 'PAY_NOW',
116
-            ],
117
-        ]);
119
+            ]);
118
 
120
 
119
         if (! $response->successful()) {
121
         if (! $response->successful()) {
120
             Log::error('PayPal create order failed', ['body' => $response->body()]);
122
             Log::error('PayPal create order failed', ['body' => $response->body()]);
139
     {
141
     {
140
         $token = $this->paypalAccessToken();
142
         $token = $this->paypalAccessToken();
141
         $base = $this->paypalBaseUrl();
143
         $base = $this->paypalBaseUrl();
142
-        $response = Http::withToken($token)->withBody('{}', 'application/json')
144
+        $response = $this->paypalHttp()
145
+            ->withToken($token)
146
+            ->withBody('{}', 'application/json')
143
             ->post($base.'/v2/checkout/orders/'.$orderId.'/capture');
147
             ->post($base.'/v2/checkout/orders/'.$orderId.'/capture');
144
 
148
 
145
         if (! $response->successful()) {
149
         if (! $response->successful()) {
214
     private function paypalAccessToken(): string
218
     private function paypalAccessToken(): string
215
     {
219
     {
216
         $base = $this->paypalBaseUrl();
220
         $base = $this->paypalBaseUrl();
217
-        $response = Http::asForm()
221
+        $response = $this->paypalHttp()
222
+            ->asForm()
218
             ->withBasicAuth(config('services.paypal.client_id'), config('services.paypal.secret'))
223
             ->withBasicAuth(config('services.paypal.client_id'), config('services.paypal.secret'))
219
             ->post($base.'/v1/oauth2/token', ['grant_type' => 'client_credentials']);
224
             ->post($base.'/v1/oauth2/token', ['grant_type' => 'client_credentials']);
220
 
225
 
225
         return $response->json('access_token');
230
         return $response->json('access_token');
226
     }
231
     }
227
 
232
 
233
+    private function paypalHttp(): \Illuminate\Http\Client\PendingRequest
234
+    {
235
+        return Http::timeout(30)->connectTimeout(10);
236
+    }
237
+
228
     private function paypalBaseUrl(): string
238
     private function paypalBaseUrl(): string
229
     {
239
     {
230
         return config('services.paypal.mode') === 'live'
240
         return config('services.paypal.mode') === 'live'

+ 19
- 10
app/Services/AimonSmsService.php Ver fichero

24
         $sender = $sender ?? (string) config('services.aimon.sender', 'ElephanTech');
24
         $sender = $sender ?? (string) config('services.aimon.sender', 'ElephanTech');
25
         $body = mb_substr($body, 0, 600);
25
         $body = mb_substr($body, 0, 600);
26
 
26
 
27
-        $response = Http::asForm()
28
-            ->timeout(30)
29
-            ->post((string) config('services.aimon.send_url'), [
30
-                'authlogin' => config('services.aimon.login'),
31
-                'authpasswd' => config('services.aimon.password'),
32
-                'sender' => base64_encode($sender),
33
-                'body' => base64_encode($body),
34
-                'destination' => $destination,
35
-                'id_api' => (int) config('services.aimon.id_api'),
36
-            ]);
27
+        try {
28
+            $response = Http::asForm()
29
+                ->timeout(30)
30
+                ->connectTimeout(10)
31
+                ->post((string) config('services.aimon.send_url'), [
32
+                    'authlogin' => config('services.aimon.login'),
33
+                    'authpasswd' => config('services.aimon.password'),
34
+                    'sender' => base64_encode($sender),
35
+                    'body' => base64_encode($body),
36
+                    'destination' => $destination,
37
+                    'id_api' => (int) config('services.aimon.id_api'),
38
+                ]);
39
+        } catch (\Illuminate\Http\Client\ConnectionException $e) {
40
+            throw new RuntimeException(
41
+                'Aimon SMS non raggiungibile (timeout DNS/rete). '.$e->getMessage(),
42
+                0,
43
+                $e
44
+            );
45
+        }
37
 
46
 
38
         $responseBody = trim((string) $response->body());
47
         $responseBody = trim((string) $response->body());
39
 
48
 

+ 40
- 13
app/Services/SkebbySmsService.php Ver fichero

47
         $auth = $this->authHeaders();
47
         $auth = $this->authHeaders();
48
         $this->assertHasCredits($auth, $messageType);
48
         $this->assertHasCredits($auth, $messageType);
49
 
49
 
50
-        $response = Http::withHeaders($auth)
51
-            ->acceptJson()
52
-            ->asJson()
53
-            ->timeout(30)
54
-            ->post($this->baseUrl().'sms', $payload);
50
+        try {
51
+            $response = Http::withHeaders($auth)
52
+                ->acceptJson()
53
+                ->asJson()
54
+                ->timeout(30)
55
+                ->connectTimeout(10)
56
+                ->post($this->baseUrl().'sms', $payload);
57
+        } catch (\Illuminate\Http\Client\ConnectionException $e) {
58
+            throw new RuntimeException(
59
+                'Skebby non raggiungibile (timeout DNS/rete verso api.skebby.it). Riprova tra poco. '.$e->getMessage(),
60
+                0,
61
+                $e
62
+            );
63
+        }
55
 
64
 
56
         if ($response->status() !== 201) {
65
         if ($response->status() !== 201) {
57
             $message = data_get($response->json(), 'result')
66
             $message = data_get($response->json(), 'result')
121
         $lastError = null;
130
         $lastError = null;
122
 
131
 
123
         foreach (['login', 'token'] as $endpoint) {
132
         foreach (['login', 'token'] as $endpoint) {
124
-            $response = Http::withBasicAuth($username, $password)
125
-                ->acceptJson()
126
-                ->timeout(30)
127
-                ->get($base.$endpoint);
133
+            try {
134
+                $response = Http::withBasicAuth($username, $password)
135
+                    ->acceptJson()
136
+                    ->timeout(30)
137
+                    ->connectTimeout(10)
138
+                    ->get($base.$endpoint);
139
+            } catch (\Illuminate\Http\Client\ConnectionException $e) {
140
+                throw new RuntimeException(
141
+                    'Skebby non raggiungibile (timeout DNS/rete verso api.skebby.it). '.$e->getMessage(),
142
+                    0,
143
+                    $e
144
+                );
145
+            }
128
 
146
 
129
             $status = $response->status();
147
             $status = $response->status();
130
             $body = trim((string) $response->body());
148
             $body = trim((string) $response->body());
174
      */
192
      */
175
     private function assertHasCredits(array $auth, string $messageType): void
193
     private function assertHasCredits(array $auth, string $messageType): void
176
     {
194
     {
177
-        $response = Http::withHeaders($auth)
178
-            ->acceptJson()
179
-            ->timeout(20)
180
-            ->get($this->baseUrl().'status');
195
+        try {
196
+            $response = Http::withHeaders($auth)
197
+                ->acceptJson()
198
+                ->timeout(20)
199
+                ->connectTimeout(10)
200
+                ->get($this->baseUrl().'status');
201
+        } catch (\Illuminate\Http\Client\ConnectionException $e) {
202
+            throw new RuntimeException(
203
+                'Skebby non raggiungibile (timeout DNS/rete verso api.skebby.it). '.$e->getMessage(),
204
+                0,
205
+                $e
206
+            );
207
+        }
181
 
208
 
182
         if ($response->status() !== 200) {
209
         if ($response->status() !== 200) {
183
             return; // non bloccare se status non disponibile
210
             return; // non bloccare se status non disponibile

+ 14
- 4
app/Services/SmsService.php Ver fichero

93
 
93
 
94
             return ['ok' => true, 'message_id' => $messageId, 'provider' => $provider];
94
             return ['ok' => true, 'message_id' => $messageId, 'provider' => $provider];
95
         } catch (\Throwable $e) {
95
         } catch (\Throwable $e) {
96
+            $friendly = $e->getMessage();
97
+            if (str_contains($friendly, 'Resolving timed out') || str_contains($friendly, 'cURL error 28')) {
98
+                $friendly = 'Timeout di rete verso il provider SMS (DNS). Verifica connettività del server verso api.skebby.it / secure.apisms.it.';
99
+            }
100
+
96
             Log::error('SMS: invio firma consegna fallito', [
101
             Log::error('SMS: invio firma consegna fallito', [
97
                 'acquisto_id' => $acquisto->id,
102
                 'acquisto_id' => $acquisto->id,
98
                 'provider' => $provider,
103
                 'provider' => $provider,
103
 
108
 
104
             $acquisto->mergeMeta([
109
             $acquisto->mergeMeta([
105
                 'sms_firma_provider' => $provider,
110
                 'sms_firma_provider' => $provider,
106
-                'sms_firma_error' => mb_substr($e->getMessage(), 0, 500),
111
+                'sms_firma_error' => mb_substr($friendly, 0, 500),
107
             ]);
112
             ]);
108
             $acquisto->save();
113
             $acquisto->save();
109
 
114
 
110
-            return ['ok' => false, 'error' => $e->getMessage(), 'provider' => $provider];
115
+            return ['ok' => false, 'error' => $friendly, 'provider' => $provider];
111
         }
116
         }
112
     }
117
     }
113
 
118
 
178
 
183
 
179
             return ['ok' => true, 'message_id' => $messageId, 'provider' => $provider];
184
             return ['ok' => true, 'message_id' => $messageId, 'provider' => $provider];
180
         } catch (\Throwable $e) {
185
         } catch (\Throwable $e) {
186
+            $friendly = $e->getMessage();
187
+            if (str_contains($friendly, 'Resolving timed out') || str_contains($friendly, 'cURL error 28')) {
188
+                $friendly = 'Timeout di rete verso il provider SMS (DNS). Verifica connettività del server verso api.skebby.it / secure.apisms.it.';
189
+            }
190
+
181
             Log::error('SMS: invio firma riconsegna fallito', [
191
             Log::error('SMS: invio firma riconsegna fallito', [
182
                 'acquisto_id' => $acquisto->id,
192
                 'acquisto_id' => $acquisto->id,
183
                 'provider' => $provider,
193
                 'provider' => $provider,
188
 
198
 
189
             $acquisto->mergeMeta([
199
             $acquisto->mergeMeta([
190
                 'sms_firma_riconsegna_provider' => $provider,
200
                 'sms_firma_riconsegna_provider' => $provider,
191
-                'sms_firma_riconsegna_error' => mb_substr($e->getMessage(), 0, 500),
201
+                'sms_firma_riconsegna_error' => mb_substr($friendly, 0, 500),
192
             ]);
202
             ]);
193
             $acquisto->save();
203
             $acquisto->save();
194
 
204
 
195
-            return ['ok' => false, 'error' => $e->getMessage(), 'provider' => $provider];
205
+            return ['ok' => false, 'error' => $friendly, 'provider' => $provider];
196
         }
206
         }
197
     }
207
     }
198
 }
208
 }

Loading…
Cancelar
Guardar