🏨 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>
107 lines
4.2 KiB
PHP
107 lines
4.2 KiB
PHP
<?php
|
|
defined('ABSPATH') || exit;
|
|
|
|
class EB_Redsys_Payment_Gateway {
|
|
|
|
private $api;
|
|
private $test_mode;
|
|
private $merchant_code;
|
|
private $terminal;
|
|
private $encryption_key;
|
|
|
|
public function __construct() {
|
|
$this->id = 'redsys';
|
|
$this->title = __('Credit Card (Redsys)', 'eb-redsys-gateway');
|
|
$this->description = __('Pay securely via credit card using Redsys.', 'eb-redsys-gateway');
|
|
|
|
// Load settings
|
|
$this->test_mode = get_option('eb_redsys_test_mode', 'yes');
|
|
$this->merchant_code = get_option('eb_redsys_merchant_code');
|
|
$this->terminal = get_option('eb_redsys_terminal');
|
|
$this->encryption_key = get_option('eb_redsys_encryption_key');
|
|
|
|
// Initialize API
|
|
$this->api = new Redsys_API();
|
|
|
|
// Hooks
|
|
add_action('eb_payment_gateway_redsys', array($this, 'process_payment'));
|
|
add_action('eb_payment_gateway_redsys_callback', array($this, 'process_callback'));
|
|
}
|
|
|
|
public function get_endpoint() {
|
|
return ($this->test_mode === 'yes')
|
|
? 'https://sis-t.redsys.es:25443/sis/realizarPago'
|
|
: 'https://sis.redsys.es/sis/realizarPago';
|
|
}
|
|
|
|
public function process_payment($booking_data) {
|
|
$order_id = $booking_data['booking_id'];
|
|
$amount = $booking_data['amount'];
|
|
|
|
// Prepare payment data
|
|
$payment_data = array(
|
|
'DS_MERCHANT_AMOUNT' => $amount * 100, // Amount in cents
|
|
'DS_MERCHANT_ORDER' => $order_id,
|
|
'DS_MERCHANT_MERCHANTCODE' => $this->merchant_code,
|
|
'DS_MERCHANT_CURRENCY' => '978', // EUR
|
|
'DS_MERCHANT_TRANSACTIONTYPE' => '0', // Authorization
|
|
'DS_MERCHANT_TERMINAL' => $this->terminal,
|
|
'DS_MERCHANT_MERCHANTURL' => add_query_arg('gateway', 'redsys', eb_get_callback_url()),
|
|
'DS_MERCHANT_URLOK' => add_query_arg('result', 'success', eb_get_return_url($order_id)),
|
|
'DS_MERCHANT_URLKO' => add_query_arg('result', 'failure', eb_get_return_url($order_id))
|
|
);
|
|
|
|
// For future dated payments
|
|
if (!empty($booking_data['check_in_date'])) {
|
|
$payment_data['DS_MERCHANT_DATEFRECUENCY'] = '1'; // Daily frequency
|
|
$payment_data['DS_MERCHANT_CHARGEEXPIRYDATE'] = date('d/m/Y', strtotime($booking_data['check_in_date']));
|
|
$payment_data['DS_MERCHANT_TRANSACTIONTYPE'] = 'L'; // Deferred payment
|
|
}
|
|
|
|
// Generate signature
|
|
$signature = $this->api->createMerchantSignature($this->encryption_key, $payment_data);
|
|
|
|
// Build form
|
|
$form = '<form method="post" id="redsys-payment-form" action="' . esc_url($this->get_endpoint()) . '">';
|
|
$form .= '<input type="hidden" name="Ds_SignatureVersion" value="HMAC_SHA256_V1">';
|
|
$form .= '<input type="hidden" name="Ds_MerchantParameters" value="' . $this->api->createMerchantParameters($payment_data) . '">';
|
|
$form .= '<input type="hidden" name="Ds_Signature" value="' . $signature . '">';
|
|
$form .= '</form>';
|
|
$form .= '<script>document.getElementById("redsys-payment-form").submit();</script>';
|
|
|
|
echo $form;
|
|
exit;
|
|
}
|
|
|
|
public function process_callback() {
|
|
$params = $_POST['Ds_MerchantParameters'];
|
|
$signature = $_POST['Ds_Signature'];
|
|
|
|
// Verify signature
|
|
if (!$this->api->check_signature($params, $signature, $this->encryption_key)) {
|
|
wp_die('Invalid signature', 'Redsys Error', array('response' => 403));
|
|
}
|
|
|
|
$response = $this->api->decode_parameters($params);
|
|
|
|
// Check response code
|
|
if ($response['Ds_Response'] < 100) {
|
|
// Payment successful
|
|
$order_id = $response['Ds_Order'];
|
|
$transaction_id = $response['Ds_AuthorisationCode'];
|
|
|
|
// Update booking status
|
|
eb_update_booking_status($order_id, 'completed', $transaction_id);
|
|
|
|
echo "OK"; // Response to Redsys
|
|
exit;
|
|
}
|
|
|
|
// Payment failed
|
|
$order_id = $response['Ds_Order'];
|
|
eb_update_booking_status($order_id, 'failed');
|
|
|
|
echo "KO";
|
|
exit;
|
|
}
|
|
} |