← All changes
|
paypal/controllers/FrmPayPalLiteActionsController.php
+58
-7
6.32.1
→
trunk
View file →
| @@ -1295,16 +1295,21 @@ | ||
| 1295 | 1295 | $include_messages = false; |
| 1296 | 1296 | break; |
| 1297 | 1297 | } |
| 1298 | 1298 | |
| 1299 | - $components = array(); | |
| 1300 | - $include_google_apple_pay = $include_buttons && 'subscription' !== $intent && is_ssl() && self::include_google_pay_apple_pay(); | |
| 1299 | + $components = array(); | |
| 1300 | + $supports_wallet_buttons = $include_buttons && 'subscription' !== $intent && is_ssl() && self::include_google_pay_apple_pay(); | |
| 1301 | + $include_google_pay = $supports_wallet_buttons && self::include_google_pay(); | |
| 1302 | + $include_apple_pay = $supports_wallet_buttons && self::include_apple_pay(); | |
| 1301 | 1303 | |
| 1302 | 1304 | if ( $include_buttons ) { |
| 1303 | 1305 | $components[] = 'buttons'; |
| 1304 | 1306 | |
| 1305 | - if ( $include_google_apple_pay ) { | |
| 1307 | + if ( $include_google_pay ) { | |
| 1306 | 1308 | $components[] = 'googlepay'; |
| 1309 | + } | |
| 1310 | + | |
| 1311 | + if ( $include_apple_pay ) { | |
| 1307 | 1312 | $components[] = 'applepay'; |
| 1308 | 1313 | } |
| 1309 | 1314 | } |
| 1310 | 1315 | |
| @@ -1342,9 +1347,9 @@ | ||
| 1342 | 1347 | $sdk_url = add_query_arg( $query_args, 'https://www.paypal.com/sdk/js' ); |
| 1343 | 1348 | |
| 1344 | 1349 | wp_register_script( 'paypal-sdk', $sdk_url, array(), null, false ); |
| 1345 | 1350 | |
| 1346 | - if ( $include_google_apple_pay ) { | |
| 1351 | + if ( $include_apple_pay ) { | |
| 1347 | 1352 | wp_register_script( 'apple-pay-sdk', 'https://applepay.cdn-apple.com/jsapi/1.latest/apple-pay-sdk.js', array(), null, false ); |
| 1348 | 1353 | } |
| 1349 | 1354 | |
| 1350 | 1355 | $has_break = FrmAppHelper::pro_is_installed() && (bool) FrmField::get_all_types_in_form( $form_id, 'break' ); |
| @@ -1385,9 +1390,9 @@ | ||
| 1385 | 1390 | ); |
| 1386 | 1391 | |
| 1387 | 1392 | $dependencies = array( 'paypal-sdk', 'formidable' ); |
| 1388 | 1393 | |
| 1389 | - if ( $include_google_apple_pay ) { | |
| 1394 | + if ( $include_apple_pay ) { | |
| 1390 | 1395 | $dependencies[] = 'apple-pay-sdk'; |
| 1391 | 1396 | } |
| 1392 | 1397 | |
| 1393 | 1398 | $script_url = FrmPayPalLiteAppHelper::plugin_url() . 'js/frontend.js'; |
| @@ -1399,9 +1404,9 @@ | ||
| 1399 | 1404 | FrmAppHelper::plugin_version(), |
| 1400 | 1405 | false |
| 1401 | 1406 | ); |
| 1402 | 1407 | |
| 1403 | - if ( $include_google_apple_pay ) { | |
| 1408 | + if ( $include_google_pay ) { | |
| 1404 | 1409 | wp_enqueue_script( |
| 1405 | 1410 | 'google-pay', |
| 1406 | 1411 | 'https://pay.google.com/gp/p/js/pay.js', |
| 1407 | 1412 | array(), |
| @@ -1417,9 +1422,12 @@ | ||
| 1417 | 1422 | 'settings' => $action_settings, |
| 1418 | 1423 | 'style' => self::get_style_for_js( $form_id ), |
| 1419 | 1424 | 'buttonStyle' => self::get_button_style_for_js( $action ), |
| 1420 | 1425 | 'imagesUrl' => FrmPayPalLiteAppHelper::plugin_url() . 'images/', |
| 1421 | - 'includeGooglePayApplePay' => $include_google_apple_pay, | |
| 1426 | + 'includeGooglePay' => $include_google_pay, | |
| 1427 | + 'includeApplePay' => $include_apple_pay, | |
| 1428 | + 'includeGooglePayApplePay' => $include_google_pay || $include_apple_pay, | |
| 1429 | + 'mode' => FrmPayPalLiteAppHelper::active_mode(), | |
| 1422 | 1430 | ); |
| 1423 | 1431 | |
| 1424 | 1432 | wp_localize_script( 'formidable-paypal', 'frmPayPalVars', $paypal_vars ); |
| 1425 | 1433 | } |
| @@ -1424,8 +1432,13 @@ | ||
| 1424 | 1432 | wp_localize_script( 'formidable-paypal', 'frmPayPalVars', $paypal_vars ); |
| 1425 | 1433 | } |
| 1426 | 1434 | |
| 1427 | 1435 | /** |
| 1436 | + * Check if the Google Pay and Apple Pay wallet buttons are allowed at all. | |
| 1437 | + * | |
| 1438 | + * This gates both wallets together. To turn off just one of them, use | |
| 1439 | + * frm_paypal_commerce_include_google_pay or frm_paypal_commerce_include_apple_pay instead. | |
| 1440 | + * | |
| 1428 | 1441 | * @since 6.31 |
| 1429 | 1442 | * |
| 1430 | 1443 | * @return bool |
| 1431 | 1444 | */ |
| @@ -1435,8 +1448,46 @@ | ||
| 1435 | 1448 | * |
| 1436 | 1449 | * @param bool $include_google_pay_apple_pay |
| 1437 | 1450 | */ |
| 1438 | 1451 | return (bool) apply_filters( 'frm_include_google_pay_apple_pay', true ); |
| 1452 | + } | |
| 1453 | + | |
| 1454 | + /** | |
| 1455 | + * Check if the Google Pay wallet button is allowed for PayPal Commerce. | |
| 1456 | + * | |
| 1457 | + * Only called when frm_include_google_pay_apple_pay allows the wallets, so this | |
| 1458 | + * filter turns off Google Pay without affecting Apple Pay. | |
| 1459 | + * | |
| 1460 | + * @since 6.34 | |
| 1461 | + * | |
| 1462 | + * @return bool | |
| 1463 | + */ | |
| 1464 | + private static function include_google_pay() { | |
| 1465 | + /** | |
| 1466 | + * @since 6.34 | |
| 1467 | + * | |
| 1468 | + * @param bool $include_google_pay | |
| 1469 | + */ | |
| 1470 | + return (bool) apply_filters( 'frm_paypal_commerce_include_google_pay', true ); | |
| 1471 | + } | |
| 1472 | + | |
| 1473 | + /** | |
| 1474 | + * Check if the Apple Pay wallet button is allowed for PayPal Commerce. | |
| 1475 | + * | |
| 1476 | + * Only called when frm_include_google_pay_apple_pay allows the wallets, so this | |
| 1477 | + * filter turns off Apple Pay without affecting Google Pay. | |
| 1478 | + * | |
| 1479 | + * @since 6.34 | |
| 1480 | + * | |
| 1481 | + * @return bool | |
| 1482 | + */ | |
| 1483 | + private static function include_apple_pay() { | |
| 1484 | + /** | |
| 1485 | + * @since 6.34 | |
| 1486 | + * | |
| 1487 | + * @param bool $include_apple_pay | |
| 1488 | + */ | |
| 1489 | + return (bool) apply_filters( 'frm_paypal_commerce_include_apple_pay', true ); | |
| 1439 | 1490 | } |
| 1440 | 1491 | |
| 1441 | 1492 | /** |
| 1442 | 1493 | * @since 6.31 |