Commit inicial - WordPress Análisis de Precios Unitarios

- WordPress core y plugins
- Tema Twenty Twenty-Four configurado
- Plugin allow-unfiltered-html.php simplificado
- .gitignore configurado para excluir wp-config.php y uploads

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
root
2025-11-03 21:04:30 -06:00
commit a22573bf0b
24068 changed files with 4993111 additions and 0 deletions

View File

@@ -0,0 +1,236 @@
<tr valign="top">
<th colspan=2>
<h3><?php _e( 'Braintree Settings', 'rcp' ); ?></h3>
</th>
</tr>
<tr>
<th>
<label for="rcp_settings[braintree_live_merchantId]"><?php _e( 'Live Merchant ID', 'rcp' ); ?></label>
</th>
<td>
<input type="text" class="regular-text" id="rcp_settings[braintree_live_merchantId]" style="width: 300px;"
name="rcp_settings[braintree_live_merchantId]"
value="<?php if ( isset( $rcp_options['braintree_live_merchantId'] ) ) {
echo esc_attr( $rcp_options['braintree_live_merchantId'] );
} ?>"/>
<p class="description"><?php _e( 'Enter your Braintree live merchant ID.', 'rcp' ); ?></p>
</td>
</tr>
<tr>
<th>
<label for="rcp_settings[braintree_live_publicKey]"><?php _e( 'Live Public Key', 'rcp' ); ?></label>
</th>
<td>
<input type="<?php echo isset( $rcp_options['braintree_live_publicKey'] ) ? 'password' : 'text'; ?>"
class="regular-text" id="rcp_settings[braintree_live_publicKey]"
style="width: 300px;" name="rcp_settings[braintree_live_publicKey]"
value="<?php if ( isset( $rcp_options['braintree_live_publicKey'] ) ) {
echo esc_attr( $rcp_options['braintree_live_publicKey'] );
} ?>"/>
<button type="button" class="button button-secondary">
<span toggle="rcp_settings[braintree_live_publicKey]"
class="dashicons dashicons-hidden toggle-credentials"></span>
</button>
<p class="description"><?php _e( 'Enter your Braintree live public key.', 'rcp' ); ?></p>
</td>
</tr>
<tr>
<th>
<label for="rcp_settings[braintree_live_privateKey]"><?php _e( 'Live Private Key', 'rcp' ); ?></label>
</th>
<td>
<input type="<?php echo isset( $rcp_options['braintree_live_privateKey'] ) ? 'password' : 'text'; ?>"
class="regular-text" id="rcp_settings[braintree_live_privateKey]"
style="width: 300px;" name="rcp_settings[braintree_live_privateKey]"
value="<?php if ( isset( $rcp_options['braintree_live_privateKey'] ) ) {
echo esc_attr( $rcp_options['braintree_live_privateKey'] );
} ?>"/>
<button type="button" class="button button-secondary">
<span toggle="rcp_settings[braintree_live_privateKey]"
class="dashicons dashicons-hidden toggle-credentials"></span>
</button>
<p class="description"><?php _e( 'Enter your Braintree live private key.', 'rcp' ); ?></p>
</td>
</tr>
<tr>
<th>
<label for="rcp_settings[braintree_live_encryptionKey]"><?php _e( 'Live Client Side Encryption Key', 'rcp' ); ?></label>
</th>
<td>
<?php if ( ! empty( $rcp_options['braintree_live_encryptionKey'] ) ) : ?>
<textarea
class="regular-text"
id="rcp_settings[braintree_live_encryptionKey]"
style="width: 300px;height: 100px; display: none"
name="rcp_settings[braintree_live_encryptionKey]"
/><?php if ( isset( $rcp_options['braintree_live_encryptionKey'] ) ) { echo esc_attr( trim($rcp_options['braintree_live_encryptionKey'] ) ); } ?></textarea>
<input
type="password"
id="rcp_settings[braintree_live_encryptionKey_input]"
style="width: 300px;height: 100px; display: inline-block;"
name="rcp_settings[braintree_live_encryptionKey_input]"
value="<?php echo isset( $rcp_options['braintree_live_encryptionKey'] ) ? esc_attr( $rcp_options['braintree_live_encryptionKey'] ) : '' ?>"
/>
<button type="button" class="button button-secondary">
<span
toggle="rcp_settings[braintree_live_encryptionKey]"
class="dashicons dashicons-visibility toggle-textarea"
id="rcp_setting_braintree_toggle_live"></span>
</button>
<?php else : ?>
<textarea
class="regular-text"
id="rcp_settings[braintree_live_encryptionKey]" style="width: 300px;height: 100px;"
name="rcp_settings[braintree_live_encryptionKey]"
/><?php echo isset( $rcp_options['braintree_live_encryptionKey'] ) ? esc_attr( trim($rcp_options['braintree_live_encryptionKey'] ) ) : ''; ?></textarea>
<input
type="password"
id="rcp_settings[braintree_live_encryptionKey_input]"
style="display:none; width: 300px;height: 100px;"
name="rcp_settings[braintree_live_encryptionKey_input]"
value="<?php echo isset( $rcp_options['braintree_live_encryptionKey'] ) ? esc_attr( $rcp_options['braintree_live_encryptionKey'] ) : '' ?>"
/>
<button type="button" class="button button-secondary">
<span toggle="rcp_settings[braintree_live_encryptionKey]"
class="dashicons dashicons-hidden toggle-textarea"
id="rcp_setting_braintree_toggle_live"></span>
</button>
<?php endif; ?>
<p class="description"><?php _e( 'Enter your Braintree live client side encryption key.', 'rcp' ); ?></p>
</td>
</tr>
<tr>
<th>
<label for="rcp_settings[braintree_sandbox_merchantId]"><?php _e( 'Sandbox Merchant ID', 'rcp' ); ?></label>
</th>
<td>
<input type="text" class="regular-text" id="rcp_settings[braintree_sandbox_merchantId]"
style="width: 300px;" name="rcp_settings[braintree_sandbox_merchantId]"
value="<?php if ( isset( $rcp_options['braintree_sandbox_merchantId'] ) ) {
echo esc_attr( $rcp_options['braintree_sandbox_merchantId'] );
} ?>"/>
<p class="description"><?php _e( 'Enter your Braintree sandbox merchant ID.', 'rcp' ); ?></p>
</td>
</tr>
<tr>
<th>
<label for="rcp_settings[braintree_sandbox_publicKey]"><?php _e( 'Sandbox Public Key', 'rcp' ); ?></label>
</th>
<td>
<?php if ( ! empty( $rcp_options['braintree_sandbox_publicKey'] ) ) : ?>
<input type="password" class="regular-text" id="rcp_settings[braintree_sandbox_publicKey]"
style="width: 300px;" name="rcp_settings[braintree_sandbox_publicKey]"
value="<?php if ( isset( $rcp_options['braintree_sandbox_publicKey'] ) ) {
echo esc_attr( $rcp_options['braintree_sandbox_publicKey'] );
} ?>"/>
<button type="button" class="button button-secondary">
<span toggle="rcp_settings[braintree_sandbox_publicKey]"
class="dashicons dashicons-visibility toggle-credentials"></span>
</button>
<?php else : ?>
<input type="text" class="regular-text" id="rcp_settings[braintree_sandbox_publicKey]"
style="width: 300px;" name="rcp_settings[braintree_sandbox_publicKey]"
value="<?php if ( isset( $rcp_options['braintree_sandbox_publicKey'] ) ) {
echo esc_attr( $rcp_options['braintree_sandbox_publicKey'] );
} ?>"/>
<button type="button" class="button button-secondary">
<span toggle="rcp_settings[braintree_sandbox_publicKey]"
class="dashicons dashicons-hidden toggle-credentials"></span>
</button>
<?php endif; ?>
<p class="description"><?php _e( 'Enter your Braintree sandbox public key.', 'rcp' ); ?></p>
</td>
</tr>
<tr>
<th>
<label for="rcp_settings[braintree_sandbox_privateKey]"><?php _e( 'Sandbox Private Key', 'rcp' ); ?></label>
</th>
<td>
<?php if ( ! empty( $rcp_options['braintree_sandbox_privateKey'] ) ) : ?>
<input type="password" class="regular-text" id="rcp_settings[braintree_sandbox_privateKey]"
style="width: 300px;" name="rcp_settings[braintree_sandbox_privateKey]"
value="<?php if ( isset( $rcp_options['braintree_sandbox_privateKey'] ) ) {
echo esc_attr( $rcp_options['braintree_sandbox_privateKey'] );
} ?>"/>
<button type="button" class="button button-secondary">
<span toggle="rcp_settings[braintree_sandbox_privateKey]"
class="dashicons dashicons-visibility toggle-credentials"></span>
</button>
<?php else : ?>
<input type="text" class="regular-text" id="rcp_settings[braintree_sandbox_privateKey]"
style="width: 300px;" name="rcp_settings[braintree_sandbox_privateKey]"
value="<?php if ( isset( $rcp_options['braintree_sandbox_privateKey'] ) ) {
echo esc_attr( $rcp_options['braintree_sandbox_privateKey'] );
} ?>"/>
<button type="button" class="button button-secondary">
<span toggle="rcp_settings[braintree_sandbox_privateKey]"
class="dashicons dashicons-hidden toggle-credentials"></span>
</button>
<?php endif; ?>
<p class="description"><?php _e( 'Enter your Braintree sandbox private key.', 'rcp' ); ?></p>
</td>
</tr>
<tr>
<th>
<label for="rcp_settings[braintree_sandbox_encryptionKey]"><?php _e( 'Sandbox Client Side Encryption Key', 'rcp' ); ?></label>
</th>
<td>
<?php if ( ! empty( $rcp_options['braintree_sandbox_encryptionKey'] ) ) : ?>
<textarea
class="regular-text"
id="rcp_settings[braintree_sandbox_encryptionKey]"
style="width: 300px;height: 100px; display: none"
name="rcp_settings[braintree_sandbox_encryptionKey]"
/><?php if ( isset( $rcp_options['braintree_sandbox_encryptionKey'] ) ) { echo esc_attr( $rcp_options['braintree_sandbox_encryptionKey'] ); } ?></textarea>
<input
type="password"
id="rcp_settings[braintree_sandbox_encryptionKey_input]"
style="width: 300px; height: 100px; display: inline-block"
name="rcp_settings[braintree_sandbox_encryptionKey_input]"
value="<?php if ( isset( $rcp_options['braintree_sandbox_encryptionKey'] ) ) { echo esc_attr( $rcp_options['braintree_sandbox_encryptionKey'] ); } ?>"
/>
<button type="button" class="button button-secondary">
<span
toggle="rcp_settings[braintree_sandbox_encryptionKey]"
class="dashicons dashicons-visibility toggle-textarea"
id="rcp_setting_braintree_toggle_sandbox">
</span>
</button>
<?php else : ?>
<textarea
class="regular-text"
id="rcp_settings[braintree_sandbox_encryptionKey]"
style="width: 300px;height: 100px;"
name="rcp_settings[braintree_sandbox_encryptionKey]"
/><?php if ( isset( $rcp_options['braintree_sandbox_encryptionKey'] ) ) { echo esc_attr( $rcp_options['braintree_sandbox_encryptionKey'] ); } ?></textarea>
<input
type="password"
id="rcp_settings[braintree_sandbox_encryptionKey_input]"
style="display:none; width: 300px;"
name="rcp_settings[braintree_sandbox_encryptionKey_input]"
value="<?php if ( isset( $rcp_options['braintree_sandbox_encryptionKey'] ) ) { echo esc_attr( $rcp_options['braintree_sandbox_encryptionKey'] ); } ?>"
/>
<button type="button" class="button button-secondary">
<span
toggle="rcp_settings[braintree_sandbox_encryptionKey]"
class="dashicons dashicons-hidden toggle-textarea"
id="rcp_setting_braintree_toggle_sandbox">
</span>
</button>
<?php endif; ?>
<p class="description"><?php _e( 'Enter your Braintree sandbox client side encryption key.', 'rcp' ); ?></p>
</td>
</tr>
</table>

View File

@@ -0,0 +1,341 @@
<?php
/**
* Braintree Functions
*
* @package Restrict Content Pro
* @subpackage Gateways/Braintree/Functions
* @copyright Copyright (c) 2017, Sandhills Development
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 2.8
*/
/**
* Determines if a membership is Braintree subscription.
*
* @param int|RCP_Membership $membership_object_or_id Membership ID or object.
*
* @since 3.0
* @return bool
*/
function rcp_is_braintree_membership( $membership_object_or_id ) {
if ( ! is_object( $membership_object_or_id ) ) {
$membership = rcp_get_membership( $membership_object_or_id );
} else {
$membership = $membership_object_or_id;
}
$is_braintree = false;
if ( ! empty( $membership ) && $membership->get_id() > 0 ) {
$subscription_id = $membership->get_gateway_customer_id();
if ( false !== strpos( $subscription_id, 'bt_' ) ) {
$is_braintree = true;
}
}
/**
* Filters whether or not the membership is a Braintree subscription.
*
* @param bool $is_braintree
* @param RCP_Membership $membership
*
* @since 3.0
*/
return (bool) apply_filters( 'rcp_is_braintree_membership', $is_braintree, $membership );
}
/**
* Determines if all necessary Braintree API credentials are available.
*
* @since 2.7
* @return bool
*/
function rcp_has_braintree_api_access() {
global $rcp_options;
if ( rcp_is_sandbox() ) {
$merchant_id = ! empty( $rcp_options['braintree_sandbox_merchantId'] ) ? sanitize_text_field( $rcp_options['braintree_sandbox_merchantId'] ) : '';
$public_key = ! empty( $rcp_options['braintree_sandbox_publicKey'] ) ? sanitize_text_field( $rcp_options['braintree_sandbox_publicKey'] ) : '';
$private_key = ! empty( $rcp_options['braintree_sandbox_privateKey'] ) ? sanitize_text_field( $rcp_options['braintree_sandbox_privateKey'] ) : '';
$encryption_key = ! empty( $rcp_options['braintree_sandbox_encryptionKey'] ) ? sanitize_text_field( $rcp_options['braintree_sandbox_encryptionKey'] ) : '';
} else {
$merchant_id = ! empty( $rcp_options['braintree_live_merchantId'] ) ? sanitize_text_field( $rcp_options['braintree_live_merchantId'] ) : '';
$public_key = ! empty( $rcp_options['braintree_live_publicKey'] ) ? sanitize_text_field( $rcp_options['braintree_live_publicKey'] ) : '';
$private_key = ! empty( $rcp_options['braintree_live_privateKey'] ) ? sanitize_text_field( $rcp_options['braintree_live_privateKey'] ) : '';
$encryption_key = ! empty( $rcp_options['braintree_live_encryptionKey'] ) ? sanitize_text_field( $rcp_options['braintree_live_encryptionKey'] ) : '';
}
if ( ! empty( $merchant_id ) && ! empty( $public_key ) && ! empty( $private_key ) && ! empty( $encryption_key ) ) {
return true;
}
return false;
}
/**
* Cancel a Braintree membership by subscription ID.
*
* @param string $subscription_id Braintree subscription ID.
*
* @since 3.0
* @return true|WP_Error True on success, WP_Error on failure.
*/
function rcp_braintree_cancel_membership( $subscription_id ) {
global $rcp_options;
$ret = true;
if ( rcp_is_sandbox() ) {
$merchant_id = ! empty( $rcp_options['braintree_sandbox_merchantId'] ) ? sanitize_text_field( $rcp_options['braintree_sandbox_merchantId'] ) : '';
$public_key = ! empty( $rcp_options['braintree_sandbox_publicKey'] ) ? sanitize_text_field( $rcp_options['braintree_sandbox_publicKey'] ) : '';
$private_key = ! empty( $rcp_options['braintree_sandbox_privateKey'] ) ? sanitize_text_field( $rcp_options['braintree_sandbox_privateKey'] ) : '';
$encryption_key = ! empty( $rcp_options['braintree_sandbox_encryptionKey'] ) ? sanitize_text_field( $rcp_options['braintree_sandbox_encryptionKey'] ) : '';
$environment = 'sandbox';
} else {
$merchant_id = ! empty( $rcp_options['braintree_live_merchantId'] ) ? sanitize_text_field( $rcp_options['braintree_live_merchantId'] ) : '';
$public_key = ! empty( $rcp_options['braintree_live_publicKey'] ) ? sanitize_text_field( $rcp_options['braintree_live_publicKey'] ) : '';
$private_key = ! empty( $rcp_options['braintree_live_privateKey'] ) ? sanitize_text_field( $rcp_options['braintree_live_privateKey'] ) : '';
$encryption_key = ! empty( $rcp_options['braintree_live_encryptionKey'] ) ? sanitize_text_field( $rcp_options['braintree_live_encryptionKey'] ) : '';
$environment = 'production';
}
if ( ! class_exists( 'Braintree\\Gateway' ) ) {
require_once RCP_PLUGIN_DIR . 'pro/includes/libraries/braintree/lib/Braintree.php';
}
$gateway = new Braintree\Gateway( array(
'environment' => $environment,
'merchantId' => $merchant_id,
'publicKey' => $public_key,
'privateKey' => $private_key
) );
try {
$result = $gateway->subscription()->cancel( $subscription_id );
if ( ! $result->success ) {
$status = $result->errors->forKey( 'subscription' )->onAttribute( 'status' );
/**
* Don't throw an exception if the subscription is already cancelled.
*/
if ( '81905' != $status[0]->code ) {
$ret = new WP_Error( 'rcp_braintree_error', $result->message );
}
}
} catch ( Exception $e ) {
$ret = new WP_Error( 'rcp_braintree_error', $e->getMessage() );
}
return $ret;
}
/**
* Checks for the legacy Braintree gateway
* and deactivates it and shows a notice.
*
* @since 2.8
* @return void
*/
function rcp_braintree_detect_legacy_plugin() {
if ( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
return;
}
if ( is_plugin_active( 'rcp-braintree/rcp-braintree.php' ) ) {
deactivate_plugins( 'rcp-braintree/rcp-braintree.php', true );
}
}
add_action( 'admin_init', 'rcp_braintree_detect_legacy_plugin' );
/**
* Checks for legacy Braintree webhook endpoints
* and fires off the webhook processing for those requests.
*
* @since 2.8
* @return void
*/
add_action( 'init', function() {
if ( ! empty( $_GET['bt_challenge'] ) || ( ! empty( $_POST['bt_signature'] ) && ! empty( $_POST['bt_payload'] ) ) ) {
add_filter( 'rcp_process_gateway_webhooks', '__return_true' );
}
}, -100000 ); // Must run before rcp_process_gateway_webooks which is hooked on -99999
/**
* Add JS to the update card form
*
* @since 3.3
* @return void
*/
function rcp_braintree_update_card_form_js() {
global $rcp_membership;
if ( ! rcp_is_braintree_membership( $rcp_membership ) || ! rcp_has_braintree_api_access() ) {
return;
}
$gateway = new RCP_Payment_Gateway_Braintree();
$gateway->scripts();
}
add_action( 'rcp_before_update_billing_card_form', 'rcp_braintree_update_card_form_js' );
/**
* Update the billing card for a given membership
*
* @param RCP_Membership $membership
*
* @since 3.3
* @return void
*/
function rcp_braintree_update_membership_billing_card( $membership ) {
if ( ! $membership instanceof RCP_Membership ) {
return;
}
if ( ! rcp_is_braintree_membership( $membership ) ) {
return;
}
if ( empty( $_POST['payment_method_nonce'] ) ) {
wp_die( __( 'Missing payment method nonce.', 'rcp' ) );
}
$subscription_id = $membership->get_gateway_subscription_id();
if ( empty( $subscription_id ) ) {
wp_die( __( 'Invalid subscription.', 'rcp' ) );
}
global $rcp_options;
if ( rcp_is_sandbox() ) {
$merchant_id = ! empty( $rcp_options['braintree_sandbox_merchantId'] ) ? sanitize_text_field( $rcp_options['braintree_sandbox_merchantId'] ) : '';
$public_key = ! empty( $rcp_options['braintree_sandbox_publicKey'] ) ? sanitize_text_field( $rcp_options['braintree_sandbox_publicKey'] ) : '';
$private_key = ! empty( $rcp_options['braintree_sandbox_privateKey'] ) ? sanitize_text_field( $rcp_options['braintree_sandbox_privateKey'] ) : '';
$environment = 'sandbox';
} else {
$merchant_id = ! empty( $rcp_options['braintree_live_merchantId'] ) ? sanitize_text_field( $rcp_options['braintree_live_merchantId'] ) : '';
$public_key = ! empty( $rcp_options['braintree_live_publicKey'] ) ? sanitize_text_field( $rcp_options['braintree_live_publicKey'] ) : '';
$private_key = ! empty( $rcp_options['braintree_live_privateKey'] ) ? sanitize_text_field( $rcp_options['braintree_live_privateKey'] ) : '';
$environment = 'production';
}
if ( ! class_exists( 'Braintree\\Gateway' ) ) {
require_once RCP_PLUGIN_DIR . 'pro/includes/libraries/braintree/lib/Braintree.php';
}
$gateway = new Braintree\Gateway( array(
'environment' => $environment,
'merchantId' => $merchant_id,
'publicKey' => $public_key,
'privateKey' => $private_key
) );
try {
$gateway->subscription()->update( $subscription_id, array(
'paymentMethodNonce' => sanitize_text_field( $_POST['payment_method_nonce'] )
) );
wp_redirect( add_query_arg( 'card', 'updated' ) ); exit;
} catch ( \Exception $e ) {
wp_die( sprintf( __( 'An error occurred: %s', 'rcp' ), $e->getMessage() ) );
}
}
add_action( 'rcp_update_membership_billing_card', 'rcp_braintree_update_membership_billing_card' );
/**
* The origin of this function was the migration of 3DS V1 to 3DS V2.
*
* Output the additional fields needed by Braintree to fulfill the 3DS2 such as address fields.
*
* @return void
*/
function rcp_braintree_additional_fields() { ?>
<fieldset class="rcp_braintree_billing_info">
<h3><?php echo apply_filters ( 'rcp_braintree_billing_legend_label', __( 'Billing Information', 'rcp' ) ); ?></h3>
<p id="rcp_braintree_billing_phoneNumber_wrap">
<label for="rcp_braintree_billing_phoneNumber"><?php echo apply_filters ( 'rcp_braintree_billing_phoneNumber_label', __( 'Phone Number', 'rcp' ) ); ?></label>
<input name="rcp_braintree_billing_phoneNumber" id="rcp_braintree_billing_phoneNumber" class="required"
type="text" placeholder="1234567890"
<?php if( isset( $_POST['rcp_braintree_billing_phoneNumber'] ) ) { echo 'value="' . esc_attr( $_POST['rcp_braintree_billing_phoneNumber'] ) . '"'; } ?>/>
</p>
<p id="rcp_braintree_billing_firstname_wrap">
<label for="rcp_braintree_billing_firstname"><?php echo apply_filters ( 'rcp_braintree_billing_firstname_label', __( 'Given Name', 'rcp' ) ); ?></label>
<input name="rcp_braintree_billing_firstname" id="rcp_braintree_billing_firstname" class="required"
type="text" placeholder="First"
<?php if( isset( $_POST['rcp_braintree_billing_firstname'] ) ) { echo 'value="' . esc_attr( $_POST['rcp_braintree_billing_firstname'] ) . '"'; } ?>/>
</p>
<p id="rcp_braintree_billing_lastname_wrap">
<label for="rcp_braintree_billing_lastname"><?php echo apply_filters ( 'rcp_braintree_billing_lastname_label', __( 'Surname', 'rcp' ) ); ?></label>
<input name="rcp_braintree_billing_lastname" id="rcp_braintree_billing_lastname" class="required"
type="text" placeholder="Last"
<?php if( isset( $_POST['rcp_braintree_billing_lastname'] ) ) { echo 'value="' . esc_attr( $_POST['rcp_braintree_billing_lastname'] ) . '"'; } ?>/>
</p>
<input type="hidden" id="braintree_3ds_nonce" name="braintree_3ds_nonce" value="<?php echo esc_attr( wp_create_nonce( 'braintree_3ds' ) ); ?>">
</fieldset>
<?php
}
add_action( 'rcp_braintree_additional_fields', 'rcp_braintree_additional_fields' );
/**
* Sanitize the fields that the user enter and validate the nonce.
*
* @return void return json created by WordPress.
*/
function rcp_braintree_3ds_validation_fields() {
$post = wp_unslash( $_POST );
$nonce = wp_verify_nonce( sanitize_text_field( $post['nonce'] ),'braintree_3ds' );
// Bail if nonce is not valid.
if( false === $nonce ){
wp_send_json_error( [
'status' => 'failed',
'message' => 'Invalid Nonce. Consider reloading the page.',
], 401);
}
$billing_address = array_key_exists( 'billingAddress', $post) ? array_map( 'rcp_sanitize_fields', $post['billingAddress'] ) : $post;
if(array_key_exists( 'additionalInformation', $post) ) {
$additional_information = array_map( 'rcp_sanitize_fields', $post['additionalInformation'] );
$additional_information['shippingAddress'] = array_key_exists( 'shippingAddress', $additional_information ) ? array_map( 'rcp_sanitize_fields', $additional_information['shippingAddress'] ) : $additional_information;
}
$result = [
'billingAddress' => $billing_address,
'additionalInformation' => $billing_address,
];
wp_send_json_success( $result, 200 );
}
/**
* Function that will check if the current value if a string and sanitize it, otherwise it will just return the
* Array|Object.
*
* @param array|string $_field The field to check.
* @since 3.5.23.1
* @return array|string The Sanitized String or the Array|Object.
*/
function rcp_sanitize_fields( $_field ) {
if( is_object( $_field ) || is_array( $_field ) ) {
return $_field;
}
return sanitize_text_field( $_field );
}

View File

@@ -0,0 +1 @@
<?php // Silence is golden.

View File

@@ -0,0 +1,361 @@
/* global rcp_braintree_script_options */
jQuery( function( $ ) {
/**
* Braintree registration
*/
var RCP_Braintree_Registration = {
/**
* Braintree drop-in UI instance
*/
dropinInstance: false,
/**
* Whether or not card details have been entered
*/
hasCardDetails: false,
/**
* Initialize
*/
init: function () {
$( 'body' ).on( 'rcp_gateway_loaded', RCP_Braintree_Registration.mountUI );
$( '#rcp_submit' ).on( 'click', RCP_Braintree_Registration.maybeBlockSubmit );
$( 'body' ).on( 'rcp_registration_form_processed', RCP_Braintree_Registration.tokenizePayment );
},
/**
* Mount the drop-in UI when the gateway is loaded
*
* @param e
* @param gateway
*/
mountUI: function( e, gateway ) {
if ( ! document.getElementById( 'rcp-braintree-client-token' ) ) {
return;
}
rcp_braintree_script_options.dropin_ui_config = {
authorization: $( '#rcp-braintree-client-token' ).val(),
container: '#rcp-braintree-dropin-container',
threeDSecure: true
};
braintree.dropin.create( rcp_braintree_script_options.dropin_ui_config ).then( function( dropinInstance ) {
RCP_Braintree_Registration.dropinInstance = dropinInstance;
// Flag as having payment details or not.
if ( dropinInstance.isPaymentMethodRequestable() ) {
RCP_Braintree_Registration.hasCardDetails = true;
}
dropinInstance.on( 'paymentMethodRequestable', function ( requestableEvent ) {
RCP_Braintree_Registration.hasCardDetails = true;
} );
dropinInstance.on( 'noPaymentMethodRequestable', function ( requestableEvent ) {
RCP_Braintree_Registration.hasCardDetails = false;
} );
} ).catch( function( error ) {
// Handle errors from creating drop-in.
rcpBraintreeHandleError( error );
} );
},
/**
* Prevent form submission if card details haven't been filled out yet
*
* @param e
*/
maybeBlockSubmit: function ( e ) {
if ( 'braintree' === rcp_get_gateway().val() && document.getElementById( 'rcp-braintree-client-token' ) && ! RCP_Braintree_Registration.hasCardDetails ) {
e.stopPropagation();
rcpBraintreeHandleError( rcp_script_options.enter_card_details );
return false;
}
},
registerTestInformation: function () {
// Using timeout since the elements are not loaded with the initial DOM elements.
setTimeout(function(){
$( '#rcp_braintree_test_check' ).on('click', function (event) {
if ( true === $( this ).prop('checked') ) {
$( '#rcp_braintree_billing_lastname' ).val('Doe');
$( '#rcp_braintree_billing_phoneNumber' ).val('1234567890');
$( '#rcp_braintree_billing_firstname' ).val('Santino');
}
else {
$( '#rcp_braintree_billing_lastname' ).val('');
$( '#rcp_braintree_billing_phoneNumber' ).val('');
$( '#rcp_braintree_billing_firstname' ).val('');
}
});
},2500);
},
/**
* Collect card details, handle 3D secure if available, and tokenize the payment method
*
* @param event
* @param form
* @param response
*/
tokenizePayment: function( event, form, response ) {
if ( ! document.getElementById( 'rcp-braintree-client-token' ) || 'braintree' !== rcp_get_gateway().val() ) {
return;
}
let paymentMethodOptions = rcp_braintree_script_options.payment_method_options;
let additionalInformation = {};
let billingAddress = {};
// Set email address(es) for logged out customers.
if ( 'undefined' !== typeof( paymentMethodOptions.threeDSecure ) && '' === paymentMethodOptions.threeDSecure.email ) {
paymentMethodOptions.threeDSecure.email = $( '#rcp_user_email' ).val();
}
if ( 'undefined' !== typeof( paymentMethodOptions.threeDSecure ) && 'undefined' !== typeof( paymentMethodOptions.threeDSecure.additionalInformation ) && '' === paymentMethodOptions.threeDSecure.additionalInformation.deliveryEmail ) {
additionalInformation.deliveryEmail = $( '#rcp_user_email' ).val();
// paymentMethodOptions.threeDSecure.additionalInformation.deliveryEmail = $( '#rcp_user_email' ).val();
}
// We need to collect the billing and additional information.
billingAddress = {
givenName: $( '#rcp_braintree_billing_firstname' ).val(),
surname: $( '#rcp_braintree_billing_lastname' ).val(),
phoneNumber: $( '#rcp_braintree_billing_phoneNumber' ).val(),
/* streetAddress: $( '#rcp_braintree_billing_streetAddress' ).val(),
extendedAddress: $( '#rcp_braintree_billing_extendedAddress' ).val(),
locality: $( '#rcp_braintree_billing_locality' ).val(),
region: $( '#rcp_braintree_billing_region' ).val(),
postalCode: $( '#rcp_braintree_billing_postalCode' ).val(),
countryCodeAlpha2: $( '#rcp_braintree_billing_countryCodeAlpha2' ).val()
*/
};
/**
* Make sure that the fields that user is entering are being sanitized by the backend.
*/
$.when ( $.ajax({
type: 'post',
dataType: 'json',
url: rcp_script_options.ajaxurl,
data: {
action: 'rcp_braintree_3ds_validation_fields',
nonce: $( '#braintree_3ds_nonce' ).val(),
billingAddress: billingAddress
}
} ) ).then( function( validationResponse) {
if( validationResponse.success ) {
// Let's check for empty fields.
for ( const key in validationResponse.data.billingAddress ) {
if( '' === validationResponse.data.billingAddress[key] ){
rcpBraintreeHandleError( rcp_script_options.braintree_empty_fields );
return false;
}
}
// Add to the threeDSecure object the billing fields and the additional fields.
paymentMethodOptions.threeDSecure.billingAddress = validationResponse.data.billingAddress;
paymentMethodOptions.threeDSecure.additionalInformation = additionalInformation;
// Set authorization amount.
if ( 'undefined' !== typeof paymentMethodOptions.threeDSecure ) {
paymentMethodOptions.threeDSecure.amount = (response.total > 0) ? response.total : response.recurring_total;
}
RCP_Braintree_Registration.dropinInstance.requestPaymentMethod( paymentMethodOptions ).then( function( payload ) {
if ( payload.liabilityShiftPossible && ! payload.liabilityShifted ) {
// 3D secure was possible, but failed.
// Clear the payment method.
RCP_Braintree_Registration.dropinInstance.clearSelectedPaymentMethod();
// Display error message.
rcpBraintreeHandleError( rcp_braintree_script_options.try_new_payment );
} else {
// Payment was successfully tokenized. Set up the nonce so we can use it for processing transactions server-side.
$( form ).find( '#rcp_submit_wrap' ).append( '<input type="hidden" name="payment_method_nonce" value="' + payload.nonce + '"/>' );
// Submit registration.
rcp_submit_registration_form( form, response );
}
} ).catch( function( error ) {
// Handle errors from payment method request.
rcpBraintreeHandleError( error );
} );
}
else {
throw 'RCP 3DS: There was an error validating you information.';
}
}).fail( function( error ) {
rcpBraintreeHandleError( rcp_script_options.braintree_invalid_nonce );
throw 'RCP 3DS: There was an error validating you information. Nonce expired. Reload the page.';
});
}
};
RCP_Braintree_Registration.init();
RCP_Braintree_Registration.registerTestInformation();
/**
* Update card details
*/
let RCP_Braintree_Update_Card = {
container: false,
recurringAmount: 0.00,
hasCardDetails: false,
init: function () {
RCP_Braintree_Update_Card.container = $( '#rcp_update_card_form' );
if ( ! RCP_Braintree_Update_Card.container.length ) {
return;
}
RCP_Braintree_Update_Card.mountUI();
RCP_Braintree_Update_Card.container.on( 'submit', RCP_Braintree_Update_Card.tokenizePayment );
},
/**
* Mount the drop-in UI
*/
mountUI: function() {
if ( ! document.getElementById( 'rcp-braintree-client-token' ) ) {
return;
}
rcp_braintree_script_options.dropin_ui_config.authorization = $( '#rcp-braintree-client-token' ).val();
let dropinArgs = rcp_braintree_script_options.dropin_ui_config;
/*
* Enabling this would allow customers to delete their saved payment methods. I've commented it out for now
* because if the customer deletes their CURRENT payment method then Braintree will automatically cancel
* the subscription, which is a bit annoying.
*/
//dropinArgs.vaultManager = true;
/*
* We set `preselectVaultedPaymentMethod` to false because we can't yet configure which one is pre-selected
* and we don't want to confuse anyone by having the wrong payment method pre-selected.
*/
dropinArgs.preselectVaultedPaymentMethod = false;
braintree.dropin.create( dropinArgs ).then( function( dropinInstance ) {
RCP_Braintree_Update_Card.dropinInstance = dropinInstance;
// Flag as having payment details or not.
if ( dropinInstance.isPaymentMethodRequestable() ) {
RCP_Braintree_Update_Card.hasCardDetails = true;
}
dropinInstance.on( 'paymentMethodRequestable', function ( requestableEvent ) {
RCP_Braintree_Update_Card.hasCardDetails = true;
} );
dropinInstance.on( 'noPaymentMethodRequestable', function ( requestableEvent ) {
RCP_Braintree_Update_Card.hasCardDetails = false;
} );
} ).catch( function( error ) {
// Handle errors from creating drop-in.
rcpBraintreeHandleError( error );
} );
},
/**
* Disable the submit button and change the text to "Please wait..."
*/
disableButton: function() {
let button = RCP_Braintree_Update_Card.container.find( '#rcp_submit' );
button.prop( 'disabled', true ).data( 'text', button.val() ).val( rcp_braintree_script_options.please_wait );
},
/**
* Enable the submit button and re-set the text back to the original value
*/
enableButton: function() {
let button = RCP_Braintree_Update_Card.container.find( '#rcp_submit' );
button.prop( 'disabled', false ).val( button.data( 'text' ) );
},
/**
* Tokenize the payment method
* @param e
*/
tokenizePayment: function ( e ) {
e.preventDefault();
if ( ! RCP_Braintree_Update_Card.hasCardDetails ) {
rcpBraintreeHandleError( rcp_script_options.enter_card_details );
return false;
}
// Clear errors.
$( '#rcp-braintree-dropin-errors' ).empty();
RCP_Braintree_Update_Card.disableButton();
let paymentMethodOptions = rcp_braintree_script_options.payment_method_options;
// Set authorization amount.
paymentMethodOptions.threeDSecure.amount = $( '#rcp-braintree-recurring-amount' ).val();
RCP_Braintree_Update_Card.dropinInstance.requestPaymentMethod( paymentMethodOptions ).then( function( payload ) {
if ( payload.liabilityShiftPossible && ! payload.liabilityShifted ) {
// 3D secure was possible, but failed.
// Clear the payment method.
RCP_Braintree_Update_Card.dropinInstance.clearSelectedPaymentMethod();
// Display error message.
throw rcp_braintree_script_options.try_new_payment;
} else {
// Payment was successfully tokenized. Set up the nonce so we can use it for processing transactions server-side.
RCP_Braintree_Update_Card.container.append( '<input type="hidden" name="payment_method_nonce" value="' + payload.nonce + '"/>' );
RCP_Braintree_Update_Card.container.off( 'submit', RCP_Braintree_Update_Card.tokenizePayment ).submit();
}
} ).catch( function( error ) {
// Handle errors from payment method request.
rcpBraintreeHandleError( error );
RCP_Braintree_Update_Card.enableButton();
return false;
} );
}
};
RCP_Braintree_Update_Card.init();
} );
/**
* Handle Braintree errors
* @param {string} error Error message.
*/
function rcpBraintreeHandleError( error ) {
let $ = jQuery;
let form = $( '#rcp_registration_form' );
let errorWrapper = $( '#rcp-braintree-dropin-errors' );
errorWrapper.empty().append( '<div class="rcp_message error" role="list"><p class="rcp_error" role="listitem">' + error + '</p>' );
if ( form.length > 0 ) {
form.unblock();
$( '#rcp_submit' ).val( rcp_script_options.register );
}
rcp_processing = false;
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1 @@
<?php // Silence is golden.