public static function payment_fields(SI_Invoice $invoice)
 {
     $fields = array('payment_amount' => array('type' => 'text', 'weight' => 1, 'label' => self::__('Amount'), 'attributes' => array()), 'payment_transaction_id' => array('type' => 'text', 'weight' => 5, 'label' => self::__('ID'), 'attributes' => array()), 'payment_date' => array('type' => 'date', 'weight' => 10, 'label' => self::__('Date Received'), 'attributes' => array('autocomplete' => 'off'), 'default' => date_i18n(get_option('date_format'))), 'payment_notes' => array('type' => 'textarea', 'weight' => 15, 'label' => self::__('Notes'), 'attributes' => array()), 'invoice_id' => array('type' => 'hidden', 'value' => $invoice->get_id(), 'weight' => 10000), 'payments_nonce' => array('type' => 'hidden', 'value' => wp_create_nonce(SI_Controller::NONCE), 'weight' => 10001));
     $fields = apply_filters('si_admin_payment_fields_fields', $fields);
     uasort($fields, array(__CLASS__, 'sort_by_weight'));
     return $fields;
 }
 public static function maybe_change_order_status(SI_Invoice $invoice, $status = '')
 {
     $order_id = get_post_meta($invoice->get_id(), self::ORDER_ID_META, true);
     if (!$order_id) {
         return;
     }
     $order = wc_get_order($order_id);
     switch ($status) {
         case SI_Invoice::STATUS_PAID:
             $order->update_status('completed', __('Invoice payment complete', 'sprout-invoices'));
             break;
         case SI_Invoice::STATUS_WO:
             $order->update_status('cancelled', __('Invoice written-off', 'sprout-invoices'));
             break;
         default:
             break;
     }
 }
Esempio n. 3
0
 /**
  * Maybe create a status update record
  * @param  SI_Estimate $estimate
  * @param  string      $status
  * @param  string      $original_status
  * @return null
  */
 public static function maybe_create_status_update_record(SI_Invoice $invoice, $status = '', $original_status = '')
 {
     do_action('si_new_record', sprintf(si__('Status changed: %s to <b>%s</b>.'), SI_Invoice::get_status_label($original_status), SI_Invoice::get_status_label($status)), self::HISTORY_STATUS_UPDATE, $invoice->get_id(), sprintf(si__('Status update for %s.'), $invoice->get_id()), 0, false);
 }
 public static function invoice_data(SI_Invoice $invoice)
 {
     $invoice_data = array('title' => $invoice->get_title(), 'id' => $invoice->get_id(), 'invoice_id' => $invoice->get_invoice_id(), 'status' => $invoice->get_status(), 'balance' => $invoice->get_balance(), 'deposit' => $invoice->get_deposit(), 'issue_date' => $invoice->get_issue_date(), 'estimate_id' => $invoice->get_estimate_id(), 'due_date' => $invoice->get_due_date(), 'expiration_date' => $invoice->get_expiration_date(), 'client_id' => $invoice->get_client_id(), 'client_data' => array(), 'po_number' => $invoice->get_po_number(), 'discount' => $invoice->get_discount(), 'tax' => $invoice->get_tax(), 'tax2' => $invoice->get_tax2(), 'currency' => $invoice->get_currency(), 'subtotal' => $invoice->get_subtotal(), 'calculated_total' => $invoice->get_calculated_total(), 'project_id' => $invoice->get_project_id(), 'terms' => $invoice->get_terms(), 'notes' => $invoice->get_notes(), 'line_items' => $invoice->get_line_items(), 'user_id' => $invoice->get_user_id(), 'payment_ids' => $invoice->get_payments());
     if ($invoice->get_client_id()) {
         $client = SI_Client::get_instance($invoice->get_client_id());
         if (is_a($client, 'SI_Client')) {
             $invoice_data['client_data'] = self::client_data($client);
         }
     }
     return $invoice_data;
 }
function si_is_invoice_recurring(SI_Invoice $invoice)
{
    return SI_Subscription_Payments::has_subscription_payment($invoice->get_id());
}
Esempio n. 6
0
 /**
  * Process a payment
  *
  * @param SI_Checkouts $checkout
  * @param SI_Invoice $invoice
  * @return SI_Payment|bool false if the payment failed, otherwise a Payment object
  */
 public function process_payment(SI_Checkouts $checkout, SI_Invoice $invoice)
 {
     $amount = isset($_POST['sa_checks_amount']) ? $_POST['sa_checks_amount'] : false;
     $number = isset($_POST['sa_checks_check_number']) ? $_POST['sa_checks_check_number'] : false;
     $date = isset($_POST['sa_checks_mailed']) ? $_POST['sa_checks_mailed'] : false;
     $notes = isset($_POST['sa_checks_notes']) ? $_POST['sa_checks_notes'] : '';
     if (!isset($_POST['sa_checks_nonce']) || !wp_verify_nonce($_POST['sa_checks_nonce'], self::NONCE)) {
         return false;
     }
     if (!$amount) {
         return false;
     }
     // create new payment
     $payment_id = SI_Payment::new_payment(array('payment_method' => self::get_payment_method(), 'invoice' => $invoice->get_id(), 'amount' => $amount, 'transaction_id' => $number, 'data' => array('amount' => $amount, 'check_number' => $number, 'date' => strtotime($date), 'notes' => $notes)), SI_Payment::STATUS_PENDING);
     if (!$payment_id) {
         return false;
     }
     $payment = SI_Payment::get_instance($payment_id);
     if ($date != '') {
         $payment->set_post_date(date('Y-m-d H:i:s', strtotime($date)));
     }
     do_action('payment_pending', $payment);
     return $payment;
 }
 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;
 }
 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 sender_submission_fields(SI_Invoice $invoice)
 {
     $fields = array();
     $from_name = SI_Notifications_Control::from_name(array('invoice_id' => $invoice->get_id()));
     $from_email = SI_Notifications_Control::from_email(array('invoice_id' => $invoice->get_id()));
     $fields['send_as'] = array('weight' => 1, 'label' => __('Sender', 'sprout-invoices'), 'type' => 'text', 'placeholder' => '', 'attributes' => array('readonly' => 'readonly'), 'default' => $from_name . ' <' . $from_email . '>');
     // options for recipients
     $client = $invoice->get_client();
     $recipient_options = '<div class="form-group"><div class="input_wrap">';
     // client users
     if (is_a($client, 'SI_Client')) {
         $client_users = $client->get_associated_users();
         foreach ($client_users as $user_id) {
             if (!is_wp_error($user_id)) {
                 $recipient_options .= sprintf('<label class="clearfix"><input type="checkbox" name="sa_metabox_recipients[]" value="%1$s"> %2$s</label>', $user_id, esc_attr(SI_Notifications::get_user_email($user_id)));
             }
         }
     }
     $recipient_options .= sprintf('<label class="clearfix"><input type="checkbox" name="sa_metabox_custom_recipient_check" disabled="disabled"><input type="text" name="sa_metabox_custom_recipient" placeholder="%1$s"><span class="helptip" title="%2$s"></span></label>', __('*****@*****.**', 'sprout-invoices'), __('Entering an email will prevent some notification shortcodes from working since there is no client.', 'sprout-invoices'));
     // Send to me.
     $recipient_options .= sprintf('<label class="clearfix"><input type="checkbox" name="sa_metabox_recipients[]" value="%1$s"> %2$s</label>', get_current_user_id(), __('Send me a copy', 'sprout-invoices'));
     $recipient_options .= '</div></div>';
     $fields['recipients'] = array('weight' => 5, 'label' => sprintf('%s <span class="helptip" title="%s"></span>', __('Recipients', 'sprout-invoices'), __('A notification will be sent if recipients are selected and this invoice is saved.', 'sprout-invoices')), 'type' => 'bypass', 'output' => $recipient_options);
     $fields['sender_note'] = array('weight' => 10, 'label' => __('Note', 'sprout-invoices'), 'type' => 'textarea', 'default' => $invoice->get_sender_note(), 'description' => __('This note will be added to the Invoice Notification via the [admin_note] shortcode.', 'sprout-invoices'));
     $fields['doc_id'] = array('type' => 'hidden', 'value' => $invoice->get_id(), 'weight' => 10000);
     $fields['notification_nonce'] = array('type' => 'hidden', 'value' => wp_create_nonce(SI_Controller::NONCE), 'weight' => 10001);
     $fields = apply_filters('si_sender_submission_fields', $fields);
     uasort($fields, array(__CLASS__, 'sort_by_weight'));
     return $fields;
 }
 public static function invoice_has_subscription_payments($bool, SI_Invoice $invoice, SI_Payment $payment)
 {
     // Set the payment token on the invoice.
     $data = $payment->get_data();
     if (isset($data['payment_token'])) {
         self::set_token($invoice->get_id(), $data['payment_token']);
         // has subscription options
         return self::has_subscription_payment($invoice->get_id());
     }
     return $bool;
 }
Esempio n. 11
0
 /**
  * Create the recurring payment profile.
  */
 private function add_customer_to_plan(SI_Checkouts $checkout, SI_Invoice $invoice)
 {
     $invoice_id = $invoice->get_id();
     self::setup_stripe();
     try {
         $user = si_who_is_paying($invoice);
         $purchase_data = $this->purchase_data($checkout, $invoice);
         if (!$purchase_data) {
             return false;
         }
         $price = SI_Subscription_Payments::get_renew_price($invoice_id);
         $amount_in_cents = self::convert_money_to_cents(sprintf('%0.2f', $price));
         $balance = si_has_invoice_deposit($invoice_id) ? $invoice->get_deposit() : $invoice->get_balance();
         $subscribe = Stripe_Customer::create(array('card' => $purchase_data, 'plan' => $invoice_id . $amount_in_cents, 'email' => $user->user_email, 'account_balance' => self::convert_money_to_cents(sprintf('%0.2f', $balance - $price))));
         $subscribe = array('id' => $subscribe->id, 'subscription_id' => $subscribe->subscriptions->data[0]->id, 'amount' => $amount_in_cents, 'plan' => $invoice_id . $amount_in_cents, 'card' => $purchase_data, 'email' => $user->user_email);
         // Payment
         $payment_id = SI_Payment::new_payment(array('payment_method' => self::PAYMENT_METHOD, 'invoice' => $invoice_id, 'amount' => $price, 'data' => array('live' => self::MODE_LIVE === self::$api_mode, 'api_response' => $subscribe)), SI_Payment::STATUS_RECURRING);
         do_action('si_stripe_recurring_payment_profile_created', $payment_id);
         // Passed back to create the initial payment
         $response = $subscribe;
         $response['amount'] = $amount_in_cents;
         $response['plan'] = $invoice_id . $amount_in_cents;
         return $response;
     } catch (Exception $e) {
         self::set_error_messages($e->getMessage());
         return false;
     }
 }