/** * Generate a key for a certain transaction product. * * @internal * * @since 1.0 * * @param \IT_Exchange_Transaction $transaction * @param Product $product * @param Factory $factory * @param string $status Optionally override the new key's status. Default active. * @param string $key Optionally specify the license key to be used. If empty, uses Factory. * * @return Key */ function generate_key_for_transaction_product(\IT_Exchange_Transaction $transaction, Product $product, Factory $factory, $status = '', $key = '') { $customer = it_exchange_get_transaction_customer($transaction); if (!$customer instanceof \IT_Exchange_Customer) { $customer = new \IT_Exchange_Customer($customer); } if (!$key) { $key = $factory->make(); } foreach ($transaction->get_products() as $tran_product) { if ($tran_product['product_id'] == $product->ID) { if (empty($tran_product['itemized_data'])) { continue; } if (is_string($tran_product['itemized_data'])) { $itemized = maybe_unserialize($tran_product['itemized_data']); } else { $itemized = $tran_product['itemized_data']; } if (isset($itemized['it_variant_combo_hash'])) { $hash = $itemized['it_variant_combo_hash']; $max = $product->get_feature('licensing', array('field' => 'limit', 'for_hash' => $hash)); } } } if (!isset($max)) { $max = $product->get_feature('licensing', array('field' => 'limit')); } if (!$product->has_feature('recurring-payments')) { $expires = null; } else { $type = $product->get_feature('recurring-payments', array('setting' => 'interval')); $count = $product->get_feature('recurring-payments', array('setting' => 'interval-count')); $interval = convert_rp_to_date_interval($type, $count); $expires = make_date_time($transaction->post_date_gmt); $expires->add($interval); } return Key::create($key, $transaction, $product, $customer, $max, $expires, $status); }
/** * Function to return the vars for adding new order for iT Exchange, ID integration */ function iditexch_payment_vars($transaction_id, $product_id, $price, $count) { // Getting post for date and status $post = get_post($transaction_id); if (isset($post)) { $date = $post->post_date; $is_paid = it_exchange_transaction_is_cleared_for_delivery(new IT_Exchange_Transaction($post)); if ($is_paid) { $status = 'C'; } else { $status = strtoupper(substr($post->post_status, 0, 1)); } } // else { // $status = 'P'; // } // Getting the shipping of transaction $transaction = get_post($transaction_id); $shipping_method = it_exchange_get_transaction_shipping_method($transaction); // If we are not getting the shipping method, get user details from his id if (empty($shipping_method)) { // Getting transaction customer $customer = it_exchange_get_transaction_customer($transaction); // $user_id = get_post_meta($transaction_id, '_it_exchange_customer_id', true); // $user_info = get_userdata($user_id); $first_name = $customer->wp_user->first_name; $last_name = $customer->wp_user->last_name; $email = $customer->wp_user->user_email; } else { $first_name = $shipping_method['first-name']; $last_name = $shipping_method['last-name']; $email = $shipping_method['email']; } // Getting the level and ID project id from iT exchange product_id list($project_id, $level) = get_paired_level_from_itexch_product($product_id); $vars = array('id' => null, 'first_name' => $first_name, 'last_name' => $last_name, 'email' => $email, 'address' => '', 'state' => '', 'city' => '', 'zip' => '', 'country' => '', 'product_id' => $project_id, 'transaction_id' => $transaction_id . '-v' . $level . '-' . $count, 'preapproval_key' => '', 'product_level' => $level, 'prod_price' => $price, 'status' => $status, 'created_at' => $date); return $vars; }
/** * Initialize this object. * * @param \stdClass $data */ protected function init(\stdClass $data) { $this->key = $data->lkey; $this->transaction = it_exchange_get_transaction($data->transaction_id); $this->product = itelic_get_product($data->product); // account for guest checkouts if ($data->customer) { $this->customer = it_exchange_get_customer($data->customer); } else { $customer = it_exchange_get_transaction_customer($this->transaction); if (!$customer instanceof \IT_Exchange_Customer) { $customer = new \IT_Exchange_Customer($customer); $customer->wp_user->display_name = sprintf(__("Guest (%s)", Plugin::SLUG), $customer->wp_user->user_email); } $this->customer = $customer; } $this->status = $data->status; $this->max = $data->max; if (!empty($data->expires) && $data->expires != '0000-00-00 00:00:00') { $this->expires = make_date_time($data->expires); } foreach (array('transaction', 'product', 'customer') as $maybe_error) { if (!$this->{$maybe_error} || is_wp_error($this->{$maybe_error})) { throw new \InvalidArgumentException("Invalid {$maybe_error}"); } } }