function test_add_payment()
 {
     $payment_total = $this->invoice->get_balance();
     // 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(), 0);
 }
 public static function create_admin_payment($invoice_id = 0, $amount = '0.00', $number = '', $date = '', $notes = '')
 {
     if (did_action('si_new_payment') > 0) {
         // make sure this
         return;
     }
     $invoice = SI_Invoice::get_instance($invoice_id);
     // create new payment
     $payment_id = SI_Payment::new_payment(array('payment_method' => self::get_payment_method(), 'invoice' => $invoice_id, 'amount' => $amount, 'transaction_id' => $number, 'data' => array('amount' => $amount, 'check_number' => $number, 'date' => strtotime($date), 'notes' => $notes)), SI_Payment::STATUS_COMPLETE);
     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('admin_payment', $payment_id, $invoice);
     do_action('payment_complete', $payment);
 }
 function build_test_payment($invoice_id, $total = 0, $date = false, $status = '')
 {
     $invoice = SI_Invoice::get_instance($invoice_id);
     // Randomize if no total is set.
     $payment_total = !$total ? rand(1, 300) : $total;
     $status = $status != '' ? $status : SI_Payment::STATUS_AUTHORIZED;
     // create new payment
     $payment_id = SI_Payment::new_payment(array('payment_method' => SI_Paypal_EC::PAYMENT_METHOD, 'invoice' => $invoice->get_id(), 'amount' => $payment_total, 'data' => array('api_response' => array())), $status);
     $this->payment_ids[] = $payment_id;
     $new_payment = SI_Payment::get_instance($payment_id);
     do_action('payment_authorized', $new_payment);
     if (!$date) {
         $date = time();
     }
     if (!is_integer($date)) {
         $date = strtotime($date);
     }
     $new_payment->set_post_date(date('Y-m-d H:i:s', $date));
     $this->assertTrue(in_array($payment_id, $this->payment_ids));
     return $payment_id;
 }
예제 #4
0
 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;
 }
예제 #5
0
 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;
 }
예제 #6
0
 public static function create_payment($data = array())
 {
     $payment_id = SI_Payment::new_payment($data);
     return self::payment_data($payment_id);
 }
예제 #7
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;
 }
 /**
  * Create the recurring payment profile.
  */
 private function create_recurring_payment_profile(SI_Checkouts $checkout, SI_Invoice $invoice, SI_Payment $payment)
 {
     $post_data = $this->create_recurring_payment_nvp_data($checkout, $invoice, $payment);
     if (!$post_data) {
         return false;
         // paying for it some other way
     }
     do_action('si_log', __CLASS__ . '::' . __FUNCTION__ . ' - PayPal EC Recurring Payment Request', $post_data);
     $response = wp_safe_remote_post($this->get_api_url(), array('httpversion' => '1.1', 'body' => $post_data, 'timeout' => apply_filters('http_request_timeout', 15), 'sslverify' => false));
     do_action('si_log', __CLASS__ . '::' . __FUNCTION__ . ' - PayPal EC Recurring Payment Response (Raw)', $response);
     if (is_wp_error($response)) {
         return false;
     }
     if ($response['response']['code'] != '200') {
         return false;
     }
     $response = wp_parse_args(wp_remote_retrieve_body($response));
     do_action('si_log', __CLASS__ . '::' . __FUNCTION__ . ' - PayPal EC Recurring Payment Response (Parsed)', $response);
     if (empty($response['PROFILEID'])) {
         do_action('si_paypal_recurring_payment_profile_failed', $response);
         return false;
     }
     $payment_id = SI_Payment::new_payment(array('payment_method' => self::get_payment_method(), 'invoice' => $invoice->get_id(), 'amount' => $post_data['AMT'], 'data' => array('live' => self::$api_mode == self::MODE_LIVE, 'api_response' => $response)), SI_Payment::STATUS_RECURRING);
     // let the world know
     do_action('si_paypal_recurring_payment_profile_created', $payment_id);
     return true;
 }
예제 #9
0
 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;
 }
예제 #10
0
 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 static function create_payment($data = array())
 {
     $payment_id = SI_Payment::new_payment($data);
     $payment = SI_Payment::get_instance($payment_id);
     if (!is_a($payment, 'SI_Payment')) {
         return;
     }
     return self::payment_data($payment);
 }
예제 #12
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;
     }
 }