/** * Add original transaction ID for capturing a prior authorization * * @since 3.0 * @param WC_Order $order order object * @return WC_Order object with payment and transaction information attached */ protected function get_order_for_capture($order) { $order = parent::get_order_for_capture($order); $order->auth_net_aim_ref_trans_id = SV_WC_Plugin_Compatibility::get_order_custom_field($order, 'wc_authorize_net_aim_trans_id'); $order->description = sprintf(__('%s - Capture for Order %s', $this->text_domain), esc_html(get_bloginfo('name')), $order->get_order_number()); return $order; }
/** * Search for an order with order_number $order_number. This method can be * useful for 3rd party plugins that want to rely on the Sequential Order * Numbers plugin and perform lookups by custom order number. * * @param string $order_number order number to search for * @return int post_id for the order identified by $order_number, or 0 */ public function find_order_by_order_number($order_number) { // search for the order by custom order number $query_args = array('numberposts' => 1, 'meta_key' => '_order_number_formatted', 'meta_value' => $order_number, 'post_type' => 'shop_order', 'post_status' => 'publish', 'fields' => 'ids'); list($order_id) = get_posts($query_args); // order was found if (null !== $order_id) { return $order_id; } // if we didn't find the order, then it may be that this plugin was disabled and an order was placed in the interim $order = new WC_Order($order_number); if ('' !== SV_WC_Plugin_Compatibility::get_order_custom_field($order, 'order_number_formatted')) { // _order_number was set, so this is not an old order, it's a new one that just happened to have post_id that matched the searched-for order_number return 0; } return $order->id; }
/** * Create the transaction XML, this handles all transaction types and both credit card/eCheck transactions * * @since 3.0 * @param string $type transaction type * @param WC_Order $order order object */ private function create_transaction($type, WC_Order $order) { // store the order object for later use $this->order = $order; // <createTransactionRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"> $this->startElementNs(null, 'createTransactionRequest', 'AnetApi/xml/v1/schema/AnetApiSchema.xsd'); // add authentication info $this->add_authentication(); // <refId> $this->writeElement('refId', $order->id); // <transactionRequest> $this->startElement('transactionRequest'); // <transactionType> $this->writeElement('transactionType', $type); // <amount> $this->writeElement('amount', $order->payment_total); // payment info $this->add_payment(); // <order> $this->startElement('order'); // <invoiceNumber> $this->writeElement('invoiceNumber', ltrim($order->get_order_number(), _x('#', 'hash before the order number', WC_Authorize_Net_AIM::TEXT_DOMAIN))); // <description> $this->writeElement('description', substr($order->description, 0, 255)); // </order> $this->endElement(); // <lineItems> $this->add_line_items(); // <tax> if ($order->get_total_tax() > 0) { $this->add_taxes(); } // <shipping> if (SV_WC_Plugin_Compatibility::get_total_shipping($order) > 0) { $this->add_shipping(); } // <poNumber> if (isset($order->po_number)) { $this->writeElement('poNumber', substr(preg_replace('/\\W/', '', $order->po_number), 0, 25)); } // <customer> $this->startElement('customer'); // <id> $this->writeElement('id', $order->user_id); // <email> if ($order->billing_email) { $this->writeElement('email', $order->billing_email); } // </customer> $this->endElement(); // <billTo> + <shipTo> $this->add_addresses(); // <customerIP> $this->writeElement('customerIP', SV_WC_Plugin_Compatibility::get_order_custom_field($order, 'customer_ip_address')); // <transactionSettings> $this->add_transaction_settings(); // <userFields> $this->add_user_defined_fields(); // </transactionRequest> $this->endElement(); // </createTransactionRequest> $this->endElement(); }