🏨 Hotel Booking Enhancements: - Implemented Eagle Booking Advanced Pricing add-on - Added Booking.com-style rate management system - Created professional calendar interface for pricing - Integrated deals and discounts functionality 💰 Advanced Pricing Features: - Dynamic pricing models (per room, per person, per adult) - Base rates, adult rates, and child rates management - Length of stay discounts and early bird deals - Mobile rates and secret deals implementation - Seasonal promotions and flash sales 📅 Availability Management: - Real-time availability tracking - Stop sell and restriction controls - Closed to arrival/departure functionality - Minimum/maximum stay requirements - Automatic sold-out management 💳 Payment Integration: - Maintained Redsys payment gateway integration - Seamless integration with existing Eagle Booking - No modifications to core Eagle Booking plugin 🛠️ Technical Implementation: - Custom database tables for advanced pricing - WordPress hooks and filters integration - AJAX-powered admin interface - Data migration from existing Eagle Booking - Professional calendar view for revenue management 📊 Admin Interface: - Booking.com-style management dashboard - Visual rate and availability calendar - Bulk operations for date ranges - Statistics and analytics dashboard - Modal dialogs for quick editing 🔧 Code Quality: - WordPress coding standards compliance - Secure database operations with prepared statements - Proper input validation and sanitization - Error handling and logging - Responsive admin interface 🤖 Generated with Claude Code (https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
186 lines
6.1 KiB
PHP
186 lines
6.1 KiB
PHP
<?php
|
|
defined('ABSPATH') || exit;
|
|
|
|
class Redsys_API {
|
|
|
|
private $environment;
|
|
private $api_client;
|
|
|
|
public function __construct() {
|
|
require_once dirname(__FILE__) . '/apiRedsysFinal.php';
|
|
require_once dirname(__FILE__) . '/RESTConstants.php';
|
|
|
|
$this->api_client = new RedsysAPI();
|
|
$this->environment = get_option('eb_redsys_test_mode') === 'yes' ? 'test' : 'live';
|
|
}
|
|
|
|
/**
|
|
* Create merchant parameters
|
|
*/
|
|
public function createMerchantParameters($params) {
|
|
// Convert params to JSON
|
|
$json = json_encode($params);
|
|
|
|
// Encode in base64
|
|
return $this->api_client->encodeBase64($json);
|
|
}
|
|
|
|
/**
|
|
* Create merchant signature
|
|
*/
|
|
public function createMerchantSignature($key, $data) {
|
|
return $this->api_client->createMerchantSignature($key, $data);
|
|
}
|
|
|
|
/**
|
|
* Decode merchant parameters
|
|
*/
|
|
public function decodeMerchantParameters($data) {
|
|
$decoded = $this->api_client->decodeBase64($data);
|
|
return json_decode($decoded, true);
|
|
}
|
|
|
|
/**
|
|
* Check signature
|
|
*/
|
|
public function check_signature($merchant_parameters, $signature, $key) {
|
|
$calculated_signature = $this->api_client->createMerchantSignatureNotif($key, $merchant_parameters);
|
|
return $signature === $calculated_signature;
|
|
}
|
|
|
|
/**
|
|
* Get endpoint URL
|
|
*/
|
|
public function get_endpoint() {
|
|
if ($this->environment === 'test') {
|
|
return 'https://sis-t.redsys.es:25443/sis/realizarPago';
|
|
} else {
|
|
return 'https://sis.redsys.es/sis/realizarPago';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Create notification signature
|
|
*/
|
|
public function createNotificationSignature($key, $data) {
|
|
return $this->api_client->createMerchantSignatureNotif($key, $data);
|
|
}
|
|
|
|
/**
|
|
* Format order number
|
|
*/
|
|
public function formatOrderNumber($booking_id) {
|
|
// Ensure order number is exactly 12 digits
|
|
return str_pad($booking_id, 12, '0', STR_PAD_LEFT);
|
|
}
|
|
|
|
/**
|
|
* Format amount
|
|
*/
|
|
public function formatAmount($amount) {
|
|
// Convert to cents and ensure no decimal places
|
|
return number_format($amount * 100, 0, '', '');
|
|
}
|
|
|
|
/**
|
|
* Create future payment parameters
|
|
*/
|
|
public function createFuturePaymentParams($params, $execution_date) {
|
|
$params['DS_MERCHANT_TRANSACTIONTYPE'] = 'L'; // Deferred payment
|
|
$params['DS_MERCHANT_DATEFRECUENCY'] = '1'; // Daily frequency
|
|
$params['DS_MERCHANT_CHARGEEXPIRYDATE'] = date('d/m/Y', strtotime($execution_date));
|
|
|
|
return $params;
|
|
}
|
|
|
|
/**
|
|
* Create subscription parameters
|
|
*/
|
|
public function createSubscriptionParams($params) {
|
|
$params['DS_MERCHANT_TRANSACTIONTYPE'] = 'L';
|
|
$params['DS_MERCHANT_COF_INI'] = 'S'; // Initial recurring payment
|
|
$params['DS_MERCHANT_COF_TYPE'] = 'R'; // Recurring payment type
|
|
|
|
return $params;
|
|
}
|
|
|
|
/**
|
|
* Create subsequent payment parameters
|
|
*/
|
|
public function createSubsequentPaymentParams($params, $reference_id) {
|
|
$params['DS_MERCHANT_TRANSACTIONTYPE'] = '0';
|
|
$params['DS_MERCHANT_IDENTIFIER'] = $reference_id;
|
|
$params['DS_MERCHANT_DIRECTPAYMENT'] = 'true';
|
|
|
|
return $params;
|
|
}
|
|
|
|
/**
|
|
* Parse notification response
|
|
*/
|
|
public function parseNotification($data) {
|
|
if (!isset($data['Ds_SignatureVersion']) ||
|
|
!isset($data['Ds_MerchantParameters']) ||
|
|
!isset($data['Ds_Signature'])) {
|
|
return false;
|
|
}
|
|
|
|
$decoded_params = $this->decodeMerchantParameters($data['Ds_MerchantParameters']);
|
|
|
|
return array(
|
|
'params' => $decoded_params,
|
|
'signature' => $data['Ds_Signature']
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Validate response code
|
|
*/
|
|
public function isSuccessResponse($response_code) {
|
|
// Response codes less than 100 indicate success
|
|
return $response_code < 100;
|
|
}
|
|
|
|
/**
|
|
* Get response message
|
|
*/
|
|
public function getResponseMessage($response_code) {
|
|
$messages = array(
|
|
'0000' => __('Transaction authorized for payments and pre-authorizations', 'eb-redsys-gateway'),
|
|
'0900' => __('Transaction authorized for refunds and confirmations', 'eb-redsys-gateway'),
|
|
'0101' => __('Card expired', 'eb-redsys-gateway'),
|
|
'0102' => __('Card temporarily suspended or under suspicion of fraud', 'eb-redsys-gateway'),
|
|
'0104' => __('Operation not allowed for this type of card', 'eb-redsys-gateway'),
|
|
'0116' => __('Insufficient funds', 'eb-redsys-gateway'),
|
|
'0118' => __('Card not registered', 'eb-redsys-gateway'),
|
|
'0129' => __('Security code (CVV2/CVC2) incorrect', 'eb-redsys-gateway'),
|
|
'0180' => __('Card not recognized', 'eb-redsys-gateway'),
|
|
'0184' => __('Cardholder authentication failed', 'eb-redsys-gateway'),
|
|
'0190' => __('Transaction declined without specific reason', 'eb-redsys-gateway'),
|
|
'0191' => __('Wrong expiration date', 'eb-redsys-gateway'),
|
|
'0904' => __('Merchant not registered at FUC', 'eb-redsys-gateway'),
|
|
'0909' => __('System error', 'eb-redsys-gateway'),
|
|
'0912' => __('Issuer not available', 'eb-redsys-gateway'),
|
|
'0913' => __('Duplicate order', 'eb-redsys-gateway'),
|
|
'0944' => __('Wrong session', 'eb-redsys-gateway'),
|
|
'0950' => __('Refund operation not allowed', 'eb-redsys-gateway'),
|
|
);
|
|
|
|
return isset($messages[$response_code])
|
|
? $messages[$response_code]
|
|
: __('Unknown error', 'eb-redsys-gateway');
|
|
}
|
|
|
|
/**
|
|
* Log error
|
|
*/
|
|
public function log_error($message, $data = array()) {
|
|
if (function_exists('eb_log')) {
|
|
$log_message = 'Redsys API Error: ' . $message;
|
|
if (!empty($data)) {
|
|
$log_message .= ' | Data: ' . print_r($data, true);
|
|
}
|
|
eb_log($log_message);
|
|
}
|
|
}
|
|
} |