PluginProbe
The Innovative Form Builder – IvyForms / trunk
The Innovative Form Builder – IvyForms vtrunk
1.5.1 1.5 1.4.1 1.4 trunk 0.1.2 0.2 0.2.1 0.3 0.3.1 0.4 0.5 0.6 0.6.1 0.6.1-backup 0.6.1.1 0.7 0.8 0.8.1 0.8.2 0.9 0.9.1 1.0 1.1 1.1.1 All 27 releases
ivyforms / backend / src / Services / Payment / SquareEnvironment.php

SquareEnvironment.php in The Innovative Form Builder – IvyForms trunk, at backend/src/Services/Payment/SquareEnvironment.php

50 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace IvyForms\Services\Payment;
4
5 use IvyForms\Plugin\Plugin;
6
7 /**
8 * Resolves Square sandbox vs production endpoints from IvyForms constants or middleware config.
9 */
10 class SquareEnvironment
11 {
12 public static function isSandbox(): bool
13 {
14 if (defined('IVYFORMS_SQUARE_AUTH_URL') && IVYFORMS_SQUARE_AUTH_URL !== '') {
15 return str_contains((string) IVYFORMS_SQUARE_AUTH_URL, 'sandbox');
16 }
17
18 if (defined('IVYFORMS_SQUARE_APP_ID') && IVYFORMS_SQUARE_APP_ID !== '') {
19 return str_starts_with((string) IVYFORMS_SQUARE_APP_ID, 'sandbox-sq');
20 }
21
22 $plugin = Plugin::getInstance();
23 if ($plugin->container !== null) {
24 try {
25 $squareOAuthService = $plugin->container->get(SquareOAuthService::class);
26
27 return $squareOAuthService->isMiddlewareSandbox();
28 } catch (\Throwable $e) {
29 // Fall through to default.
30 }
31 }
32
33 return true;
34 }
35
36 public static function getApiBaseUrl(): string
37 {
38 return self::isSandbox()
39 ? 'https://connect.squareupsandbox.com/v2'
40 : 'https://connect.squareup.com/v2';
41 }
42
43 public static function getWebPaymentsSdkUrl(): string
44 {
45 return self::isSandbox()
46 ? 'https://sandbox.web.squarecdn.com/v1/square.js'
47 : 'https://web.squarecdn.com/v1/square.js';
48 }
49 }
50