updated plugin Easy Digital Downloads
version 3.1.2
This commit is contained in:
@ -57,6 +57,8 @@ add_action( 'wp_ajax_nopriv_edd_load_gateway', 'edd_load_ajax_gateway' );
|
||||
* Sets an error on checkout if no gateways are enabled
|
||||
*
|
||||
* @since 1.3.4
|
||||
* @since 3.1.2 Updated to include a different message for users who do not have the manage_shop_settings capability.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function edd_no_gateway_error() {
|
||||
@ -65,7 +67,12 @@ function edd_no_gateway_error() {
|
||||
if ( empty( $gateways ) && edd_get_cart_total() > 0 ) {
|
||||
remove_action( 'edd_after_cc_fields', 'edd_default_cc_address_fields' );
|
||||
remove_action( 'edd_cc_form', 'edd_get_cc_form' );
|
||||
edd_set_error( 'no_gateways', __( 'You must enable a payment gateway to use Easy Digital Downloads', 'easy-digital-downloads' ) );
|
||||
if ( current_user_can( 'manage_shop_settings' ) ) {
|
||||
$error_message = __( 'You must enable a payment gateway to use Easy Digital Downloads', 'easy-digital-downloads' );
|
||||
} else {
|
||||
$error_message = __( 'Your order cannot be completed at this time. Please try again or contact site support.', 'easy-digital-downloads' );
|
||||
}
|
||||
edd_set_error( 'no_gateways', $error_message );
|
||||
} else {
|
||||
edd_unset_error( 'no_gateways' );
|
||||
}
|
||||
|
@ -501,3 +501,119 @@ function edd_count_sales_by_gateway( $gateway_label = 'paypal', $status = 'compl
|
||||
'status' => $status,
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if a gateway is setup.
|
||||
*
|
||||
* @since 3.1.2
|
||||
*
|
||||
* @param string $gateway The gateway to check.
|
||||
*
|
||||
* @return bool True if the gateway is setup, false otherwise.
|
||||
*/
|
||||
function edd_is_gateway_setup( $gateway = '' ) {
|
||||
// Return false if no gateway is passed.
|
||||
if ( empty( $gateway ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$gateways = edd_get_payment_gateways();
|
||||
|
||||
// If the gateway is not registered, return false.
|
||||
if ( ! array_key_exists( $gateway, $gateways ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Some core gateways, we can just determine here, otherwise we'll use the default case to run the filter.
|
||||
switch ( $gateway ) {
|
||||
case 'stripe':
|
||||
$api_key = edd_is_test_mode()
|
||||
? edd_get_option( 'test_publishable_key' )
|
||||
: edd_get_option( 'live_publishable_key' );
|
||||
|
||||
$is_setup = ! empty( $api_key );
|
||||
break;
|
||||
|
||||
case 'paypal_commerce':
|
||||
$is_setup = EDD\Gateways\PayPal\ready_to_accept_payments();
|
||||
break;
|
||||
|
||||
default:
|
||||
/**
|
||||
* Run a filter to determine if a gateway is setup.
|
||||
*
|
||||
* This defaults to 'true' so that gateways that do not have a setup check to
|
||||
* continue to work.
|
||||
*
|
||||
* This hook would fire on the gateway slug, prefixed with `edd_is_gateway_setup_`.
|
||||
* Example: edd_is_gateway_setup_paypal_express
|
||||
*
|
||||
* @since 3.1.2
|
||||
*
|
||||
* @param bool $is_setup Whether or not the gateway is setup.
|
||||
*/
|
||||
$is_setup = apply_filters( 'edd_is_gateway_setup_' . $gateway, true );
|
||||
break;
|
||||
}
|
||||
|
||||
return $is_setup;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the URL to the gateway settings page.
|
||||
*
|
||||
* @since 3.1.2
|
||||
*
|
||||
* @param string $gateway The gateway to get the settings URL for.
|
||||
*
|
||||
* @return string The URL to the gateway settings page.
|
||||
*/
|
||||
function edd_get_gateway_settings_url( $gateway = '' ) {
|
||||
// Return false if no gateway is passed.
|
||||
if ( empty( $gateway ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$gateways = edd_get_payment_gateways();
|
||||
|
||||
// If the gateway is not registered, return false.
|
||||
if ( ! array_key_exists( $gateway, $gateways ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// Some core gateways, we can just determine here, otherwise we'll use the default case to run the filter.
|
||||
switch ( $gateway ) {
|
||||
case 'stripe':
|
||||
$gateway_settings_url = edd_get_admin_url(
|
||||
array(
|
||||
'page' => 'edd-settings',
|
||||
'tab' => 'gateways',
|
||||
'section' => 'edd-stripe',
|
||||
)
|
||||
);
|
||||
break;
|
||||
|
||||
case 'paypal_commerce':
|
||||
$gateway_settings_url = EDD\Gateways\PayPal\Admin\get_settings_url();
|
||||
break;
|
||||
|
||||
default:
|
||||
/**
|
||||
* Run a filter to assign a settings URL for the gateway.
|
||||
*
|
||||
* This defaults to an empty string so that gateways that do not have
|
||||
* a setup check to continue to work.
|
||||
*
|
||||
* This hook would fire on the gateway slug, prefixed with `edd_gateway_settings_url_`.
|
||||
* Example: edd_gateway_settings_url_paypal_express
|
||||
*
|
||||
* @since 3.1.2
|
||||
*
|
||||
* @param string $gateway_settings_url The URL to the gateway settings.
|
||||
*/
|
||||
$gateway_settings_url = apply_filters( 'edd_gateway_settings_url_' . $gateway, '' );
|
||||
break;
|
||||
}
|
||||
|
||||
return $gateway_settings_url;
|
||||
}
|
||||
|
@ -25,30 +25,22 @@ if ( ! defined( 'EDD_PAYPAL_PARTNER_CONNECT_URL' ) ) {
|
||||
* If they are connected, their account details are shown instead.
|
||||
*
|
||||
* @since 2.11
|
||||
* @return string
|
||||
* @return void
|
||||
*/
|
||||
function connect_settings_field() {
|
||||
$is_connected = PayPal\has_rest_api_connection();
|
||||
$mode = edd_is_test_mode() ? __( 'sandbox', 'easy-digital-downloads' ) : __( 'live', 'easy-digital-downloads' );
|
||||
ob_start();
|
||||
|
||||
if ( ! $is_connected ) {
|
||||
/**
|
||||
* Show Connect
|
||||
*/
|
||||
|
||||
/*
|
||||
* If we have Partner details but no REST credentials then that most likely means
|
||||
* PayPal wasn't opened in the modal. We'll show an error message about popups.
|
||||
*/
|
||||
if ( get_partner_details() ) {
|
||||
$onboarding_data = get_onboarding_data();
|
||||
if ( 200 !== $onboarding_data['code'] || empty( $onboarding_data['body']->signupLink ) ) {
|
||||
?>
|
||||
<div class="notice notice-error inline">
|
||||
<p>
|
||||
<?php
|
||||
echo wp_kses( sprintf(
|
||||
/* Translators: %1$s opening <strong> tag; %2$s closing </strong> tag */
|
||||
__( '%1$sConnection failure:%2$s This is most likely due to your browser blocking the connection. Most store owners have the best success with Chrome, but for some reason, a few select browsers/devices prevent the connection from EDD and PayPal from working. You might have to enable popups, then restart your browser. If that doesn\'t work, please try a different browser or device and see if that works. If you continue to experience this error, please contact support.', 'easy-digital-downloads' ),
|
||||
__( '%1$sPayPal Communication Error:%2$s We are having trouble communicating with PayPal at the moment. Please try again later, and if the issue persists, reach out to our support team.', 'easy-digital-downloads' ),
|
||||
'<strong>',
|
||||
'</strong>'
|
||||
), array( 'strong' => array() ) );
|
||||
@ -56,17 +48,17 @@ function connect_settings_field() {
|
||||
</p>
|
||||
</div>
|
||||
<?php
|
||||
} else {
|
||||
?>
|
||||
<a type="button" target="_blank" id="edd-paypal-commerce-link" class="button button-secondary" href="<?php echo $onboarding_data['body']->signupLink; ?>&displayMode=minibrowser" data-paypal-onboard-complete="eddPayPalOnboardingCallback" data-paypal-button="true" data-paypal-onboard-button="true" data-nonce="<?php echo esc_attr( wp_create_nonce( 'edd_process_paypal_connect' ) ); ?>">
|
||||
<?php
|
||||
/* Translators: %s - the store mode, either `sandbox` or `live` */
|
||||
printf( esc_html__( 'Connect with PayPal in %s mode', 'easy-digital-downloads' ), esc_html( $mode ) );
|
||||
?>
|
||||
</a>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<button type="button" id="edd-paypal-commerce-connect" class="button" data-nonce="<?php echo esc_attr( wp_create_nonce( 'edd_process_paypal_connect' ) ); ?>">
|
||||
<?php
|
||||
/* Translators: %s - the store mode, either `sandbox` or `live` */
|
||||
printf( esc_html__( 'Connect with PayPal in %s mode', 'easy-digital-downloads' ), esc_html( $mode ) );
|
||||
?>
|
||||
</button>
|
||||
<a href="#" target="_blank" id="edd-paypal-commerce-link" class="edd-hidden" data-paypal-onboard-complete="eddPayPalOnboardingCallback" data-paypal-button="true">
|
||||
<?php esc_html_e( 'Sign up for PayPal', 'easy-digital-downloads' ); ?>
|
||||
</a>
|
||||
<div id="edd-paypal-commerce-errors"></div>
|
||||
<?php
|
||||
} else {
|
||||
@ -86,70 +78,121 @@ function connect_settings_field() {
|
||||
?>
|
||||
|
||||
<?php
|
||||
return ob_get_clean();
|
||||
}
|
||||
add_action( 'edd_paypal_connect_button', __NAMESPACE__ . '\connect_settings_field' );
|
||||
|
||||
/**
|
||||
* Single function to make a request to get the onboarding URL and nonce.
|
||||
*
|
||||
* Previously we did this in process_connect method, but we've moved away from the AJAX useage of this
|
||||
* in favor of doing it on loading the settings field, to make loading the modal more reliable and faster.
|
||||
*
|
||||
* @since 3.1.2
|
||||
*/
|
||||
function get_onboarding_data() {
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
return array(
|
||||
'code' => 403,
|
||||
'body' => array(
|
||||
'message' => __( 'You do not have permission to perform this action.', 'easy-digital-downloads' ),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
$mode = edd_is_test_mode() ? API::MODE_SANDBOX : API::MODE_LIVE;
|
||||
|
||||
$existing_connect_details = get_partner_details( $mode );
|
||||
|
||||
if ( ! empty( $existing_connect_details ) ) {
|
||||
// Ensure the data we have contains all necessary details.
|
||||
if (
|
||||
( ! empty( $existing_connect_details->expires ) && $existing_connect_details->expires > time() ) &&
|
||||
! empty( $existing_connect_details->nonce ) &&
|
||||
! empty( $existing_connect_details->signupLink ) && // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
|
||||
! empty( $existing_connect_details->product )
|
||||
) {
|
||||
return array(
|
||||
'code' => 200,
|
||||
'body' => $existing_connect_details,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$response = wp_remote_post(
|
||||
EDD_PAYPAL_PARTNER_CONNECT_URL . 'signup-link',
|
||||
array(
|
||||
'headers' => array(
|
||||
'Content-Type' => 'application/json',
|
||||
),
|
||||
'user-agent' => 'Easy Digital Downloads/' . EDD_VERSION . '; ' . get_bloginfo( 'name' ),
|
||||
'body' => wp_json_encode(
|
||||
array(
|
||||
'mode' => $mode,
|
||||
'country_code' => edd_get_shop_country(),
|
||||
'currency_code' => edd_get_currency(),
|
||||
'return_url' => get_settings_url(),
|
||||
)
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$code = wp_remote_retrieve_response_code( $response );
|
||||
|
||||
if ( is_wp_error( $response ) ) {
|
||||
|
||||
return array(
|
||||
'code' => $code,
|
||||
'body' => $response->get_error_message(),
|
||||
);
|
||||
}
|
||||
|
||||
$body = wp_remote_retrieve_body( $response );
|
||||
$body = json_decode( $body );
|
||||
|
||||
// We're storing an expiration so we can get a new one if it's been a day.
|
||||
$body->expires = time() + DAY_IN_SECONDS;
|
||||
|
||||
// We need to store this temporarily so we can use the nonce again in the next request.
|
||||
update_option( 'edd_paypal_commerce_connect_details_' . $mode, wp_json_encode( $body ), false );
|
||||
|
||||
return array(
|
||||
'code' => $code,
|
||||
'body' => $body,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* AJAX handler for processing the PayPal Connection.
|
||||
*
|
||||
* @since 2.11
|
||||
* @deprecated 3.1.2 Instead of doing this via an AJAX request, we now do this on page load.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function process_connect() {
|
||||
_edd_deprecated_function( __FUNCTION__, '3.1.2', 'EDD_PayPal_Commerce::get_onboarding_data()' );
|
||||
|
||||
// This validates the nonce.
|
||||
check_ajax_referer( 'edd_process_paypal_connect' );
|
||||
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
wp_send_json_error( __( 'You do not have permission to perform this action.', 'easy-digital-downloads' ) );
|
||||
}
|
||||
$onboarding_data = get_onboarding_data();
|
||||
|
||||
$mode = edd_is_test_mode() ? API::MODE_SANDBOX : API::MODE_LIVE;
|
||||
|
||||
$response = wp_remote_post( EDD_PAYPAL_PARTNER_CONNECT_URL . 'signup-link', array(
|
||||
'headers' => array(
|
||||
'Content-Type' => 'application/json',
|
||||
),
|
||||
'body' => json_encode( array(
|
||||
'mode' => $mode,
|
||||
'country_code' => edd_get_shop_country(),
|
||||
'currency_code' => edd_get_currency(),
|
||||
'return_url' => get_settings_url()
|
||||
) ),
|
||||
'user-agent' => 'Easy Digital Downloads/' . EDD_VERSION . '; ' . get_bloginfo( 'name' ),
|
||||
) );
|
||||
|
||||
if ( is_wp_error( $response ) ) {
|
||||
wp_send_json_error( $response->get_error_message() );
|
||||
}
|
||||
|
||||
$code = wp_remote_retrieve_response_code( $response );
|
||||
$body = json_decode( wp_remote_retrieve_body( $response ) );
|
||||
|
||||
if ( 200 !== intval( $code ) ) {
|
||||
if ( 200 !== intval( $onboarding_data['code'] ) ) {
|
||||
wp_send_json_error( sprintf(
|
||||
/* Translators: %d - HTTP response code; %s - Response from the API */
|
||||
__( 'Unexpected response code: %d. Error: %s', 'easy-digital-downloads' ),
|
||||
$code,
|
||||
json_encode( $body )
|
||||
$onboarding_data['code'],
|
||||
wp_json_encode( $onboarding_data['body'] )
|
||||
) );
|
||||
}
|
||||
|
||||
if ( empty( $body->signupLink ) || empty( $body->nonce ) ) {
|
||||
if ( empty( $onboarding_data['body']->signupLink ) || empty( $onboarding_data['body']->nonce ) ) {
|
||||
wp_send_json_error( __( 'An unexpected error occurred.', 'easy-digital-downloads' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* We need to store this temporarily so we can use the nonce again in the next request.
|
||||
*
|
||||
* @see get_access_token()
|
||||
*/
|
||||
update_option( 'edd_paypal_commerce_connect_details_' . $mode, json_encode( $body ) );
|
||||
|
||||
wp_send_json_success( $body );
|
||||
wp_send_json_success( $onboarding_data['body'] );
|
||||
}
|
||||
|
||||
add_action( 'wp_ajax_edd_paypal_commerce_connect', __NAMESPACE__ . '\process_connect' );
|
||||
|
||||
/**
|
||||
* AJAX handler for processing the PayPal Reconnect.
|
||||
*
|
||||
@ -187,7 +230,6 @@ function process_reconnect() {
|
||||
|
||||
wp_safe_redirect( esc_url_raw( get_settings_url() ) );
|
||||
}
|
||||
|
||||
add_action( 'wp_ajax_edd_paypal_commerce_reconnect', __NAMESPACE__ . '\process_reconnect' );
|
||||
|
||||
/**
|
||||
@ -195,7 +237,7 @@ add_action( 'wp_ajax_edd_paypal_commerce_reconnect', __NAMESPACE__ . '\process_r
|
||||
*
|
||||
* @param string $mode Store mode. If omitted, current mode is used.
|
||||
*
|
||||
* @return array|null
|
||||
* @return stdObj|null
|
||||
*/
|
||||
function get_partner_details( $mode = '' ) {
|
||||
if ( ! $mode ) {
|
||||
@ -232,23 +274,27 @@ function get_and_save_credentials() {
|
||||
|
||||
$paypal_subdomain = edd_is_test_mode() ? '.sandbox' : '';
|
||||
$api_url = 'https://api-m' . $paypal_subdomain . '.paypal.com/';
|
||||
|
||||
/*
|
||||
* First get a temporary access token from PayPal.
|
||||
*/
|
||||
$response = wp_remote_post( $api_url . 'v1/oauth2/token', array(
|
||||
$api_args = array(
|
||||
'headers' => array(
|
||||
'Content-Type' => 'application/x-www-form-urlencoded',
|
||||
'Authorization' => sprintf( 'Basic %s', base64_encode( $_POST['share_id'] ) ),
|
||||
'timeout' => 15
|
||||
'timeout' => 15,
|
||||
),
|
||||
'body' => array(
|
||||
'grant_type' => 'authorization_code',
|
||||
'code' => $_POST['auth_code'],
|
||||
'code_verifier' => $partner_details->nonce
|
||||
'code_verifier' => $partner_details->nonce,
|
||||
),
|
||||
'user-agent' => 'Easy Digital Downloads/' . EDD_VERSION . '; ' . get_bloginfo( 'name' ),
|
||||
) );
|
||||
);
|
||||
|
||||
/*
|
||||
* First get a temporary access token from PayPal.
|
||||
*/
|
||||
$response = wp_remote_post(
|
||||
$api_url . 'v1/oauth2/token',
|
||||
$api_args
|
||||
);
|
||||
|
||||
if ( is_wp_error( $response ) ) {
|
||||
wp_send_json_error( $response->get_error_message() );
|
||||
@ -258,11 +304,13 @@ function get_and_save_credentials() {
|
||||
$body = json_decode( wp_remote_retrieve_body( $response ) );
|
||||
|
||||
if ( empty( $body->access_token ) ) {
|
||||
wp_send_json_error( sprintf(
|
||||
/* Translators: %d - HTTP response code */
|
||||
__( 'Unexpected response from PayPal while generating token. Response code: %d. Please try again.', 'easy-digital-downloads' ),
|
||||
$code
|
||||
) );
|
||||
wp_send_json_error(
|
||||
sprintf(
|
||||
/* Translators: %d - HTTP response code */
|
||||
__( 'Unexpected response from PayPal while generating token. Response code: %d. Please try again.', 'easy-digital-downloads' ),
|
||||
$code
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -599,10 +647,16 @@ function process_delete() {
|
||||
'paypal_' . $mode . '_client_id',
|
||||
'paypal_' . $mode . '_client_secret',
|
||||
);
|
||||
|
||||
foreach ( $edd_settings_to_delete as $option_name ) {
|
||||
edd_delete_option( $option_name );
|
||||
}
|
||||
|
||||
// Unset the PayPal Commerce gateway as an enabled gateway.
|
||||
$enabled_gateways = edd_get_option( 'gateways', array() );
|
||||
unset( $enabled_gateways['paypal_commerce'] );
|
||||
edd_update_option( 'gateways', $enabled_gateways );
|
||||
|
||||
wp_safe_redirect( esc_url_raw( get_settings_url() ) );
|
||||
exit;
|
||||
}
|
||||
|
@ -10,29 +10,51 @@
|
||||
|
||||
namespace EDD\Gateways\PayPal\Admin;
|
||||
|
||||
use EDD\Gateways\PayPal;
|
||||
|
||||
/**
|
||||
* Enqueue PayPal connect admin JS.
|
||||
*
|
||||
* @since 2.11
|
||||
*/
|
||||
function enqueue_connect_scripts() {
|
||||
if ( edd_is_admin_page( 'settings' ) && isset( $_GET['section'] ) && 'paypal_commerce' === $_GET['section'] ) {
|
||||
\EDD\Gateways\PayPal\maybe_enqueue_polyfills();
|
||||
if ( edd_is_admin_page( 'settings' ) && isset( $_GET['section'] ) && 'paypal_commerce' === $_GET['section'] ) { /* phpcs:ignore WordPress.Security.NonceVerification.Recommended */
|
||||
PayPal\maybe_enqueue_polyfills();
|
||||
|
||||
$subdomain = edd_is_test_mode() ? 'sandbox.' : '';
|
||||
|
||||
wp_enqueue_script(
|
||||
'sandhills-paypal-partner-js',
|
||||
'https://www.' . $subdomain . 'paypal.com/webapps/merchantboarding/js/lib/lightbox/partner.js',
|
||||
array(),
|
||||
null,
|
||||
true
|
||||
wp_localize_script(
|
||||
'edd-admin-settings',
|
||||
'eddPayPalConnectVars',
|
||||
array(
|
||||
'defaultError' => esc_html__( 'An unexpected error occurred. Please refresh the page and try again.', 'easy-digital-downloads' ),
|
||||
'isConnected' => PayPal\has_rest_api_connection(),
|
||||
)
|
||||
);
|
||||
|
||||
wp_localize_script( 'edd-admin-settings', 'eddPayPalConnectVars', array(
|
||||
'defaultError' => esc_html__( 'An unexpected error occurred. Please refresh the page and try again.', 'easy-digital-downloads' )
|
||||
) );
|
||||
}
|
||||
}
|
||||
|
||||
add_action( 'admin_enqueue_scripts', __NAMESPACE__ . '\enqueue_connect_scripts' );
|
||||
|
||||
/**
|
||||
* Forces the Cache-Control header on the PayPal Commerce settings page to send the no-store header
|
||||
* which prevents the back-forward cache (bfcache) from storing a copy of this page in local
|
||||
* cache. This helps make sure that page elements modified via AJAX and DOM manipulations aren't
|
||||
* incorrectly shown as if they never changed.
|
||||
*
|
||||
* See: https://github.com/easydigitaldownloads/EDD-Software-Licensing/issues/1346#issuecomment-382159918
|
||||
*
|
||||
* @since 3.6
|
||||
* @param array $headers An array of nocache headers.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function _bfcache_buster( $headers ) {
|
||||
if ( ! is_admin() ) {
|
||||
return $headers;
|
||||
}
|
||||
|
||||
if ( edd_is_admin_page( 'settings' ) && isset( $_GET['section'] ) && 'paypal_commerce' === $_GET['section'] ) { /* phpcs:ignore WordPress.Security.NonceVerification.Recommended */
|
||||
$headers['Cache-Control'] = 'no-cache, must-revalidate, max-age=0, no-store';
|
||||
}
|
||||
|
||||
return $headers;
|
||||
}
|
||||
add_filter( 'nocache_headers', __NAMESPACE__ . '\_bfcache_buster', 10, 1 );
|
||||
|
@ -23,6 +23,7 @@ function get_settings_url() {
|
||||
return admin_url( 'edit.php?post_type=download&page=edd-settings&tab=gateways§ion=paypal_commerce' );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Register the PayPal Standard gateway subsection
|
||||
*
|
||||
@ -36,7 +37,6 @@ function register_paypal_gateway_section( $gateway_sections ) {
|
||||
|
||||
return $gateway_sections;
|
||||
}
|
||||
|
||||
add_filter( 'edd_settings_sections_gateways', __NAMESPACE__ . '\register_paypal_gateway_section', 1, 1 );
|
||||
|
||||
/**
|
||||
@ -55,58 +55,55 @@ function register_gateway_settings( $gateway_settings ) {
|
||||
'name' => '<h3>' . __( 'PayPal Settings', 'easy-digital-downloads' ) . '</h3>',
|
||||
'type' => 'header',
|
||||
),
|
||||
'paypal_documentation' => array(
|
||||
'id' => 'paypal_documentation',
|
||||
'name' => __( 'Documentation', 'easy-digital-downloads' ),
|
||||
'desc' => documentation_settings_field(),
|
||||
'type' => 'descriptive_text'
|
||||
),
|
||||
'paypal_connect_button' => array(
|
||||
'id' => 'paypal_connect_button',
|
||||
'name' => __( 'Connection Status', 'easy-digital-downloads' ),
|
||||
'desc' => connect_settings_field(),
|
||||
'type' => 'descriptive_text',
|
||||
'class' => 'edd-paypal-connect-row',
|
||||
'type' => 'hook',
|
||||
),
|
||||
'paypal_sandbox_client_id' => array(
|
||||
'id' => 'paypal_sandbox_client_id',
|
||||
'name' => __( 'Test Client ID', 'easy-digital-downloads' ),
|
||||
'desc' => __( 'Enter your test client ID.', 'easy-digital-downloads' ),
|
||||
'type' => 'text',
|
||||
'size' => 'regular',
|
||||
'class' => 'edd-hidden'
|
||||
'desc' => __( 'Enter your test client ID.', 'easy-digital-downloads' ),
|
||||
'type' => 'text',
|
||||
'size' => 'regular',
|
||||
'class' => 'edd-hidden',
|
||||
),
|
||||
'paypal_sandbox_client_secret' => array(
|
||||
'id' => 'paypal_sandbox_client_secret',
|
||||
'name' => __( 'Test Client Secret', 'easy-digital-downloads' ),
|
||||
'desc' => __( 'Enter your test client secret.', 'easy-digital-downloads' ),
|
||||
'type' => 'password',
|
||||
'size' => 'regular',
|
||||
'class' => 'edd-hidden'
|
||||
'id' => 'paypal_sandbox_client_secret',
|
||||
'name' => __( 'Test Client Secret', 'easy-digital-downloads' ),
|
||||
'desc' => __( 'Enter your test client secret.', 'easy-digital-downloads' ),
|
||||
'type' => 'password',
|
||||
'size' => 'regular',
|
||||
'class' => 'edd-hidden',
|
||||
),
|
||||
'paypal_live_client_id' => array(
|
||||
'id' => 'paypal_live_client_id',
|
||||
'name' => __( 'Live Client ID', 'easy-digital-downloads' ),
|
||||
'desc' => __( 'Enter your live client ID.', 'easy-digital-downloads' ),
|
||||
'type' => 'text',
|
||||
'size' => 'regular',
|
||||
'class' => 'edd-hidden'
|
||||
'id' => 'paypal_live_client_id',
|
||||
'name' => __( 'Live Client ID', 'easy-digital-downloads' ),
|
||||
'desc' => __( 'Enter your live client ID.', 'easy-digital-downloads' ),
|
||||
'type' => 'text',
|
||||
'size' => 'regular',
|
||||
'class' => 'edd-hidden',
|
||||
),
|
||||
'paypal_live_client_secret' => array(
|
||||
'id' => 'paypal_live_client_secret',
|
||||
'name' => __( 'Live Client Secret', 'easy-digital-downloads' ),
|
||||
'desc' => __( 'Enter your live client secret.', 'easy-digital-downloads' ),
|
||||
'type' => 'password',
|
||||
'size' => 'regular',
|
||||
'class' => 'edd-hidden'
|
||||
'id' => 'paypal_live_client_secret',
|
||||
'name' => __( 'Live Client Secret', 'easy-digital-downloads' ),
|
||||
'desc' => __( 'Enter your live client secret.', 'easy-digital-downloads' ),
|
||||
'type' => 'password',
|
||||
'size' => 'regular',
|
||||
'class' => 'edd-hidden',
|
||||
),
|
||||
'paypal_documentation' => array(
|
||||
'id' => 'paypal_documentation',
|
||||
'name' => '',
|
||||
'type' => 'hook',
|
||||
),
|
||||
);
|
||||
|
||||
$is_connected = PayPal\has_rest_api_connection();
|
||||
if ( ! $is_connected ) {
|
||||
$paypal_settings['paypal_settings']['tooltip_title'] = __( 'Connect with PayPal', 'easy-digital-downloads' );
|
||||
$paypal_settings['paypal_settings']['tooltip_desc'] = __( 'Connecting your store with PayPal allows Easy Digital Downloads to automatically configure your store to securely communicate PayPal.<br \><br \>You may see "Sandhills Development, LLC", mentioned during the process—that is the company behind Easy Digital Downloads.', 'easy-digital-downloads' );
|
||||
|
||||
$paypal_settings['paypal_settings']['tooltip_desc'] = __( 'Connecting your store with PayPal allows Easy Digital Downloads to automatically configure your store to securely communicate with PayPal.<br \><br \>You may see "Sandhills Development, LLC", mentioned during the process—that is the company behind Easy Digital Downloads.', 'easy-digital-downloads' );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -129,15 +126,15 @@ add_filter( 'edd_settings_gateways', __NAMESPACE__ . '\register_gateway_settings
|
||||
* @return string
|
||||
*/
|
||||
function documentation_settings_field() {
|
||||
ob_start();
|
||||
?>
|
||||
<p>
|
||||
<?php
|
||||
echo wp_kses( sprintf(
|
||||
__( 'To learn more about the PayPal gateway, visit <a href="%s" target="_blank">our documentation</a>.', 'easy-digital-downloads' ),
|
||||
'https://easydigitaldownloads.com/docs/paypal-setup/'
|
||||
), array( 'a' => array( 'href' => true, 'target' => true ) ) )
|
||||
?>
|
||||
<a class="button button-secondary" href="https://easydigitaldownloads.com/docs/paypal-setup/" target="_blank">
|
||||
<?php esc_html_e( 'View Documentation', 'easy-digital-downloads' ); ?>
|
||||
</a>
|
||||
|
||||
<a id="edd-paypal-commerce-get-help" class="edd-hidden" href="https://easydigitaldownloads.com/support/" target="_blank">
|
||||
<?php esc_html_e( 'Get Help', 'easy-digital-downloads' ); ?>
|
||||
</a>
|
||||
</p>
|
||||
<?php
|
||||
if ( ! is_ssl() ) {
|
||||
@ -154,6 +151,5 @@ function documentation_settings_field() {
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
return ob_get_clean();
|
||||
}
|
||||
add_action( 'edd_paypal_documentation', __NAMESPACE__ . '\documentation_settings_field' );
|
||||
|
@ -27,6 +27,11 @@ function maybe_remove_paypal_standard( $gateways ) {
|
||||
unset( $gateways['paypal'] );
|
||||
}
|
||||
|
||||
// Ensures we don't show the PayPal Standard option in Site Health.
|
||||
if ( did_action( 'admin_head-site-health.php' ) && ! paypal_standard_enabled() ) {
|
||||
unset( $gateways['paypal'] );
|
||||
}
|
||||
|
||||
return $gateways;
|
||||
}
|
||||
|
||||
|
@ -30,18 +30,8 @@ function maybe_enqueue_polyfills() {
|
||||
return;
|
||||
}
|
||||
|
||||
global $wp_version;
|
||||
if ( version_compare( $wp_version, '5.0', '>=' ) ) {
|
||||
wp_enqueue_script( 'wp-polyfill' );
|
||||
} else {
|
||||
wp_enqueue_script(
|
||||
'wp-polyfill',
|
||||
EDD_PLUGIN_URL . 'assets/js/wp-polyfill.min.js',
|
||||
array(),
|
||||
false,
|
||||
false
|
||||
);
|
||||
}
|
||||
wp_enqueue_script( 'wp-polyfill' );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1 +1 @@
|
||||
!function(e){var n={};function t(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:r})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,n){if(1&n&&(e=t(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(t.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var o in e)t.d(r,o,function(n){return e[n]}.bind(null,o));return r},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},t.p="",t(t.s=109)}({109:function(e,n,t){(function(e){jQuery((function(){jQuery(".edds-admin-notice").each((function(){var n=e(this),t=n.data("id"),r=n.data("nonce");n.on("click",".notice-dismiss",(function(e){return e.preventDefault(),e.stopPropagation(),wp.ajax.post("edds_admin_notices_dismiss_ajax",{id:t,nonce:r})}))}))}))}).call(this,t(6))},6:function(e,n){e.exports=jQuery}});
|
||||
!function(e){var n={};function t(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:r})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,n){if(1&n&&(e=t(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(t.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var o in e)t.d(r,o,function(n){return e[n]}.bind(null,o));return r},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},t.p="",t(t.s=113)}({113:function(e,n,t){(function(e){jQuery((function(){jQuery(".edds-admin-notice").each((function(){var n=e(this),t=n.data("id"),r=n.data("nonce");n.on("click",".notice-dismiss",(function(e){return e.preventDefault(),e.stopPropagation(),wp.ajax.post("edds_admin_notices_dismiss_ajax",{id:t,nonce:r})}))}))}))}).call(this,t(6))},6:function(e,n){e.exports=jQuery}});
|
File diff suppressed because one or more lines are too long
@ -3,7 +3,7 @@
|
||||
* Plugin Name: Easy Digital Downloads - Stripe Pro Payment Gateway
|
||||
* Plugin URI: https://easydigitaldownloads.com/downloads/stripe-gateway/
|
||||
* Description: Adds support for pre-authorized credit card payments and removes additional transaction fees.
|
||||
* Version: 2.9.2.2
|
||||
* Version: 2.9.5.1
|
||||
* Requires at least: 5.4
|
||||
* Requires PHP: 7.1
|
||||
* Author: Easy Digital Downloads
|
||||
@ -44,7 +44,7 @@ function edd_stripe_core_bootstrap() {
|
||||
}
|
||||
|
||||
if ( ! defined( 'EDD_STRIPE_VERSION' ) ) {
|
||||
define( 'EDD_STRIPE_VERSION', '2.9.2.2' );
|
||||
define( 'EDD_STRIPE_VERSION', '2.9.5.1' );
|
||||
}
|
||||
|
||||
if ( ! defined( 'EDD_STRIPE_API_VERSION' ) ) {
|
||||
|
@ -214,3 +214,64 @@ function edds_show_refund_checkbox( \EDD\Orders\Order $order ) {
|
||||
<?php
|
||||
}
|
||||
add_action( 'edd_after_submit_refund_table', 'edds_show_refund_checkbox' );
|
||||
|
||||
/**
|
||||
* Allows processing flags for the EDD Stripe settings.
|
||||
*
|
||||
* As we transition settings like the Card Elements, we need a way to be able to toggle
|
||||
* these things back on for some people. Enabling debug mode, setting flags, and then disabling
|
||||
* debug mode allows us to handle this.
|
||||
*
|
||||
* @since 2.9.4
|
||||
*/
|
||||
function edds_process_settings_flags() {
|
||||
// If we're not on the settings page, bail.
|
||||
if ( ! edd_is_admin_page( 'settings', 'gateways' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If it isn't the Stripe section, bail.
|
||||
if ( ! isset( $_GET['section'] ) || 'edd-stripe' !== $_GET['section'] ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Gather the flag we're trying to set.
|
||||
$flag = isset( $_GET['flag'] ) ? $_GET['flag'] : false;
|
||||
|
||||
if ( false === $flag ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! current_user_can( 'manage_shop_settings' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$nonce = isset( $_GET['_wpnonce'] ) ? $_GET['_wpnonce'] : false;
|
||||
if ( empty( $nonce ) || ! wp_verify_nonce( $nonce, $flag ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch( $flag ) {
|
||||
case 'disable-card-elements':
|
||||
delete_option( '_edds_legacy_elements_enabled' );
|
||||
break;
|
||||
|
||||
case 'enable-card-elements':
|
||||
add_option( '_edds_legacy_elements_enabled', 1, false );
|
||||
break;
|
||||
}
|
||||
|
||||
// Redirect to the settings page.
|
||||
wp_safe_redirect(
|
||||
edd_get_admin_url(
|
||||
array(
|
||||
'page' => 'edd-settings',
|
||||
'tab' => 'gateways',
|
||||
'section' => 'edd-stripe',
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
exit;
|
||||
}
|
||||
add_action( 'admin_init', 'edds_process_settings_flags', 1 );
|
@ -198,6 +198,47 @@ function edds_add_settings( $settings ) {
|
||||
|
||||
$settings['edd-stripe'] = $stripe_settings;
|
||||
|
||||
// If EDD is in Debug Mode, add some 'hidden' settings to the Stripe settings.
|
||||
if ( edd_is_debug_mode() ) {
|
||||
$card_elements_enabled = get_option( '_edds_legacy_elements_enabled', false );
|
||||
|
||||
$debug_settings = array(
|
||||
'stripe_debug' => array(
|
||||
'id' => 'stripe_debug',
|
||||
'name' => __( 'Debugging Settings', 'easy-digital-downloads' ),
|
||||
'desc' => '<div class="notice inline notice-warning">' .
|
||||
'<p>' . __( 'The following settings are available while Easy Digital Downloads is in debug mode. They are not designed to be primary settings and should be used only while debugging or when instructed to be used by the Easy Digital Downloads Team.', 'easy-digital-downloads' ) . '</p>' .
|
||||
'<p>' . __( 'There is no guarantee that these settings will remain available in future versions of Easy Digital Downloads. Easy Digital Downloads Debug Mode should be disabled once changes to these settings have been made.', 'easy-digital-downloads' ) . '</p>' .
|
||||
'</p></div>',
|
||||
'type' => 'descriptive_text',
|
||||
),
|
||||
);
|
||||
|
||||
$card_elements_action = $card_elements_enabled ? 'disable-card-elements' : 'enable-card-elements';
|
||||
$card_elements_button_label = $card_elements_enabled ? __( 'Disable access to Card Elements', 'easy-digital-downloads' ) : __( 'Enable access to Card Elements', 'easy-digital-downloads' );
|
||||
$card_elements_state_label = $card_elements_enabled ? __( 'Access to Legacy Card Elements is Enabled', 'easy-digital-downloads' ) : __( 'Access to Legacy Card Elements is Disabled', 'easy-digital-downloads' );
|
||||
|
||||
$link_class = $card_elements_enabled ? 'edd-button__toggle--enabled' : 'edd-button__toggle--disabled';
|
||||
|
||||
$debug_settings['toggle_card_elements'] = array(
|
||||
'id' => 'stripe_toggle_card_elements',
|
||||
'name' => __( 'Toggle Card Elements', 'easy-digital-downloads' ),
|
||||
'type' => 'descriptive_text',
|
||||
'desc' => sprintf(
|
||||
'%1$s<span class="screen-reader-text">' . $card_elements_button_label . '</span>%2$s',
|
||||
'<a class="edd-button__toggle ' . $link_class . '" href="' . wp_nonce_url( edd_get_admin_url( array(
|
||||
'page' => 'edd-settings',
|
||||
'tab' => 'gateways',
|
||||
'section' => 'edd-stripe',
|
||||
'flag' => $card_elements_action,
|
||||
) ), $card_elements_action ) . '">',
|
||||
'</a>'
|
||||
) .'<strong>' . $card_elements_state_label . '</strong><br />' . __( 'Card Elements is the legacy Stripe integration. Easy Digital Downloads has updated to use the more secure and reliable Payment Elements feature of Stripe. This toggle allows sites without access to Card Elements to enable or disable it.', 'easy-digital-downloads' ),
|
||||
);
|
||||
|
||||
$settings['edd-stripe'] = array_merge( $settings['edd-stripe'], $debug_settings );
|
||||
}
|
||||
|
||||
// Set up the new setting field for the Test Mode toggle notice.
|
||||
$notice = array(
|
||||
'stripe_connect_test_mode_toggle_notice' => array(
|
||||
|
@ -242,6 +242,11 @@ function edds_stripe_connect_process_disconnect() {
|
||||
edd_delete_option( $option );
|
||||
}
|
||||
|
||||
// Remove Stripe from the enabled gateways.
|
||||
$gateways = edd_get_option( 'gateways', array() );
|
||||
unset( $gateways['stripe'] );
|
||||
edd_update_option( 'gateways', $gateways );
|
||||
|
||||
$redirect = remove_query_arg(
|
||||
array(
|
||||
'_wpnonce',
|
||||
@ -265,9 +270,9 @@ function edds_stripe_connect_maybe_refresh_account_country() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Stripe Connect has not been used, bail.
|
||||
$account_id = edd_get_option( 'stripe_connect_account_id', '' );
|
||||
$account_id = edd_stripe()->connect()->get_connect_id();
|
||||
|
||||
// Stripe Connect has not been used, bail.
|
||||
if ( empty( $account_id ) ) {
|
||||
return;
|
||||
}
|
||||
@ -307,10 +312,10 @@ add_action( 'admin_init', 'edds_stripe_connect_maybe_refresh_account_country' );
|
||||
* @since 2.8.0
|
||||
*/
|
||||
function edds_stripe_connect_setting_field() {
|
||||
$stripe_connect_url = edds_stripe_connect_url();
|
||||
$stripe_disconnect_url = edds_stripe_connect_disconnect_url();
|
||||
$stripe_connect_url = edds_stripe_connect_url();
|
||||
$stripe_disconnect_url = edds_stripe_connect_disconnect_url();
|
||||
|
||||
$stripe_connect_account_id = edd_get_option( 'stripe_connect_account_id' );
|
||||
$stripe_connect_account_id = edd_stripe()->connect()->get_connect_id();
|
||||
|
||||
$api_key = edd_is_test_mode()
|
||||
? edd_get_option( 'test_publishable_key' )
|
||||
@ -678,20 +683,6 @@ function edds_stripe_connect_admin_notices_register() {
|
||||
);
|
||||
|
||||
try {
|
||||
// Stripe Connect - Manually managed keys.
|
||||
$registry->add(
|
||||
'stripe-connect-manual',
|
||||
array(
|
||||
'message' => sprintf(
|
||||
'<p>%s</p><p>%s</p>',
|
||||
esc_html__( 'Your current Stripe payment connection is out of date. Enable more secure and reliable payments by clicking the button below to enable Stripe Connect.', 'easy-digital-downloads' ),
|
||||
$connect_button
|
||||
),
|
||||
'type' => 'error',
|
||||
'dismissible' => true,
|
||||
)
|
||||
);
|
||||
|
||||
// Stripe Connect.
|
||||
$registry->add(
|
||||
'stripe-connect',
|
||||
@ -768,20 +759,11 @@ function edds_stripe_connect_admin_notices_print() {
|
||||
$mode_toggle = isset( $_GET['edd-message'] ) && 'connect-to-stripe' === $_GET['edd-message'];
|
||||
|
||||
if ( array_key_exists( 'stripe', $enabled_gateways ) && empty( $api_key ) ) {
|
||||
wp_enqueue_style(
|
||||
'edd-stripe-admin-styles',
|
||||
EDDSTRIPE_PLUGIN_URL . 'assets/css/build/admin.min.css',
|
||||
array(),
|
||||
EDD_STRIPE_VERSION
|
||||
);
|
||||
edd_stripe_connect_admin_style();
|
||||
|
||||
// Stripe Connect.
|
||||
if ( false === $mode_toggle ) {
|
||||
if ( edds_stripe_connect_can_manage_keys() ) {
|
||||
$notices->output( 'stripe-connect-manual' );
|
||||
} else {
|
||||
$notices->output( 'stripe-connect' );
|
||||
}
|
||||
$notices->output( 'stripe-connect' );
|
||||
// Stripe Connect reconnect.
|
||||
} else {
|
||||
$notices->output( 'stripe-connect-reconnect' );
|
||||
@ -790,3 +772,94 @@ function edds_stripe_connect_admin_notices_print() {
|
||||
} catch( Exception $e ) {}
|
||||
}
|
||||
add_action( 'admin_notices', 'edds_stripe_connect_admin_notices_print' );
|
||||
|
||||
/**
|
||||
* Adds a Stripe Connect site health test.
|
||||
*
|
||||
* @since 2.9.3
|
||||
* @param array $tests The array of Site Health tests.
|
||||
* @return array
|
||||
*/
|
||||
function edds_stripe_connect_site_health_test( $tests ) {
|
||||
$active_gateways = edd_get_enabled_payment_gateways();
|
||||
if ( ! empty( $active_gateways['stripe'] ) && current_user_can( 'manage_shop_settings' ) ) {
|
||||
$tests['direct']['edds_stripe_connect'] = array(
|
||||
'label' => __( 'Stripe Connect', 'easy-digital-downloads' ),
|
||||
'test' => 'edds_get_test_stripe_connect',
|
||||
);
|
||||
}
|
||||
|
||||
return $tests;
|
||||
}
|
||||
add_filter( 'site_status_tests', 'edds_stripe_connect_site_health_test' );
|
||||
|
||||
/**
|
||||
* Adds the Stripe Connect Site Health test.
|
||||
*
|
||||
* @since 2.9.3
|
||||
* @return array
|
||||
*/
|
||||
function edds_get_test_stripe_connect() {
|
||||
$result = array(
|
||||
'label' => __( 'You are securely connected to Stripe', 'easy-digital-downloads' ),
|
||||
'status' => 'good',
|
||||
'badge' => array(
|
||||
'label' => __( 'Easy Digital Downloads: Stripe', 'easy-digital-downloads' ),
|
||||
'color' => 'blue',
|
||||
),
|
||||
'description' => sprintf(
|
||||
'<p>%s</p>',
|
||||
__( 'Stripe Connect helps ensure easy setup and security.', 'easy-digital-downloads' )
|
||||
),
|
||||
'actions' => '',
|
||||
'test' => 'edds_stripe_connect',
|
||||
);
|
||||
|
||||
$elements_mode = edds_get_elements_mode();
|
||||
if ( edd_stripe()->connect()->is_connected ) {
|
||||
if ( 'payment-elements' === $elements_mode ) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
// User is connected but on the Card Elements, we should give them a recommendation to use the Payment Elements.
|
||||
$result['label'] = __( 'You are using the legacy Card Elements fields', 'easy-digital-downloads' );
|
||||
$result['status'] = 'recommended';
|
||||
$result['badge']['color'] = 'orange';
|
||||
$result['description'] = sprintf(
|
||||
'<p>%s</p>',
|
||||
esc_html__( 'Increase conversions, security, and reliability by using the Payment Elements integration for Stripe.', 'easy-digital-downloads' )
|
||||
);
|
||||
$result['actions'] = sprintf(
|
||||
'<a href="%s" class="button button-primary"><span>%s</span></a>',
|
||||
esc_url(
|
||||
edd_get_admin_url(
|
||||
array(
|
||||
'page' => 'edd-settings',
|
||||
'tab' => 'gateways',
|
||||
'section' => 'edd-stripe',
|
||||
)
|
||||
)
|
||||
),
|
||||
esc_html__( 'Switch to Payment Elements', 'easy-digital-downloads' )
|
||||
);
|
||||
|
||||
} else {
|
||||
$result['label'] = __( 'You are using manually managed Stripe API keys', 'easy-digital-downloads' );
|
||||
$result['status'] = 'critical';
|
||||
$result['badge']['color'] = 'red';
|
||||
$result['description'] = sprintf(
|
||||
'<p>%s</p>',
|
||||
esc_html__( 'By securely connecting your Easy Digital Downloads store with Stripe Connect, you\'ll get access to more reliable payments and use managed API keys which are more secure.', 'easy-digital-downloads' )
|
||||
);
|
||||
$result['actions'] = sprintf(
|
||||
'<a href="%s" class="edd-stripe-connect"><span>%s</span></a>',
|
||||
esc_url( edds_stripe_connect_url() ),
|
||||
esc_html__( 'Connect with Stripe', 'easy-digital-downloads' )
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
edd_stripe_connect_admin_style();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
@ -40,19 +40,17 @@ add_action( 'admin_init', function() {
|
||||
}
|
||||
|
||||
$elements_mode = 'payment-elements';
|
||||
$connect = edd_stripe()->connect();
|
||||
|
||||
if (
|
||||
edds_stripe_connect_can_manage_keys() ||
|
||||
! empty( edd_get_option( 'stripe_connect_account_id', false ) )
|
||||
! empty( $connect->get_connect_id() ) ||
|
||||
edds_stripe_connect_can_manage_keys()
|
||||
) {
|
||||
$elements_mode = 'card-elements';
|
||||
add_option( '_edds_legacy_elements_enabled', 1, false );
|
||||
}
|
||||
|
||||
edd_update_option( 'stripe_elements_mode', $elements_mode );
|
||||
|
||||
if ( 'card-elements' === $elements_mode ) {
|
||||
add_option( '_edds_legacy_elements_enabled', 1, false );
|
||||
}
|
||||
} );
|
||||
|
||||
/**
|
||||
|
@ -52,6 +52,14 @@ class EDD_Stripe {
|
||||
*/
|
||||
public $regional_support;
|
||||
|
||||
/**
|
||||
* Stripe Connect status class.
|
||||
*
|
||||
* @since 2.9.3
|
||||
* @var \EDD\Stripe\Connect
|
||||
*/
|
||||
public $connect;
|
||||
|
||||
/**
|
||||
* Instantiates or returns the singleton instance.
|
||||
*
|
||||
@ -93,6 +101,7 @@ class EDD_Stripe {
|
||||
require_once EDDS_PLUGIN_DIR . '/vendor/autoload.php';
|
||||
}
|
||||
|
||||
require_once EDDS_PLUGIN_DIR . '/includes/functions.php';
|
||||
require_once EDDS_PLUGIN_DIR . '/includes/class-stripe-api.php';
|
||||
|
||||
// We need this one to load early so we can use it in the upcoming includes.
|
||||
@ -107,7 +116,6 @@ class EDD_Stripe {
|
||||
require_once EDDS_PLUGIN_DIR . '/includes/utils/class-registry.php';
|
||||
require_once EDDS_PLUGIN_DIR . '/includes/utils/modal.php';
|
||||
|
||||
require_once EDDS_PLUGIN_DIR . '/includes/functions.php';
|
||||
require_once EDDS_PLUGIN_DIR . '/includes/deprecated.php';
|
||||
require_once EDDS_PLUGIN_DIR . '/includes/compat.php';
|
||||
require_once EDDS_PLUGIN_DIR . '/includes/i18n.php';
|
||||
@ -137,7 +145,6 @@ class EDD_Stripe {
|
||||
// Load Apple Pay functions.
|
||||
require_once EDDS_PLUGIN_DIR . '/includes/payment-methods/apple-pay.php';
|
||||
|
||||
|
||||
// Stripe Elements, separated by elements type.
|
||||
switch ( $elements_mode ) {
|
||||
case 'card-elements':
|
||||
@ -216,6 +223,21 @@ class EDD_Stripe {
|
||||
$this->rate_limiting = new EDD_Stripe_Rate_Limiting();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Stripe Connect utility class.
|
||||
*
|
||||
* @since 2.9.3
|
||||
*/
|
||||
public function connect() {
|
||||
if ( ! is_null( $this->connect ) ) {
|
||||
return $this->connect;
|
||||
}
|
||||
require_once EDDS_PLUGIN_DIR . '/includes/class-stripe-connect.php';
|
||||
$this->connect = new EDD\Stripe\Connect();
|
||||
|
||||
return $this->connect;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs database upgrades.
|
||||
*
|
||||
|
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace EDD\Stripe;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* The class to manage the Stripe Connect properties.
|
||||
*/
|
||||
class Connect {
|
||||
|
||||
/**
|
||||
* Whether the site is connected to Stripe with Stripe Connect.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $is_connected;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->is_connected = ! empty( $this->get_connect_id() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the connect ID.
|
||||
*
|
||||
* @return string|false
|
||||
*/
|
||||
public function get_connect_id() {
|
||||
return edd_get_option( 'stripe_connect_account_id', false );
|
||||
}
|
||||
}
|
@ -9,10 +9,9 @@
|
||||
*/
|
||||
function edds_stripe_connect_can_manage_keys() {
|
||||
|
||||
$stripe_connect_account_id = edd_get_option( 'stripe_connect_account_id', false );
|
||||
$secret = edd_is_test_mode() ? edd_get_option( 'test_secret_key' ) : edd_get_option( 'live_secret_key' );
|
||||
$secret = edd_is_test_mode() ? edd_get_option( 'test_secret_key' ) : edd_get_option( 'live_secret_key' );
|
||||
|
||||
return empty( $stripe_connect_account_id ) && $secret;
|
||||
return $secret && empty( edd_stripe()->connect()->get_connect_id() );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -21,6 +20,7 @@ function edds_stripe_connect_can_manage_keys() {
|
||||
* If the user is gated into the legacy mode, set the default to card-elements.
|
||||
*
|
||||
* @since 2.9.0
|
||||
* @since 2.9.5.1 We're now listening for an elements_mode flag in POST requests.
|
||||
*
|
||||
* @return string The elements mode string.
|
||||
*/
|
||||
@ -43,6 +43,17 @@ function edds_get_elements_mode() {
|
||||
( isset( $_GET['action'] ) && 'update' === $_GET['action'] ) &&
|
||||
( isset( $_GET['subscription_id'] ) && is_numeric( $_GET['subscription_id'] ) )
|
||||
) {
|
||||
add_filter( 'edd_get_option_stripe_split_payment_fields', '__return_false' );
|
||||
return 'card-elements';
|
||||
}
|
||||
|
||||
/**
|
||||
* Card elements does a lot with AJAX requests, which will lose the context of being on the Subscription update form, so
|
||||
* we are sending in a flag for using card elements with the elements_mode equal to 'card-elements' in those POST requests.
|
||||
*
|
||||
* @since 2.9.5.1
|
||||
*/
|
||||
if ( isset( $_POST['elements_mode'] ) && 'card-elements' === $_POST['elements_mode'] ) {
|
||||
return 'card-elements';
|
||||
}
|
||||
|
||||
|
@ -250,6 +250,28 @@ function edds_get_stripe_payment_elements_fields() {
|
||||
return apply_filters( 'edds_stripe_payment_elements_fields', $default_fields );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of terms for the payment elements.
|
||||
*
|
||||
* @since 2.9.4
|
||||
*
|
||||
* @return array The terms array by payment method.
|
||||
*/
|
||||
function edds_get_stripe_payment_elements_terms() {
|
||||
$terms = array( 'card' => 'auto' );
|
||||
|
||||
/**
|
||||
* Allows filtering the payment elements terms.
|
||||
*
|
||||
* @see https://stripe.com/docs/js/elements_object/create_payment_element#payment_element_create-options-terms
|
||||
*
|
||||
* @since 2.9.4
|
||||
* @param array The terms array by payment method.
|
||||
*/
|
||||
|
||||
return apply_filters( 'edds_stripe_payment_elements_terms', $terms );
|
||||
}
|
||||
|
||||
/**
|
||||
* Gathers all the possible customizations for the Stripe Payment Elements.
|
||||
*
|
||||
@ -273,6 +295,7 @@ function edds_gather_payment_element_customizations() {
|
||||
'fonts' => edds_get_stripe_payment_elements_fonts(),
|
||||
'paymentMethodTypes' => edds_payment_element_payment_method_types(),
|
||||
'fields' => edds_get_stripe_payment_elements_fields(),
|
||||
'terms' => edds_get_stripe_payment_elements_terms(),
|
||||
'i18n' => array(
|
||||
'errorMessages' => edds_get_localized_error_messages(),
|
||||
),
|
||||
|
@ -283,10 +283,8 @@ function edds_process_purchase_form( $purchase_data ) {
|
||||
$intent_args
|
||||
);
|
||||
|
||||
$stripe_connect_account_id = edd_get_option( 'stripe_connect_account_id' );
|
||||
|
||||
if (
|
||||
! empty( $stripe_connect_account_id ) &&
|
||||
! empty( edd_stripe()->connect()->get_connect_id() ) &&
|
||||
true === edds_stripe_connect_account_country_supports_application_fees()
|
||||
) {
|
||||
$intent_args['application_fee_amount'] = round( $amount * 0.02 );
|
||||
|
@ -234,10 +234,10 @@ function edds_process_purchase_form( $purchase_data ) {
|
||||
$intent_args
|
||||
);
|
||||
|
||||
$stripe_connect_account_id = edd_get_option( 'stripe_connect_account_id' );
|
||||
$intent_type = 'PaymentIntent';
|
||||
|
||||
if (
|
||||
! empty( $stripe_connect_account_id ) &&
|
||||
! empty( edd_stripe()->connect()->get_connect_id() ) &&
|
||||
true === edds_stripe_connect_account_country_supports_application_fees()
|
||||
) {
|
||||
$intent_args['application_fee_amount'] = round( $amount * 0.02 );
|
||||
|
@ -78,11 +78,10 @@ function edds_apple_pay_admin_notices_print() {
|
||||
wp_enqueue_script( 'edds-admin-notices' );
|
||||
|
||||
try {
|
||||
$is_connected = edd_get_option( 'stripe_connect_account_id', '' );
|
||||
$error = edd_get_option( 'stripe_apple_pay_domain_error', '' );
|
||||
$test_mode = edd_is_test_mode();
|
||||
$error = edd_get_option( 'stripe_apple_pay_domain_error', '' );
|
||||
$test_mode = edd_is_test_mode();
|
||||
|
||||
if ( ! empty( $is_connected ) && ! empty( $error ) && false === $test_mode ) {
|
||||
if ( ! empty( edd_stripe()->connect()->is_connected ) && ! empty( $error ) && false === $test_mode ) {
|
||||
$notices->output( 'apple-pay-' . $_SERVER['HTTP_HOST'] );
|
||||
}
|
||||
} catch( Exception $e ) {}
|
||||
@ -189,8 +188,7 @@ function edds_apple_pay_create_directory_and_move_file() {
|
||||
* @since 2.8.0
|
||||
*/
|
||||
function edds_apple_pay_check_domain() {
|
||||
$is_connected = edd_get_option( 'stripe_connect_account_id', '' );
|
||||
if ( empty( $is_connected ) ) {
|
||||
if ( empty( edd_stripe()->connect()->is_connected ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -221,7 +219,7 @@ add_action( 'admin_init', 'edds_apple_pay_check_domain', 10 );
|
||||
*/
|
||||
function edds_apple_pay_verify_domain() {
|
||||
// If Stripe isn't connected, just return.
|
||||
if ( empty( edd_get_option( 'stripe_connect_account_id', '' ) ) ) {
|
||||
if ( empty( edd_stripe()->connect()->is_connected ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -258,7 +256,7 @@ function edds_apple_pay_verify_domain() {
|
||||
// Create directory and move file if needed.
|
||||
edds_apple_pay_create_directory_and_move_file();
|
||||
|
||||
$stripe_connect_account_id = edd_get_option( 'stripe_connect_account_id', '' );
|
||||
$stripe_connect_account_id = edd_stripe()->connect()->get_connect_id();
|
||||
|
||||
if (
|
||||
empty( $stripe_connect_account_id ) || // If we don't have a stripe connect account ID
|
||||
|
@ -160,7 +160,7 @@ function edd_stripe_connect_admin_script( $hook ) {
|
||||
return;
|
||||
}
|
||||
|
||||
wp_enqueue_style( 'edd-stripe-admin-styles', EDDSTRIPE_PLUGIN_URL . 'assets/css/build/admin.min.css', array(), EDD_STRIPE_VERSION );
|
||||
edd_stripe_connect_admin_style();
|
||||
|
||||
wp_enqueue_script( 'edd-stripe-admin-scripts', EDDSTRIPE_PLUGIN_URL . 'assets/js/build/admin.min.js', array( 'jquery' ), EDD_STRIPE_VERSION );
|
||||
|
||||
@ -180,3 +180,19 @@ function edd_stripe_connect_admin_script( $hook ) {
|
||||
);
|
||||
}
|
||||
add_action( 'admin_enqueue_scripts', 'edd_stripe_connect_admin_script' );
|
||||
|
||||
/**
|
||||
* Enqueues the Stripe admin style.
|
||||
*
|
||||
* @since 2.9.3
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function edd_stripe_connect_admin_style() {
|
||||
wp_enqueue_style(
|
||||
'edd-stripe-admin-styles',
|
||||
EDDSTRIPE_PLUGIN_URL . 'assets/css/build/admin.min.css',
|
||||
array(),
|
||||
EDD_STRIPE_VERSION
|
||||
);
|
||||
}
|
||||
|
@ -120,6 +120,7 @@ function edds_output_payment_elements_form() {
|
||||
// Payment Elements needs to not allow checking out with mixed carts or multiple subscriptions.
|
||||
if ( function_exists( 'edd_recurring' ) ) {
|
||||
if ( ( count( edd_get_cart_contents() ) > 1 && edd_recurring()->cart_contains_recurring() ) || edd_recurring()->cart_is_mixed() ) {
|
||||
add_filter( 'edd_checkout_button_purchase', '__return_empty_string', 999 );
|
||||
?>
|
||||
<div class="edd_errors edd-alert edd-alert-info">
|
||||
<p class="edd_error" id="edd_error_edd-stripe-incompatible-cart"><?php echo edds_get_single_subscription_cart_error(); ?></p>
|
||||
|
@ -98,7 +98,7 @@ class InstalledVersions
|
||||
{
|
||||
foreach (self::getInstalled() as $installed) {
|
||||
if (isset($installed['versions'][$packageName])) {
|
||||
return $includeDevRequirements || !isset($installed['versions'][$packageName]['dev_requirement']) || $installed['versions'][$packageName]['dev_requirement'] === false;
|
||||
return $includeDevRequirements || empty($installed['versions'][$packageName]['dev_requirement']);
|
||||
}
|
||||
}
|
||||
|
||||
@ -119,7 +119,7 @@ class InstalledVersions
|
||||
*/
|
||||
public static function satisfies(VersionParser $parser, $packageName, $constraint)
|
||||
{
|
||||
$constraint = $parser->parseConstraints((string) $constraint);
|
||||
$constraint = $parser->parseConstraints($constraint);
|
||||
$provided = $parser->parseConstraints(self::getVersionRanges($packageName));
|
||||
|
||||
return $provided->matches($constraint);
|
||||
@ -328,9 +328,7 @@ class InstalledVersions
|
||||
if (isset(self::$installedByVendor[$vendorDir])) {
|
||||
$installed[] = self::$installedByVendor[$vendorDir];
|
||||
} elseif (is_file($vendorDir.'/composer/installed.php')) {
|
||||
/** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
|
||||
$required = require $vendorDir.'/composer/installed.php';
|
||||
$installed[] = self::$installedByVendor[$vendorDir] = $required;
|
||||
$installed[] = self::$installedByVendor[$vendorDir] = require $vendorDir.'/composer/installed.php';
|
||||
if (null === self::$installed && strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) {
|
||||
self::$installed = $installed[count($installed) - 1];
|
||||
}
|
||||
@ -342,17 +340,12 @@ class InstalledVersions
|
||||
// only require the installed.php file if this file is loaded from its dumped location,
|
||||
// and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
|
||||
if (substr(__DIR__, -8, 1) !== 'C') {
|
||||
/** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
|
||||
$required = require __DIR__ . '/installed.php';
|
||||
self::$installed = $required;
|
||||
self::$installed = require __DIR__ . '/installed.php';
|
||||
} else {
|
||||
self::$installed = array();
|
||||
}
|
||||
}
|
||||
|
||||
if (self::$installed !== array()) {
|
||||
$installed[] = self::$installed;
|
||||
}
|
||||
$installed[] = self::$installed;
|
||||
|
||||
return $installed;
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
<?php return array(
|
||||
'root' => array(
|
||||
'name' => 'easy-digital-downloads/edd-stripe',
|
||||
'pretty_version' => '2.9.2.2',
|
||||
'version' => '2.9.2.2',
|
||||
'reference' => '7e59ac4f4357cb3b388182e0601056f60f0b2407',
|
||||
'pretty_version' => 'dev-master',
|
||||
'version' => 'dev-master',
|
||||
'reference' => '53b4520542b33c13127f604da77f09f7cf9cf902',
|
||||
'type' => 'wordpress-plugin',
|
||||
'install_path' => __DIR__ . '/../../',
|
||||
'aliases' => array(),
|
||||
@ -11,9 +11,9 @@
|
||||
),
|
||||
'versions' => array(
|
||||
'easy-digital-downloads/edd-stripe' => array(
|
||||
'pretty_version' => '2.9.2.2',
|
||||
'version' => '2.9.2.2',
|
||||
'reference' => '7e59ac4f4357cb3b388182e0601056f60f0b2407',
|
||||
'pretty_version' => 'dev-master',
|
||||
'version' => 'dev-master',
|
||||
'reference' => '53b4520542b33c13127f604da77f09f7cf9cf902',
|
||||
'type' => 'wordpress-plugin',
|
||||
'install_path' => __DIR__ . '/../../',
|
||||
'aliases' => array(),
|
||||
|
Reference in New Issue
Block a user