Esempio n. 1
0
 protected function call_step($id, $type = 'display')
 {
     $id = apply_filters('appthemes_checkout_call_step', $id);
     $this->current_step = $id;
     if ($this->steps->is_empty()) {
         return false;
     }
     if (!$this->steps->contains($id)) {
         return false;
     }
     $callbacks = $this->steps->get($this->current_step);
     $callback = $callbacks['payload'][$type == 'display' ? 1 : 0];
     $order_id = $this->get_data('order_id');
     if (!$order_id) {
         $order = new APP_Draft_Order();
     } else {
         $order = appthemes_get_order($order_id);
     }
     if (is_callable($callback)) {
         call_user_func($callback, $order, $this);
     } else {
         if (is_string($callback)) {
             locate_template($callback, true);
         } else {
             return false;
         }
     }
     if ($order instanceof APP_Draft_Order && $order->is_modified()) {
         $new_order = APP_Order_Factory::duplicate($order);
         if (!$new_order) {
             return false;
         }
         $this->add_data('order_id', $new_order->get_id());
         // save checkout type & hash in order
         update_post_meta($new_order->get_id(), 'checkout_type', $this->checkout_type);
         update_post_meta($new_order->get_id(), 'checkout_hash', $this->hash);
         // save complete and cancel urls in order
         if ($complete_url = $this->get_data('complete_url')) {
             update_post_meta($new_order->get_id(), 'complete_url', $complete_url);
         }
         if ($cancel_url = $this->get_data('cancel_url')) {
             update_post_meta($new_order->get_id(), 'cancel_url', $cancel_url);
         }
     }
     if ($this->step_cancelled) {
         $this->redirect(appthemes_get_step_url($this->get_previous_step($id)));
         exit;
     }
     if ($this->step_finished) {
         $this->redirect(appthemes_get_step_url($this->get_next_step($id)));
         exit;
     }
     $this->current_step = false;
     return true;
 }
Esempio n. 2
0
 public function test_register()
 {
     $queue = new APP_Order_Processing();
     $queue->schedule_process();
     $this->assertNotEquals(0, wp_next_scheduled('app_order_processing'));
     $draft = new APP_Draft_Order();
     $draft->complete();
     $new_order = APP_Draft_Order::upgrade($draft);
     $child_order = APP_Order_Factory::duplicate($new_order);
     $child_order->set_gateway('mock-gateway');
     wp_update_post(array('ID' => $child_order->get_id(), 'post_status' => APPTHEMES_ORDER_COMPLETED, 'post_parent' => $new_order->get_id()));
     $child_order->schedule_payment(date('Y-m-d H:i:s', strtotime('-1 day')));
     $items_processed = $queue->process();
     $this->assertEquals(1, $items_processed);
     $order = appthemes_get_order($child_order->get_id(), true);
     $this->assertEquals(APPTHEMES_ORDER_ACTIVATED, $order->get_status());
 }
/**
 * Schedules the next reccurance of an activated recurring order
 * Hooked to appthemes_transaction_activated
 */
function appthemes_schedule_next_order_recurrance($order)
{
    if ($order->is_recurring()) {
        $next_order = APP_Order_Factory::duplicate($order);
        $date = date('Y-m-d H:i:s', strtotime('+' . intval($order->get_recurring_period()) . ' days'));
        wp_update_post(array('ID' => $next_order->get_id(), 'post_parent' => $order->get_id(), 'post_status' => APPTHEMES_ORDER_PENDING, 'post_date' => $date));
    }
}
Esempio n. 4
0
 function test_order_copy()
 {
     $this->assertNotEmpty($this->order->get_author());
     $new_order = APP_Order_Factory::duplicate($this->order);
     $check_fields = array('description', 'status', 'author', 'gateway', 'currency', 'total', 'ip_address');
     $this->compareFields($this->order, $new_order, $check_fields);
     $this->order->set_currency('GBP');
     $this->order->add_item('payment-test', 5.99, $this->order->get_id());
     $this->order->set_gateway('paypal');
     $this->order->set_description('asdfasdfasfd');
     $modified_order = APP_Order_Factory::duplicate($this->order);
     $this->compareFields($this->order, $modified_order, $check_fields);
 }
Esempio n. 5
0
/**
 * Schedules the next reccurance of an activated recurring order
 * Hooked to appthemes_transaction_activated
 */
function appthemes_schedule_next_order_recurrance($order)
{
    if ($order->is_recurring()) {
        $next_order = APP_Order_Factory::duplicate($order);
        $type = $order->get_recurring_period_type();
        switch ($type) {
            case 'Y':
                $period_type = 'years';
                break;
            case 'W':
                $period_type = 'weeks';
                break;
            case 'M':
                $period_type = 'months';
                break;
            case 'D':
            default:
                $period_type = 'days';
                break;
        }
        $date = date('Y-m-d H:i:s', strtotime('+' . intval($order->get_recurring_period()) . ' ' . $period_type));
        wp_update_post(array('ID' => $next_order->get_id(), 'post_parent' => $order->get_id(), 'post_status' => APPTHEMES_ORDER_PENDING, 'post_date' => $date));
    }
}