← All changes
|
paypal/controllers/FrmPayPalLiteActionsController.php
+88
-34
6.31
→
trunk
View file →
| @@ -614,9 +614,9 @@ | ||
| 614 | 614 | if ( ! isset( $subscription->status ) ) { |
| 615 | 615 | return false; |
| 616 | 616 | } |
| 617 | 617 | |
| 618 | - return in_array( $subscription->status, array( 'ACTIVE', 'APPROVED', 'APPROVAL_PENDING' ), true ); | |
| 618 | + return in_array( $subscription->status, array( 'ACTIVE', 'APPROVED' ), true ); | |
| 619 | 619 | } |
| 620 | 620 | |
| 621 | 621 | /** |
| 622 | 622 | * Validate that the subscription amount matches the expected amount. |
| @@ -628,13 +628,8 @@ | ||
| 628 | 628 | * |
| 629 | 629 | * @return bool |
| 630 | 630 | */ |
| 631 | 631 | private static function validate_subscription_amount( $subscription, $expected_amount ) { |
| 632 | - // Vault-created subscriptions in APPROVAL_PENDING have no billing details yet. | |
| 633 | - if ( isset( $subscription->status ) && 'APPROVAL_PENDING' === $subscription->status ) { | |
| 634 | - return true; | |
| 635 | - } | |
| 636 | - | |
| 637 | 632 | $subscription_amount = $subscription->billing_info->last_payment->amount->value ?? $subscription->plan->billing_cycles[0]->pricing_scheme->fixed_price->value ?? ''; |
| 638 | 633 | |
| 639 | 634 | if ( ! $subscription_amount ) { |
| 640 | 635 | return false; |
| @@ -1263,27 +1258,34 @@ | ||
| 1263 | 1258 | if ( 'subscription' === $intent ) { |
| 1264 | 1259 | $query_args['vault'] = 'true'; |
| 1265 | 1260 | } |
| 1266 | 1261 | |
| 1267 | - $include_buttons = false; | |
| 1268 | - $include_card_fields = false; | |
| 1269 | - $include_messages = true; | |
| 1262 | + if ( 'subscription' === $intent ) { | |
| 1263 | + $include_buttons = true; | |
| 1264 | + $include_card_fields = false; | |
| 1265 | + } else { | |
| 1266 | + // One time payments. | |
| 1267 | + $include_buttons = false; | |
| 1268 | + $include_card_fields = false; | |
| 1270 | 1269 | |
| 1271 | - switch ( $action->post_content['paypal_layout'] ?? 'card_and_checkout' ) { | |
| 1272 | - case 'card_only': | |
| 1273 | - $include_card_fields = true; | |
| 1274 | - break; | |
| 1270 | + switch ( $action->post_content['paypal_layout'] ?? 'card_and_checkout' ) { | |
| 1271 | + case 'card_only': | |
| 1272 | + $include_card_fields = true; | |
| 1273 | + break; | |
| 1275 | 1274 | |
| 1276 | - case 'checkout_only': | |
| 1277 | - $include_buttons = true; | |
| 1278 | - break; | |
| 1275 | + case 'checkout_only': | |
| 1276 | + $include_buttons = true; | |
| 1277 | + break; | |
| 1279 | 1278 | |
| 1280 | - default: | |
| 1281 | - $include_buttons = true; | |
| 1282 | - $include_card_fields = true; | |
| 1283 | - break; | |
| 1284 | - } | |
| 1279 | + default: | |
| 1280 | + $include_buttons = true; | |
| 1281 | + $include_card_fields = true; | |
| 1282 | + break; | |
| 1283 | + } | |
| 1284 | + }//end if | |
| 1285 | 1285 | |
| 1286 | + $include_messages = true; | |
| 1287 | + | |
| 1286 | 1288 | switch ( $action->post_content['pay_later'] ?? 'auto' ) { |
| 1287 | 1289 | case 'off': |
| 1288 | 1290 | $query_args['disable-funding'] = 'paylater'; |
| 1289 | 1291 | break; |
| @@ -1293,16 +1295,21 @@ | ||
| 1293 | 1295 | $include_messages = false; |
| 1294 | 1296 | break; |
| 1295 | 1297 | } |
| 1296 | 1298 | |
| 1297 | - $components = array(); | |
| 1298 | - $include_google_apple_pay = $include_buttons && 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(); | |
| 1299 | 1303 | |
| 1300 | 1304 | if ( $include_buttons ) { |
| 1301 | 1305 | $components[] = 'buttons'; |
| 1302 | 1306 | |
| 1303 | - if ( $include_google_apple_pay ) { | |
| 1307 | + if ( $include_google_pay ) { | |
| 1304 | 1308 | $components[] = 'googlepay'; |
| 1309 | + } | |
| 1310 | + | |
| 1311 | + if ( $include_apple_pay ) { | |
| 1305 | 1312 | $components[] = 'applepay'; |
| 1306 | 1313 | } |
| 1307 | 1314 | } |
| 1308 | 1315 | |
| @@ -1340,9 +1347,9 @@ | ||
| 1340 | 1347 | $sdk_url = add_query_arg( $query_args, 'https://www.paypal.com/sdk/js' ); |
| 1341 | 1348 | |
| 1342 | 1349 | wp_register_script( 'paypal-sdk', $sdk_url, array(), null, false ); |
| 1343 | 1350 | |
| 1344 | - if ( $include_google_apple_pay ) { | |
| 1351 | + if ( $include_apple_pay ) { | |
| 1345 | 1352 | wp_register_script( 'apple-pay-sdk', 'https://applepay.cdn-apple.com/jsapi/1.latest/apple-pay-sdk.js', array(), null, false ); |
| 1346 | 1353 | } |
| 1347 | 1354 | |
| 1348 | 1355 | $has_break = FrmAppHelper::pro_is_installed() && (bool) FrmField::get_all_types_in_form( $form_id, 'break' ); |
| @@ -1383,9 +1390,9 @@ | ||
| 1383 | 1390 | ); |
| 1384 | 1391 | |
| 1385 | 1392 | $dependencies = array( 'paypal-sdk', 'formidable' ); |
| 1386 | 1393 | |
| 1387 | - if ( $include_google_apple_pay ) { | |
| 1394 | + if ( $include_apple_pay ) { | |
| 1388 | 1395 | $dependencies[] = 'apple-pay-sdk'; |
| 1389 | 1396 | } |
| 1390 | 1397 | |
| 1391 | 1398 | $script_url = FrmPayPalLiteAppHelper::plugin_url() . 'js/frontend.js'; |
| @@ -1397,9 +1404,9 @@ | ||
| 1397 | 1404 | FrmAppHelper::plugin_version(), |
| 1398 | 1405 | false |
| 1399 | 1406 | ); |
| 1400 | 1407 | |
| 1401 | - if ( $include_google_apple_pay ) { | |
| 1408 | + if ( $include_google_pay ) { | |
| 1402 | 1409 | wp_enqueue_script( |
| 1403 | 1410 | 'google-pay', |
| 1404 | 1411 | 'https://pay.google.com/gp/p/js/pay.js', |
| 1405 | 1412 | array(), |
| @@ -1408,15 +1415,19 @@ | ||
| 1408 | 1415 | ); |
| 1409 | 1416 | } |
| 1410 | 1417 | |
| 1411 | 1418 | $paypal_vars = array( |
| 1412 | - 'formId' => $form_id, | |
| 1413 | - 'nonce' => wp_create_nonce( 'frm_paypal_ajax' ), | |
| 1414 | - 'ajax' => esc_url_raw( FrmAppHelper::get_ajax_url() ), | |
| 1415 | - 'settings' => $action_settings, | |
| 1416 | - 'style' => self::get_style_for_js( $form_id ), | |
| 1417 | - 'buttonStyle' => self::get_button_style_for_js( $action ), | |
| 1418 | - 'imagesUrl' => FrmPayPalLiteAppHelper::plugin_url() . 'images/', | |
| 1419 | + 'formId' => $form_id, | |
| 1420 | + 'nonce' => wp_create_nonce( 'frm_paypal_ajax' ), | |
| 1421 | + 'ajax' => esc_url_raw( FrmAppHelper::get_ajax_url() ), | |
| 1422 | + 'settings' => $action_settings, | |
| 1423 | + 'style' => self::get_style_for_js( $form_id ), | |
| 1424 | + 'buttonStyle' => self::get_button_style_for_js( $action ), | |
| 1425 | + 'imagesUrl' => FrmPayPalLiteAppHelper::plugin_url() . 'images/', | |
| 1426 | + 'includeGooglePay' => $include_google_pay, | |
| 1427 | + 'includeApplePay' => $include_apple_pay, | |
| 1428 | + 'includeGooglePayApplePay' => $include_google_pay || $include_apple_pay, | |
| 1429 | + 'mode' => FrmPayPalLiteAppHelper::active_mode(), | |
| 1419 | 1430 | ); |
| 1420 | 1431 | |
| 1421 | 1432 | wp_localize_script( 'formidable-paypal', 'frmPayPalVars', $paypal_vars ); |
| 1422 | 1433 | } |
| @@ -1421,8 +1432,13 @@ | ||
| 1421 | 1432 | wp_localize_script( 'formidable-paypal', 'frmPayPalVars', $paypal_vars ); |
| 1422 | 1433 | } |
| 1423 | 1434 | |
| 1424 | 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 | + * | |
| 1425 | 1441 | * @since 6.31 |
| 1426 | 1442 | * |
| 1427 | 1443 | * @return bool |
| 1428 | 1444 | */ |
| @@ -1432,8 +1448,46 @@ | ||
| 1432 | 1448 | * |
| 1433 | 1449 | * @param bool $include_google_pay_apple_pay |
| 1434 | 1450 | */ |
| 1435 | 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 ); | |
| 1436 | 1490 | } |
| 1437 | 1491 | |
| 1438 | 1492 | /** |
| 1439 | 1493 | * @since 6.31 |