/** * Adds line items to the request * * @since 2.0.0 * @return array */ protected function get_line_items() { $line_items = array(); // order line items foreach (SV_WC_Helper::get_order_line_items($this->order) as $item) { if ($item->item_total >= 0) { $line_items[] = array('itemId' => SV_WC_Helper::str_truncate($item->id, 31), 'name' => SV_WC_Helper::str_to_sane_utf8(SV_WC_Helper::str_truncate($item->name, 31)), 'description' => SV_WC_Helper::str_to_sane_utf8(SV_WC_Helper::str_truncate($item->description, 255)), 'quantity' => $item->quantity, 'unitPrice' => SV_WC_Helper::number_format($item->item_total)); } } // order fees foreach ($this->order->get_fees() as $fee_id => $fee) { if ($this->order->get_item_total($fee) >= 0) { $line_items[] = array('itemId' => SV_WC_Helper::str_truncate($fee_id, 31), 'name' => SV_WC_Helper::str_truncate(htmlentities($fee['name'], ENT_QUOTES, 'UTF-8', false), 31), 'description' => __('Order Fee', 'woocommerce-gateway-authorize-net-cim'), 'quantity' => 1, 'unitPrice' => SV_WC_Helper::number_format($this->order->get_item_total($fee))); } } // maximum of 30 line items per order if (count($line_items) > 30) { $line_items = array_slice($line_items, 0, 30); } return $line_items; }
/** * Sanitize address fields by removing invalid UTF-8, direct response delimiter, * and truncate to field length limits * * @since 2.0.5 * @param string $field_name address field name * @param array $field field data * @return string sanitized field */ protected function sanitize_address_field($field_name, $field) { if ('phone' === $field_name) { $value = preg_replace('/\\D/', '', $field['value']); } else { // authorize.net claims to support unicode, but not all code points yet. // Unrecognized code points will display in their control panel with question marks $value = SV_WC_Helper::str_to_sane_utf8($field['value']); } // remove any usages of our hybrid direct response delimiter so as to not break response parsing // see WC_Authorize_Net_CIM_API_Profile_Response::parse_direct_response() $value = str_replace(':|:', '', $value); // truncate to field limits return $value ? SV_WC_Helper::str_truncate($value, $field['limit']) : null; }
/** * Add any Authorize.Net CIM specific transaction information as * class members of WC_Order instance. Added members can include: * * + po_number - PO Number to be included with the transaction via the legacy filter below * * @since 2.0.0 * @see WC_Gateway_Authorize_Net_CIM::get_order() * @param int $order_id order ID being processed * @return WC_Order object with payment and transaction information attached */ public function get_order($order_id) { // add common order members $order = parent::get_order($order_id); // backwards compat for transaction/PO number filters introduced in v1.x // @deprecated in 2.0.0 $order->description = apply_filters('wc_authorize_net_cim_transaction_description', $order->description, $order->id, $this); // remove any weirdness in the description $order->description = SV_WC_Helper::str_to_sane_utf8($order->description); // @deprecated in 2.0.0 $po_number = apply_filters('wc_authorize_net_cim_transaction_po_number', false, $order_id, $this); if ($po_number) { $order->po_number = $po_number; } // add shipping address ID for profile transactions (using existing payment method or adding a new one) if ($order->get_user_id() && (!empty($order->payment->token) || $this->get_payment_tokens_handler()->should_tokenize())) { $shipping_address = $this->get_shipping_address($order->get_user_id()); $order->payment->shipping_address_id = $shipping_address->get_id(); } return $order; }