public function test_save_and_clean_billing_info_for_payment_method()
 {
     $pm = EE_Payment_Method::new_instance(array('PMD_type' => 'Aim'));
     $pm->save();
     //reset the country model because it caches its list of countries which is used when
     //making most billing forms
     EEM_Country::reset();
     $form = $pm->type_obj()->billing_form();
     $form_name = $form->name();
     $form_values = array('first_name' => 'e', 'last_name' => 'e', 'email' => '*****@*****.**', 'address' => '123', 'address2' => '', 'city' => 'someville', 'state' => 12, 'country' => 'US', 'zip' => '1235', 'phone' => '9991231234', 'credit_card' => '4007000000027', 'exp_month' => '12', 'exp_year' => '2020', 'cvv' => '123');
     $form->receive_form_submission(array($form_name => $form_values));
     $this->assertTrue($form->is_valid(), 'error was: ' . $form->get_validation_error_string());
     $p = $this->new_model_obj_with_dependencies('Payment', array('PMD_ID' => $pm->ID()));
     $reg = $this->new_model_obj_with_dependencies('Registration', array('TXN_ID' => $p->TXN_ID()));
     $att = $reg->attendee();
     $att->save_and_clean_billing_info_for_payment_method($form, $pm);
     //ok so now it should ahve been saved. Let's verify that
     $billing_info_form = $att->billing_info_for_payment_method($pm);
     $this->assertInstanceOf('EE_Billing_Attendee_Info_Form', $billing_info_form);
     //it should ahve been cleaned too, so lets tweak teh form values ot what they should be
     $form_values['credit_card'] = 'XXXXXXXXX0027';
     $form_values['cvv'] = 'XXX';
     $form_values['exp_month'] = '';
     $form_values['exp_year'] = 0;
     foreach ($form_values as $input_name => $value) {
         $input = $billing_info_form->get_input($input_name);
         $this->assertInstanceOf('EE_Form_Input_Base', $input);
         $this->assertEquals($value, $input->raw_value(), $input_name);
     }
 }
 /**
  *
  * @param EE_Transaction       $transaction
  * @param float                $amount
  * @param EE_Billing_Info_Form $billing_info
  * @param string               $return_url
  * @param string                 $fail_url
  * @param string               $method
  * @param bool           $by_admin
  * @return EE_Payment
  * @throws EE_Error
  */
 function process_payment(EE_Transaction $transaction, $amount = null, $billing_info = null, $return_url = null, $fail_url = '', $method = 'CART', $by_admin = false)
 {
     // @todo: add surcharge for the payment method, if any
     if ($this->_gateway) {
         //there is a gateway, so we're going to make a payment object
         //but wait! do they already have a payment in progress that we thought was failed?
         $duplicate_properties = array('STS_ID' => EEM_Payment::status_id_failed, 'TXN_ID' => $transaction->ID(), 'PMD_ID' => $this->_pm_instance->ID(), 'PAY_source' => $method, 'PAY_amount' => $amount !== null ? $amount : $transaction->remaining(), 'PAY_gateway_response' => null);
         $payment = EEM_Payment::instance()->get_one(array($duplicate_properties));
         //if we didn't already have a payment in progress for the same thing,
         //then we actually want to make a new payment
         if (!$payment instanceof EE_Payment) {
             $payment = EE_Payment::new_instance(array_merge($duplicate_properties, array('PAY_timestamp' => time(), 'PAY_txn_id_chq_nmbr' => null, 'PAY_po_number' => null, 'PAY_extra_accntng' => null, 'PAY_details' => null)));
         }
         //make sure the payment has been saved to show we started it, and so it has an ID should the gateway try to log it
         $payment->save();
         $billing_values = $this->_get_billing_values_from_form($billing_info);
         //  Offsite Gateway
         if ($this->_gateway instanceof EE_Offsite_Gateway) {
             $payment = $this->_gateway->set_redirection_info($payment, $billing_values, $return_url, EE_Config::instance()->core->txn_page_url(array('e_reg_url_link' => $transaction->primary_registration()->reg_url_link(), 'ee_payment_method' => $this->_pm_instance->slug())), $fail_url);
             $payment->save();
             //  Onsite Gateway
         } elseif ($this->_gateway instanceof EE_Onsite_Gateway) {
             $payment = $this->_gateway->do_direct_payment($payment, $billing_values);
             $payment->save();
         } else {
             throw new EE_Error(sprintf(__('Gateway for payment method type "%s" is "%s", not a subclass of either EE_Offsite_Gateway or EE_Onsite_Gateway, or null (to indicate NO gateway)', 'event_espresso'), get_class($this), gettype($this->_gateway)));
         }
     } else {
         // no gateway provided
         // there is no payment. Must be an offline gateway
         // create a payment object anyways, but dont save it
         $payment = EE_Payment::new_instance(array('STS_ID' => EEM_Payment::status_id_pending, 'TXN_ID' => $transaction->ID(), 'PMD_ID' => $transaction->payment_method_ID(), 'PAY_amount' => 0.0, 'PAY_timestamp' => time()));
     }
     // if there is billing info, clean it and save it now
     if ($billing_info instanceof EE_Billing_Attendee_Info_Form) {
         $this->_save_billing_info_to_attendee($billing_info, $transaction);
     }
     return $payment;
 }
Ejemplo n.º 3
0
 function espresso_replace_invoice_shortcodes($content)
 {
     $EE = EE_Registry::instance();
     //Create the logo
     $invoice_logo_url = $this->invoice_payment_method->get_extra_meta('pdf_logo_image', TRUE, $EE->CFG->organization->logo_url);
     if (!empty($invoice_logo_url)) {
         $image_size = getimagesize($invoice_logo_url);
         $invoice_logo_image = '<img class="logo screen" src="' . $invoice_logo_url . '" ' . $image_size[3] . ' alt="logo" /> ';
     } else {
         $invoice_logo_image = '';
     }
     $SearchValues = array("[organization]", "[registration_code]", "[transaction_id]", "[name]", "[base_url]", "[download_link]", "[invoice_logo_image]", "[street]", "[city]", "[state]", "[zip]", "[email]", "[vat]", "[registration_date]", "[instructions]");
     $primary_attendee = $this->transaction->primary_registration()->attendee();
     $org_state = EE_Registry::instance()->load_model('State')->get_one_by_ID($EE->CFG->organization->STA_ID);
     if ($org_state) {
         $org_state_name = $org_state->name();
     } else {
         $org_state_name = '';
     }
     $ReplaceValues = array($EE->CFG->organization->get_pretty('name'), $this->registration->reg_code(), $this->transaction->ID(), $primary_attendee->full_name(), is_dir(EVENT_ESPRESSO_GATEWAY_DIR . '/invoice') ? EVENT_ESPRESSO_GATEWAY_URL . 'Invoice/lib/templates/' : EE_GATEWAYS_URL . 'Invoice/lib/templates/', $this->registration->invoice_url(), $invoice_logo_image, empty($EE->CFG->organization->address_2) ? $EE->CFG->organization->get_pretty('address_1') : $EE->CFG->organization->get_pretty('address_1') . '<br>' . $EE->CFG->organization->get_pretty('address_2'), $EE->CFG->organization->get_pretty('city'), $org_state_name, $EE->CFG->organization->get_pretty('zip'), $EE->CFG->organization->get_pretty('email'), $EE->CFG->organization->vat, $this->registration->get_i18n_datetime('REG_date', get_option('date_format')), $this->invoice_payment_method->get_extra_meta('pdf_instructions', TRUE));
     return str_replace($SearchValues, $ReplaceValues, $content);
 }
 /**
  * 		generates HTML for the Registration main meta box
  *		@access public
  *		@return void
  */
 public function _reg_details_meta_box()
 {
     EEH_Autoloader::register_line_item_display_autoloaders();
     EEH_Autoloader::register_line_item_filter_autoloaders();
     EE_Registry::instance()->load_Helper('Line_Item');
     $transaction = $this->_registration->transaction() ? $this->_registration->transaction() : EE_Transaction::new_instance();
     $this->_session = $transaction->session_data();
     $filters = new EE_Line_Item_Filter_Collection();
     $filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
     $filters->add(new EE_Non_Zero_Line_Item_Filter());
     $line_item_filter_processor = new EE_Line_Item_Filter_Processor($filters, $transaction->total_line_item());
     $filtered_line_item_tree = $line_item_filter_processor->process();
     $this->_template_args['REG_ID'] = $this->_registration->ID();
     $line_item_display = new EE_Line_Item_Display('reg_admin_table', 'EE_Admin_Table_Registration_Line_Item_Display_Strategy');
     $this->_template_args['line_item_table'] = $line_item_display->display_line_item($filtered_line_item_tree, array('EE_Registration' => $this->_registration));
     $attendee = $this->_registration->attendee();
     $this->_template_args['view_transaction_button'] = EE_Registry::instance()->CAP->current_user_can('ee_read_transaction', 'espresso_transactions_view_transaction') ? EEH_Template::get_button_or_link(EE_Admin_Page::add_query_args_and_nonce(array('action' => 'view_transaction', 'TXN_ID' => $transaction->ID()), TXN_ADMIN_URL), __(' View Transaction'), 'button secondary-button right', 'dashicons dashicons-cart') : '';
     $this->_template_args['resend_registration_button'] = $attendee instanceof EE_Attendee && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'espresso_registrations_resend_registration') ? EEH_Template::get_button_or_link(EE_Admin_Page::add_query_args_and_nonce(array('action' => 'resend_registration', '_REG_ID' => $this->_registration->ID(), 'redirect_to' => 'view_registration'), REG_ADMIN_URL), __(' Resend Registration'), 'button secondary-button right', 'dashicons dashicons-email-alt') : '';
     $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
     $payment = $transaction->get_first_related('Payment');
     $payment = !$payment instanceof EE_Payment ? EE_Payment::new_instance() : $payment;
     $payment_method = $payment->get_first_related('Payment_Method');
     $payment_method = !$payment_method instanceof EE_Payment_Method ? EE_Payment_Method::new_instance() : $payment_method;
     $reg_status_class = 'status-' . $this->_registration->status_ID();
     $reg_details = array('payment_method' => $payment_method->name(), 'response_msg' => $payment->gateway_response(), 'registration_id' => $this->_registration->get('REG_code'), 'registration_session' => $this->_registration->session_ID(), 'ip_address' => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '', 'user_agent' => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '');
     if (isset($reg_details['registration_id'])) {
         $this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
         $this->_template_args['reg_details']['registration_id']['label'] = __('Registration ID', 'event_espresso');
         $this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
     }
     if (isset($reg_details['payment_method'])) {
         $this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
         $this->_template_args['reg_details']['payment_method']['label'] = __('Most Recent Payment Method', 'event_espresso');
         $this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
         $this->_template_args['reg_details']['response_msg']['value'] = $reg_details['response_msg'];
         $this->_template_args['reg_details']['response_msg']['label'] = __('Payment method response', 'event_espresso');
         $this->_template_args['reg_details']['response_msg']['class'] = 'regular-text';
     }
     $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
     $this->_template_args['reg_details']['registration_session']['label'] = __('Registration Session', 'event_espresso');
     $this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
     $this->_template_args['reg_details']['ip_address']['value'] = $reg_details['ip_address'];
     $this->_template_args['reg_details']['ip_address']['label'] = __('Registration placed from IP', 'event_espresso');
     $this->_template_args['reg_details']['ip_address']['class'] = 'regular-text';
     $this->_template_args['reg_details']['user_agent']['value'] = $reg_details['user_agent'];
     $this->_template_args['reg_details']['user_agent']['label'] = __('Registrant User Agent', 'event_espresso');
     $this->_template_args['reg_details']['user_agent']['class'] = 'large-text';
     $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'default', 'event_id' => $this->_registration->event_ID()), REG_ADMIN_URL);
     $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
     echo EEH_Template::display_template($template_path, $this->_template_args, TRUE);
 }
 /**
  * Processes a direct refund request, saves the payment, and updates the transaction appropriately.
  *
  * @param EE_Payment_Method $payment_method
  * @param EE_Payment        $payment_to_refund
  * @param array             $refund_info
  * @return EE_Payment
  * @throws \EE_Error
  */
 public function process_refund(EE_Payment_Method $payment_method, EE_Payment $payment_to_refund, $refund_info = array())
 {
     if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj()->supports_sending_refunds()) {
         $payment_method->type_obj()->process_refund($payment_to_refund, $refund_info);
         $this->update_txn_based_on_payment($payment_to_refund->transaction(), $payment_to_refund);
     }
     return $payment_to_refund;
 }
 /**
  * _activate_payment_method_button
  *
  * @access protected
  * @param \EE_Payment_Method $payment_method
  * @return \EE_Form_Section_Proper
  */
 protected function _activate_payment_method_button(EE_Payment_Method $payment_method)
 {
     $link_text_and_title = sprintf(__('Activate %1$s Payment Method?', 'event_espresso'), $payment_method->admin_name());
     return new EE_Form_Section_Proper(array('name' => 'activate_' . $payment_method->slug() . '_settings_form', 'html_id' => 'activate_' . $payment_method->slug() . '_settings_form', 'action' => '#', 'layout_strategy' => new EE_Admin_Two_Column_Layout(), 'subsections' => apply_filters('FHEE__Payments_Admin_Page___activate_payment_method_button__form_subsections', array(new EE_Form_Section_HTML(EEH_HTML::tr(EEH_HTML::th(EEH_HTML::label(__('Click to Activate ', 'event_espresso'))) . EEH_HTML::td(EEH_HTML::link(EE_Admin_Page::add_query_args_and_nonce(array('action' => 'activate_payment_method', 'payment_method_type' => $payment_method->type()), EE_PAYMENTS_ADMIN_URL), $link_text_and_title, $link_text_and_title, 'activate_' . $payment_method->slug(), 'espresso-button-green button-primary'))))), $payment_method)));
 }
 /**
  * Gets the postmeta key that holds this attendee's billing info for the
  * specified payment method
  * @param EE_Payment_Method $payment_method
  * @return string
  */
 public function get_billing_info_postmeta_name($payment_method)
 {
     if ($payment_method->type_obj() instanceof EE_PMT_Base) {
         return 'billing_info_' . $payment_method->type_obj()->system_name();
     } else {
         return NULL;
     }
 }
 /**
  * _get_return_url
  *
  * @access protected
  * @param \EE_Payment_Method $payment_method
  * @return string
  */
 protected function _get_return_url(EE_Payment_Method $payment_method)
 {
     $return_url = '';
     switch ($payment_method->type_obj()->payment_occurs()) {
         case EE_PMT_Base::offsite:
             $return_url = add_query_arg(array('action' => 'process_gateway_response', 'selected_method_of_payment' => $this->checkout->selected_method_of_payment, 'spco_txn' => $this->checkout->transaction->ID()), $this->reg_step_url());
             break;
         case EE_PMT_Base::onsite:
         case EE_PMT_Base::offline:
             $return_url = $this->checkout->next_step->reg_step_url();
             break;
     }
     return $return_url;
 }
 /**
  * 		generates HTML for the Registration main meta box
  *		@access public
  *		@return void
  */
 public function _reg_details_meta_box()
 {
     $transaction = $this->_registration->transaction() ? $this->_registration->transaction() : EE_Transaction::new_instance();
     $this->_session = $transaction->session_data();
     $this->_template_args['REG_ID'] = $this->_registration->ID();
     $this->_template_args['line_items'] = $transaction->get_many_related('Line_Item', array(array('LIN_type' => 'line-item')));
     $attendee = $this->_registration->attendee();
     // process taxes
     if ($transaction) {
         //get all "tax" line items for this transaction and we'll use them for the tax display.
         $taxes = $transaction->get_many_related('Line_Item', array(array('LIN_type' => EEM_Line_Item::type_tax)));
         $this->_template_args['taxes'] = !empty($taxes) ? $taxes : array();
     } else {
         $this->_template_args['taxes'] = array();
     }
     $this->_template_args['view_transaction_button'] = EE_Registry::instance()->CAP->current_user_can('ee_read_transaction', 'espresso_transactions_view_transaction') ? EEH_Template::get_button_or_link(EE_Admin_Page::add_query_args_and_nonce(array('action' => 'view_transaction', 'TXN_ID' => $transaction->ID()), TXN_ADMIN_URL), __(' View Transaction'), 'button secondary-button right', 'dashicons dashicons-cart') : '';
     $this->_template_args['resend_registration_button'] = $attendee instanceof EE_Attendee && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'espresso_registrations_resend_registration') ? EEH_Template::get_button_or_link(EE_Admin_Page::add_query_args_and_nonce(array('action' => 'resend_registration', '_REG_ID' => $this->_registration->ID(), 'redirect_to' => 'view_registration'), REG_ADMIN_URL), __(' Resend Registration'), 'button secondary-button right', 'dashicons dashicons-email-alt') : '';
     $this->_template_args['grand_total'] = EEH_Template::format_currency($transaction->total());
     $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
     $payment = $transaction->get_first_related('Payment');
     $payment = !$payment instanceof EE_Payment ? EE_Payment::new_instance() : $payment;
     $payment_method = $payment->get_first_related('Payment_Method');
     $payment_method = !$payment_method instanceof EE_Payment_Method ? EE_Payment_Method::new_instance() : $payment_method;
     $reg_status_class = 'status-' . $this->_registration->status_ID();
     $reg_details = array('payment_method' => $payment_method->name(), 'response_msg' => $payment->gateway_response(), 'registration_id' => $this->_registration->get('REG_code'), 'registration_session' => $this->_registration->session_ID(), 'ip_address' => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '', 'user_agent' => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '');
     if (isset($reg_details['registration_id'])) {
         $this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
         $this->_template_args['reg_details']['registration_id']['label'] = __('Registration ID', 'event_espresso');
         $this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
     }
     if (isset($reg_details['payment_method'])) {
         $this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
         $this->_template_args['reg_details']['payment_method']['label'] = __('Most Recent Payment Method', 'event_espresso');
         $this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
         $this->_template_args['reg_details']['response_msg']['value'] = $reg_details['response_msg'];
         $this->_template_args['reg_details']['response_msg']['label'] = __('Payment method response', 'event_espresso');
         $this->_template_args['reg_details']['response_msg']['class'] = 'regular-text';
     }
     $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
     $this->_template_args['reg_details']['registration_session']['label'] = __('Registration Session', 'event_espresso');
     $this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
     $this->_template_args['reg_details']['ip_address']['value'] = $reg_details['ip_address'];
     $this->_template_args['reg_details']['ip_address']['label'] = __('Registration placed from IP', 'event_espresso');
     $this->_template_args['reg_details']['ip_address']['class'] = 'regular-text';
     $this->_template_args['reg_details']['user_agent']['value'] = $reg_details['user_agent'];
     $this->_template_args['reg_details']['user_agent']['label'] = __('Registrant User Agent', 'event_espresso');
     $this->_template_args['reg_details']['user_agent']['class'] = 'large-text';
     $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'default', 'event_id' => $this->_registration->event_ID()), REG_ADMIN_URL);
     $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
     echo EEH_Template::display_template($template_path, $this->_template_args, TRUE);
 }
 /**
  * Process the IPN. Firstly, we'll hope we put the standard args into the IPN URL so
  * we can easily find what registration the IPN is for and what payment method.
  * However, if not, we'll give all payment methods a chance to claim it and process it.
  * If a payment is found for the IPN info, it is saved.
  * @param 	$_req_data
  * @param EE_Transaction    			$transaction    optional (or a transactions id)
  * @param EE_Payment_Method 	$payment_method (or a slug or id of one)
  * @param boolean           				$update_txn  	whether or not to call EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()
  * @param bool $separate_IPN_request whether the IPN uses a separate request ( true like PayPal ) or is processed manually ( false like Mijireh )
  * @throws EE_Error
  * @throws Exception
  * @return EE_Payment
  */
 public function process_ipn($_req_data, $transaction = NULL, $payment_method = NULL, $update_txn = true, $separate_IPN_request = true)
 {
     $_req_data = $this->_remove_unusable_characters($_req_data);
     EE_Registry::instance()->load_model('Change_Log');
     EE_Processor_Base::set_IPN($separate_IPN_request);
     if ($transaction instanceof EE_Transaction && $payment_method instanceof EE_Payment_Method) {
         $obj_for_log = EEM_Payment::instance()->get_one(array(array('TXN_ID' => $transaction->ID(), 'PMD_ID' => $payment_method->ID()), 'order_by' => array('PAY_timestamp' => 'desc')));
     } elseif ($payment_method instanceof EE_Payment) {
         $obj_for_log = $payment_method;
     } elseif ($transaction instanceof EE_Transaction) {
         $obj_for_log = $transaction;
     } else {
         $obj_for_log = null;
     }
     $log = EEM_Change_Log::instance()->log(EEM_Change_Log::type_gateway, array('IPN data received' => $_req_data), $obj_for_log);
     try {
         /**
          * @var EE_Payment $payment
          */
         $payment = NULL;
         if ($transaction && $payment_method) {
             /** @type EE_Transaction $transaction */
             $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
             /** @type EE_Payment_Method $payment_method */
             $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method);
             if ($payment_method->type_obj() instanceof EE_PMT_Base) {
                 $payment = $payment_method->type_obj()->handle_ipn($_req_data, $transaction);
                 $log->set_object($payment);
             } else {
                 // not a payment
                 EE_Error::add_error(sprintf(__('A valid payment method could not be determined due to a technical issue.%sPlease refresh your browser and try again or contact %s for assistance.', 'event_espresso'), '<br/>', EE_Registry::instance()->CFG->organization->get_pretty('email')), __FILE__, __FUNCTION__, __LINE__);
             }
         } else {
             //that's actually pretty ok. The IPN just wasn't able
             //to identify which transaction or payment method this was for
             // give all active payment methods a chance to claim it
             $active_pms = EEM_Payment_Method::instance()->get_all_active();
             foreach ($active_pms as $payment_method) {
                 try {
                     $payment = $payment_method->type_obj()->handle_unclaimed_ipn($_req_data);
                     EEM_Change_Log::instance()->log(EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $payment);
                     break;
                 } catch (EE_Error $e) {
                     //that's fine- it apparently couldn't handle the IPN
                 }
             }
         }
         // 			EEM_Payment_Log::instance()->log("got to 7",$transaction,$payment_method);
         if ($payment instanceof EE_Payment) {
             $payment->save();
             //  update the TXN
             $this->update_txn_based_on_payment($transaction, $payment, $update_txn, $separate_IPN_request);
         } else {
             //we couldn't find the payment for this IPN... let's try and log at least SOMETHING
             if ($payment_method) {
                 EEM_Change_Log::instance()->log(EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $payment_method);
             } elseif ($transaction) {
                 EEM_Change_Log::instance()->log(EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $transaction);
             }
         }
         return $payment;
     } catch (EE_Error $e) {
         do_action('AHEE__log', __FILE__, __FUNCTION__, sprintf("Error occurred while receiving IPN. Transaction: %s, req data: %s. The error was '%s'", print_r($transaction, TRUE), print_r($_req_data, TRUE), $e->getMessage()));
         throw $e;
     }
 }
 /**
  * Activates a payment method of the given type.
  * @global type $current_user
  * @param string $payment_method_type the PMT_type; for EE_PMT_Invoice this would be 'Invoice'
  * @return EE_Payment_Method
  */
 public function activate_a_payment_method_of_type($payment_method_type)
 {
     $payment_method = EEM_Payment_Method::instance()->get_one_of_type($payment_method_type);
     if (!$payment_method) {
         global $current_user;
         $pm_type_class = $this->payment_method_class_from_type($payment_method_type);
         if (class_exists($pm_type_class)) {
             /** @var $pm_type_obj EE_PMT_Base */
             $pm_type_obj = new $pm_type_class();
             $payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_type_obj->system_name());
             if (!$payment_method) {
                 $payment_method = EE_Payment_Method::new_instance(array('PMD_type' => $pm_type_obj->system_name(), 'PMD_name' => $pm_type_obj->pretty_name(), 'PMD_admin_name' => $pm_type_obj->pretty_name(), 'PMD_slug' => $pm_type_obj->system_name(), 'PMD_wp_user' => $current_user->ID, 'PMD_order' => EEM_Payment_Method::instance()->count(array(array('PMD_type' => array('!=', 'Admin_Only')))) * 10));
             }
             $payment_method->set_active();
             $payment_method->set_description($pm_type_obj->default_description());
             //handles the goofy case where someone activates the invoice gateway which is also
             $payment_method->set_type($pm_type_obj->system_name());
             if (!$payment_method->button_url()) {
                 $payment_method->set_button_url($pm_type_obj->default_button_url());
             }
             $payment_method->save();
             foreach ($payment_method->get_all_usable_currencies() as $currency_obj) {
                 $payment_method->_add_relation_to($currency_obj, 'Currency');
             }
             //now add setup its default extra meta properties
             $extra_metas = $payment_method->type_obj()->settings_form()->extra_meta_inputs();
             foreach ($extra_metas as $meta_name => $input) {
                 $payment_method->update_extra_meta($meta_name, $input->raw_value());
             }
         }
     } else {
         $payment_method->set_active();
         $payment_method->save();
     }
     if ($payment_method->type() == 'Invoice') {
         $messages = EE_Registry::instance()->load_lib('messages');
         $messages->ensure_message_type_is_active('invoice', 'html');
         $messages->ensure_messenger_is_active('pdf');
         EE_Error::add_attention(sprintf(__('Note, when the invoice payment method is activated, the invoice message type, html messenger, and pdf messenger are activated as well for the %1$smessages system%2$s.', 'event_espresso'), '<a href="' . admin_url('admin.php?page=espresso_messages') . '">', '</a>'));
     }
     return $payment_method;
 }
 /**
  *
  * @param EE_PMT_Payflow_Pro_Onsite $payment_method_type
  * @param EE_Payment_Method $payment_method
  */
 public function __construct(EE_PMT_Payflow_Pro_Onsite $payment_method_type, EE_Payment_Method $payment_method)
 {
     $settings = $payment_method->settings_array();
     $options_array = array('name' => 'eea_payflow_pro_onsite_billing_form', 'subsections' => array('credit_card' => new EE_Credit_Card_Input(array('html_class' => 'ee-payflow-pro-billing-form-credit-card', 'required' => true, 'html_label_text' => __('Card Number', 'event_espresso'))), 'exp_month' => new EE_Credit_Card_Month_Input(true, array('html_class' => 'ee-payflow-pro-billing-form-exp-month', 'required' => true, 'html_label_text' => __('Expiry Month', 'event_espresso'))), 'exp_year' => new EE_Credit_Card_Year_Input(array('html_class' => 'ee-payflow-pro-billing-form-exp-year', 'required' => true, 'html_label_text' => __('Expiry Year', 'event_espresso')), false), 'card_cvv' => new EE_CVV_Input(array('html_class' => 'ee-payflow-pro-billing-form-card-cvv', 'required' => true, 'html_label_text' => __('CVV', 'event_espresso')))), 'exclude' => array('phone'));
     parent::__construct($payment_method, $options_array);
 }
 /**
  * Makes sure the payment method is related to the specified payment method
  *
  * @param EE_Payment_Method $payment_method
  * @return EE_Payment_Method
  * @throws \EE_Error
  */
 public function set_usable_currencies_on_payment_method($payment_method)
 {
     foreach ($payment_method->get_all_usable_currencies() as $currency_obj) {
         $payment_method->_add_relation_to($currency_obj, 'Currency');
     }
     return $payment_method;
 }