public static function create_payment($payment = array()) { if (!isset($payment['Invoice ID'])) { do_action('si_error', 'No Invoice ID given within payment import', $payment); return; } // Find the associated invoice $invoices = SI_Post_Type::find_by_meta(SI_Invoice::POST_TYPE, array(self::CSV_ID => $payment['Invoice ID'])); // Can't assign a payment without an invoice if (empty($invoices)) { do_action('si_error', 'No invoice found for this payment', $payment['Payment ID']); return; } $invoice = SI_Invoice::get_instance($invoices[0]); if (!is_a($invoice, 'SI_Invoice')) { return; } $payment_id = SI_Payment::new_payment(array('payment_method' => isset($payment['Payment Method']) ? $payment['Payment Method'] : self::PAYMENT_METHOD, 'invoice' => $invoice->get_id(), 'amount' => round($payment['Amount'], 2), 'transaction_id' => isset($payment['Payment ID']) ? $payment['Payment ID'] : '', 'data' => array('api_response' => $payment))); $new_payment = SI_Payment::get_instance($payment_id); $new_payment->set_post_date(date('Y-m-d H:i:s', strtotime($payment['Date']))); return $new_payment; }
public static function create_payment($payment) { $possible_dups = SI_Post_Type::find_by_meta(SI_Payment::POST_TYPE, array(self::FRESHBOOKS_ID => $payment['payment_id'])); // Don't create a duplicate if this was already imported. if (!empty($possible_dups)) { do_action('si_error', 'Invoice imported already', $payment['payment_id']); return; } // Find the associated invoice $invoices = SI_Post_Type::find_by_meta(SI_Invoice::POST_TYPE, array(self::FRESHBOOKS_ID => $payment['invoice_id'])); $invoice = SI_Invoice::get_instance($invoices[0]); $invoice_id = is_a($invoice, 'SI_Invoice') ? $invoice->get_id() : 0; // Can't assign a payment without an invoice if (!$invoice_id) { do_action('si_error', 'No invoice found for this payment', $payment['payment_id']); return; } $payment_id = SI_Payment::new_payment(array('payment_method' => isset($payment['type']) && !is_array($payment['type']) ? $payment['type'] : self::PAYMENT_METHOD, 'invoice' => $invoice_id, 'amount' => round($payment['amount'], 2), 'transaction_id' => isset($payment['payment_id']) ? $payment['payment_id'] : '', 'data' => array('api_response' => $payment))); $new_payment = SI_Payment::get_instance($payment_id); $new_payment->set_post_date(date('Y-m-d H:i:s', strtotime($payment['date']))); return $new_payment; }
public static function get_child_clones($invoice_id = 0) { $invoice_ids = SI_Post_Type::find_by_meta(SI_Invoice::POST_TYPE, array(self::$meta_keys['cloned_from'] => $invoice_id)); return $invoice_ids; }
public static function create_invoice_payment($payment = array(), SI_Invoice $invoice) { $possible_dups = SI_Post_Type::find_by_meta(SI_Payment::POST_TYPE, array(self::WPINVOICE_ID => $payment['ID'])); // Don't create a duplicate if this was already imported. if (!empty($possible_dups)) { do_action('si_error', 'Invoice imported already', $payment['ID']); return; } $payment_id = SI_Payment::new_payment(array('payment_method' => isset($payment['action']) ? self::PAYMENT_METHOD . ' :: ' . $payment['action'] : self::PAYMENT_METHOD, 'invoice' => $invoice->get_id(), 'amount' => $payment['value'], 'transaction_id' => isset($payment['ID']) ? $payment['object_id'] . '::' . $payment['ID'] : '', 'data' => array('api_response' => $payment))); $new_payment = SI_Payment::get_instance($payment_id); $new_payment->set_post_date(date('Y-m-d H:i:s', $payment['time'])); return $new_payment; }
public static function create_invoice_payment(Harvest_Payment $payment, SI_Invoice $invoice) { $possible_dups = SI_Post_Type::find_by_meta(SI_Payment::POST_TYPE, array(self::HARVEST_ID => $payment->id)); // Don't create a duplicate if this was already imported. if (!empty($possible_dups)) { do_action('si_error', 'Invoice imported already', $payment->id); return; } $payment_id = SI_Payment::new_payment(array('payment_method' => isset($payment->recorded_by) ? $payment->recorded_by : self::PAYMENT_METHOD, 'invoice' => $invoice->get_ID(), 'amount' => $payment->amount, 'transaction_id' => isset($payment->pay_pal_transaction_id) ? $payment->pay_pal_transaction_id : '', 'data' => array('api_response' => array('amount' => $payment->amount, 'authorization' => $payment->authorization, 'created_at' => $payment->created_at, 'id' => $payment->id, 'invoice_id' => $payment->invoice_id, 'paid_at' => $payment->paid_at, 'paypal_transaction_id' => $payment->pay_pal_transaction_id, 'payment_gateway_id' => $payment->payment_gateway_id, 'recorded_by' => $payment->recorded_by, 'recorded_by_email' => $payment->recorded_by_email, 'updated_at' => $payment->updated_at)))); $new_payment = SI_Payment::get_instance($payment_id); $new_payment->set_post_date(date('Y-m-d H:i:s', strtotime($payment->created_at))); return $new_payment; }
public function get_invoice_id($order_id = 0) { $invoices = SI_Post_Type::find_by_meta(SI_Invoice::POST_TYPE, array(Woo_Integration::ORDER_ID_META => $order_id)); if (empty($invoices)) { return 0; } $invoice_id = $invoices[0]; return $invoice_id; }
public static function validate_token() { $user_id = 0; if (!isset($_REQUEST[self::USER_QUERY_ARG]) || $_REQUEST[self::USER_QUERY_ARG] == '') { return false; } if (!isset($_REQUEST[self::CLIENT_TOKEN_QUERY_ARG]) || $_REQUEST[self::CLIENT_TOKEN_QUERY_ARG] == '') { return false; } $user_id = $_REQUEST[self::USER_QUERY_ARG]; $token = $_REQUEST[self::CLIENT_TOKEN_QUERY_ARG]; // Search for client with token. $clients = SI_Post_Type::find_by_meta(SI_Client::POST_TYPE, array(self::CLIENT_TOKEN_META => $token)); if (empty($clients)) { return false; } foreach ($clients as $client_id) { $client = SI_Client::get_instance($client_id); // confirm user id is associated still. if (!in_array($user_id, $client->get_associated_users())) { return false; } } return $clients; }