예제 #1
3
/**
 * @param boolean $result
 * @param EM_Booking $EM_Booking
 * @return boolean
 */
function bp_em_record_activity_booking_save($result, $EM_Booking)
{
    if ($result) {
        $rejected_statuses = array(0, 2, 3);
        //these statuses apply to rejected/cancelled bookings
        $user = $EM_Booking->person;
        $member_slug = function_exists('bp_get_members_root_slug') ? bp_get_members_root_slug() : BP_MEMBERS_SLUG;
        $member_link = trailingslashit(bp_get_root_domain()) . $member_slug . '/' . $user->user_login;
        $user_link = "<a href='" . $member_link . "/'>" . $user->display_name . "</a>";
        $event_link = $EM_Booking->get_event()->output('#_EVENTLINK');
        $status = $EM_Booking->booking_status;
        $EM_Event = $EM_Booking->get_event();
        if (empty($EM_Event->group_id)) {
            if ($status == 1 || !get_option('dbem_bookings_approval') && $status < 2) {
                $action = sprintf(__('%s is attending %s.', 'dbem'), $user_link, $event_link);
            } elseif (($EM_Booking->previous_status == 1 || !get_option('dbem_bookings_approval') && $EM_Booking->previous_status < 2) && in_array($status, $rejected_statuses)) {
                $action = sprintf(__('%s will not be attending %s anymore.', 'dbem'), $user_link, $event_link);
            }
        } else {
            $group = new BP_Groups_Group($EM_Event->group_id);
            $group_link = '<a href="' . bp_get_group_permalink($group) . '">' . bp_get_group_name($group) . '</a>';
            if ($status == 1 || !get_option('dbem_bookings_approval') && $status < 2) {
                $action = sprintf(__('%s is attending %s of the group %s.', 'dbem'), $user_link, $event_link, $group_link);
            } elseif (($EM_Booking->previous_status == 1 || !get_option('dbem_bookings_approval') && $EM_Booking->previous_status < 2) && in_array($status, $rejected_statuses)) {
                $action = sprintf(__('%s will not be attending %s of group %s anymore.', 'dbem'), $user_link, $event_link, $group_link);
            }
        }
        if (!empty($action)) {
            bp_em_record_activity(array('user_id' => $EM_Booking->person->ID, 'action' => $action, 'primary_link' => $EM_Event->output('#_EVENTURL'), 'type' => 'new_booking', 'item_id' => $EM_Event->event_id, 'secondary_item_id' => $EM_Booking->booking_id, 'hide_sitewide' => $EM_Event->event_private));
            //group activity
            if (!empty($EM_Event->group_id)) {
                //tis a group event
                bp_em_record_activity(array('component' => 'groups', 'item_id' => $EM_Event->group_id, 'user_id' => $EM_Booking->person->ID, 'action' => $action, 'primary_link' => $EM_Event->output('#_EVENTURL'), 'type' => 'new_booking', 'secondary_item_id' => $EM_Booking->booking_id, 'hide_sitewide' => $EM_Event->event_private));
            }
        }
    }
    return $result;
}
예제 #2
0
/**
 * @param boolean $result
 * @param EM_Booking $EM_Booking
 * @return boolean
 */
function bp_em_record_activity_booking_save($result, $EM_Booking)
{
    if ($result) {
        $user = $EM_Booking->person;
        $user_link = "<a href='" . get_bloginfo('wpurl') . '/' . BP_MEMBERS_SLUG . '/' . $user->user_login . "/'>" . $user->display_name . "</a>";
        $event_link = $EM_Booking->get_event()->output('#_EVENTLINK');
        $status = $EM_Booking->status;
        if ($status == 1 || !get_option('dbem_bookings_approval') && $status < 2) {
            $action = sprintf(__('%s is attending %s.', 'dbem'), $user_link, $event_link);
        } elseif (($EM_Booking->previous_status == 1 || !get_option('dbem_bookings_approval') && $EM_Booking->previous_status < 2) && ($status > 1 || empty($status) || !get_option('dbem_bookings_approval') && $status != 1)) {
            $action = sprintf(__('%s will not be attending %s anymore.', 'dbem'), $user_link, $event_link);
        }
        $EM_Event = $EM_Booking->get_event();
        if (!empty($EM_Event->group_id)) {
            $group = new BP_Groups_Group($EM_Event->group_id);
            $group_link = '<a href="' . bp_get_group_permalink($group) . '">' . bp_get_group_name($group) . '</a>';
            if ($status == 1 || !get_option('dbem_bookings_approval') && $status < 2) {
                $action = sprintf(__('%s is attending %s of the group %s.', 'dbem'), $user_link, $event_link, $group_link);
            } elseif (($EM_Booking->previous_status == 1 || !get_option('dbem_bookings_approval') && $EM_Booking->previous_status < 2) && ($status > 1 || empty($status) || !get_option('dbem_bookings_approval') && $status != 1)) {
                $action = sprintf(__('%s will not be attending %s of group %s anymore.', 'dbem'), $user_link, $event_link, $group_link);
            }
        }
        if (!empty($action)) {
            bp_em_record_activity(array('user_id' => $EM_Booking->person->ID, 'action' => $action, 'primary_link' => $EM_Event->output('#_EVENTURL'), 'type' => 'new_booking', 'item_id' => $EM_Event->id, 'secondary_item_id' => $EM_Booking->id));
            //group activity
            if (!empty($EM_Event->group_id)) {
                //tis a group event
                bp_em_record_activity(array('component' => 'groups', 'item_id' => $EM_Event->group_id, 'user_id' => $EM_Booking->person->ID, 'action' => $action, 'primary_link' => $EM_Event->output('#_EVENTURL'), 'type' => 'new_booking', 'secondary_item_id' => $EM_Booking->id));
            }
        }
    }
    return $result;
}
예제 #3
0
/**
 * Catch booking saves and add a BP notification.
 * @param boolean $result
 * @param EM_Booking $EM_Booking
 * @return boolean
 */
function bp_em_add_booking_notification($result, $EM_Booking)
{
    global $bp;
    if (get_option('dbem_bookings_approval') && $EM_Booking->get_status() == 0) {
        $action = 'pending_booking';
    } elseif ($EM_Booking->get_status() == 1 || get_option('dbem_bookings_approval') && $EM_Booking->get_status() == 0) {
        $action = 'confirmed_booking';
    } elseif ($EM_Booking->get_status() == 3) {
        $action = 'cancelled_booking';
    }
    if (!empty($action) && !(get_option('dbem_bookings_registration_disable') && get_option('dbem_bookings_registration_user') == $EM_Booking->get_event()->get_contact()->ID)) {
        bp_notifications_add_notification(array('item_id' => $EM_Booking->booking_id, 'secondary_item_id' => $EM_Booking->event_id, 'user_id' => $EM_Booking->get_event()->get_contact()->ID, 'component_name' => 'events', 'component_action' => $action));
    }
    return $result;
}
예제 #4
0
 /**
  * Creates an EM_Tickets instance, 
  * @param EM_Event $event
  * @return null
  */
 function EM_Tickets($object = false)
 {
     global $wpdb;
     if (is_object($object) && get_class($object) == "EM_Event") {
         //Creates a blank tickets object if needed
         $this->event = $object;
         $sql = "SELECT * FROM " . EM_TICKETS_TABLE . " WHERE event_id ='{$this->event->id}'";
         $tickets = $wpdb->get_results($sql, ARRAY_A);
         foreach ($tickets as $ticket) {
             $EM_Ticket = new EM_Ticket($ticket);
             $EM_Ticket->event = $this->event;
             $this->tickets[] = $EM_Ticket;
         }
     } elseif (is_object($object) && get_class($object) == "EM_Booking") {
         $this->booking = $object;
         $this->event = $this->booking->get_event();
         $sql = "SELECT * FROM " . EM_TICKETS_TABLE . " t LEFT JOIN " . EM_TICKETS_BOOKINGS_TABLE . " bt ON bt.ticket_id=t.ticket_id  WHERE booking_id ='{$this->booking->id}'";
         $tickets = $wpdb->get_results($sql, ARRAY_A);
         foreach ($tickets as $ticket) {
             $EM_Ticket = new EM_Ticket($ticket);
             $EM_Ticket->event = $this->event;
             $this->tickets[] = $EM_Ticket;
         }
     } elseif (is_array($object)) {
         if (is_object(current($object)) && get_class(current($object)) == 'EM_Ticket') {
             $this->tickets = $object;
         } else {
             foreach ($object as $ticket) {
                 $EM_Ticket = new EM_Ticket($ticket);
                 $EM_Ticket->event = $this->event;
                 $this->tickets[] = $EM_Ticket;
             }
         }
     }
     do_action('em_tickets', $this, $object);
 }
예제 #5
0
/**
 * Catch booking saves and add a BP notification.
 * @param boolean $result
 * @param EM_Booking $EM_Booking
 * @return boolean
 */
function bp_em_add_booking_notification($result, $EM_Booking)
{
    global $bp;
    if (get_option('dbem_bookings_approval') && $EM_Booking->get_status() == 0) {
        $action = 'pending_booking';
    } elseif ($EM_Booking->get_status() == 1 || get_option('dbem_bookings_approval') && $EM_Booking->get_status() == 0) {
        $action = 'confirmed_booking';
    } elseif ($EM_Booking->get_status() == 3) {
        $action = 'cancelled_booking';
    }
    if (!empty($action)) {
        bp_core_add_notification($EM_Booking->booking_id, $EM_Booking->get_event()->get_contact()->ID, 'events', $action);
    }
    return $result;
}
 /**
  * Hooks into the em_booking_email_messages filter to modify email templates if the relevant custom email template exists for the event or gateway if events don't exist
  * @param array $msg
  * @param EM_Booking $EM_Booking contains event information used to retrieve custom email templates
  */
 public static function em_booking_email_messages($msg, $EM_Booking)
 {
     //get the event object and custom emails array
     $EM_Event = $EM_Booking->get_event();
     $custom_emails = self::get_event_emails($EM_Event);
     $users_to_check = $gateway_users = array();
     if (get_option('dbem_custom_emails_events')) {
         $users_to_check = array('admin' => 'admin', 'user' => 'user');
     }
     //firstly, check if we're using a gateway, and if there's an email to send for that gateway
     if (!empty($EM_Booking->booking_meta['gateway']) && get_option('dbem_custom_emails_gateways') && $EM_Booking->get_price() > 0) {
         $gateway = $EM_Booking->booking_meta['gateway'];
         $gateway_users = array($gateway . '-admin' => 'admin', $gateway . '-user' => 'user');
         $gateway_emails = maybe_unserialize(get_option('em_' . $EM_Booking->booking_meta['gateway'] . "_emails"));
         $users_to_check = array_merge($users_to_check, $gateway_users);
     }
     //set both admin and user email messages according to settings in custom emails
     foreach ($users_to_check as $user => $email_type) {
         if (!empty($custom_emails[$user][$EM_Booking->booking_status]) && $custom_emails[$user][$EM_Booking->booking_status]['status'] == 1) {
             //override default email with custom email
             $msg[$email_type]['subject'] = $custom_emails[$user][$EM_Booking->booking_status]['subject'];
             $msg[$email_type]['body'] = $custom_emails[$user][$EM_Booking->booking_status]['message'];
         } elseif (!empty($custom_emails[$user][$EM_Booking->booking_status]) && $custom_emails[$user][$EM_Booking->booking_status]['status'] == 2) {
             //disable the email entirely
             $msg[$email_type]['subject'] = $msg[$user]['body'] = '';
         } elseif (!empty($EM_Booking->booking_meta['gateway']) && array_key_exists($user, $gateway_users) && !empty($gateway_emails[$user][$EM_Booking->booking_status]['status'])) {
             //we requested the default for this gateway, so check if there's a overriden default for this gateway
             if ($gateway_emails[$user][$EM_Booking->booking_status]['status'] == 1) {
                 //override default gateway email with custom email
                 $msg[$email_type]['subject'] = $gateway_emails[$user][$EM_Booking->booking_status]['subject'];
                 $msg[$email_type]['body'] = $gateway_emails[$user][$EM_Booking->booking_status]['message'];
             } elseif ($gateway_emails[$user][$EM_Booking->booking_status]['status'] == 2) {
                 //disable the gateway email entirely
                 $msg[$email_type]['subject'] = $msg[$email_type]['body'] = '';
             }
         }
     }
     return $msg;
 }
 /**
  * @param EM_Booking $EM_Booking
  * @return mixed
  */
 function get_booking_actions($EM_Booking)
 {
     $booking_actions = array();
     $url = $EM_Booking->get_event()->get_bookings_url();
     switch ($EM_Booking->booking_status) {
         case 0:
             if (get_option('dbem_bookings_approval')) {
                 $booking_actions = array('approve' => '<a class="em-bookings-approve" href="' . em_add_get_params($url, array('action' => 'bookings_approve', 'booking_id' => $EM_Booking->booking_id)) . '">' . __('Approve', 'dbem') . '</a>', 'reject' => '<a class="em-bookings-reject" href="' . em_add_get_params($url, array('action' => 'bookings_reject', 'booking_id' => $EM_Booking->booking_id)) . '">' . __('Reject', 'dbem') . '</a>', 'delete' => '<span class="trash"><a class="em-bookings-delete" href="' . em_add_get_params($url, array('action' => 'bookings_delete', 'booking_id' => $EM_Booking->booking_id)) . '">' . __('Delete', 'dbem') . '</a></span>', 'edit' => '<a class="em-bookings-edit" href="' . em_add_get_params($EM_Booking->get_event()->get_bookings_url(), array('booking_id' => $EM_Booking->booking_id, 'em_ajax' => null, 'em_obj' => null)) . '">' . __('Edit/View', 'dbem') . '</a>');
                 break;
             }
             //if approvals are off, treat as a 1
         //if approvals are off, treat as a 1
         case 1:
             $booking_actions = array('unapprove' => '<a class="em-bookings-unapprove" href="' . em_add_get_params($url, array('action' => 'bookings_unapprove', 'booking_id' => $EM_Booking->booking_id)) . '">' . __('Unapprove', 'dbem') . '</a>', 'reject' => '<a class="em-bookings-reject" href="' . em_add_get_params($url, array('action' => 'bookings_reject', 'booking_id' => $EM_Booking->booking_id)) . '">' . __('Reject', 'dbem') . '</a>', 'delete' => '<span class="trash"><a class="em-bookings-delete" href="' . em_add_get_params($url, array('action' => 'bookings_delete', 'booking_id' => $EM_Booking->booking_id)) . '">' . __('Delete', 'dbem') . '</a></span>', 'edit' => '<a class="em-bookings-edit" href="' . em_add_get_params($EM_Booking->get_event()->get_bookings_url(), array('booking_id' => $EM_Booking->booking_id, 'em_ajax' => null, 'em_obj' => null)) . '">' . __('Edit/View', 'dbem') . '</a>');
             break;
         case 2:
             $booking_actions = array('approve' => '<a class="em-bookings-approve" href="' . em_add_get_params($url, array('action' => 'bookings_approve', 'booking_id' => $EM_Booking->booking_id)) . '">' . __('Approve', 'dbem') . '</a>', 'delete' => '<span class="trash"><a class="em-bookings-delete" href="' . em_add_get_params($url, array('action' => 'bookings_delete', 'booking_id' => $EM_Booking->booking_id)) . '">' . __('Delete', 'dbem') . '</a></span>', 'edit' => '<a class="em-bookings-edit" href="' . em_add_get_params($EM_Booking->get_event()->get_bookings_url(), array('booking_id' => $EM_Booking->booking_id, 'em_ajax' => null, 'em_obj' => null)) . '">' . __('Edit/View', 'dbem') . '</a>');
             break;
         case 3:
             $booking_actions = array('approve' => '<a class="em-bookings-approve" href="' . em_add_get_params($url, array('action' => 'bookings_approve', 'booking_id' => $EM_Booking->booking_id)) . '">' . __('Approve', 'dbem') . '</a>', 'delete' => '<span class="trash"><a class="em-bookings-delete" href="' . em_add_get_params($url, array('action' => 'bookings_delete', 'booking_id' => $EM_Booking->booking_id)) . '">' . __('Delete', 'dbem') . '</a></span>', 'edit' => '<a class="em-bookings-edit" href="' . em_add_get_params($EM_Booking->get_event()->get_bookings_url(), array('booking_id' => $EM_Booking->booking_id, 'em_ajax' => null, 'em_obj' => null)) . '">' . __('Edit/View', 'dbem') . '</a>');
             break;
         case 4:
             $booking_actions = apply_filters('em_bookings_table_booking_actions_4', array('delete' => '<span class="trash"><a class="em-bookings-delete" href="' . em_add_get_params($url, array('action' => 'bookings_delete', 'booking_id' => $EM_Booking->booking_id)) . '">' . __('Delete', 'dbem') . '</a></span>'), $EM_Booking);
             break;
         case 5:
             $booking_actions = apply_filters('em_bookings_table_booking_actions_5', array('delete' => '<span class="trash"><a class="em-bookings-delete" href="' . em_add_get_params($url, array('action' => 'bookings_delete', 'booking_id' => $EM_Booking->booking_id)) . '">' . __('Delete', 'dbem') . '</a></span>'), $EM_Booking);
             break;
         default:
             $booking_actions = apply_filters('em_bookings_table_booking_actions_' . $EM_Booking->booking_status, array(), $EM_Booking);
             break;
     }
     if (!get_option('dbem_bookings_approval')) {
         unset($booking_actions['unapprove']);
     }
     return apply_filters('em_bookings_table_cols_col_action', $booking_actions, $EM_Booking);
 }
 /**
  * Returns a formatted multi-dimensional associative array of booking form and user information for a specific booking (not including attendees).
  * example : array('booking' => array('Label'=>'Value', 'Label 2'=>'Value 2'), 'registration' => array(...)...);
  * @param EM_Booking $EM_Booking
  */
 public static function get_booking_data($EM_Booking, $include_registration_info = false)
 {
     $booking_data = array('booking' => array());
     if ($include_registration_info) {
         $booking_data['registration'] = array();
     }
     if (is_array($EM_Booking->booking_meta['booking']) || $include_registration_info && is_array($EM_Booking->booking_meta['registration'])) {
         $EM_Form = self::get_form($EM_Booking->get_event());
         foreach ($EM_Form->form_fields as $fieldid => $field) {
             $input_value = $field_value = isset($EM_Booking->booking_meta['booking'][$fieldid]) ? $EM_Booking->booking_meta['booking'][$fieldid] : 'n/a';
             if (!array_key_exists($fieldid, $EM_Form->user_fields) && !in_array($fieldid, array('user_email', 'user_name')) && $field['type'] != 'html') {
                 if (in_array($field['type'], array('date', 'time')) && $input_value == 'n/a') {
                     $input_value = '';
                 }
                 $booking_data['booking'][$field['label']] = $EM_Form->get_formatted_value($field, $input_value);
             } elseif ($field['type'] != 'html') {
                 $booking_data['registration'][$field['label']] = $EM_Form->get_formatted_value($field, $input_value);
             }
         }
     }
     return $booking_data;
 }
 /**
  * Adds relevant actions to booking shown in the bookings table
  * @param EM_Booking $EM_Booking
  */
 function bookings_table_actions($actions, $EM_Booking)
 {
     return array('approve' => '<a class="em-bookings-approve em-bookings-approve-offline" href="' . em_add_get_params($_SERVER['REQUEST_URI'], array('action' => 'bookings_approve', 'booking_id' => $EM_Booking->booking_id)) . '">' . __('Approve', 'dbem') . '</a>', 'delete' => '<span class="trash"><a class="em-bookings-delete" href="' . em_add_get_params($_SERVER['REQUEST_URI'], array('action' => 'bookings_delete', 'booking_id' => $EM_Booking->booking_id)) . '">' . __('Delete', 'dbem') . '</a></span>', 'edit' => '<a class="em-bookings-edit" href="' . em_add_get_params($EM_Booking->get_event()->get_bookings_url(), array('booking_id' => $EM_Booking->booking_id, 'em_ajax' => null, 'em_obj' => null)) . '">' . __('Edit/View', 'dbem') . '</a>');
 }
 /**
  * Retreive the authorize_aim vars needed to send to the gateway to proceed with payment
  * @param EM_Booking $EM_Booking
  */
 function authorize_and_capture($EM_Booking)
 {
     global $EM_Notices;
     $sale = $this->get_api();
     //Get transaction ID for authorization/capture
     $sale->amount = $amount = $EM_Booking->get_price(false, false, true);
     $sale->exp_date = $_REQUEST['x_exp_date_month'] . '/' . $_REQUEST['x_exp_date_year'];
     $sale->card_num = $_REQUEST['x_card_num'];
     $sale->card_code = $_REQUEST['x_card_code'];
     //Email Info
     $sale->email_customer = get_option('em_' . $this->gateway . '_email_customer', 0) ? '1' : '0';
     //for later
     $sale->header_email_receipt = get_option('em_' . $this->gateway . '_header_email_receipt');
     $sale->footer_email_receipt = get_option('em_' . $this->gateway . '_footer_email_receipt');
     //Order Info
     $sale->invoice_num = $EM_Booking->booking_id;
     $sale->description = preg_replace('/[^a-zA-Z0-9\\s]/i', "", $EM_Booking->get_event()->event_name);
     //clean event name
     //Customer Info
     $sale->email = $EM_Booking->get_person()->user_email;
     $sale->customer_ip = $_SERVER['REMOTE_ADDR'];
     $sale->cust_id = get_option('dbem_bookings_registration_disable') ? 'booking-' . $EM_Booking->booking_id : 'user-' . $EM_Booking->get_person()->ID;
     //Address Info
     $names = explode(' ', $EM_Booking->get_person()->get_name());
     if (!empty($names[0])) {
         $sale->first_name = array_shift($names);
     }
     if (implode(' ', $names) != '') {
         $sale->last_name = implode(' ', $names);
     }
     //address slightly special address field
     $address = '';
     if (EM_Gateways::get_customer_field('address', $EM_Booking) != '') {
         $address = EM_Gateways::get_customer_field('address', $EM_Booking);
     }
     if (EM_Gateways::get_customer_field('address_2', $EM_Booking) != '') {
         $address .= ', ' . EM_Gateways::get_customer_field('address_2', $EM_Booking);
     }
     if (!empty($address)) {
         $sale->address = substr($address, 0, 60);
     }
     //cut off at 60 characters
     if (EM_Gateways::get_customer_field('city', $EM_Booking) != '') {
         $sale->city = EM_Gateways::get_customer_field('city', $EM_Booking);
     }
     if (EM_Gateways::get_customer_field('state', $EM_Booking) != '') {
         $sale->state = EM_Gateways::get_customer_field('state', $EM_Booking);
     }
     if (EM_Gateways::get_customer_field('zip', $EM_Booking) != '') {
         $sale->zip = EM_Gateways::get_customer_field('zip', $EM_Booking);
     }
     if (EM_Gateways::get_customer_field('country', $EM_Booking) != '') {
         $countries = em_get_countries();
         $sale->country = $countries[EM_Gateways::get_customer_field('country', $EM_Booking)];
     }
     if (EM_Gateways::get_customer_field('phone', $EM_Booking) != '') {
         $sale->phone = EM_Gateways::get_customer_field('phone', $EM_Booking);
     }
     if (EM_Gateways::get_customer_field('fax', $EM_Booking) != '') {
         $sale->fax = EM_Gateways::get_customer_field('fax', $EM_Booking);
     }
     if (EM_Gateways::get_customer_field('company', $EM_Booking) != '') {
         $sale->company = EM_Gateways::get_customer_field('company', $EM_Booking);
     }
     //Itemized Billing
     $tax_enabled = get_option('dbem_bookings_tax') > 0 ? 'Y' : 'N';
     foreach ($EM_Booking->get_tickets_bookings()->tickets_bookings as $EM_Ticket_Booking) {
         $price = round($EM_Ticket_Booking->get_price() / $EM_Ticket_Booking->get_spaces(), 2);
         if ($price > 0) {
             $ticket_name = substr($EM_Ticket_Booking->get_ticket()->ticket_name, 0, 31);
             $sale->addLineItem($EM_Ticket_Booking->get_ticket()->ticket_id, $ticket_name, $EM_Ticket_Booking->get_ticket()->ticket_description, $EM_Ticket_Booking->get_spaces(), $price, $tax_enabled);
         }
     }
     if ($tax_enabled == 'Y') {
         $sale->tax = number_format($EM_Booking->get_price_taxes(), 2);
     }
     //Add discounts to itemized billing
     $discount = $EM_Booking->get_price_discounts_amount('pre') + $EM_Booking->get_price_discounts_amount('post');
     if ($discount > 0) {
         $sale->addLineItem(0, __('Discount', 'em-pro'), '', 1, $discount, 'N');
     }
     //Get Payment
     $sale = apply_filters('em_gateawy_authorize_aim_sale_var', $sale, $EM_Booking, $this);
     $response = $sale->authorizeAndCapture();
     //Handle result
     $result = $response->approved == true;
     if ($result) {
         $EM_Booking->booking_meta[$this->gateway] = array('txn_id' => $response->transaction_id, 'amount' => $amount);
         $this->record_transaction($EM_Booking, $amount, 'USD', date('Y-m-d H:i:s', current_time('timestamp')), $response->transaction_id, 'Completed', '');
     } else {
         $EM_Booking->add_error($response->response_reason_text);
     }
     //Return transaction_id or false
     return apply_filters('em_gateway_authorize_aim_authorize', $result, $EM_Booking, $this);
 }
예제 #11
0
 /**
  * @param EM_Booking $EM_Booking
  * @return mixed
  */
 function get_booking_actions($EM_Booking)
 {
     $booking_actions = array();
     $url = $EM_Booking->get_event()->get_bookings_url();
     switch ($EM_Booking->booking_status) {
         case 0:
             //pending
             if (get_option('dbem_bookings_approval')) {
                 $booking_actions = array('approve' => '<a class="em-bookings-approve" href="' . em_add_get_params($url, array('action' => 'bookings_approve', 'booking_id' => $EM_Booking->booking_id)) . '">' . __('Approve', 'dbem') . '</a>', 'reject' => '<a class="em-bookings-reject" href="' . em_add_get_params($url, array('action' => 'bookings_reject', 'booking_id' => $EM_Booking->booking_id)) . '">' . __('Reject', 'dbem') . '</a>', 'delete' => '<span class="trash"><a class="em-bookings-delete" href="' . em_add_get_params($url, array('action' => 'bookings_delete', 'booking_id' => $EM_Booking->booking_id)) . '">' . __('Delete', 'dbem') . '</a></span>', 'edit' => '<a class="em-bookings-edit" href="' . em_add_get_params($EM_Booking->get_event()->get_bookings_url(), array('booking_id' => $EM_Booking->booking_id, 'em_ajax' => null, 'em_obj' => null)) . '">' . __('Edit/View', 'dbem') . '</a>');
                 break;
             }
             //if approvals are off, treat as a 1
         //if approvals are off, treat as a 1
         case 1:
             //approved
             $booking_actions = array('unapprove' => '<a class="em-bookings-unapprove" href="' . em_add_get_params($url, array('action' => 'bookings_unapprove', 'booking_id' => $EM_Booking->booking_id)) . '">' . __('Unapprove', 'dbem') . '</a>', 'reject' => '<a class="em-bookings-reject" href="' . em_add_get_params($url, array('action' => 'bookings_reject', 'booking_id' => $EM_Booking->booking_id)) . '">' . __('Reject', 'dbem') . '</a>', 'delete' => '<span class="trash"><a class="em-bookings-delete" href="' . em_add_get_params($url, array('action' => 'bookings_delete', 'booking_id' => $EM_Booking->booking_id)) . '">' . __('Delete', 'dbem') . '</a></span>', 'edit' => '<a class="em-bookings-edit" href="' . em_add_get_params($EM_Booking->get_event()->get_bookings_url(), array('booking_id' => $EM_Booking->booking_id, 'em_ajax' => null, 'em_obj' => null)) . '">' . __('Edit/View', 'dbem') . '</a>');
             break;
         case 2:
             //rejected
             $booking_actions = array('approve' => '<a class="em-bookings-approve" href="' . em_add_get_params($url, array('action' => 'bookings_approve', 'booking_id' => $EM_Booking->booking_id)) . '">' . __('Approve', 'dbem') . '</a>', 'delete' => '<span class="trash"><a class="em-bookings-delete" href="' . em_add_get_params($url, array('action' => 'bookings_delete', 'booking_id' => $EM_Booking->booking_id)) . '">' . __('Delete', 'dbem') . '</a></span>', 'edit' => '<a class="em-bookings-edit" href="' . em_add_get_params($EM_Booking->get_event()->get_bookings_url(), array('booking_id' => $EM_Booking->booking_id, 'em_ajax' => null, 'em_obj' => null)) . '">' . __('Edit/View', 'dbem') . '</a>');
             break;
         case 3:
             //cancelled
         //cancelled
         case 4:
             //awaiting online payment - similar to pending but always needs approval in EM Free
         //awaiting online payment - similar to pending but always needs approval in EM Free
         case 5:
             //awaiting payment - similar to pending but always needs approval in EM Free
             $booking_actions = array('approve' => '<a class="em-bookings-approve" href="' . em_add_get_params($url, array('action' => 'bookings_approve', 'booking_id' => $EM_Booking->booking_id)) . '">' . __('Approve', 'dbem') . '</a>', 'delete' => '<span class="trash"><a class="em-bookings-delete" href="' . em_add_get_params($url, array('action' => 'bookings_delete', 'booking_id' => $EM_Booking->booking_id)) . '">' . __('Delete', 'dbem') . '</a></span>', 'edit' => '<a class="em-bookings-edit" href="' . em_add_get_params($EM_Booking->get_event()->get_bookings_url(), array('booking_id' => $EM_Booking->booking_id, 'em_ajax' => null, 'em_obj' => null)) . '">' . __('Edit/View', 'dbem') . '</a>');
             break;
     }
     if (!get_option('dbem_bookings_approval')) {
         unset($booking_actions['unapprove']);
     }
     $booking_actions = apply_filters('em_bookings_table_booking_actions_' . $EM_Booking->booking_status, $booking_actions, $EM_Booking);
     return apply_filters('em_bookings_table_cols_col_action', $booking_actions, $EM_Booking);
 }
예제 #12
0
/**
 * @param boolean $result
 * @param EM_Booking $EM_Booking
 * @return boolean
 */
function bp_em_record_activity_booking_save($result, $EM_Booking)
{
    /* @todo this isn't good at detecting status changes. */
    if (!empty($EM_Booking->event_id) && $result) {
        $action_type = 'new_booking';
        if (!empty($EM_Booking->last_bp_activity) && $EM_Booking->last_bp_activity == $action_type) {
            return $result;
        }
        //prevent duplicates
        $EM_Booking->last_bp_activity = $action_type;
        $rejected_statuses = array(0, 2, 3);
        //these statuses apply to rejected/cancelled bookings
        $user = $EM_Booking->get_person();
        $member_link = bp_core_get_user_domain($user->ID);
        $user_link = "<a href='" . $member_link . "/'>" . $user->display_name . "</a>";
        $event_link = $EM_Booking->get_event()->output('#_EVENTLINK');
        $status = $EM_Booking->booking_status;
        $EM_Event = $EM_Booking->get_event();
        if (empty($EM_Event->group_id)) {
            if ($status == 1 || !get_option('dbem_bookings_approval') && $status < 2) {
                $action = sprintf(__('%s is attending %s.', 'events-manager'), $user_link, $event_link);
            } elseif (($EM_Booking->previous_status == 1 || !get_option('dbem_bookings_approval') && $EM_Booking->previous_status < 2) && in_array($status, $rejected_statuses)) {
                $action = sprintf(__('%s will not be attending %s anymore.', 'events-manager'), $user_link, $event_link);
                //$action_type = 'cancelled_booking';
            }
        } else {
            $group = new BP_Groups_Group($EM_Event->group_id);
            $group_link = '<a href="' . bp_get_group_permalink($group) . '">' . bp_get_group_name($group) . '</a>';
            if ($status == 1 || !get_option('dbem_bookings_approval') && $status < 2) {
                $action = sprintf(__('%s is attending %s of the group %s.', 'events-manager'), $user_link, $event_link, $group_link);
            } elseif (($EM_Booking->previous_status == 1 || !get_option('dbem_bookings_approval') && $EM_Booking->previous_status < 2) && in_array($status, $rejected_statuses)) {
                $action = sprintf(__('%s will not be attending %s of group %s anymore.', 'events-manager'), $user_link, $event_link, $group_link);
                //$action_type = 'cancelled_booking';
            }
        }
        if (!empty($action)) {
            if (empty($EM_Event->group_id)) {
                bp_em_record_activity(array('user_id' => $EM_Booking->person->ID, 'action' => $action, 'primary_link' => $EM_Event->output('#_EVENTURL'), 'type' => $action_type, 'item_id' => $EM_Event->event_id, 'secondary_item_id' => $EM_Booking->booking_id, 'hide_sitewide' => $EM_Event->event_private));
            } else {
                //tis a group event
                bp_em_record_activity(array('component' => 'groups', 'user_id' => $EM_Booking->person->ID, 'action' => $action, 'primary_link' => $EM_Event->output('#_EVENTURL'), 'type' => $action_type, 'item_id' => $EM_Event->group_id, 'secondary_item_id' => $EM_Booking->booking_id, 'hide_sitewide' => $EM_Event->event_private));
            }
        }
    }
    return $result;
}
예제 #13
0
 /**
  * @param boolean $result
  * @param EM_Booking $EM_Booking
  * @return boolean
  */
 public static function em_booking_get_post($result, $EM_Booking)
 {
     if (!empty($_REQUEST['coupon_code'])) {
         $EM_Coupon = EM_Coupons::event_get_coupon($_REQUEST['coupon_code'], $EM_Booking->get_event());
         if ($EM_Coupon === false && !empty($EM_Booking->booking_id)) {
             //if a previously saved booking, account for the fact it may not work
             $EM_Coupon = new EM_Coupon($EM_Booking->booking_meta['coupon']);
         }
         if ($EM_Coupon !== false) {
             $EM_Booking->booking_meta['coupon'] = $EM_Coupon->to_array();
             //we add an clean a coupon array here for the first time
             $EM_Booking->calculate_price();
             //refresh price
         } else {
             $EM_Booking->booking_meta['coupon'] = array('coupon_code' => $_REQUEST['coupon_code']);
             //will not validate later
         }
     }
     return apply_filters('em_coupons_em_booking_get_post', $result, $EM_Booking);
 }
 /**
  * Retreive the paypal pro vars needed to send to the gateway to proceed with payment
  * @param EM_Booking $EM_Booking
  */
 function processStripe($EM_Booking)
 {
     global $EM_Notices;
     if (empty($_POST['stripe_card_num'])) {
         $EM_Booking->add_error(__('Please enter credit card number', 'em-pro') . '"');
         return false;
     }
     if (empty($_POST['stripe_exp_date_month'])) {
         $EM_Booking->add_error(__('Please select expire month', 'em-pro') . '"');
         return false;
     }
     if (empty($_POST['stripe_exp_date_year'])) {
         $EM_Booking->add_error(__('Please select expire year', 'em-pro') . '"');
         return false;
     }
     if (empty($_POST['stripe_card_code'])) {
         $EM_Booking->add_error(__('Please enter CVV number', 'em-pro') . '"');
         return false;
     }
     if ($this->debug == 'yes') {
         // Send request to paypal
         EM_Pro::log(sprintf(__('Payment Processing Start here', 'emp_stripe')));
     }
     // Get the credit card details submitted by the form
     include "lib/Stripe.php";
     if ($this->debug == 'yes') {
         EM_Pro::log(sprintf(__('Payment Processing start after include library', 'emp_stripe')));
     }
     Stripe::setApiKey($this->SecretKey);
     if ($this->debug == 'yes') {
         EM_Pro::log(sprintf(__('Set Secret Key', 'emp_stripe')));
     }
     try {
         $amount = $EM_Booking->get_price(false, false, true);
         if ($this->debug == 'yes') {
             EM_Pro::log(sprintf(__('Credit Card token create', 'emp_stripe')));
         }
         $token_id = Stripe_Token::create(array("card" => array("number" => $_POST['stripe_card_num'], "exp_month" => $_POST['stripe_exp_date_month'], "exp_year" => $_POST['stripe_exp_date_year'], "cvc" => $_POST['stripe_card_code'])));
         if ($this->debug == 'yes') {
             EM_Pro::log(sprintf(__('Token genreated ID : %s', 'emp_stripe'), print_r($token_id->id, true)));
         }
         //Email Info
         $email_customer = get_option('em_' . $this->gateway . '_header_email_customer', 0) ? '1' : '0';
         //for later
         $header_email_receipt = get_option('em_' . $this->gateway . '_header_email_receipt');
         $footer_email_receipt = get_option('em_' . $this->gateway . '_footer_email_receipt');
         //Order Info
         $booking_id = $EM_Booking->booking_id;
         $booking_description = preg_replace('/[^a-zA-Z0-9\\s]/i', "", $EM_Booking->get_event()->event_name);
         //clean event name
         $charge = Stripe_Charge::create(array("amount" => $amount * 100, "currency" => get_option('dbem_bookings_currency', 'USD'), "card" => $token_id->id, "metadata" => array("order_id" => $booking_id), "description" => $booking_description));
         if ($this->debug == 'yes') {
             EM_Pro::log(sprintf(__('Return Response from Stripe: %s', 'emp_stripe'), print_r($charge, true)));
         }
         if ($token_id->id != '') {
             if ($charge->paid == true) {
                 if ($this->debug == 'yes') {
                     EM_Pro::log(sprintf(__('Payment Received...', 'emp_stripe')));
                 }
                 $EM_Booking->booking_meta[$this->gateway] = array('txn_id' => $charge->id, 'amount' => $amount);
                 $this->record_transaction($EM_Booking, $amount, get_option('dbem_bookings_currency', 'USD'), date('Y-m-d H:i:s', current_time('timestamp')), $charge->id, 'Completed', '');
                 $result = true;
             } else {
                 if ($this->debug == 'yes') {
                     EM_Pro::log(sprintf(__('Stripe payment failed. Payment declined.', 'emp_stripe')));
                 }
                 $EM_Booking->add_error('Stripe payment failed. Payment declined.');
                 $result = false;
             }
         } else {
             if ($this->debug == 'yes') {
                 EM_Pro::log(sprintf(__('Stripe payment failed. Payment declined. Please Check your Admin settings', 'emp_stripe')));
             }
             $EM_Booking->add_error('Stripe payment failed. Payment declined. Please Check your Admin settings');
         }
         //Return transaction_id or false
         return apply_filters('em_gateway_stripe_capture', $result, $EM_Booking, $this);
     } catch (Exception $e) {
         $EM_Booking->add_error(__('Connection error:', 'em-pro') . ': "' . $e->getMessage() . '"');
         return false;
     }
 }
	/**
	* attempt to process payment
	* @param EM_Booking $EM_Booking
	* @return boolean
	*/
	public function processPayment($EM_Booking){
		// process the payment
		$isLiveSite = !(get_option('em_' . EM_EWAY_GATEWAY . '_mode') == 'sandbox');
		if (!$isLiveSite && get_option('em_' . EM_EWAY_GATEWAY . '_test_force')) {
			$customerID = EWAY_PAYMENTS_TEST_CUSTOMER;
		}
		else {
			$customerID = get_option('em_' . EM_EWAY_GATEWAY . '_cust_id');
		}

		if (get_option('em_' . EM_EWAY_GATEWAY . '_stored')) {
			$eway = new EwayPaymentsStoredPayment($customerID, $isLiveSite);
		}
		else {
			$eway = new EwayPaymentsPayment($customerID, $isLiveSite);
		}

		$eway->invoiceDescription			= $EM_Booking->get_event()->event_name;
		//~ $eway->invoiceDescription		= $EM_Booking->output('#_BOOKINGTICKETDESCRIPTION');
		$eway->invoiceReference				= $EM_Booking->booking_id;						// customer invoice reference
		$eway->transactionNumber			= $EM_Booking->booking_id;						// transaction reference
		$eway->cardHoldersName				= self::getPostValue('x_card_name');
		$eway->cardNumber					= strtr(self::getPostValue('x_card_num'), array(' ' => '', '-' => ''));
		$eway->cardExpiryMonth				= self::getPostValue('x_exp_date_month');
		$eway->cardExpiryYear				= self::getPostValue('x_exp_date_year');
		$eway->cardVerificationNumber		= self::getPostValue('x_card_code');
		$eway->emailAddress					= $EM_Booking->get_person()->user_email;
		$eway->postcode						= self::getPostValue('zip');

		// for Beagle (free) security
		if (get_option('em_' . EM_EWAY_GATEWAY . '_beagle')) {
			$eway->customerCountryCode		= EM_Gateways::get_customer_field('country', $EM_Booking);
		}

		// attempt to split name into parts, and hope to not offend anyone!
		$names = explode(' ', $EM_Booking->get_person()->get_name());
		if (!empty($names[0])) {
			$eway->firstName				= array_shift($names);		// remove first name from array
		}
		$eway->lastName						= trim(implode(' ', $names));

		// use cardholder name for last name if no customer name entered
		if (empty($eway->firstName) && empty($eway->lastName)) {
			$eway->lastName = $eway->cardHoldersName;
		}

		// aggregate street, city, state, country into a single string
		$parts = array (
			EM_Gateways::get_customer_field('address', $EM_Booking),
			EM_Gateways::get_customer_field('address_2', $EM_Booking),
			EM_Gateways::get_customer_field('city', $EM_Booking),
			EM_Gateways::get_customer_field('state', $EM_Booking),
			self::getCountryName(EM_Gateways::get_customer_field('country', $EM_Booking)),
		);
		$eway->address						= implode(', ', array_filter($parts, 'strlen'));

		// if live, pass through amount exactly, but if using test site, round up to whole dollars or eWAY will fail
		$amount = $EM_Booking->get_price(false, false, true);
		$amount = apply_filters('em_eway_amount', $amount, $EM_Booking);
		$eway->amount						= $isLiveSite ? $amount : ceil($amount);

		// allow plugins/themes to modify invoice description and reference, and set option fields
		$eway->invoiceDescription			= apply_filters('em_eway_invoice_desc', $eway->invoiceDescription, $EM_Booking);
		$eway->invoiceReference				= apply_filters('em_eway_invoice_ref', $eway->invoiceReference, $EM_Booking);
		$eway->option1						= apply_filters('em_eway_option1', '', $EM_Booking);
		$eway->option2						= apply_filters('em_eway_option2', '', $EM_Booking);
		$eway->option3						= apply_filters('em_eway_option3', '', $EM_Booking);

		// Get Payment
		try {
			$result = false;
			$response = $eway->processPayment();

			if ($response->status) {
				// transaction was successful, so record transaction number and continue
				$EM_Booking->booking_meta[EM_EWAY_GATEWAY] = array(
					'txn_id'	=> $response->transactionNumber,
					'authcode'	=> $response->authCode,
					'amount'	=> $response->amount,
				);

				$notes = array();
				if (!empty($response->authCode)) {
					$notes[] = 'Authcode: ' . $response->authCode;
				}
				if (!empty($response->beagleScore)) {
					$notes[] = 'Beagle score: ' . $response->beagleScore;
				}
				$note = implode("\n", $notes);

				$status = get_option('em_' . EM_EWAY_GATEWAY . '_stored') ? 'Pending' : 'Completed';
				$this->record_transaction($EM_Booking, $response->amount, 'AUD', date('Y-m-d H:i:s', current_time('timestamp')), $response->transactionNumber, $status, $note);
				$result = true;
			}
			else {
				// transaction was unsuccessful, so record the error
				$EM_Booking->add_error($response->error);
			}
		}
		catch (Exception $e) {
			// an exception occured, so record the error
			$EM_Booking->add_error($e->getMessage());
			return;
		}

		// Return status
		return apply_filters('em_gateway_eway_authorize', $result, $EM_Booking, $this);
	}