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,380 @@
<?php
/**
* PayPal Functions
*
* @package Restrict Content Pro
* @subpackage Gateways/PayPal/Functions
* @copyright Copyright (c) 2017, Pippin Williamson
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
*/
/**
* Determine if a member is a PayPal subscriber
*
* @deprecated 3.0 Use `rcp_is_paypal_membership()` instead.
* @see rcp_is_paypal_membership()
*
* @param int $user_id The ID of the user to check
*
* @since 2.0
* @access public
* @return bool
*/
function rcp_is_paypal_subscriber( $user_id = 0 ) {
if( empty( $user_id ) ) {
$user_id = get_current_user_id();
}
$ret = false;
$customer = rcp_get_customer_by_user_id( $user_id );
if ( ! empty( $customer ) ) {
$membership = rcp_get_customer_single_membership( $customer->get_id() );
if ( ! empty( $membership ) ) {
$ret = rcp_is_paypal_membership( $membership );
}
}
return (bool) apply_filters( 'rcp_is_paypal_subscriber', $ret, $user_id );
}
/**
* Determines if a membership is a PayPal subscription.
*
* @param int|RCP_Membership $membership_object_or_id Membership ID or object.
*
* @since 3.0
* @return bool
*/
function rcp_is_paypal_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_paypal = false;
if ( ! empty( $membership ) && $membership->get_id() > 0 ) {
$subscription_id = $membership->get_gateway_subscription_id();
if ( false !== strpos( $subscription_id, 'I-' ) ) {
$is_paypal = true;
}
}
/**
* Filters whether or not the membership is a PayPal subscription.
*
* @param bool $is_paypal
* @param RCP_Membership $membership
*
* @since 3.0
*/
return (bool) apply_filters( 'rcp_is_paypal_membership', $is_paypal, $membership );
}
/**
* Determine if PayPal API access is enabled
*
* @access public
* @since 2.1
* @return bool
*/
function rcp_has_paypal_api_access() {
global $rcp_options;
$ret = false;
$prefix = 'live_';
if( rcp_is_sandbox() ) {
$prefix = 'test_';
}
$username = $prefix . 'paypal_api_username';
$password = $prefix . 'paypal_api_password';
$signature = $prefix . 'paypal_api_signature';
if( ! empty( $rcp_options[ $username ] ) && ! empty( $rcp_options[ $password ] ) && ! empty( $rcp_options[ $signature ] ) ) {
$ret = true;
}
return $ret;
}
/**
* Retrieve PayPal API credentials
*
* @access public
* @since 2.1
* @return array Array of credentials.
*/
function rcp_get_paypal_api_credentials() {
global $rcp_options;
$ret = false;
$prefix = 'live_';
if( rcp_is_sandbox() ) {
$prefix = 'test_';
}
$creds = array(
'username' => $rcp_options[ $prefix . 'paypal_api_username' ],
'password' => $rcp_options[ $prefix . 'paypal_api_password' ],
'signature' => $rcp_options[ $prefix . 'paypal_api_signature' ]
);
return apply_filters( 'rcp_get_paypal_api_credentials', $creds );
}
/**
* Process an update card form request
*
* @deprecated 3.0 Use `rcp_paypal_update_membership_billing_card()` instead.
* @see rcp_paypal_update_membership_billing_card()
*
* @param int $member_id ID of the member.
* @param RCP_Member $member_obj Member object.
*
* @access private
* @since 2.6
* @return void
*/
function rcp_paypal_update_billing_card( $member_id, $member_obj ) {
if( empty( $member_id ) ) {
return;
}
if( ! is_a( $member_obj, 'RCP_Member' ) ) {
return;
}
$customer = rcp_get_customer_by_user_id( $member_id );
if ( empty( $customer ) ) {
return;
}
$membership = rcp_get_customer_single_membership( $customer->get_id() );
if ( empty( $membership ) ) {
return;
}
rcp_paypal_update_membership_billing_card( $membership );
}
//add_action( 'rcp_update_billing_card', 'rcp_paypal_update_billing_card', 10, 2 );
/**
* Update the billing card for a given membership.
*
* @param RCP_Membership $membership
*
* @since 3.0
* @return void
*/
function rcp_paypal_update_membership_billing_card( $membership ) {
if ( ! is_a( $membership, 'RCP_Membership' ) ) {
return;
}
if ( ! rcp_is_paypal_membership( $membership ) ) {
return;
}
if( rcp_is_sandbox() ) {
$api_endpoint = 'https://api-3t.sandbox.paypal.com/nvp';
} else {
$api_endpoint = 'https://api-3t.paypal.com/nvp';
}
$error = '';
$subscription_id = $membership->get_gateway_subscription_id();
$credentials = rcp_get_paypal_api_credentials();
$card_number = isset( $_POST['rcp_card_number'] ) && is_numeric( $_POST['rcp_card_number'] ) ? $_POST['rcp_card_number'] : '';
$card_exp_month = isset( $_POST['rcp_card_exp_month'] ) && is_numeric( $_POST['rcp_card_exp_month'] ) ? $_POST['rcp_card_exp_month'] : '';
$card_exp_year = isset( $_POST['rcp_card_exp_year'] ) && is_numeric( $_POST['rcp_card_exp_year'] ) ? $_POST['rcp_card_exp_year'] : '';
$card_cvc = isset( $_POST['rcp_card_cvc'] ) && is_numeric( $_POST['rcp_card_cvc'] ) ? $_POST['rcp_card_cvc'] : '';
$card_zip = isset( $_POST['rcp_card_zip'] ) ? sanitize_text_field( $_POST['rcp_card_zip'] ) : '' ;
if ( empty( $card_number ) || empty( $card_exp_month ) || empty( $card_exp_year ) || empty( $card_cvc ) || empty( $card_zip ) ) {
$error = __( 'Please enter all required fields.', 'rcp' );
}
if ( empty( $error ) ) {
$args = array(
'USER' => $credentials['username'],
'PWD' => $credentials['password'],
'SIGNATURE' => $credentials['signature'],
'VERSION' => '124',
'METHOD' => 'UpdateRecurringPaymentsProfile',
'PROFILEID' => $subscription_id,
'ACCT' => $card_number,
'EXPDATE' => $card_exp_month . $card_exp_year,
// needs to be in the format 062019
'CVV2' => $card_cvc,
'ZIP' => $card_zip,
'BUTTONSOURCE' => 'EasyDigitalDownloads_SP',
);
$request = wp_remote_post( $api_endpoint, array(
'timeout' => 45,
'sslverify' => false,
'body' => $args,
'httpversion' => '1.1',
) );
$body = wp_remote_retrieve_body( $request );
$code = wp_remote_retrieve_response_code( $request );
$message = wp_remote_retrieve_response_message( $request );
if ( is_wp_error( $request ) ) {
$error = $request->get_error_message();
} elseif ( 200 == $code && 'OK' == $message ) {
if( is_string( $body ) ) {
wp_parse_str( $body, $body );
}
if ( 'failure' === strtolower( $body['ACK'] ) ) {
$error = $body['L_ERRORCODE0'] . ': ' . $body['L_LONGMESSAGE0'];
} else {
// Request was successful, but verify the profile ID that came back matches
if ( $subscription_id !== $body['PROFILEID'] ) {
$error = __( 'Error updating subscription', 'rcp' );
rcp_log( sprintf( 'Invalid PayPal subscription ID. Expected: %s; Provided: %s.', $subscription_id, $body['PROFILEID'] ), true );
}
}
} else {
$error = __( 'Something has gone wrong, please try again', 'rcp' );
}
}
if( ! empty( $error ) ) {
wp_redirect( add_query_arg( array( 'card' => 'not-updated', 'msg' => urlencode( $error ) ) ) ); exit;
}
wp_redirect( add_query_arg( array( 'card' => 'updated', 'msg' => '' ) ) ); exit;
}
add_action( 'rcp_update_membership_billing_card', 'rcp_paypal_update_membership_billing_card' );
/**
* Log the start of a valid IPN request
*
* @param array $payment_data Payment information to be stored in the DB.
* @param int $user_id ID of the user the payment is for.
* @param array $posted Data sent via the IPN.
*
* @since 2.9
* @return void
*/
function rcp_log_valid_paypal_ipn( $payment_data, $user_id, $posted ) {
rcp_log( sprintf( 'Started processing valid PayPal IPN request for user #%d. Payment Data: %s', $user_id, var_export( $payment_data, true ) ) );
}
add_action( 'rcp_valid_ipn', 'rcp_log_valid_paypal_ipn', 10, 3 );
/**
* Cancel a PayPal membership by profile ID.
*
* @param string $payment_profile_id Gateway payment profile ID.
*
* @since 3.0
* @return true|WP_Error True on success, WP_Error on failure.
*/
function rcp_paypal_cancel_membership( $payment_profile_id ) {
global $rcp_options;
if ( ! rcp_has_paypal_api_access() ) {
return new WP_Error( 'paypal_cancel_failed_no_api', __( 'PayPal cancellation failed - no API access.', 'rcp' ) );
}
// Set PayPal API key credentials.
$api_username = rcp_is_sandbox() ? 'test_paypal_api_username' : 'live_paypal_api_username';
$api_password = rcp_is_sandbox() ? 'test_paypal_api_password' : 'live_paypal_api_password';
$api_signature = rcp_is_sandbox() ? 'test_paypal_api_signature' : 'live_paypal_api_signature';
$api_endpoint = rcp_is_sandbox() ? 'https://api-3t.sandbox.paypal.com/nvp' : 'https://api-3t.paypal.com/nvp';
$args = array(
'USER' => trim( $rcp_options[$api_username] ),
'PWD' => trim( $rcp_options[$api_password] ),
'SIGNATURE' => trim( $rcp_options[$api_signature] ),
'VERSION' => '124',
'METHOD' => 'ManageRecurringPaymentsProfileStatus',
'PROFILEID' => $payment_profile_id,
'ACTION' => 'Cancel'
);
$error_msg = '';
$request = wp_remote_post( $api_endpoint, array( 'body' => $args, 'timeout' => 30, 'httpversion' => '1.1' ) );
if ( is_wp_error( $request ) ) {
$success = false;
$error_msg = $request->get_error_message();
} else {
$body = wp_remote_retrieve_body( $request );
$code = wp_remote_retrieve_response_code( $request );
$message = wp_remote_retrieve_response_message( $request );
if ( is_string( $body ) ) {
wp_parse_str( $body, $body );
}
if ( 200 !== (int) $code ) {
$success = false;
}
if ( 'OK' !== $message ) {
$success = false;
}
if ( isset( $body['ACK'] ) && 'success' === strtolower( $body['ACK'] ) ) {
$success = true;
} else {
$success = false;
if ( isset( $body['L_LONGMESSAGE0'] ) ) {
$error_msg = $body['L_LONGMESSAGE0'];
}
}
}
if ( ! $success ) {
$success = new WP_Error( 'paypal_cancel_fail', $error_msg );
}
return $success;
}

View File

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

View File

@@ -0,0 +1,300 @@
<?php
/**
* PayPal IPN Listener
*
* A class to listen for and handle Instant Payment Notifications (IPN) from
* the PayPal server.
*
* https://github.com/Quixotix/PHP-PayPal-IPN
*
* @package PHP-PayPal-IPN
* @author Micah Carrick
* @copyright (c) 2011 - Micah Carrick
* @version 2.0.3
* @license http://opensource.org/licenses/gpl-3.0.html
*/
class IpnListener {
/**
* If true, the recommended cURL PHP library is used to send the post back
* to PayPal. If flase then fsockopen() is used. Default true.
*
* @var boolean
*/
public $use_curl = true;
/**
* If true, explicitly sets cURL to use SSL version 3. Use this if cURL
* is compiled with GnuTLS SSL.
*
* @var boolean
*/
public $force_ssl_v3 = false;
/**
* If true, an SSL secure connection (port 443) is used for the post back
* as recommended by PayPal. If false, a standard HTTP (port 80) connection
* is used. Default true.
*
* @var boolean
*/
public $use_ssl = true;
/**
* If true, the paypal sandbox URI www.sandbox.paypal.com is used for the
* post back. If false, the live URI www.paypal.com is used. Default false.
*
* @var boolean
*/
public $use_sandbox = false;
/**
* The amount of time, in seconds, to wait for the PayPal server to respond
* before timing out. Default 30 seconds.
*
* @var int
*/
public $timeout = 30;
private $post_data = array();
private $post_uri = '';
private $response_status = '';
private $response = '';
const PAYPAL_HOST = 'www.paypal.com';
const SANDBOX_HOST = 'www.sandbox.paypal.com';
/**
* Post Back Using cURL
*
* Sends the post back to PayPal using the cURL library. Called by
* the processIpn() method if the use_curl property is true. Throws an
* exception if the post fails. Populates the response, response_status,
* and post_uri properties on success.
*
* @param string The post data as a URL encoded string
*/
protected function curlPost($encoded_data) {
if ($this->use_ssl) {
$uri = 'https://'.$this->getPaypalHost().'/cgi-bin/webscr';
$this->post_uri = $uri;
} else {
$uri = 'http://'.$this->getPaypalHost().'/cgi-bin/webscr';
$this->post_uri = $uri;
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $uri);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $encoded_data);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
if ($this->force_ssl_v3) {
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
}
$this->response = curl_exec($ch);
$this->response_status = strval(curl_getinfo($ch, CURLINFO_HTTP_CODE));
if ($this->response === false || $this->response_status == '0') {
$errno = curl_errno($ch);
$errstr = curl_error($ch);
throw new Exception("cURL error: [$errno] $errstr");
}
}
/**
* Post Back Using fsockopen()
*
* Sends the post back to PayPal using the fsockopen() function. Called by
* the processIpn() method if the use_curl property is false. Throws an
* exception if the post fails. Populates the response, response_status,
* and post_uri properties on success.
*
* @param string The post data as a URL encoded string
*/
protected function fsockPost($encoded_data) {
if ($this->use_ssl) {
$uri = 'ssl://'.$this->getPaypalHost();
$port = '443';
$this->post_uri = $uri.'/cgi-bin/webscr';
} else {
$uri = $this->getPaypalHost(); // no "http://" in call to fsockopen()
$port = '80';
$this->post_uri = 'http://'.$uri.'/cgi-bin/webscr';
}
$fp = fsockopen($uri, $port, $errno, $errstr, $this->timeout);
if (!$fp) {
// fsockopen error
throw new Exception("fsockopen error: [$errno] $errstr");
}
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: ".strlen($encoded_data)."\r\n";
$header .= "Connection: Close\r\n\r\n";
fputs($fp, $header.$encoded_data."\r\n\r\n");
while(!feof($fp)) {
if (empty($this->response)) {
// extract HTTP status from first line
$this->response .= $status = fgets($fp, 1024);
$this->response_status = trim(substr($status, 9, 4));
} else {
$this->response .= fgets($fp, 1024);
}
}
fclose($fp);
}
private function getPaypalHost() {
if ($this->use_sandbox) return IpnListener::SANDBOX_HOST;
else return IpnListener::PAYPAL_HOST;
}
/**
* Get POST URI
*
* Returns the URI that was used to send the post back to PayPal. This can
* be useful for troubleshooting connection problems. The default URI
* would be "ssl://www.sandbox.paypal.com:443/cgi-bin/webscr"
*
* @return string
*/
public function getPostUri() {
return $this->post_uri;
}
/**
* Get Response
*
* Returns the entire response from PayPal as a string including all the
* HTTP headers.
*
* @return string
*/
public function getResponse() {
return $this->response;
}
/**
* Get Response Status
*
* Returns the HTTP response status code from PayPal. This should be "200"
* if the post back was successful.
*
* @return string
*/
public function getResponseStatus() {
return $this->response_status;
}
/**
* Get Text Report
*
* Returns a report of the IPN transaction in plain text format. This is
* useful in emails to order processors and system administrators. Override
* this method in your own class to customize the report.
*
* @return string
*/
public function getTextReport() {
$r = '';
// date and POST url
for ($i=0; $i<80; $i++) { $r .= '-'; }
$r .= "\n[".date('m/d/Y g:i A').'] - '.$this->getPostUri();
if ($this->use_curl) $r .= " (curl)\n";
else $r .= " (fsockopen)\n";
// HTTP Response
for ($i=0; $i<80; $i++) { $r .= '-'; }
$r .= "\n{$this->getResponse()}\n";
// POST vars
for ($i=0; $i<80; $i++) { $r .= '-'; }
$r .= "\n";
foreach ($this->post_data as $key => $value) {
$r .= str_pad($key, 25)."$value\n";
}
$r .= "\n\n";
return $r;
}
/**
* Process IPN
*
* Handles the IPN post back to PayPal and parsing the response. Call this
* method from your IPN listener script. Returns true if the response came
* back as "VERIFIED", false if the response came back "INVALID", and
* throws an exception if there is an error.
*
* @param array
*
* @return boolean
*/
public function processIpn($post_data=null) {
$encoded_data = 'cmd=_notify-validate';
if ($post_data === null) {
// use raw POST data
if (!empty($_POST)) {
$this->post_data = $_POST;
$encoded_data .= '&'.file_get_contents('php://input');
} else {
throw new Exception("No POST data found.");
}
} else {
// use provided data array
$this->post_data = $post_data;
foreach ($this->post_data as $key => $value) {
$encoded_data .= "&$key=".urlencode($value);
}
}
if ($this->use_curl) $this->curlPost($encoded_data);
else $this->fsockPost($encoded_data);
if (strpos($this->response_status, '200') === false) {
throw new Exception("Invalid response status: ".$this->response_status);
}
if (strpos($this->response, "VERIFIED") !== false) {
return true;
} elseif (strpos($this->response, "INVALID") !== false) {
return false;
} else {
throw new Exception("Unexpected response from PayPal.");
}
}
/**
* Require Post Method
*
* Throws an exception and sets a HTTP 405 response header if the request
* method was not POST.
*/
public function requirePostMethod() {
// require POST requests
if ($_SERVER['REQUEST_METHOD'] && $_SERVER['REQUEST_METHOD'] != 'POST') {
header('Allow: POST', true, 405);
throw new Exception("Invalid HTTP request method.");
}
}
}
?>