Hotel Raxa - Advanced Booking System Implementation

🏨 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>
This commit is contained in:
Hotel Raxa Dev
2025-07-11 07:43:22 +02:00
commit 5b1e2453c7
9816 changed files with 2784509 additions and 0 deletions

View File

@@ -0,0 +1,337 @@
<?php
add_filter(
'wpcf7_pre_construct_contact_form_properties',
'wpcf7_sendinblue_register_property',
10, 2
);
/**
* Registers the sendinblue contact form property.
*/
function wpcf7_sendinblue_register_property( $properties, $contact_form ) {
$service = WPCF7_Sendinblue::get_instance();
if ( $service->is_active() ) {
$properties += array(
'sendinblue' => array(),
);
}
return $properties;
}
add_action(
'wpcf7_save_contact_form',
'wpcf7_sendinblue_save_contact_form',
10, 3
);
/**
* Saves the sendinblue property value.
*/
function wpcf7_sendinblue_save_contact_form( $contact_form, $args, $context ) {
$service = WPCF7_Sendinblue::get_instance();
if ( ! $service->is_active() ) {
return;
}
$prop = (array) ( $_POST['wpcf7-sendinblue'] ?? array() );
$prop = wp_parse_args(
$prop,
array(
'enable_contact_list' => false,
'contact_lists' => array(),
'enable_transactional_email' => false,
'email_template' => 0,
)
);
$prop['contact_lists'] = array_map( 'absint', $prop['contact_lists'] );
$prop['email_template'] = absint( $prop['email_template'] );
$contact_form->set_properties( array(
'sendinblue' => $prop,
) );
}
add_filter(
'wpcf7_editor_panels',
'wpcf7_sendinblue_editor_panels',
10, 1
);
/**
* Builds the editor panel for the sendinblue property.
*/
function wpcf7_sendinblue_editor_panels( $panels ) {
$service = WPCF7_Sendinblue::get_instance();
if ( ! $service->is_active() ) {
return $panels;
}
$contact_form = WPCF7_ContactForm::get_current();
$prop = wp_parse_args(
$contact_form->prop( 'sendinblue' ),
array(
'enable_contact_list' => false,
'contact_lists' => array(),
'enable_transactional_email' => false,
'email_template' => 0,
)
);
$editor_panel = static function () use ( $prop, $service ) {
$description = sprintf(
esc_html(
__( "You can set up the Brevo integration here. For details, see %s.", 'contact-form-7' )
),
wpcf7_link(
__( 'https://contactform7.com/sendinblue-integration/', 'contact-form-7' ),
__( 'Brevo integration', 'contact-form-7' )
)
);
$lists = wpcf7_sendinblue_get_lists();
$templates = $service->get_templates();
?>
<h2><?php echo esc_html( __( 'Brevo', 'contact-form-7' ) ); ?></h2>
<fieldset>
<legend><?php echo $description; ?></legend>
<table class="form-table" role="presentation">
<tbody>
<tr class="<?php echo $prop['enable_contact_list'] ? '' : 'inactive'; ?>">
<th scope="row">
<?php
echo esc_html( __( 'Contact lists', 'contact-form-7' ) );
?>
</th>
<td>
<fieldset>
<legend class="screen-reader-text">
<?php
echo esc_html( __( 'Contact lists', 'contact-form-7' ) );
?>
</legend>
<label for="wpcf7-sendinblue-enable-contact-list">
<input type="checkbox" name="wpcf7-sendinblue[enable_contact_list]" id="wpcf7-sendinblue-enable-contact-list" value="1" <?php checked( $prop['enable_contact_list'] ); ?> />
<?php
echo esc_html(
__( "Add form submitters to your contact lists", 'contact-form-7' )
);
?>
</label>
</fieldset>
</td>
</tr>
<tr>
<th scope="row"></th>
<td>
<fieldset>
<?php
if ( $lists ) {
echo sprintf(
'<legend>%1$s</legend>',
esc_html( __( 'Select lists to which contacts are added:', 'contact-form-7' ) )
);
echo '<ul>';
foreach ( $lists as $list ) {
echo sprintf(
'<li><label><input %1$s /> %2$s</label></li>',
wpcf7_format_atts( array(
'type' => 'checkbox',
'name' => 'wpcf7-sendinblue[contact_lists][]',
'value' => $list['id'],
'checked' => in_array( $list['id'], $prop['contact_lists'] ),
) ),
esc_html( $list['name'] )
);
}
echo '</ul>';
} else {
echo sprintf(
'<legend>%1$s</legend>',
esc_html( __( 'You have no contact list yet.', 'contact-form-7' ) )
);
}
?>
</fieldset>
<?php
echo sprintf(
'<p><a %1$s>%2$s <span class="screen-reader-text">%3$s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
wpcf7_format_atts( array(
'href' => 'https://my.sendinblue.com/lists',
'target' => '_blank',
'rel' => 'external noreferrer noopener',
) ),
esc_html( __( 'Manage your contact lists', 'contact-form-7' ) ),
esc_html( __( '(opens in a new tab)', 'contact-form-7' ) )
);
?>
</td>
</tr>
<tr class="<?php echo $prop['enable_transactional_email'] ? '' : 'inactive'; ?>">
<th scope="row">
<?php
echo esc_html( __( 'Welcome email', 'contact-form-7' ) );
?>
</th>
<td>
<fieldset>
<legend class="screen-reader-text">
<?php
echo esc_html( __( 'Welcome email', 'contact-form-7' ) );
?>
</legend>
<label for="wpcf7-sendinblue-enable-transactional-email">
<input type="checkbox" name="wpcf7-sendinblue[enable_transactional_email]" id="wpcf7-sendinblue-enable-transactional-email" value="1" <?php checked( $prop['enable_transactional_email'] ); ?> />
<?php
echo esc_html(
__( "Send a welcome email to new contacts", 'contact-form-7' )
);
?>
</label>
</fieldset>
</td>
</tr>
<tr>
<th scope="row"></th>
<td>
<fieldset>
<?php
if ( $templates ) {
echo sprintf(
'<legend>%1$s</legend>',
esc_html( __( 'Select an email template:', 'contact-form-7' ) )
);
echo '<select name="wpcf7-sendinblue[email_template]">';
echo sprintf(
'<option %1$s>%2$s</option>',
wpcf7_format_atts( array(
'value' => 0,
'selected' => 0 === $prop['email_template'],
) ),
esc_html( __( '&mdash; Select &mdash;', 'contact-form-7' ) )
);
foreach ( $templates as $template ) {
echo sprintf(
'<option %1$s>%2$s</option>',
wpcf7_format_atts( array(
'value' => $template['id'],
'selected' => $prop['email_template'] === $template['id'],
) ),
esc_html( $template['name'] )
);
}
echo '</select>';
} else {
echo sprintf(
'<legend>%1$s</legend>',
esc_html( __( 'You have no active email template yet.', 'contact-form-7' ) )
);
}
?>
</fieldset>
<?php
echo sprintf(
'<p><a %1$s>%2$s <span class="screen-reader-text">%3$s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
wpcf7_format_atts( array(
'href' => 'https://my.sendinblue.com/camp/lists/template',
'target' => '_blank',
'rel' => 'external noreferrer noopener',
) ),
esc_html( __( 'Manage your email templates', 'contact-form-7' ) ),
esc_html( __( '(opens in a new tab)', 'contact-form-7' ) )
);
?>
</td>
</tr>
</tbody>
</table>
</fieldset>
<?php
};
$panels += array(
'sendinblue-panel' => array(
'title' => __( 'Brevo', 'contact-form-7' ),
'callback' => $editor_panel,
),
);
return $panels;
}
/**
* Retrieves contact lists from Brevo's database.
*/
function wpcf7_sendinblue_get_lists() {
static $lists = array();
$service = WPCF7_Sendinblue::get_instance();
if ( ! empty( $lists ) or ! $service->is_active() ) {
return $lists;
}
$limit = 50;
$offset = 0;
while ( count( $lists ) < $limit * 10 ) {
$lists_next = (array) $service->get_lists( array(
'limit' => $limit,
'offset' => $offset,
) );
if ( ! empty( $lists_next ) ) {
$lists = array_merge( $lists, $lists_next );
}
if ( count( $lists_next ) < $limit ) {
break;
}
$offset += $limit;
}
return $lists;
}

View File

@@ -0,0 +1,101 @@
<?php
/**
* Double Opt-In Helper-related functions
*
* @link https://contactform7.com/doi-helper/
*/
add_action(
'doihelper_init',
'wpcf7_sendinblue_doi_register_agent',
10, 0
);
/**
* Registers wpcf7_sendinblue as an agent.
*/
function wpcf7_sendinblue_doi_register_agent() {
if ( ! function_exists( 'doihelper_register_agent' ) ) {
return;
}
doihelper_register_agent( 'wpcf7_sendinblue', array(
'optin_callback' => apply_filters(
'wpcf7_sendinblue_doi_optin_callback',
'wpcf7_sendinblue_doi_default_optin_callback'
),
'email_callback' => apply_filters(
'wpcf7_sendinblue_doi_email_callback',
'wpcf7_sendinblue_doi_default_email_callback'
),
) );
}
/**
* Default optin_callback function.
*/
function wpcf7_sendinblue_doi_default_optin_callback( $properties ) {
$service = WPCF7_Sendinblue::get_instance();
if ( ! $service->is_active() ) {
return;
}
if ( ! empty( $properties['contact'] ) ) {
$contact_id = $service->create_contact( $properties['contact'] );
if ( $contact_id and ! empty( $properties['email'] ) ) {
$service->send_email( $properties['email'] );
}
}
}
/**
* Default email_callback function.
*/
function wpcf7_sendinblue_doi_default_email_callback( $args ) {
if ( ! isset( $args['token'] ) or ! isset( $args['email_to'] ) ) {
return;
}
$site_title = wp_specialchars_decode(
get_bloginfo( 'name' ),
ENT_QUOTES
);
$link = add_query_arg(
array( 'doitoken' => $args['token'] ),
home_url()
);
$to = $args['email_to'];
$subject = sprintf(
/* translators: %s: blog name */
__( 'Opt-in confirmation from %s', 'contact-form-7' ),
$site_title
);
$message = sprintf(
/* translators: 1: blog name, 2: confirmation link */
__( 'Hello,
This is a confirmation email sent from %1$s.
We have received your submission to our web form, according to which you have allowed us to add you to our contact list. But, the process has not yet been completed. To complete it, please click the following link.
%2$s
If it was not your intention, or if you have no idea why you received this message, please do not click on the link, and ignore this message. We will never collect or use your personal data without your clear consent.
Sincerely,
%1$s', 'contact-form-7' ),
$site_title,
$link
);
wp_mail( $to, $subject, $message );
}

View File

@@ -0,0 +1,247 @@
<?php
/**
* Brevo module main file
*
* @link https://contactform7.com/sendinblue-integration/
*/
wpcf7_include_module_file( 'sendinblue/service.php' );
wpcf7_include_module_file( 'sendinblue/contact-form-properties.php' );
wpcf7_include_module_file( 'sendinblue/doi.php' );
add_action( 'wpcf7_init', 'wpcf7_sendinblue_register_service', 10, 0 );
/**
* Registers the Sendinblue service.
*/
function wpcf7_sendinblue_register_service() {
$integration = WPCF7_Integration::get_instance();
$integration->add_service( 'sendinblue',
WPCF7_Sendinblue::get_instance()
);
}
add_action( 'wpcf7_submit', 'wpcf7_sendinblue_submit', 10, 2 );
/**
* Callback to the wpcf7_submit action hook. Creates a contact
* based on the submission.
*/
function wpcf7_sendinblue_submit( $contact_form, $result ) {
if ( $contact_form->in_demo_mode() ) {
return;
}
$service = WPCF7_Sendinblue::get_instance();
if ( ! $service->is_active() ) {
return;
}
if ( empty( $result['posted_data_hash'] ) ) {
return;
}
if ( empty( $result['status'] )
or ! in_array( $result['status'], array( 'mail_sent', 'mail_failed' ) ) ) {
return;
}
$submission = WPCF7_Submission::get_instance();
$consented = true;
foreach ( $contact_form->scan_form_tags( 'feature=name-attr' ) as $tag ) {
if ( $tag->has_option( 'consent_for:sendinblue' )
and null == $submission->get_posted_data( $tag->name ) ) {
$consented = false;
break;
}
}
if ( ! $consented ) {
return;
}
$prop = wp_parse_args(
$contact_form->prop( 'sendinblue' ),
array(
'enable_contact_list' => false,
'contact_lists' => array(),
'enable_transactional_email' => false,
'email_template' => 0,
)
);
if ( ! $prop['enable_contact_list'] ) {
return;
}
$attributes = wpcf7_sendinblue_collect_parameters();
$params = array(
'contact' => array(),
'email' => array(),
);
if ( ! empty( $attributes['EMAIL'] ) or ! empty( $attributes['SMS'] ) ) {
$params['contact'] = apply_filters(
'wpcf7_sendinblue_contact_parameters',
array(
'email' => $attributes['EMAIL'],
'attributes' => (object) $attributes,
'listIds' => (array) $prop['contact_lists'],
'updateEnabled' => false,
)
);
}
if ( $prop['enable_transactional_email'] and $prop['email_template'] ) {
$first_name = isset( $attributes['FIRSTNAME'] )
? trim( $attributes['FIRSTNAME'] )
: '';
$last_name = isset( $attributes['LASTNAME'] )
? trim( $attributes['LASTNAME'] )
: '';
if ( $first_name or $last_name ) {
$email_to_name = sprintf(
/* translators: 1: first name, 2: last name */
_x( '%1$s %2$s', 'personal name', 'contact-form-7' ),
$first_name,
$last_name
);
} else {
$email_to_name = '';
}
$params['email'] = apply_filters(
'wpcf7_sendinblue_email_parameters',
array(
'templateId' => absint( $prop['email_template'] ),
'to' => array(
array(
'name' => $email_to_name,
'email' => $attributes['EMAIL'],
),
),
'params' => (object) $attributes,
'tags' => array( 'Contact Form 7' ),
)
);
}
if ( is_email( $attributes['EMAIL'] ) ) {
$token = null;
do_action_ref_array( 'wpcf7_doi', array(
'wpcf7_sendinblue',
array(
'email_to' => $attributes['EMAIL'],
'properties' => $params,
),
&$token,
) );
if ( isset( $token ) ) {
return;
}
}
if ( ! empty( $params['contact'] ) ) {
$contact_id = $service->create_contact( $params['contact'] );
if ( $contact_id and ! empty( $params['email'] ) ) {
$service->send_email( $params['email'] );
}
}
}
/**
* Collects parameters for Sendinblue contact data based on submission.
*
* @return array Sendinblue contact parameters.
*/
function wpcf7_sendinblue_collect_parameters() {
$params = array();
$submission = WPCF7_Submission::get_instance();
foreach ( (array) $submission->get_posted_data() as $name => $val ) {
$name = strtoupper( $name );
if ( 'YOUR-' == substr( $name, 0, 5 ) ) {
$name = substr( $name, 5 );
}
if ( $val ) {
$params += array(
$name => $val,
);
}
}
if ( isset( $params['SMS'] ) ) {
$sms = trim( implode( ' ', (array) $params['SMS'] ) );
$sms = preg_replace( '/[#*].*$/', '', $sms ); // Remove extension
$is_international = false ||
str_starts_with( $sms, '+' ) ||
str_starts_with( $sms, '00' );
if ( $is_international ) {
$sms = preg_replace( '/^[+0]+/', '', $sms );
}
$sms = preg_replace( '/[^0-9]/', '', $sms );
if ( $is_international and 6 < strlen( $sms ) and strlen( $sms ) < 16 ) {
$params['SMS'] = '+' . $sms;
} else { // Invalid telephone number
unset( $params['SMS'] );
}
}
if ( isset( $params['NAME'] ) ) {
$your_name = implode( ' ', (array) $params['NAME'] );
$your_name = explode( ' ', $your_name );
if ( ! isset( $params['LASTNAME'] ) ) {
$params['LASTNAME'] = implode(
' ',
array_slice( $your_name, 1 )
);
}
if ( ! isset( $params['FIRSTNAME'] ) ) {
$params['FIRSTNAME'] = implode(
' ',
array_slice( $your_name, 0, 1 )
);
}
}
$params = array_map(
function ( $param ) {
if ( is_array( $param ) ) {
$param = wpcf7_array_flatten( $param );
$param = reset( $param );
}
return $param;
},
$params
);
$params = apply_filters(
'wpcf7_sendinblue_collect_parameters',
$params
);
return $params;
}

View File

@@ -0,0 +1,392 @@
<?php
if ( ! class_exists( 'WPCF7_Service' ) ) {
return;
}
class WPCF7_Sendinblue extends WPCF7_Service {
use WPCF7_Sendinblue_API;
private static $instance;
private $api_key;
public static function get_instance() {
if ( empty( self::$instance ) ) {
self::$instance = new self;
}
return self::$instance;
}
private function __construct() {
$option = WPCF7::get_option( 'sendinblue' );
if ( isset( $option['api_key'] ) ) {
$this->api_key = $option['api_key'];
}
}
public function get_title() {
return __( 'Brevo', 'contact-form-7' );
}
public function is_active() {
return (bool) $this->get_api_key();
}
public function get_api_key() {
return $this->api_key;
}
public function get_categories() {
return array( 'email_marketing' );
}
public function icon() {
}
public function link() {
echo wpcf7_link(
'https://get.brevo.com/wpcf7-integration',
'brevo.com'
);
}
protected function log( $url, $request, $response ) {
wpcf7_log_remote_request( $url, $request, $response );
}
protected function menu_page_url( $args = '' ) {
$args = wp_parse_args( $args, array() );
$url = menu_page_url( 'wpcf7-integration', false );
$url = add_query_arg( array( 'service' => 'sendinblue' ), $url );
if ( ! empty( $args ) ) {
$url = add_query_arg( $args, $url );
}
return $url;
}
protected function save_data() {
WPCF7::update_option( 'sendinblue', array(
'api_key' => $this->api_key,
) );
}
protected function reset_data() {
$this->api_key = null;
$this->save_data();
}
public function load( $action = '' ) {
if ( 'setup' == $action and 'POST' == $_SERVER['REQUEST_METHOD'] ) {
check_admin_referer( 'wpcf7-sendinblue-setup' );
if ( ! empty( $_POST['reset'] ) ) {
$this->reset_data();
$redirect_to = $this->menu_page_url( 'action=setup' );
} else {
$this->api_key = trim( $_POST['api_key'] ?? '' );
$confirmed = $this->confirm_key();
if ( true === $confirmed ) {
$redirect_to = $this->menu_page_url( array(
'message' => 'success',
) );
$this->save_data();
} elseif ( false === $confirmed ) {
$redirect_to = $this->menu_page_url( array(
'action' => 'setup',
'message' => 'unauthorized',
) );
} else {
$redirect_to = $this->menu_page_url( array(
'action' => 'setup',
'message' => 'invalid',
) );
}
}
wp_safe_redirect( $redirect_to );
exit();
}
}
public function admin_notice( $message = '' ) {
if ( 'unauthorized' === $message ) {
wp_admin_notice(
sprintf(
'<strong>%1$s</strong>: %2$s',
esc_html( __( "Error", 'contact-form-7' ) ),
esc_html( __( "You have not been authenticated. Make sure the provided API key is correct.", 'contact-form-7' ) )
),
'type=error'
);
}
if ( 'invalid' === $message ) {
wp_admin_notice(
sprintf(
'<strong>%1$s</strong>: %2$s',
esc_html( __( "Error", 'contact-form-7' ) ),
esc_html( __( "Invalid key values.", 'contact-form-7' ) )
),
'type=error'
);
}
if ( 'success' === $message ) {
wp_admin_notice(
esc_html( __( "Settings saved.", 'contact-form-7' ) ),
'type=success'
);
}
}
public function display( $action = '' ) {
echo sprintf(
'<p>%s</p>',
esc_html( __( "Store and organize your contacts while protecting user privacy on Brevo, the leading CRM & email marketing platform in Europe. Brevo offers unlimited contacts and advanced marketing features.", 'contact-form-7' ) )
);
echo sprintf(
'<p><strong>%s</strong></p>',
wpcf7_link(
__( 'https://contactform7.com/sendinblue-integration/', 'contact-form-7' ),
__( 'Brevo integration', 'contact-form-7' )
)
);
if ( $this->is_active() ) {
echo sprintf(
'<p class="dashicons-before dashicons-yes">%s</p>',
esc_html( __( "Brevo is active on this site.", 'contact-form-7' ) )
);
}
if ( 'setup' == $action ) {
$this->display_setup();
} else {
echo sprintf(
'<p><a href="%1$s" class="button">%2$s</a></p>',
esc_url( $this->menu_page_url( 'action=setup' ) ),
esc_html( __( 'Setup integration', 'contact-form-7' ) )
);
}
}
private function display_setup() {
$api_key = $this->get_api_key();
?>
<form method="post" action="<?php echo esc_url( $this->menu_page_url( 'action=setup' ) ); ?>">
<?php wp_nonce_field( 'wpcf7-sendinblue-setup' ); ?>
<table class="form-table">
<tbody>
<tr>
<th scope="row"><label for="publishable"><?php echo esc_html( __( 'API key', 'contact-form-7' ) ); ?></label></th>
<td><?php
if ( $this->is_active() ) {
echo esc_html( wpcf7_mask_password( $api_key, 4, 8 ) );
echo sprintf(
'<input type="hidden" value="%s" id="api_key" name="api_key" />',
esc_attr( $api_key )
);
} else {
echo sprintf(
'<input type="text" aria-required="true" value="%s" id="api_key" name="api_key" class="regular-text code" />',
esc_attr( $api_key )
);
}
?></td>
</tr>
</tbody>
</table>
<?php
if ( $this->is_active() ) {
submit_button(
_x( 'Remove key', 'API keys', 'contact-form-7' ),
'small', 'reset'
);
} else {
submit_button( __( 'Save changes', 'contact-form-7' ) );
}
?>
</form>
<?php
}
}
/**
* Trait for the Sendinblue API (v3).
*
* @link https://developers.sendinblue.com/reference
*/
trait WPCF7_Sendinblue_API {
public function confirm_key() {
$endpoint = 'https://api.sendinblue.com/v3/account';
$request = array(
'headers' => array(
'Accept' => 'application/json',
'Content-Type' => 'application/json; charset=utf-8',
'API-Key' => $this->get_api_key(),
),
);
$response = wp_remote_get( $endpoint, $request );
$response_code = (int) wp_remote_retrieve_response_code( $response );
if ( 200 === $response_code ) { // 200 OK
return true;
} elseif ( 401 === $response_code ) { // 401 Unauthorized
return false;
} elseif ( 400 <= $response_code ) {
if ( WP_DEBUG ) {
$this->log( $endpoint, $request, $response );
}
}
}
public function get_lists( $options = '' ) {
$options = wp_parse_args( $options, array(
'limit' => 50,
'offset' => 0,
) );
$endpoint = add_query_arg(
$options,
'https://api.sendinblue.com/v3/contacts/lists'
);
$request = array(
'headers' => array(
'Accept' => 'application/json',
'Content-Type' => 'application/json; charset=utf-8',
'API-Key' => $this->get_api_key(),
),
);
$response = wp_remote_get( $endpoint, $request );
$response_code = (int) wp_remote_retrieve_response_code( $response );
if ( 200 === $response_code ) { // 200 OK
$response_body = wp_remote_retrieve_body( $response );
$response_body = json_decode( $response_body, true );
if ( empty( $response_body['lists'] ) ) {
return array();
} else {
return (array) $response_body['lists'];
}
} elseif ( 400 <= $response_code ) {
if ( WP_DEBUG ) {
$this->log( $endpoint, $request, $response );
}
}
}
public function get_templates() {
$endpoint = add_query_arg(
array(
'templateStatus' => 'true',
'limit' => 100,
'offset' => 0,
),
'https://api.sendinblue.com/v3/smtp/templates'
);
$request = array(
'headers' => array(
'Accept' => 'application/json',
'Content-Type' => 'application/json; charset=utf-8',
'API-Key' => $this->get_api_key(),
),
);
$response = wp_remote_get( $endpoint, $request );
$response_code = (int) wp_remote_retrieve_response_code( $response );
if ( 200 === $response_code ) { // 200 OK
$response_body = wp_remote_retrieve_body( $response );
$response_body = json_decode( $response_body, true );
if ( empty( $response_body['templates'] ) ) {
return array();
} else {
return (array) $response_body['templates'];
}
} elseif ( 400 <= $response_code ) {
if ( WP_DEBUG ) {
$this->log( $endpoint, $request, $response );
}
}
}
public function create_contact( $properties ) {
$endpoint = 'https://api.sendinblue.com/v3/contacts';
$request = array(
'headers' => array(
'Accept' => 'application/json',
'Content-Type' => 'application/json; charset=utf-8',
'API-Key' => $this->get_api_key(),
),
'body' => wp_json_encode( $properties ),
);
$response = wp_remote_post( $endpoint, $request );
$response_code = (int) wp_remote_retrieve_response_code( $response );
if ( in_array( $response_code, array( 201, 204 ), true ) ) {
$contact_id = wp_remote_retrieve_body( $response );
return $contact_id;
} elseif ( 400 <= $response_code ) {
if ( WP_DEBUG ) {
$this->log( $endpoint, $request, $response );
}
}
return false;
}
public function send_email( $properties ) {
$endpoint = 'https://api.sendinblue.com/v3/smtp/email';
$request = array(
'headers' => array(
'Accept' => 'application/json',
'Content-Type' => 'application/json; charset=utf-8',
'API-Key' => $this->get_api_key(),
),
'body' => wp_json_encode( $properties ),
);
$response = wp_remote_post( $endpoint, $request );
$response_code = (int) wp_remote_retrieve_response_code( $response );
if ( 201 === $response_code ) { // 201 Transactional email sent
$message_id = wp_remote_retrieve_body( $response );
return $message_id;
} elseif ( 400 <= $response_code ) {
if ( WP_DEBUG ) {
$this->log( $endpoint, $request, $response );
}
}
return false;
}
}