updated plugin Easy Digital Downloads
version 3.1.1.2
This commit is contained in:
@ -2,8 +2,6 @@
|
||||
/**
|
||||
* Payment Request: Apple Pay
|
||||
*
|
||||
* @link https://stripe.com/docs/stripe-js/elements/payment-request-button#verifying-your-domain-with-apple-pay
|
||||
*
|
||||
* @package EDD_Stripe
|
||||
* @since 2.8.0
|
||||
*/
|
||||
@ -15,7 +13,7 @@
|
||||
*
|
||||
* @return true|WP_Error True if all notices are registered, otherwise WP_Error.
|
||||
*/
|
||||
function edds_prb_apple_pay_admin_notices_register() {
|
||||
function edds_apple_pay_admin_notices_register() {
|
||||
$registry = edds_get_registry( 'admin-notices' );
|
||||
|
||||
if ( ! $registry ) {
|
||||
@ -25,8 +23,8 @@ function edds_prb_apple_pay_admin_notices_register() {
|
||||
try {
|
||||
// General error message.
|
||||
$message = (
|
||||
'<strong>' . esc_html__( 'Apple Pay domain verification error.', 'easy-digital-downloads' ) . '</strong><br />' .
|
||||
edd_get_option( 'stripe_prb_apple_pay_domain_error', '' )
|
||||
'<strong>' . esc_html__( 'Apple Pay domain verification error.', 'easy-digital-downloads' ) . '</strong><br />' .
|
||||
edd_get_option( 'stripe_apple_pay_domain_error', '' )
|
||||
);
|
||||
|
||||
$registry->add(
|
||||
@ -56,14 +54,14 @@ function edds_prb_apple_pay_admin_notices_register() {
|
||||
|
||||
return true;
|
||||
}
|
||||
add_action( 'admin_init', 'edds_prb_apple_pay_admin_notices_register', 30 );
|
||||
add_action( 'admin_init', 'edds_apple_pay_admin_notices_register', 30 );
|
||||
|
||||
/**
|
||||
* Conditionally prints registered notices.
|
||||
*
|
||||
* @since 2.8.0
|
||||
*/
|
||||
function edds_prb_apple_pay_admin_notices_print() {
|
||||
function edds_apple_pay_admin_notices_print() {
|
||||
// Current user needs capability to dismiss notices.
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
return;
|
||||
@ -80,15 +78,16 @@ function edds_prb_apple_pay_admin_notices_print() {
|
||||
wp_enqueue_script( 'edds-admin-notices' );
|
||||
|
||||
try {
|
||||
$error = edd_get_option( 'stripe_prb_apple_pay_domain_error', '' );
|
||||
$test_mode = edd_is_test_mode();
|
||||
$is_connected = edd_get_option( 'stripe_connect_account_id', '' );
|
||||
$error = edd_get_option( 'stripe_apple_pay_domain_error', '' );
|
||||
$test_mode = edd_is_test_mode();
|
||||
|
||||
if ( ! empty( $error ) && false === $test_mode ) {
|
||||
if ( ! empty( $is_connected ) && ! empty( $error ) && false === $test_mode ) {
|
||||
$notices->output( 'apple-pay-' . $_SERVER['HTTP_HOST'] );
|
||||
}
|
||||
} catch( Exception $e ) {}
|
||||
}
|
||||
add_action( 'admin_notices', 'edds_prb_apple_pay_admin_notices_print' );
|
||||
add_action( 'admin_notices', 'edds_apple_pay_admin_notices_print' );
|
||||
|
||||
/**
|
||||
* Returns information associated with the name/location of the domain verification file.
|
||||
@ -97,7 +96,7 @@ add_action( 'admin_notices', 'edds_prb_apple_pay_admin_notices_print' );
|
||||
*
|
||||
* @return array Domain verification file information.
|
||||
*/
|
||||
function edds_prb_apple_pay_get_fileinfo() {
|
||||
function edds_apple_pay_get_fileinfo() {
|
||||
$path = untrailingslashit( $_SERVER['DOCUMENT_ROOT'] );
|
||||
$dir = '.well-known';
|
||||
$file = 'apple-developer-merchantid-domain-association';
|
||||
@ -117,10 +116,10 @@ function edds_prb_apple_pay_get_fileinfo() {
|
||||
*
|
||||
* @return bool True if the domain has been verified and the association file exists.
|
||||
*/
|
||||
function edds_prb_apple_pay_is_valid() {
|
||||
function edds_apple_pay_is_valid() {
|
||||
return (
|
||||
edds_prb_apple_pay_has_domain_verification_file() &&
|
||||
edds_prb_apple_pay_has_domain_verification()
|
||||
edds_apple_pay_has_domain_verification_file() &&
|
||||
edds_apple_pay_has_domain_verification()
|
||||
);
|
||||
}
|
||||
|
||||
@ -131,8 +130,8 @@ function edds_prb_apple_pay_is_valid() {
|
||||
*
|
||||
* @return bool True if the domain verification file exists.
|
||||
*/
|
||||
function edds_prb_apple_pay_has_domain_verification_file() {
|
||||
$fileinfo = edds_prb_apple_pay_get_fileinfo();
|
||||
function edds_apple_pay_has_domain_verification_file() {
|
||||
$fileinfo = edds_apple_pay_get_fileinfo();
|
||||
|
||||
if ( ! @file_exists( $fileinfo['fullpath'] ) ) {
|
||||
return false;
|
||||
@ -148,7 +147,7 @@ function edds_prb_apple_pay_has_domain_verification_file() {
|
||||
*
|
||||
* @return bool True if the saved verified domain matches the current site.
|
||||
*/
|
||||
function edds_prb_apple_pay_has_domain_verification() {
|
||||
function edds_apple_pay_has_domain_verification() {
|
||||
return edd_get_option( 'stripe_prb_apple_pay_domain' ) === $_SERVER['HTTP_HOST'];
|
||||
}
|
||||
|
||||
@ -159,14 +158,14 @@ function edds_prb_apple_pay_has_domain_verification() {
|
||||
*
|
||||
* @throws \Exception If the directory or file cannot be created.
|
||||
*/
|
||||
function edds_prb_apple_pay_create_directory_and_move_file() {
|
||||
$file = edds_prb_apple_pay_has_domain_verification_file();
|
||||
function edds_apple_pay_create_directory_and_move_file() {
|
||||
$file = edds_apple_pay_has_domain_verification_file();
|
||||
|
||||
if ( true === $file ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$fileinfo = edds_prb_apple_pay_get_fileinfo();
|
||||
$fileinfo = edds_apple_pay_get_fileinfo();
|
||||
|
||||
// Create directory if it does not exist.
|
||||
if ( ! file_exists( trailingslashit( $fileinfo['path'] ) . $fileinfo['dir'] ) ) {
|
||||
@ -176,7 +175,7 @@ function edds_prb_apple_pay_create_directory_and_move_file() {
|
||||
}
|
||||
|
||||
// Move file if needed.
|
||||
if ( ! edds_prb_apple_pay_has_domain_verification_file() ) {
|
||||
if ( ! edds_apple_pay_has_domain_verification_file() ) {
|
||||
if ( ! @copy( trailingslashit( EDDS_PLUGIN_DIR ) . $fileinfo['file'], $fileinfo['fullpath'] ) ) { // @codingStandardsIgnoreLine
|
||||
throw new \Exception( __( 'Unable to copy domain association file to domain .well-known directory.', 'easy-digital-downloads' ) );
|
||||
}
|
||||
@ -189,8 +188,13 @@ function edds_prb_apple_pay_create_directory_and_move_file() {
|
||||
*
|
||||
* @since 2.8.0
|
||||
*/
|
||||
function edds_prb_apple_pay_check_domain() {
|
||||
$error = edd_get_option( 'stripe_prb_apple_pay_domain_error', '' );
|
||||
function edds_apple_pay_check_domain() {
|
||||
$is_connected = edd_get_option( 'stripe_connect_account_id', '' );
|
||||
if ( empty( $is_connected ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$error = edd_get_option( 'stripe_apple_pay_domain_error', '' );
|
||||
|
||||
if ( empty( $error ) ) {
|
||||
return;
|
||||
@ -201,26 +205,35 @@ function edds_prb_apple_pay_check_domain() {
|
||||
|
||||
foreach ( $domains->autoPagingIterator() as $domain ) {
|
||||
if ( $domain->domain_name === $_SERVER['HTTP_HOST'] ) {
|
||||
edd_delete_option( 'stripe_prb_apple_pay_domain_error' );
|
||||
edd_delete_option( 'stripe_apple_pay_domain_error' );
|
||||
edd_update_option( 'stripe_prb_apple_pay_domain', $_SERVER['HTTP_HOST'] );
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch ( \Exception $e ) {}
|
||||
}
|
||||
add_action( 'admin_init', 'edds_prb_apple_pay_check_domain', 10 );
|
||||
add_action( 'admin_init', 'edds_apple_pay_check_domain', 10 );
|
||||
|
||||
/**
|
||||
* Verifies the current domain.
|
||||
*
|
||||
* @since 2.8.0
|
||||
*/
|
||||
function edds_prb_apple_pay_verify_domain() {
|
||||
// Payment Request Button is not enabled, do nothing.
|
||||
if ( false === edds_prb_is_enabled() ) {
|
||||
function edds_apple_pay_verify_domain() {
|
||||
// If Stripe isn't connected, just return.
|
||||
if ( empty( edd_get_option( 'stripe_connect_account_id', '' ) ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Payment Request Button is not enabled, and card-elements is used.
|
||||
$elements_mode = edds_get_elements_mode();
|
||||
|
||||
if ( 'card-elements' === $elements_mode ) {
|
||||
if ( function_exists( 'edds_prb_is_enabled' ) && false === edds_prb_is_enabled() ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Avoid getting caught in AJAX requests.
|
||||
if ( defined( 'DOING_AJAX' ) && true === DOING_AJAX ) {
|
||||
return;
|
||||
@ -237,19 +250,21 @@ function edds_prb_apple_pay_verify_domain() {
|
||||
}
|
||||
|
||||
// Current domain matches and the file exists, do nothing.
|
||||
if ( true === edds_prb_apple_pay_is_valid() ) {
|
||||
if ( true === edds_apple_pay_is_valid() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// Create directory and move file if needed.
|
||||
edds_prb_apple_pay_create_directory_and_move_file();
|
||||
edds_apple_pay_create_directory_and_move_file();
|
||||
|
||||
$stripe_connect_account_id = edd_get_option( 'stripe_connect_account_id', '' );
|
||||
|
||||
// Automatically verify when using "real" API keys.
|
||||
if ( empty( $stripe_connect_account_id ) ) {
|
||||
$verification = edds_api_request(
|
||||
if (
|
||||
empty( $stripe_connect_account_id ) || // If we don't have a stripe connect account ID
|
||||
( ! empty( $stripe_connect_account_id ) && empty( edd_get_option( 'stripe_prb_apple_pay_domain') ) ) // Or if we do have a stripe connect account ID, but we haven't registered the domain for Apple Pay
|
||||
) {
|
||||
edds_api_request(
|
||||
'ApplePayDomain',
|
||||
'create',
|
||||
array(
|
||||
@ -274,7 +289,7 @@ function edds_prb_apple_pay_verify_domain() {
|
||||
}
|
||||
} catch ( \Exception $e ) {
|
||||
// Set error if something went wrong.
|
||||
edd_update_option( 'stripe_prb_apple_pay_domain_error', $e->getMessage() );
|
||||
edd_update_option( 'stripe_apple_pay_domain_error', $e->getMessage() );
|
||||
}
|
||||
}
|
||||
add_action( 'admin_init', 'edds_prb_apple_pay_verify_domain', 20 );
|
||||
add_action( 'admin_init', 'edds_apple_pay_verify_domain', 20 );
|
@ -14,33 +14,30 @@
|
||||
function edds_buy_now_ajax_add_to_cart() {
|
||||
$data = $_POST;
|
||||
|
||||
if ( ! isset( $data['download_id'] ) || ! isset( $data['nonce'] ) ) {
|
||||
if ( empty( $data['download_id'] ) ) {
|
||||
return wp_send_json_error( array(
|
||||
'message' => __( 'Unable to add item to cart.', 'easy-digital-downloads' ),
|
||||
) );
|
||||
}
|
||||
|
||||
|
||||
$download_id = absint( $data['download_id'] );
|
||||
$price_id = absint( $data['price_id'] );
|
||||
$quantity = absint( $data['quantity'] );
|
||||
|
||||
$nonce = sanitize_text_field( $data['nonce'] );
|
||||
$valid_nonce = wp_verify_nonce( $nonce, 'edd-add-to-cart-' . $download_id );
|
||||
|
||||
if ( false === $valid_nonce ) {
|
||||
if ( false === edds_verify( 'nonce', 'edd-add-to-cart-' . $download_id ) ) {
|
||||
return wp_send_json_error( array(
|
||||
'message' => __( 'Unable to add item to cart.', 'easy-digital-downloads' ),
|
||||
) );
|
||||
}
|
||||
|
||||
// Empty cart.
|
||||
edd_empty_cart();
|
||||
$args = array(
|
||||
'quantity' => absint( $data['quantity'] ),
|
||||
'price_id' => null,
|
||||
);
|
||||
|
||||
if ( edd_has_variable_prices( $download_id ) ) {
|
||||
$args['price_id'] = absint( $data['price_id'] );
|
||||
}
|
||||
|
||||
// Add individual item.
|
||||
edd_add_to_cart( $download_id, array(
|
||||
'quantity' => $quantity,
|
||||
'price_id' => $price_id,
|
||||
) );
|
||||
edd_add_to_cart( $download_id, $args );
|
||||
|
||||
return wp_send_json_success( array(
|
||||
'checkout' => edds_buy_now_checkout(),
|
||||
@ -55,7 +52,9 @@ add_action( 'wp_ajax_nopriv_edds_add_to_cart', 'edds_buy_now_ajax_add_to_cart' )
|
||||
* @since 2.8.0
|
||||
*/
|
||||
function edds_buy_now_ajax_empty_cart() {
|
||||
edd_empty_cart();
|
||||
if ( ! empty( EDD()->cart->contents ) ) {
|
||||
EDD()->cart->empty_cart();
|
||||
}
|
||||
|
||||
return wp_send_json_success();
|
||||
}
|
||||
|
@ -26,14 +26,8 @@ function edds_buy_now_modal() {
|
||||
// Enqueue core scripts.
|
||||
add_filter( 'edd_is_checkout', '__return_true' );
|
||||
|
||||
if ( function_exists( 'edd_enqueue_scripts' ) ) {
|
||||
// https://github.com/easydigitaldownloads/easy-digital-downloads/issues/7847
|
||||
edd_enqueue_scripts();
|
||||
edd_localize_scripts();
|
||||
} else {
|
||||
edd_load_scripts();
|
||||
edd_agree_to_terms_js();
|
||||
}
|
||||
edd_enqueue_scripts();
|
||||
edd_localize_scripts();
|
||||
|
||||
remove_filter( 'edd_is_checkout', '__return_true' );
|
||||
|
||||
@ -63,6 +57,7 @@ function edds_buy_now_checkout() {
|
||||
$form_mode = $total > 0
|
||||
? 'payment-mode=stripe'
|
||||
: 'payment-mode=manual';
|
||||
|
||||
$form_action = edd_get_checkout_uri( $form_mode );
|
||||
$existing_cards = edd_stripe_get_existing_cards( get_current_user_id() );
|
||||
|
||||
@ -104,6 +99,9 @@ function edds_buy_now_checkout() {
|
||||
action="<?php echo esc_url( $form_action ); ?>"
|
||||
method="POST"
|
||||
>
|
||||
<?php if ( is_user_logged_in() && ! empty( $customer['email'] ) ) : ?>
|
||||
<input type="hidden" name="edd_email" id="edd-email" value="<?php echo esc_attr( $customer['email'] ); ?>" required/>
|
||||
<?php else: ?>
|
||||
<p>
|
||||
<label class="edd-label" for="edd-email">
|
||||
<?php esc_html_e( 'Email Address', 'easy-digital-downloads' ); ?>
|
||||
@ -123,6 +121,7 @@ function edds_buy_now_checkout() {
|
||||
<?php endif; ?>
|
||||
/>
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ( $total > 0 ) : ?>
|
||||
|
||||
@ -185,13 +184,15 @@ function edds_buy_now_checkout_purchase_label( $label ) {
|
||||
return $label;
|
||||
}
|
||||
|
||||
return sprintf(
|
||||
$label = sprintf(
|
||||
'%s - %s',
|
||||
edd_currency_filter(
|
||||
edd_format_amount( $total )
|
||||
),
|
||||
$label
|
||||
);
|
||||
|
||||
return $label;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -15,6 +15,14 @@
|
||||
* @return array Filtered gateway settings.
|
||||
*/
|
||||
function edds_prb_add_settings( $settings ) {
|
||||
/**
|
||||
* In Version 2.9.0, PRBs are no longer necessary as they are part of the
|
||||
* Payment Element.
|
||||
*/
|
||||
if ( false === _edds_legacy_elements_enabled() ) {
|
||||
return $settings;
|
||||
}
|
||||
|
||||
// Prevent adding the extra settings if the requirements are not met.
|
||||
// The `edd_settings_gateways` filter runs regardless of the short circuit
|
||||
// inside of `edds_add_settings()`
|
||||
@ -34,7 +42,8 @@ function edds_prb_add_settings( $settings ) {
|
||||
),
|
||||
);
|
||||
} else {
|
||||
$prb_settings = array(
|
||||
$elements_mode = edds_get_elements_mode();
|
||||
$prb_settings = array(
|
||||
array(
|
||||
'id' => 'stripe_prb',
|
||||
'name' => __( 'Apple Pay/Google Pay', 'easy-digital-downloads' ),
|
||||
@ -51,7 +60,7 @@ function edds_prb_add_settings( $settings ) {
|
||||
? '<br /><strong>' . __( 'Apple Pay is not available in Test Mode.', 'easy-digital-downloads' ) . '</strong> ' . sprintf(
|
||||
/* translators: %1$s Opening anchor tag, do not translate. %2$s Opening anchor tag, do not translate. */
|
||||
__( 'See our %1$sdocumentation%2$s for more information.', 'easy-digital-downloads' ),
|
||||
'<a href="' . esc_url( edds_documentation_route( 'stripe-express-checkout' ) ) . '" target="_blank" rel="noopener noreferrer">',
|
||||
'<a href="' . esc_url( edds_documentation_route( 'stripe-express-checkout-apple-pay-google-pay' ) ) . '" target="_blank" rel="noopener noreferrer">',
|
||||
'</a>'
|
||||
)
|
||||
: ''
|
||||
@ -81,12 +90,21 @@ function edds_prb_add_settings( $settings ) {
|
||||
),
|
||||
'checkout' => __( 'Checkout', 'easy-digital-downloads' ),
|
||||
),
|
||||
)
|
||||
'class' => 'payment-elements' === $elements_mode ? 'edd-hidden card-elements-feature' : 'card-elements-feature',
|
||||
),
|
||||
array(
|
||||
'id' => 'stripe_prb_elements_note',
|
||||
'name' => __( 'Apple Pay/Google Pay', 'easy-digital-downloads' ),
|
||||
'desc' => __( 'Apple Pay and Google Pay support is now provided via the Payment Elements integration.', 'easy-digital-downloads' ),
|
||||
'type' => 'descriptive_text',
|
||||
'class' => 'payment-elements' === $elements_mode ? 'payment-elements-feature' : 'edd-hidden payment-elements-feature',
|
||||
),
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
$position = array_search(
|
||||
'stripe_statement_descriptor',
|
||||
'stripe_use_existing_cards',
|
||||
array_values( wp_list_pluck( $settings['edd-stripe'], 'id' ) ),
|
||||
true
|
||||
);
|
||||
@ -119,7 +137,7 @@ function edd_edds_stripe_prb_taxes_callback() {
|
||||
'See the %1$sExpress Checkout documentation%2$s for more information.',
|
||||
'easy-digital-downloads'
|
||||
),
|
||||
'<a href="' . esc_url( edds_documentation_route( 'stripe-express-checkout' ) ) . '#edds-prb-faqs" target="_blank" rel="noopener noreferrer">',
|
||||
'<a href="' . esc_url( edds_documentation_route( 'stripe-express-checkout-apple-pay-google-pay' ) ) . '#edds-prb-faqs" target="_blank" rel="noopener noreferrer">',
|
||||
'</a>'
|
||||
),
|
||||
array(
|
||||
|
@ -21,6 +21,10 @@ function edds_prb_is_enabled( $context = array() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( 'payment-elements' === edds_get_elements_mode() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Gather allowed and enabled contexts.
|
||||
$allowed_contexts = array( 'single', 'archive', 'checkout' );
|
||||
$enabled_contexts = array_keys(
|
||||
|
@ -11,7 +11,6 @@ require_once EDDS_PLUGIN_DIR . '/includes/payment-methods/payment-request/checko
|
||||
require_once EDDS_PLUGIN_DIR . '/includes/payment-methods/payment-request/functions.php';
|
||||
require_once EDDS_PLUGIN_DIR . '/includes/payment-methods/payment-request/template.php';
|
||||
require_once EDDS_PLUGIN_DIR . '/includes/payment-methods/payment-request/shortcode.php';
|
||||
require_once EDDS_PLUGIN_DIR . '/includes/payment-methods/payment-request/apple-pay.php';
|
||||
|
||||
if ( is_admin() ) {
|
||||
require_once EDDS_PLUGIN_DIR . '/includes/payment-methods/payment-request/admin/settings.php';
|
||||
|
Reference in New Issue
Block a user