function test_add_payment_deposit() { $total = $this->invoice->get_calculated_total(); $deposit = si_get_number_format($total / 3); // pay 1/3 $this->invoice->set_deposit($deposit); $payment_total = $this->invoice->get_deposit(); // create new payment $payment_id = SI_Payment::new_payment(array('payment_method' => SI_Paypal_EC::PAYMENT_METHOD, 'invoice' => $this->invoice->get_id(), 'amount' => $payment_total, 'data' => array('api_response' => array())), SI_Payment::STATUS_AUTHORIZED); if (!$payment_id) { return false; } $payment = SI_Payment::get_instance($payment_id); do_action('payment_authorized', $payment); // Complete and fire actions $payment->set_status(SI_Payment::STATUS_COMPLETE); do_action('payment_complete', $payment); $this->assertEquals($this->invoice->get_balance(), $total - $deposit); }
public function get_subtotal() { if (isset($this->subtotal)) { return $this->subtotal; } $subtotal = 0; $line_items = $this->get_line_items(); if (!empty($line_items)) { foreach ($line_items as $key => $data) { if (isset($data['rate'])) { if (si_line_item_is_parent($key, $line_items)) { continue; } $data['rate'] = isset($data['rate']) ? $data['rate'] : 0; $qty = isset($data['qty']) ? $data['qty'] : 1; $line_total = $data['rate'] * $qty; if (isset($data['tax'])) { $tax = $line_total * ($data['tax'] / 100); $line_total = $line_total - si_get_number_format($tax); // convert so that rounding can occur before discount is removed. } $subtotal += apply_filters('si_line_item_total', $line_total, $data); } } } $this->subtotal = $subtotal; return $subtotal; }
public static function projects_time() { $nonce = $_REQUEST['nonce']; if (!wp_verify_nonce($nonce, self::SUBMISSION_NONCE)) { self::ajax_fail('Not going to fall for it!'); } if (isset($_REQUEST['project_id'])) { $project_id = $_REQUEST['project_id']; } if (!$project_id) { self::ajax_fail('No project id'); } $project = SI_Project::get_instance($project_id); if (!is_a($project, 'SI_Project')) { self::ajax_fail('Project not found'); } $times = $project->get_associated_times(); $time_data = array(); if (!empty($times)) { foreach ($times as $time_id) { $time = SI_Record::get_instance($time_id); if (!is_a($time, 'SI_Record')) { continue; } $activity = SI_Time::get_instance($time->get_associate_id()); $data = $time->get_data(); // If time is unbillable don't import // This includes not returning time that has already been invoiced. if (isset($_REQUEST['billable'])) { if (is_a($activity, 'SI_Time') && !$activity->is_billable()) { continue; } // Don't return the time that has already been invoiced if (isset($data['invoice_id'])) { continue; } } $description = is_a($activity, 'SI_Time') ? '<b>' . get_the_title($activity->get_id()) . "</b>\n" . $time->get_title() . "\n<small>" . date_i18n(get_option('date_format'), $data['date']) . '</small>' : $time->get_title() . "\n<small>" . date_i18n(get_option('date_format'), $data['date']) . '</small>'; $description = apply_filters('the_content', $description); $time_data[] = array('id' => $time_id, 'date' => date_i18n(get_option('date_format'), $data['date']), 'note' => apply_filters('the_content', $time->get_title()), 'qty' => si_get_number_format((double) $data['time_val']), 'description' => apply_filters('si_project_time_imported_description', $description), 'activity_id' => is_a($activity, 'SI_Time') ? $activity->get_id() : false, 'activity' => is_a($activity, 'SI_Time') ? $activity->get_title() : '', 'activity_rate' => is_a($activity, 'SI_Time') ? $activity->get_default_rate() : 0, 'activity_tax' => is_a($activity, 'SI_Time') ? $activity->get_default_percentage() : 0); } } if (empty($time_data)) { self::ajax_fail('Nothing to import'); } header('Content-type: application/json'); if (self::DEBUG) { header('Access-Control-Allow-Origin: *'); } echo wp_json_encode($time_data); exit; }
public static function ajax_number_formatter() { if (!isset($_REQUEST['number'])) { self::ajax_fail('Forget something?'); } $nonce = $_REQUEST['security']; if (!wp_verify_nonce($nonce, self::NONCE)) { self::ajax_fail('Not going to fall for it!'); } $number = $_REQUEST['number']; $currency = array('money' => sa_get_formatted_money($number), 'unformatted_money' => sa_get_unformatted_money($number), 'float' => si_get_number_format($number), 'int' => (int) si_get_number_format($number)); header('Content-type: application/json'); if (self::DEBUG) { header('Access-Control-Allow-Origin: *'); } echo wp_json_encode($currency); exit; }
/** * Get the invoice deposit * @param integer $id * @return string */ function si_get_invoice_deposit($id = 0) { if (!$id) { $id = get_the_ID(); } $invoice = SI_Invoice::get_instance($id); return apply_filters('si_get_invoice_deposit', si_get_number_format($invoice->get_deposit()), $invoice); }
private function create_recurring_payment_nvp_data(SI_Checkouts $checkout, SI_Invoice $invoice, SI_Payment $payment) { $invoice_id = $invoice->get_id(); $payment_data = $payment->get_data(); $term = SI_Subscription_Payments::get_term($invoice_id); // day, week, month, or year $duration = (int) SI_Subscription_Payments::get_duration($invoice_id); $price = SI_Subscription_Payments::get_renew_price($invoice_id); $terms = array('day' => 'Day', 'week' => 'Week', 'month' => 'Month', 'year' => 'Year'); if (!isset($terms[$term])) { $term = 'day'; } // The first payment was just now, so // the subscription starts based on the term $starts = strtotime(date('Y-m-d') . ' +' . $duration . ' ' . $term); $user = si_who_is_paying($invoice); // User email or none $user_email = $user ? $user->user_email : ''; $nvp = array('USER' => self::$api_username, 'PWD' => self::$api_password, 'SIGNATURE' => self::$api_signature, 'VERSION' => self::$version, 'METHOD' => 'CreateRecurringPaymentsProfile', 'PROFILESTARTDATE' => date('Y-m-d', $starts) . 'T00:00:00Z', 'PROFILEREFERENCE' => $payment->get_id(), 'DESC' => $this->recurring_desc($invoice), 'MAXFAILEDPAYMENTS' => 2, 'AUTOBILLOUTAMT' => 'AddToNextBilling', 'BILLINGPERIOD' => $terms[$term], 'BILLINGFREQUENCY' => $duration, 'TOTALBILLINGCYCLES' => 0, 'AMT' => si_get_number_format($price), 'CURRENCYCODE' => self::get_currency_code($invoice_id), 'EMAIL' => $user_email, 'L_PAYMENTREQUEST_0_ITEMCATEGORY0' => 'Digital', 'L_PAYMENTREQUEST_0_NAME0' => $invoice->get_title(), 'L_PAYMENTREQUEST_0_AMT0' => si_get_number_format($price), 'L_PAYMENTREQUEST_0_NUMBER0' => $invoice_id, 'L_PAYMENTREQUEST_0_QTY0' => 1, 'CREDITCARDTYPE' => self::get_card_type($this->cc_cache['cc_number']), 'ACCT' => $this->cc_cache['cc_number'], 'EXPDATE' => self::expiration_date($this->cc_cache['cc_expiration_month'], $this->cc_cache['cc_expiration_year']), 'CVV2' => $this->cc_cache['cc_cvv'], 'FIRSTNAME' => $checkout->cache['billing']['first_name'], 'LASTNAME' => $checkout->cache['billing']['last_name'], 'STREET' => $checkout->cache['billing']['street'], 'CITY' => $checkout->cache['billing']['city'], 'STATE' => $checkout->cache['billing']['zone'], 'COUNTRYCODE' => self::country_code($checkout->cache['billing']['country']), 'ZIP' => $checkout->cache['billing']['postal_code']); return $nvp; }
/** * Get the invoice deposit * @param integer $id * @return string */ function si_get_invoice_deposit($id = 0) { if (!$id) { global $post; $id = $post->ID; } $invoice = SI_Invoice::get_instance($id); return apply_filters('si_get_invoice_deposit', si_get_number_format($invoice->get_deposit()), $invoice); }
function si_number_format($value = 1, $dec_point = '.', $thousands_sep = '', $fraction = 2) { echo apply_filters('si_number_format', si_get_number_format($value, $dec_point, $thousands_sep), $value); }