-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.php
More file actions
137 lines (128 loc) · 5.28 KB
/
Copy pathfunction.php
File metadata and controls
137 lines (128 loc) · 5.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
if (!function_exists('paypalexpress_config')) {
/**
* Resolve a PayPal setting for the current effective store.
*
* Order: the admin_config row for the effective store (gp247_plugin_store_id) → the
* GLOBAL row (two-tier gp247_config) → the plugin's config.php static default. From
* version 3.1 the database is the single runtime source of truth; config.php holds
* only static defaults and no longer reads .env (a legacy .env is migrated into the
* database once by AppConfig::update()). Secrets stored in admin_config are decrypted
* transparently by core's read choke, so this returns plaintext.
*
* @param string $key Setting key without the "PaypalExpress_" prefix (e.g. "client_secret_live").
* @param mixed $default Fallback default when neither the database nor config.php has a value.
* @param string|int|null $storeId Resolve for this store instead of the effective one (a payment
* request is served with ITS store's account).
* @return mixed The resolved value.
*
* @aidlc-unit plugin-paypal-express
* @aidlc-story US-paypal-express-per-store-credentials
* @aidlc-adr paypal-express_per-store-credentials
*/
function paypalexpress_config(string $key, $default = null, $storeId = null)
{
$storeId ??= function_exists('gp247_plugin_store_id')
? gp247_plugin_store_id()
: (defined('GP247_STORE_ID_GLOBAL') ? GP247_STORE_ID_GLOBAL : 0);
// DB: effective store -> GLOBAL (gp247_config resolves the two tiers).
$value = gp247_config('PaypalExpress_' . $key, $storeId);
if ($value === null || $value === '') {
// Static default from config.php (no .env at runtime).
$value = config('Plugins/PaypalExpress.' . $key, $default);
}
return $value;
}
}
if (!function_exists('paypalexpress_return_url')) {
/**
* Absolute URL PayPal redirects to after a successful payment.
*
* Computed per request from the plugin route so it matches the store's current domain
* (and any locale prefix) instead of being a stored value that can drift when the
* domain changes — correct for both multi-store (per-domain) and marketplace topologies.
*
* @return string Absolute capture-payment URL.
*
* @aidlc-unit plugin-paypal-express
* @aidlc-story US-paypal-express-per-store-credentials
* @aidlc-adr paypal-express_per-store-credentials
*/
function paypalexpress_return_url(): string
{
return route('paypal-express.capture_payment');
}
}
if (!function_exists('paypalexpress_cancel_url')) {
/**
* Absolute URL PayPal redirects to when the customer cancels the payment.
*
* Computed per request from the plugin route (see paypalexpress_return_url()).
*
* @return string Absolute cancel-payment URL.
*
* @aidlc-unit plugin-paypal-express
* @aidlc-story US-paypal-express-per-store-credentials
* @aidlc-adr paypal-express_per-store-credentials
*/
function paypalexpress_cancel_url(): string
{
return route('paypal-express.cancel_payment');
}
}
if (!function_exists('paypalexpress_webhook_url')) {
/**
* Absolute URL the site owner registers as a webhook endpoint in PayPal Developer.
*
* @return string Absolute webhook URL for the current domain.
*
* @aidlc-unit plugin-paypal-express
* @aidlc-story US-paypal-express-per-store-credentials
*/
function paypalexpress_webhook_url(): string
{
return route('paypal-express.webhook');
}
}
if (!function_exists('paypalexpress_payment_request_return_url')) {
/**
* Where PayPal sends a payer back after approving a core payment request.
*
* @return string
*
* @aidlc-unit plugin-paypal-express
* @aidlc-story US-paypal-express-payment-request
*/
function paypalexpress_payment_request_return_url(): string
{
return \Illuminate\Support\Facades\Route::has('paypal-express.payment_request.return')
? route('paypal-express.payment_request.return')
: url('plugin/paypal-express/payment-request/return');
}
}
if (!function_exists('paypalexpress_register_payment_gateway')) {
/**
* Offer PayPal to the core's payment requests (pay links, refunds) — only when the
* core has that feature; an older core simply never sees the gateway.
*
* @return void
*
* @aidlc-unit plugin-paypal-express
* @aidlc-story US-paypal-express-payment-request
* @aidlc-adr paypal-express_payment-request-gateway
*/
function paypalexpress_register_payment_gateway(): void
{
if (!interface_exists(\GP247\Shop\Payment\Contracts\PaymentGateway::class)) {
return;
}
// WHY a whole-array write: dot-notation would split a gateway key containing dots.
$gateways = (array) config('gp247-config.payment.gateways', []);
$gateways['PaypalExpress'] = [
'label' => 'PayPal',
'capabilities' => ['collect', 'refund'],
'driver' => \App\GP247\Plugins\PaypalExpress\Services\PaypalPaymentRequestGateway::class,
];
config(['gp247-config.payment.gateways' => $gateways]);
}
}