@@ -25,16 +25,22 @@ class ViewConfig extends ViewConfig_parent
25
25
26
26
/**
27
27
* is this a "Flow"-Theme Compatible Theme?
28
- * @param boolean
28
+ * @var boolean
29
29
*/
30
30
protected $ isFlowCompatibleTheme = null ;
31
31
32
32
/**
33
33
* is this a "Wave"-Theme Compatible Theme?
34
- * @param boolean
34
+ * @var boolean
35
35
*/
36
36
protected $ isWaveCompatibleTheme = null ;
37
37
38
+ /**
39
+ * is this SDK necessary?
40
+ * @var boolean
41
+ */
42
+ protected $ isSDKNecessary = false ;
43
+
38
44
/**
39
45
* @return bool
40
46
*/
@@ -123,6 +129,22 @@ public function getCheckoutOrderId()
123
129
return PayPalSession::getCheckoutOrderId ();
124
130
}
125
131
132
+ /**
133
+ * @return void
134
+ */
135
+ public function setSDKIsNecessary ()
136
+ {
137
+ $ this ->isSDKNecessary = true ;
138
+ }
139
+
140
+ /**
141
+ * @return bool
142
+ */
143
+ public function isSDKNecessary ()
144
+ {
145
+ return $ this ->isSDKNecessary ;
146
+ }
147
+
126
148
/**
127
149
* @return string
128
150
*/
@@ -158,12 +180,30 @@ public function getPayPalJsSdkUrl(): string
158
180
{
159
181
$ config = Registry::getConfig ();
160
182
$ lang = Registry::getLang ();
183
+ $ params = [];
184
+ $ enableFunding = [];
185
+ $ disableFunding = [
186
+ 'bancontact ' ,
187
+ 'blik ' ,
188
+ 'eps ' ,
189
+ 'giropay ' ,
190
+ 'ideal ' ,
191
+ 'mercadopago ' ,
192
+ 'p24 ' ,
193
+ 'venmo ' ,
194
+ ];
195
+ $ components = [
196
+ 'buttons ' ,
197
+ ];
198
+
199
+ if ($ this ->getTopActiveClassName () !== 'payment ' ) {
200
+ $ disableFunding [] = 'sepa ' ;
201
+ }
161
202
162
203
$ localeCode = $ this ->getServiceFromContainer (LanguageLocaleMapper::class)
163
204
->mapLanguageToLocale ($ lang ->getLanguageAbbr ());
164
205
165
206
$ moduleSettings = $ this ->getServiceFromContainer (ModuleSettings::class);
166
- $ params = [];
167
207
168
208
$ params ['client-id ' ] = $ this ->getPayPalClientId ();
169
209
$ params ['integration-date ' ] = Constants::PAYPAL_INTEGRATION_DATE ;
@@ -174,79 +214,32 @@ public function getPayPalJsSdkUrl(): string
174
214
$ params ['currency ' ] = strtoupper ($ currency ->name );
175
215
}
176
216
177
- $ params ['components ' ] = ' buttons ' ;
178
- // Available components: enable messages+buttons for PDP
217
+ $ params ['merchant-id ' ] = $ moduleSettings -> getMerchantId () ;
218
+
179
219
if ($ this ->isPayPalBannerActive ()) {
180
- $ params [ ' components ' ] . = ', messages ' ;
220
+ $ components[] = 'messages ' ;
181
221
}
182
222
183
223
if ($ moduleSettings ->showPayPalPayLaterButton ()) {
184
- $ params [ ' enable-funding ' ] = 'paylater ' ;
224
+ $ enableFunding [ ] = 'paylater ' ;
185
225
}
186
226
187
- $ params ['disable-funding ' ] = 'sepa,bancontact,blik,eps,giropay,ideal,mercadopago,p24,venmo ' ;
188
-
189
227
if ($ moduleSettings ->isAcdcEligibility ()) {
190
- $ params [ ' disable-funding ' ] . = ',card ' ;
228
+ $ components [] = 'hosted-fields ' ;
191
229
} else {
192
- if (isset ($ params ['enable-funding ' ])) {
193
- $ params ['enable-funding ' ] .= ',card ' ;
194
- } else {
195
- $ params ['enable-funding ' ] = 'card ' ;
196
- }
230
+ $ enableFunding [] = 'card ' ;
197
231
}
198
- $ params ['locale ' ] = $ localeCode ;
199
-
200
- return Constants::PAYPAL_JS_SDK_URL . '? ' . http_build_query ($ params );
201
- }
202
232
203
- /**
204
- * Gets PayPal JS SDK url for ACDC
205
- *
206
- * @return string
207
- */
208
- public function getPayPalJsSdkUrlForACDC (): string
209
- {
210
- return $ this ->getBasePayPalJsSdkUrl ('hosted-fields ' );
211
- }
212
-
213
- /**
214
- * Gets PayPal JS SDK url for Button Payments like SEPA and CreditCardFallback
215
- *
216
- * @return string
217
- */
218
- public function getPayPalJsSdkUrlForButtonPayments (): string
219
- {
220
- return $ this ->getBasePayPalJsSdkUrl ('funding-eligibility ' , true );
221
- }
222
-
223
- protected function getBasePayPalJsSdkUrl ($ type = '' , $ continueFlow = false ): string
224
- {
225
- $ config = Registry::getConfig ();
226
- $ lang = Registry::getLang ();
227
-
228
- $ localeCode = $ this ->getServiceFromContainer (LanguageLocaleMapper::class)
229
- ->mapLanguageToLocale ($ lang ->getLanguageAbbr ());
230
-
231
- $ params = [];
232
-
233
- $ params ['client-id ' ] = $ this ->getPayPalClientId ();
234
- $ params ['integration-date ' ] = Constants::PAYPAL_INTEGRATION_DATE ;
235
-
236
- if ($ currency = $ config ->getActShopCurrencyObject ()) {
237
- $ params ['currency ' ] = strtoupper ($ currency ->name );
233
+ if ($ components ) {
234
+ $ params ['components ' ] = implode (', ' , $ components );
238
235
}
239
-
240
- if ($ continueFlow ) {
241
- $ params ['intent ' ] = strtolower (Constants::PAYPAL_ORDER_INTENT_CAPTURE );
242
- $ params ['commit ' ] = 'false ' ;
236
+ if ($ enableFunding ) {
237
+ $ params ['enable-funding ' ] = implode (', ' , $ enableFunding );
243
238
}
244
-
245
- $ params ['components ' ] = 'buttons, ' . $ type ;
246
-
247
- if ($ this ->isPayPalBannerActive ()) {
248
- $ params ['components ' ] .= ',messages ' ;
239
+ if ($ disableFunding ) {
240
+ $ params ['disable-funding ' ] = implode (', ' , $ disableFunding );
249
241
}
242
+
250
243
$ params ['locale ' ] = $ localeCode ;
251
244
252
245
return Constants::PAYPAL_JS_SDK_URL . '? ' . http_build_query ($ params );
0 commit comments