/**
  * For adding any html output above the payment overview.
  * Many gateways won't want ot display anything, so this function just returns an empty string.
  * Other gateways may want to override this, such as offline gateways.
  *
  * @param \EE_Payment $payment
  * @return string
  */
 public function payment_overview_content(EE_Payment $payment)
 {
     return EEH_Template::locate_template('payment_methods' . DS . 'Invoice' . DS . 'templates' . DS . 'invoice_payment_details_content.template.php', array_merge(array('payment_method' => $this->_pm_instance, 'payment' => $payment, 'page_confirmation_text' => '', 'page_extra_info' => '', 'invoice_url' => $payment->transaction()->primary_registration()->invoice_url('html')), $this->_pm_instance->all_extra_meta_array()));
 }
 /**
  * Message triggers for manual payment applied by admin
  * @param  bool     $success incoming success value
  * @param  EE_Payment $payment EE_payment object
  * @return bool              success/fail
  */
 public static function process_admin_payment($success = TRUE, EE_Payment $payment)
 {
     //we need to get the transaction object
     $transaction = $payment->transaction();
     if ($transaction instanceof EE_Transaction) {
         $data = array($transaction, $payment);
         $message_type = self::_get_payment_message_type($payment->STS_ID());
         //if payment amount is less than 0 then switch to payment_refund message type.
         $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type;
         //if payment_refund is selected, but the status is NOT accepted.  Then change message type to false so NO message notification goes out.
         $message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved ? false : $message_type;
         self::_load_controller();
         //verify this message type is present and active.  If it isn't then no message is sent.
         $active_mts = self::$_EEMSG->get_active_message_types();
         $message_type = in_array($message_type, $active_mts) ? $message_type : false;
         if ($message_type) {
             $success = self::$_EEMSG->send_message($message_type, $data);
             if (!$success) {
                 EE_Error::add_error(__('Something went wrong and the payment confirmation was NOT resent', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
             }
         } else {
             EE_Error::add_error(__('The message type for the status of this payment is not active or does not exist, so no notification was sent.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
         }
     }
     return $success;
 }
Пример #3
0
    /**
     * Gets content for displaying about the payment done using this gateway
     * @param EE_Payment $payment
     * @return type
     */
    public function get_payment_overview_content(EE_Payment $payment)
    {
        $registration = $payment->transaction()->primary_registration();
        //$registration = $session_data['registration'][$session_data['primary_attendee']['line_item_id']];
        if (!$this->_payment_settings['show']) {
            return;
        }
        ?>
		<div class="event-display-boxes">
			<?php 
        if (isset($this->_payment_settings['invoice_title'])) {
            ?>

				<?php 
            echo '<h4 id="invoice_title" class="payment_type_title section-heading">' . stripslashes_deep($this->_payment_settings['invoice_title']) . '</h4>';
        }
        ?>
			<p>
				<a href="<?php 
        echo $registration->invoice_url('download');
        ?>
" class="ee-button-lnk inline-button ui-priority-primary ui-state-default ui-state-hover ui-state-focus ui-corner-all" target="_blank">
					<?php 
        _e('Download PDF Invoice', 'event_espresso');
        ?>
 <span class="ee-icon ee-icon-PDF-file-type"></span>
				</a>
			</p>
			<?php 
        if (isset($this->_payment_settings['page_instructions'])) {
            echo '<div class="event-messages ui-state-highlight"><span class="ui-icon ui-icon-alert"></span><p class="instruct">' . stripslashes_deep($this->_payment_settings['page_instructions']) . '</p></div>';
        }
        if (isset($this->_payment_settings['payment_address'])) {
            ?>
				<div class="address-block">
					<?php 
            echo wpautop(stripslashes_deep($this->_payment_settings['payment_address']));
            ?>
				</div>
				<?php 
        }
        ?>
		</div>
		<?php 
    }
 /**
  * @param EE_Payment $payment to process
  * @param array      $billing_info but should be empty for this gateway
  * @param string     $return_url URL to send the user to after a successful payment on the payment provider's website
  * @param string     $notify_url URL to send the instant payment notification
  * @param string     $cancel_url URL to send the user to after a cancelled payment attempt on teh payment provider's website
  * @throws \EE_Error
  * @return EE_Payment
  */
 public function set_redirection_info($payment, $billing_info = array(), $return_url = NULL, $notify_url = NULL, $cancel_url = NULL)
 {
     /* @var $transaction EE_Transaction */
     $transaction = $payment->transaction();
     //get any of the current registrations,
     $primary_registrant = $transaction->primary_registration();
     $primary_attendee = $primary_registrant->attendee();
     $items = array();
     //if we're are charging for the full amount, show the normal line items
     if ($this->_can_easily_itemize_transaction_for($payment)) {
         $total_line_item = $transaction->total_line_item();
         $tax_total = $total_line_item->get_total_tax();
         foreach ($total_line_item->get_items() as $line_item) {
             $items[] = array('name' => $line_item->name(), 'price' => $this->format_currency($line_item->unit_price()), 'sku' => $line_item->code(), 'quantity' => $line_item->quantity());
         }
     } else {
         //its a partial payment
         $tax_total = 0;
         //partial payment, so just add 1 item
         $items[] = array('name' => sprintf(__("Partial payment for registration %s", 'event_espresso'), $primary_registrant->reg_code()), 'price' => $this->format_currency($payment->amount()), 'sku' => $primary_registrant->reg_code(), 'quantity' => 1);
     }
     $order = array('total' => $this->format_currency($payment->amount()), 'return_url' => $return_url, 'items' => $this->_prepare_for_mijireh($items), 'email' => $primary_attendee->email(), 'first_name' => $primary_attendee->fname(), 'last_name' => $primary_attendee->lname(), 'tax' => $this->format_currency($tax_total), 'partner_id' => 'ee');
     //setup address?
     if ($primary_attendee->address() && $primary_attendee->city() && $primary_attendee->state_ID() && $primary_attendee->country_ID() && $primary_attendee->zip()) {
         $shipping_address = array('first_name' => $primary_attendee->fname(), 'last_name' => $primary_attendee->lname(), 'street' => $primary_attendee->address(), 'city' => $primary_attendee->city(), 'state_province' => $primary_attendee->state_name(), 'zip_code' => $primary_attendee->zip(), 'country' => $primary_attendee->country_ID());
         if ($primary_attendee->address2()) {
             $shipping_address['apt_suite'] = $primary_attendee->address2();
         }
         if ($primary_attendee->phone()) {
             $shipping_address['phone'] = $primary_attendee->phone();
         }
         $order['shipping_address'] = $shipping_address;
     }
     do_action('AHEE_log', __FILE__, __FUNCTION__, serialize(get_object_vars($this)));
     $args = array('headers' => array('Authorization' => 'Basic ' . base64_encode($this->_access_key . ':'), 'Accept' => 'application/json'), 'body' => json_encode($order));
     $response = wp_remote_post('https://secure.mijireh.com/api/1/orders', $args);
     $this->log(array('get checkout url request_args' => $args, 'response' => $response), $payment);
     if (!$response instanceof WP_Error) {
         $response_body = json_decode($response['body']);
         if ($response_body == NULL || !isset($response_body->checkout_url)) {
             if (is_array($response_body) || is_object($response_body)) {
                 $response_body_as_array = (array) $response_body;
                 $problems_string = '';
                 foreach ($response_body_as_array as $problem_parameter => $problems) {
                     $problems_string .= sprintf(__('\\nProblems with %s: %s', 'event_espresso'), $problem_parameter, implode(", ", $problems));
                 }
             } else {
                 $problems_string = $response['body'];
             }
             if ($problems_string == '') {
                 //no message to show? wack
                 if (isset($response['headers']['status'])) {
                     $problems_string = $response['headers']['status'];
                 } else {
                     $problems_string = __('No response from Mijireh', 'event_espresso');
                 }
             }
             throw new EE_Error(sprintf(__('Errors occurred communicating with Mijireh: %s.', 'event_espresso'), $problems_string));
         }
         $payment->set_redirect_url($response_body->checkout_url);
         $payment->set_txn_id_chq_nmbr($response_body->order_number);
         $payment->set_details($response['body']);
     } else {
         $error_message = sprintf(__("Errors communicating with Mijireh: %s", 'event_espresso'), implode(",", $response->get_error_messages()));
         EE_Error::add_error($error_message, __FILE__, __FUNCTION__, __LINE__);
         throw new EE_Error($error_message);
     }
     return $payment;
 }
 /**
  * Message triggers for manual payment applied by admin
  * @param  bool     $success incoming success value
  * @param  EE_Payment $payment EE_payment object
  * @return bool              success/fail
  */
 public function process_admin_payment($success, EE_Payment $payment)
 {
     $success = TRUE;
     //we need to get the transaction object
     $transaction = $payment->transaction();
     $data = array($transaction, $payment);
     $message_type_name = $payment->amount() < 0 ? 'payment_refund' : 'payment';
     $this->_load_controller();
     $success = $this->_EEMSG->send_message($message_type_name, $data);
     if (!$success) {
         EE_Error::add_error(__('Something went wrong and the payment confirmation was NOT resent', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
     }
     return $success;
 }
 /**
  * _build_payment_json_response
  *
  * @access public
  * @param \EE_Payment $payment
  * @param array       $REG_IDs
  * @param bool | null        $delete_txn_reg_status_change
  * @return array
  */
 protected function _build_payment_json_response(EE_Payment $payment, $REG_IDs = array(), $delete_txn_reg_status_change = null)
 {
     // was the payment deleted ?
     if (is_bool($delete_txn_reg_status_change)) {
         return array('PAY_ID' => $payment->ID(), 'amount' => $payment->amount(), 'total_paid' => $payment->transaction()->paid(), 'txn_status' => $payment->transaction()->status_ID(), 'pay_status' => $payment->STS_ID(), 'registrations' => $this->_registration_payment_data_array($REG_IDs), 'delete_txn_reg_status_change' => $delete_txn_reg_status_change);
     } else {
         $this->_get_payment_status_array();
         return array('amount' => $payment->amount(), 'total_paid' => $payment->transaction()->paid(), 'txn_status' => $payment->transaction()->status_ID(), 'pay_status' => $payment->STS_ID(), 'PAY_ID' => $payment->ID(), 'STS_ID' => $payment->STS_ID(), 'status' => self::$_pay_status[$payment->STS_ID()], 'date' => $payment->timestamp('Y-m-d', 'h:i a'), 'method' => strtoupper($payment->source()), 'PM_ID' => $payment->payment_method() ? $payment->payment_method()->ID() : 1, 'gateway' => $payment->payment_method() ? $payment->payment_method()->admin_name() : __("Unknown", 'event_espresso'), 'gateway_response' => $payment->gateway_response(), 'txn_id_chq_nmbr' => $payment->txn_id_chq_nmbr(), 'po_number' => $payment->po_number(), 'extra_accntng' => $payment->extra_accntng(), 'registrations' => $this->_registration_payment_data_array($REG_IDs));
     }
 }
 /**
  * For adding any html output above the payment overview.
  * Many gateways won't want ot display anything, so this function just returns an empty string.
  * Other gateways may want to override this, such as offline gateways.
  *
  * @param \EE_Payment $payment
  * @return string
  */
 public function payment_overview_content(EE_Payment $payment)
 {
     EE_Registry::instance()->load_helper('Template');
     return EEH_Template::display_template($this->_file_folder . 'templates' . DS . 'invoice_payment_details_content.template.php', array_merge(array('payment_method' => $this->_pm_instance, 'payment' => $payment, 'page_confirmation_text' => '', 'page_extra_info' => '', 'invoice_url' => $payment->transaction()->primary_registration()->invoice_url('html')), $this->_pm_instance->all_extra_meta_array()), TRUE);
 }
 /**
  * @param EE_Payment $payment to process
  * @param array      $billing_info but should be empty for this gateway
  * @param string     $return_url URL to send the user to after a successful payment on the payment provider's website
  * @param string     $notify_url URL to send the instant payment notification
  * @param string     $cancel_url URL to send the user to after a cancelled payment attempt on teh payment provider's website
  * @throws \EE_Error
  * @return EE_Payment
  */
 public function set_redirection_info($payment, $billing_info = array(), $return_url = NULL, $notify_url = NULL, $cancel_url = NULL)
 {
     /* @var $transaction EE_Transaction */
     $transaction = $payment->transaction();
     //get any of the current registrations,
     $primary_registrant = $transaction->primary_registration();
     $primary_attendee = $primary_registrant->attendee();
     $items = array();
     //if we're are charging for the full amount, show the normal line items
     if ($this->_can_easily_itemize_transaction_for($payment)) {
         $total_line_item = $transaction->total_line_item();
         $tax_total = $total_line_item->get_total_tax();
         foreach ($total_line_item->get_items() as $line_item) {
             $items[] = array('name' => apply_filters('FHEE__EEG_Mijireh__set_redirection_info__full_amount_line_item_name', $line_item->name(), $line_item, $payment, $primary_registrant), 'price' => $this->format_currency($line_item->unit_price()), 'sku' => $line_item->code(), 'quantity' => $line_item->quantity());
         }
     } else {
         //its a partial payment
         $tax_total = 0;
         //partial payment, so just add 1 item
         $items[] = array('name' => apply_filters('FHEE__EEG_Mijireh__set_redirection_info__partial_amount_line_item_name', sprintf(__("Payment of %s for %s", 'event_espresso'), $payment->get_pretty('PAY_amount', 'no_currency_code'), $primary_registrant->event_name()), $payment, $primary_registrant), 'price' => $this->format_currency($payment->amount()), 'sku' => $primary_registrant->reg_code(), 'quantity' => 1);
     }
     $order = array('total' => $this->format_currency($payment->amount()), 'return_url' => $return_url, 'items' => $this->_prepare_for_mijireh($items), 'email' => $primary_attendee->email(), 'first_name' => $primary_attendee->fname(), 'last_name' => $primary_attendee->lname(), 'tax' => $this->format_currency($tax_total), 'partner_id' => 'ee');
     //setup address?
     if ($primary_attendee->address() && $primary_attendee->city() && $primary_attendee->state_ID() && $primary_attendee->country_ID() && $primary_attendee->zip()) {
         $shipping_address = array('first_name' => $primary_attendee->fname(), 'last_name' => $primary_attendee->lname(), 'street' => $primary_attendee->address(), 'city' => $primary_attendee->city(), 'state_province' => $primary_attendee->state_name(), 'zip_code' => $primary_attendee->zip(), 'country' => $primary_attendee->country_ID());
         if ($primary_attendee->address2()) {
             $shipping_address['apt_suite'] = $primary_attendee->address2();
         }
         if ($primary_attendee->phone()) {
             $shipping_address['phone'] = $primary_attendee->phone();
         }
         $order['shipping_address'] = $shipping_address;
     }
     $order = apply_filters('FHEE__EEG_Mijireh__set_redirection_info__order_arguments', $order, $payment, $primary_registrant);
     do_action('AHEE_log', __FILE__, __FUNCTION__, serialize(get_object_vars($this)));
     $args = array('headers' => array('Authorization' => 'Basic ' . base64_encode($this->_access_key . ':'), 'Accept' => 'application/json'), 'body' => json_encode($order));
     $response = wp_remote_post($this->_mijireh_api_orders_url, $args);
     $problems_string = false;
     $this->log(array('get checkout url request_args' => $args, 'response' => $response), $payment);
     if (!$response instanceof WP_Error) {
         $response_body = json_decode($response['body']);
         if ($response_body && isset($response_body->checkout_url)) {
             $payment->set_redirect_url($response_body->checkout_url);
             $payment->set_txn_id_chq_nmbr($response_body->order_number);
             $payment->set_details($response['body']);
         } else {
             if (is_array($response_body) || is_object($response_body)) {
                 $response_body_as_array = (array) $response_body;
                 foreach ($response_body_as_array as $problem_parameter => $problems) {
                     $problems_string .= sprintf(__('\\nProblems with %s: %s', 'event_espresso'), $problem_parameter, implode(", ", $problems));
                 }
             } else {
                 $problems_string = $response['body'];
             }
             if (!$problems_string) {
                 //no message to show? wack
                 if (isset($response['headers']['status'])) {
                     $problems_string = $response['headers']['status'];
                 } else {
                     $problems_string = __('No response from Mijireh', 'event_espresso');
                 }
             }
         }
     } else {
         $problems_string = implode(",", $response->get_error_messages());
     }
     if ($problems_string) {
         $payment->set_gateway_response(sprintf(__('Errors occurred communicating with Mijireh: %1$s', 'event_espresso'), $problems_string));
         $payment->set_details($response);
         $payment->set_redirect_url(null);
         //even though the payment's status is failed at this point anyways,
         //let's be explicit about it. The fact that the redirect url is null
         //should be enough to client code that they can't redirect the user
         $payment->set_status($this->_pay_model->failed_status());
     }
     return $payment;
 }
 /**
  * Message triggers for manual payment applied by admin
  * @param  EE_Payment $payment EE_payment object
  * @return bool              success/fail
  */
 public static function process_admin_payment(EE_Payment $payment)
 {
     EE_Registry::instance()->load_helper('MSG_Template');
     //we need to get the transaction object
     $transaction = $payment->transaction();
     if ($transaction instanceof EE_Transaction) {
         $data = array($transaction, $payment);
         $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID());
         //if payment amount is less than 0 then switch to payment_refund message type.
         $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type;
         //if payment_refund is selected, but the status is NOT accepted.  Then change message type to false so NO message notification goes out.
         $message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved ? false : $message_type;
         self::_load_controller();
         self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data);
         //get count of queued for generation
         $count_to_generate = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(array(EEM_Message::status_incomplete, EEM_Message::status_idle));
         if ($count_to_generate > 0 && self::$_MSG_PROCESSOR->get_queue()->get_message_repository()->count() !== 0) {
             add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true');
             return true;
         } else {
             $count_failed = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::instance()->stati_indicating_failed_sending());
             /**
              * Verify that there are actually errors.  If not then we return a success message because the queue might have been emptied due to successful
              * IMMEDIATE generation.
              */
             if ($count_failed > 0) {
                 EE_Error::add_error(sprintf(_n('The payment notification generation failed.', '%d payment notifications failed being sent.', $count_failed, 'event_espresso'), $count_failed), __FILE__, __FUNCTION__, __LINE__);
                 return false;
             } else {
                 add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true');
                 return true;
             }
         }
     } else {
         EE_Error::add_error('Unable to generate the payment notification because the given value for the transaction is invalid.', 'event_espresso');
         return false;
     }
 }