Ejemplo n.º 1
0
 /**
  * Constructor
  *
  * @access public
  * @since  1.0
  * @param string : $account_sid : required
  * @param string $auth_token : required
  * @param string $from_number : required - number to send SMS messages from
  * @param array $options optional : API options
  * @return \WC_Twilio_SMS_API
  */
 public function __construct($account_sid, $auth_token, $from_number, $options = array())
 {
     $this->account_sid = $account_sid;
     $this->auth_token = $auth_token;
     // don't format to e.164, as the country code is not available
     $this->from_number = preg_replace('[\\D]', '', $from_number);
     // Format the Alphanumeric Sender ID if set
     if (isset($options['asid'])) {
         $asid = preg_replace('/[^a-zA-Z0-9 ]/', '', $options['asid']);
         $asid = SV_WC_Helper::str_truncate($asid, 11);
         $this->asid = $asid;
     }
     // Set Basic HTTP Auth
     $this->wp_remote_http_args['headers']['Authorization'] = sprintf('Basic %s', base64_encode($this->account_sid . ':' . $this->auth_token));
 }
 /** Create a void for the given $order
  *
  * @since 2.0.0
  * @param WC_Order $order order object
  */
 public function create_void(WC_Order $order)
 {
     $this->order = $order;
     $this->request_data = array('refId' => $order->id, 'transactionRequest' => array('transactionType' => self::VOID, 'refTransId' => $order->refund->trans_id, 'order' => array('invoiceNumber' => ltrim($this->order->get_order_number(), _x('#', 'hash before the order number', 'woocommerce-gateway-authorize-net-cim')), 'description' => SV_WC_Helper::str_truncate($this->order->refund->reason, 255))));
 }
 /**
  * Helper method to return the item description, which is composed of item
  * meta flattened into a comma-separated string, if available. Otherwise the
  * product SKU is included.
  *
  * The description is automatically truncated to the 127 char limit.
  *
  * @since 3.0.0
  * @param array $item cart or order item
  * @param \WC_Product $product product data
  * @return string
  */
 private function get_item_description($item, $product)
 {
     if (empty($item['item_meta'])) {
         // cart item
         $item_desc = WC()->cart->get_item_data($item, true);
         $item_desc = str_replace("\n", ', ', rtrim($item_desc));
     } else {
         // order item
         $item_meta = new WC_Order_Item_Meta($item['item_meta']);
         $item_meta = SV_WC_Plugin_Compatibility::get_formatted_item_meta($item_meta);
         if (!empty($item_meta)) {
             $item_desc = array();
             foreach ($item_meta as $meta) {
                 $item_desc[] = sprintf('%s: %s', $meta['label'], $meta['value']);
             }
             $item_desc = implode(', ', $item_desc);
         } else {
             $item_desc = is_callable(array($product, 'get_sku')) && $product->get_sku() ? sprintf(__('SKU: %s', WC_PayPal_Express::TEXT_DOMAIN), $product->get_sku()) : null;
         }
     }
     return SV_WC_Helper::str_truncate($item_desc, 127);
 }
 /**
  * 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;
 }
 /** Create a refund for the given $order
  *
  * @since 2.0.0
  * @param WC_Order $order order object
  */
 public function create_refund(WC_Order $order)
 {
     $this->order = $order;
     $this->request_data = array('refId' => $this->order->id, 'transaction' => array('profileTransRefund' => array('amount' => $order->refund->amount, 'customerProfileId' => $order->refund->customer_profile_id, 'customerPaymentProfileId' => $order->refund->customer_payment_profile_id, 'order' => array('invoiceNumber' => ltrim($this->order->get_order_number(), _x('#', 'hash before the order number', 'woocommerce-gateway-authorize-net-cim')), 'description' => SV_WC_Helper::str_truncate($this->order->refund->reason, 255)), 'transId' => $order->refund->trans_id)), 'extraOptions' => $this->get_extra_options());
 }
 /**
  * Adds shipping information to the request
  *
  * @since 2.0.0
  * @return array
  */
 protected function get_shipping()
 {
     if ($this->order->get_total_shipping() > 0) {
         return array('amount' => SV_WC_Helper::number_format($this->order->get_total_shipping()), 'name' => __('Order Shipping', 'woocommerce-gateway-authorize-net-cim'), 'description' => SV_WC_Helper::str_truncate($this->order->get_shipping_method(), 255));
     } else {
         return array();
     }
 }
 /**
  * Add the credit credit card charge or auth elements
  *
  * Note: It's important that these elements appear in the expected order,
  * otherwise there will be parsing errors returned from the QBMS API
  *
  * @since 1.0
  * @param string $request_type one of CustomerCreditCardChargeRq or CustomerCreditCardAuthRq
  * @param WC_Order $order the order object
  */
 private function credit_card_charge_auth_request($request_type, $order)
 {
     // store the order object for later use
     $this->order = $order;
     $this->init_document();
     // <QBMSXMLMsgsRq>
     $this->startElement('QBMSXMLMsgsRq');
     // this is the only difference between cc charge/auth requests
     // <CustomerCreditCardChargeRq>|<CustomerCreditCardAuthRq>
     $this->startElement($request_type);
     $this->writeElement('TransRequestID', $order->trans_request_id);
     if (isset($order->payment->token) && $order->payment->token) {
         $this->writeElement('WalletEntryID', $order->payment->token);
         $this->writeElement('CustomerID', $order->customer_id);
         $this->writeElement('Amount', $order->payment_total);
         $this->writeElement('IsECommerce', true);
     } else {
         $this->writeElement('CreditCardNumber', substr($order->payment->account_number, 0, 19));
         $this->writeElement('ExpirationMonth', substr($order->payment->exp_month, 0, 12));
         $this->writeElement('ExpirationYear', $order->payment->exp_year);
         $this->writeElement('IsECommerce', true);
         $this->writeElement('Amount', $order->payment_total);
         $this->writeElement('NameOnCard', substr(isset($order->intuit_qbms_test_condition) ? 'configid=' . $order->intuit_qbms_test_condition : SV_WC_Helper::str_to_ascii($order->billing_first_name . ' ' . $order->billing_last_name), 0, 30));
         $this->writeElement('CreditCardAddress', substr(SV_WC_Helper::str_to_ascii(empty($order->billing_address_2) ? $order->billing_address_1 : $order->billing_address_1 . ' ' . $order->billing_address_2), 0, 30));
         $this->writeElement('CreditCardCity', substr(SV_WC_Helper::str_to_ascii($order->billing_city), 0, 50));
         $this->writeElement('CreditCardState', substr(SV_WC_Helper::str_to_ascii($order->billing_state), 0, 20));
         $this->writeElement('CreditCardPostalCode', substr(SV_WC_Helper::str_to_ascii(str_replace('-', '', $order->billing_postcode)), 0, 9));
     }
     $this->writeElement('SalesTaxAmount', number_format($order->get_total_tax(), 2, '.', ''));
     if (isset($order->payment->csc)) {
         $this->writeElement('CardSecurityCode', substr($order->payment->csc, 0, 4));
     }
     $this->writeElement('InvoiceID', substr(SV_WC_Helper::str_to_ascii(ltrim($order->get_order_number(), _x('#', 'hash before order number', 'woocommerce-gateway-intuit-qbms'))), 0, 100));
     // customer identifier for non-guest transactions
     if (isset($order->customer_id) && $order->customer_id) {
         $this->writeElement('UserID', substr($order->customer_id, 0, 100));
     }
     // Set the request comment to the order note by default
     $comment = $order->customer_note;
     /**
      * Filter the request comment sent to Intuit.
      *
      * @since 1.7.2
      * @param string $comment The request comment.
      * @param object $order The WooCommerce order.
      */
     $comment = (string) apply_filters('wc_payment_gateway_intuit_qbms_credit_card_request_comment', $comment, $order);
     // Optionally add the comment to the request
     if ($comment) {
         // Format the comment for the API
         $comment = SV_WC_Helper::str_truncate(SV_WC_Helper::str_to_ascii($comment), 4000);
         $this->writeElement('Comment', $comment);
     }
     // root element <GeoLocationInfo>
     $this->startElement('GeoLocationInfo');
     $this->writeElement('IPAddress', substr($_SERVER['REMOTE_ADDR'], 0, 15));
     // </GeoLocationInfo>
     $this->endElement();
     // </CustomerCreditCardChargeRq> | </CustomerCreditCardAuthRq>
     $this->endElement();
     // </QBMSXMLMsgsRq>
     $this->endElement();
     $this->close_document();
 }