/**
  * 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;
 }
 /**
  * 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);
 }
예제 #3
0
 /**
  * Triggered by the em_booking_add_yourgateway action, modifies the booking status if the event isn't free and also adds a filter to modify user feedback returned.
  * @param EM_Event $EM_Event
  * @param EM_Booking $EM_Booking
  * @param boolean $post_validation
  */
 function booking_add($EM_Event, $EM_Booking, $post_validation = false)
 {
     global $wpdb, $wp_rewrite, $EM_Notices;
     add_filter('em_action_booking_add', array(&$this, 'booking_form_feedback'), 1, 2);
     //modify the payment return
     add_filter('em_action_emp_checkout', array(&$this, 'booking_form_feedback'), 1, 2);
     //modify the payment return
     if ($EM_Booking->get_price() > 0) {
         $EM_Booking->booking_status = $this->status;
         //status 4 = awaiting online payment
     }
 }
 /**
  * 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;
     }
 }
 /**
  * Hooks into the em_booking_save filter and checks whether a partial or full payment has been submitted
  * @param boolean $result
  * @param EM_Booking $EM_Booking
  */
 function em_booking_save($result, $EM_Booking)
 {
     if ($result && !empty($_REQUEST['manual_booking']) && wp_verify_nonce($_REQUEST['manual_booking'], 'em_manual_booking_' . $_REQUEST['event_id'])) {
         remove_filter('em_booking_set_status', array(&$this, 'em_booking_set_status'), 1, 2);
         if (!empty($_REQUEST['payment_full'])) {
             $price = !empty($_REQUEST['payment_amount']) && is_numeric($_REQUEST['payment_amount']) ? $_REQUEST['payment_amount'] : $EM_Booking->get_price(false, false, true);
             $this->record_transaction($EM_Booking, $price, get_option('dbem_bookings_currency'), current_time('mysql'), '', 'Completed', __('Manual booking.', 'em-pro'));
             $EM_Booking->set_status(1, false);
         } elseif (!empty($_REQUEST['payment_amount']) && is_numeric($_REQUEST['payment_amount'])) {
             $this->record_transaction($EM_Booking, $_REQUEST['payment_amount'], get_option('dbem_bookings_currency'), current_time('mysql'), '', 'Completed', __('Manual booking.', 'em-pro'));
             if ($_REQUEST['payment_amount'] >= $EM_Booking->get_price(false, false, true)) {
                 $EM_Booking->set_status(1, false);
             }
         }
         add_filter('em_booking_set_status', array(&$this, 'em_booking_set_status'), 1, 2);
         $add_txt = '<a href=\\"' . wp_get_referer() . '\\">' . __('Add another booking', 'em-pro') . '</a>';
         add_filter('em_action_booking_add', create_function('$feedback', '$feedback["message"] = $feedback["message"] . "<p>' . $add_txt . '</p>"; return $feedback;'));
     }
     return $result;
 }
	/**
	* Intercepts return data after a booking has been made and adds eway vars, modifies feedback message.
	* @param array $return
	* @param EM_Booking $EM_Booking
	* @return array
	*/
	public function booking_form_feedback( $return, $EM_Booking = false ){
		// Double check $EM_Booking is an EM_Booking object and that we have a booking awaiting payment.
		if (!empty($return['result'])) {
			if (!empty($EM_Booking->booking_meta['gateway']) && $EM_Booking->booking_meta['gateway'] == EM_EWAY_GATEWAY && $EM_Booking->get_price() > 0) {
				$return['message'] = get_option('em_' . EM_EWAY_GATEWAY . '_booking_feedback');
			}
			else {
				// returning a free message
				$return['message'] = get_option('em_' . EM_EWAY_GATEWAY . '_booking_feedback_free');
			}
		}
		return $return;
	}