2020-09-17 16:50:04 -03:00
< ? php
2020-03-19 16:47:08 +01:00
/**
2020-10-08 20:03:07 -03:00
* Plugin Name : WooCommerce PayPal Payments
2020-10-13 09:42:34 +03:00
* Plugin URI : https :// woocommerce . com / products / woocommerce - paypal - payments /
2021-03-09 13:43:24 +02:00
* Description : PayPal ' s latest complete payments processing solution . Accept PayPal , Pay Later , credit / debit cards , alternative digital wallets local payment types and bank accounts . Turn on only PayPal options or process a full suite of payment methods . Enable global transaction with extensive currency and country coverage .
2024-06-25 14:13:10 +02:00
* Version : 2.8 . 1
2020-09-11 10:14:00 +03:00
* Author : WooCommerce
2020-10-13 09:42:34 +03:00
* Author URI : https :// woocommerce . com /
2020-03-19 16:47:08 +01:00
* License : GPL - 2.0
2022-11-09 17:11:17 +02:00
* Requires PHP : 7.2
2024-04-09 16:28:51 -03:00
* Requires Plugins : woocommerce
2021-01-15 11:00:24 +01:00
* WC requires at least : 3.9
2024-06-25 14:13:10 +02:00
* WC tested up to : 9.0
2020-10-08 20:03:07 -03:00
* Text Domain : woocommerce - paypal - payments
2020-09-17 16:50:04 -03:00
*
* @ package WooCommerce\PayPalCommerce
2020-03-19 16:47:08 +01:00
*/
2020-09-17 16:50:04 -03:00
declare ( strict_types = 1 );
2020-06-15 11:48:37 +03:00
2020-09-11 14:11:10 +03:00
namespace WooCommerce\PayPalCommerce ;
2020-04-02 08:38:00 +03:00
2022-09-26 10:44:25 +03:00
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings ;
2023-09-29 17:20:47 +03:00
define ( 'PAYPAL_API_URL' , 'https://api-m.paypal.com' );
2023-11-14 10:50:56 +02:00
define ( 'PAYPAL_URL' , 'https://www.paypal.com' );
2023-09-29 17:20:47 +03:00
define ( 'PAYPAL_SANDBOX_API_URL' , 'https://api-m.sandbox.paypal.com' );
2023-11-14 10:50:56 +02:00
define ( 'PAYPAL_SANDBOX_URL' , 'https://www.sandbox.paypal.com' );
2024-06-25 14:13:10 +02:00
define ( 'PAYPAL_INTEGRATION_DATE' , '2024-06-25' );
2020-10-01 08:53:44 +03:00
2020-10-13 09:42:34 +03:00
! defined ( 'CONNECT_WOO_CLIENT_ID' ) && define ( 'CONNECT_WOO_CLIENT_ID' , 'AcCAsWta_JTL__OfpjspNyH7c1GGHH332fLwonA5CwX4Y10mhybRZmHLA0GdRbwKwjQIhpDQy0pluX_P' );
! defined ( 'CONNECT_WOO_SANDBOX_CLIENT_ID' ) && define ( 'CONNECT_WOO_SANDBOX_CLIENT_ID' , 'AYmOHbt1VHg-OZ_oihPdzKEVbU3qg0qXonBcAztuzniQRaKE0w1Hr762cSFwd4n8wxOl-TCWohEa0XM_' );
2023-05-15 15:44:32 +02:00
! defined ( 'CONNECT_WOO_MERCHANT_ID' ) && define ( 'CONNECT_WOO_MERCHANT_ID' , 'K8SKZ36LQBWXJ' );
2020-10-13 09:42:34 +03:00
! defined ( 'CONNECT_WOO_SANDBOX_MERCHANT_ID' ) && define ( 'CONNECT_WOO_SANDBOX_MERCHANT_ID' , 'MPMFHQTVMBZ6G' );
2024-03-28 12:03:08 +01:00
! defined ( 'CONNECT_WOO_URL' ) && define ( 'CONNECT_WOO_URL' , 'https://api.woocommerce.com/integrations/ppc' );
! defined ( 'CONNECT_WOO_SANDBOX_URL' ) && define ( 'CONNECT_WOO_SANDBOX_URL' , 'https://api.woocommerce.com/integrations/ppcsandbox' );
2020-10-01 08:53:44 +03:00
2020-09-17 16:50:04 -03:00
( function () {
2022-06-13 22:07:18 +03:00
$autoload_filepath = __DIR__ . '/vendor/autoload.php' ;
if ( file_exists ( $autoload_filepath ) && ! class_exists ( '\WooCommerce\PayPalCommerce\PluginModule' ) ) {
require $autoload_filepath ;
}
2020-04-02 08:38:00 +03:00
2020-09-17 16:50:04 -03:00
/**
* Initialize the plugin and its modules .
*/
2023-03-14 16:38:28 +02:00
function init () : void {
2021-08-27 20:40:09 +03:00
$root_dir = __DIR__ ;
2022-02-17 16:52:40 +04:00
if ( ! is_woocommerce_activated () ) {
2021-01-13 14:48:19 +01:00
add_action (
'admin_notices' ,
function () {
/* translators: 1. URL link. */
echo '<div class="error"><p><strong>' . sprintf ( esc_html__ ( 'WooCommerce PayPal Payments requires WooCommerce to be installed and active. You can download %s here.' , 'woocommerce-paypal-payments' ), '<a href="https://woocommerce.com/" target="_blank">WooCommerce</a>' ) . '</strong></p></div>' ;
}
);
return ;
}
2022-12-14 11:39:22 +01:00
if ( version_compare ( PHP_VERSION , '7.2' , '<' ) ) {
2021-04-20 15:36:44 +02:00
add_action (
'admin_notices' ,
function () {
echo '<div class="error"><p>' . esc_html__ ( 'WooCommerce PayPal Payments requires PHP 7.1 or above.' , 'woocommerce-paypal-payments' ), '</p></div>' ;
}
);
return ;
}
2021-01-13 14:48:19 +01:00
2020-09-17 16:50:04 -03:00
static $initialized ;
if ( ! $initialized ) {
2021-08-27 20:40:09 +03:00
$bootstrap = require " $root_dir /bootstrap.php " ;
2021-07-26 20:13:05 +03:00
2021-08-27 20:40:09 +03:00
$app_container = $bootstrap ( $root_dir );
2021-07-26 20:13:05 +03:00
2023-03-14 16:37:29 +02:00
PPCP :: init ( $app_container );
2020-09-17 16:50:04 -03:00
$initialized = true ;
2022-02-17 18:19:55 +02:00
/**
* The hook fired after the plugin bootstrap with the app services container as parameter .
*/
2021-08-27 20:40:09 +03:00
do_action ( 'woocommerce_paypal_payments_built_container' , $app_container );
2020-09-17 16:50:04 -03:00
}
}
2020-04-02 08:38:00 +03:00
2020-09-17 16:50:04 -03:00
add_action (
'plugins_loaded' ,
function () {
init ();
2021-11-08 11:07:37 +01:00
if ( ! function_exists ( 'get_plugin_data' ) ) {
2023-03-14 16:38:28 +02:00
/**
* Skip check for WP files .
*
* @ psalm - suppress MissingFile
*/
2021-11-08 11:07:37 +01:00
require_once ABSPATH . 'wp-admin/includes/plugin.php' ;
}
2024-03-13 12:01:36 +01:00
$plugin_data = get_plugin_data ( __DIR__ . '/woocommerce-paypal-payments.php' , false );
2022-11-18 20:18:41 +04:00
$plugin_version = $plugin_data [ 'Version' ] ? ? null ;
$installed_plugin_version = get_option ( 'woocommerce-ppcp-version' );
if ( $installed_plugin_version !== $plugin_version ) {
2022-02-17 18:19:55 +02:00
/**
* The hook fired when the plugin is installed or updated .
*/
2021-11-08 11:07:37 +01:00
do_action ( 'woocommerce_paypal_payments_gateway_migrate' );
2022-11-18 20:18:41 +04:00
if ( $installed_plugin_version ) {
/**
* The hook fired when the plugin is updated .
*/
do_action ( 'woocommerce_paypal_payments_gateway_migrate_on_update' );
}
2021-11-08 11:43:44 +01:00
update_option ( 'woocommerce-ppcp-version' , $plugin_version );
2021-11-08 11:07:37 +01:00
}
2020-09-17 16:50:04 -03:00
}
);
register_activation_hook (
__FILE__ ,
function () {
init ();
2022-02-17 18:19:55 +02:00
/**
* The hook fired in register_activation_hook .
*/
2020-10-09 19:55:28 -03:00
do_action ( 'woocommerce_paypal_payments_gateway_activate' );
2020-09-17 16:50:04 -03:00
}
);
register_deactivation_hook (
__FILE__ ,
function () {
init ();
2022-02-17 18:19:55 +02:00
/**
* The hook fired in register_deactivation_hook .
*/
2020-10-09 19:55:28 -03:00
do_action ( 'woocommerce_paypal_payments_gateway_deactivate' );
2020-09-17 16:50:04 -03:00
}
);
2020-04-06 10:51:56 +03:00
2020-10-14 16:50:52 -03:00
add_filter (
'plugin_action_links_' . plugin_basename ( __FILE__ ),
2023-03-14 16:38:28 +02:00
/**
* Add " Settings " link to Plugins screen .
*
* @ param array $links
* @ retun array
*/
2020-10-14 16:50:52 -03:00
function ( $links ) {
2022-02-17 16:52:40 +04:00
if ( ! is_woocommerce_activated () ) {
2021-01-13 14:48:19 +01:00
return $links ;
}
2020-10-14 16:50:52 -03:00
array_unshift (
$links ,
sprintf (
'<a href="%1$s">%2$s</a>' ,
2022-09-26 10:44:25 +03:00
admin_url ( 'admin.php?page=wc-settings&tab=checkout§ion=ppcp-gateway&ppcp-tab=' . Settings :: CONNECTION_TAB_ID ),
2020-10-14 16:50:52 -03:00
__ ( 'Settings' , 'woocommerce-paypal-payments' )
)
);
return $links ;
}
);
2022-08-16 10:31:47 +03:00
add_filter (
'plugin_row_meta' ,
2023-03-14 16:38:28 +02:00
/**
* Add links below the description on the Plugins page .
*
* @ param array $links
* @ param string $file
* @ retun array
*/
2022-08-16 10:31:47 +03:00
function ( $links , $file ) {
if ( plugin_basename ( __FILE__ ) !== $file ) {
return $links ;
}
return array_merge (
$links ,
array (
sprintf (
2022-08-29 16:20:37 +04:00
'<a target="_blank" href="%1$s">%2$s</a>' ,
2022-08-16 10:31:47 +03:00
'https://woocommerce.com/document/woocommerce-paypal-payments/' ,
__ ( 'Documentation' , 'woocommerce-paypal-payments' )
),
sprintf (
2022-08-29 14:39:52 +04:00
'<a target="_blank" href="%1$s">%2$s</a>' ,
'https://woocommerce.com/document/woocommerce-paypal-payments/#get-help' ,
2022-08-16 10:31:47 +03:00
__ ( 'Get help' , 'woocommerce-paypal-payments' )
),
sprintf (
2022-08-29 16:20:37 +04:00
'<a target="_blank" href="%1$s">%2$s</a>' ,
2022-08-16 10:31:47 +03:00
'https://woocommerce.com/feature-requests/woocommerce-paypal-payments/' ,
__ ( 'Request a feature' , 'woocommerce-paypal-payments' )
),
sprintf (
2022-08-29 16:20:37 +04:00
'<a target="_blank" href="%1$s">%2$s</a>' ,
2022-08-16 10:31:47 +03:00
'https://github.com/woocommerce/woocommerce-paypal-payments/issues/new?assignees=&labels=type%3A+bug&template=bug_report.md' ,
__ ( 'Submit a bug' , 'woocommerce-paypal-payments' )
),
)
);
},
10 ,
2
);
2022-10-24 12:20:45 +02:00
add_action (
'before_woocommerce_init' ,
function () {
if ( class_exists ( '\Automattic\WooCommerce\Utilities\FeaturesUtil' ) ) {
2023-03-14 16:38:28 +02:00
/**
* Skip WC class check .
*
* @ psalm - suppress UndefinedClass
*/
2022-10-24 12:20:45 +02:00
\Automattic\WooCommerce\Utilities\FeaturesUtil :: declare_compatibility ( 'custom_order_tables' , __FILE__ , true );
}
}
);
2024-07-10 10:22:14 +04:00
add_action (
'in_plugin_update_message-woocommerce-paypal-payments/woocommerce-paypal-payments.php' ,
static function ( array $plugin_data , \stdClass $new_data ) {
if ( version_compare ( $plugin_data [ 'Version' ], '3.0.0' , '<' ) &&
version_compare ( $new_data -> new_version , '3.0.0' , '>=' ) ) {
printf (
'<div class="update-message"><p><strong>%s</strong>: %s</p></div>' ,
esc_html__ ( 'Warning' , 'woocommerce-paypal-payments' ),
esc_html__ ( 'WooCommerce PayPal Payments version 3.0.0 contains significant changes that may impact your website. We strongly recommend reviewing the changes and testing the update on a staging site before updating it on your production environment.' , 'woocommerce-paypal-payments' )
);
}
},
10 ,
2
);
2022-02-17 16:52:40 +04:00
/**
* Check if WooCommerce is active .
*
* @ return bool true if WooCommerce is active , otherwise false .
*/
function is_woocommerce_activated () : bool {
return class_exists ( 'woocommerce' );
}
2020-09-17 16:50:04 -03:00
} )();