public function test_retrieve_order() { $order = APP_Order_Factory::create(); $receipt = APP_Order_Receipt::retrieve($order->get_id()); // Receipt should contain the same values as the original $this->assertEquals($order->get_id(), $receipt->get_id()); $this->assertEquals($order->get_description(), $receipt->get_description()); $this->assertEquals($order->get_author(), $receipt->get_author()); $this->assertEquals($order->get_ip_address(), $receipt->get_ip_address()); $this->assertEquals($order->get_return_url(), $receipt->get_return_url()); $this->assertEquals($order->get_cancel_url(), $receipt->get_cancel_url()); $this->assertEquals($order->get_total(), $receipt->get_total()); $this->assertEquals($order->get_currency(), $receipt->get_currency()); // Customized Data should also retain their value $order = APP_Order_Factory::create(); $order->set_description('New Description'); $order->add_item('test', 100, $order->get_id()); $receipt = APP_Order_Receipt::retrieve($order->get_id()); $this->assertEquals($order->get_id(), $receipt->get_id()); $this->assertEquals($order->get_description(), $receipt->get_description()); $this->assertEquals($order->get_author(), $receipt->get_author()); $this->assertEquals($order->get_ip_address(), $receipt->get_ip_address()); $this->assertEquals($order->get_return_url(), $receipt->get_return_url()); $this->assertEquals($order->get_cancel_url(), $receipt->get_cancel_url()); $this->assertEquals($order->get_total(), $receipt->get_total()); $this->assertEquals($order->get_currency(), $receipt->get_currency()); }
/** * Retrieves an existing order by ID * @param int $order_id Order ID * @return APP_Order Object representing the order */ public static function retrieve($order_id) { if (!is_int($order_id)) { trigger_error('Order ID must be numeric', E_USER_WARNING); } $order = APP_Order_Factory::retrieve($order_id); return new APP_Order_Receipt($order); }
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; }
/** * Upgrrades a Draft Order to a Main Order * @param APP_Draft_Order $draft_order The draft order to Upgrade * @return APP_Order An upgraded order */ public static function upgrade($draft_order) { if (!$draft_order instanceof APP_Draft_Order) { trigger_error('Invalid draft order given. Must be instance of APP_Draft_Order'); } $order = APP_Order_Factory::create(); $order->set_description($draft_order->get_description()); $order->set_gateway($draft_order->get_gateway()); $order->set_currency($draft_order->get_currency()); foreach ($draft_order->get_items() as $item) { $order->add_item($item['type'], $item['price'], $item['post_id']); } return $order; }
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)); } }
function pagseguro_create_payment_listener() { $code = isset($_POST['notificationCode']) && trim($_POST['notificationCode']) !== "" ? trim($_POST['notificationCode']) : null; $type = isset($_POST['notificationType']) && trim($_POST['notificationType']) !== "" ? trim($_POST['notificationType']) : null; if ($code && $type) { pagseguro_log('::::: Notificação PagSeguro recebida :::::'); $options = APP_Gateway_Registry::get_gateway_options('pagseguro'); $email = $options['user_email']; $token = $options['use_sandbox'] ? $options['user_token_sandbox'] : $options['user_token']; $url = $options['use_sandbox'] ? 'https://ws.sandbox.pagseguro.uol.com.br/v2/transactions/notifications/' : 'https://ws.pagseguro.uol.com.br/v2/transactions/notifications/'; $url = $url . $code . '?email=' . $email . '&token=' . $token; $ch = curl_init($url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $transaction = curl_exec($ch); if ($transaction == 'Unauthorized') { pagseguro_log('Transação não autorizada. Token: ' . $token); exit; } curl_close($ch); $transaction = simplexml_load_string($transaction); $status = $transaction->status; $order = APP_Order_Factory::retrieve(intval($transaction->reference)); if (false === $order) { pagseguro_log('ERRO: Não foi encontrado pedido com ID_TRANSACAO == ' . $transaction->reference); return; } switch ($status) { case 3: if ($order->get_status() == 'tr_activated') { pagseguro_log('Notificação repetida para ' . $transaction->reference . '. Ignorando...'); return; } $order->activate(); pagseguro_log('Pedido ' . $transaction->reference . ' foi ativado'); break; case 7: if ($order->get_status() == 'tr_failed') { pagseguro_log('Notificação repetida para ' . $transaction->reference . '. Ignorando...'); } $order->failed(); pagseguro_log('Pedido ' . $transaction->reference . ' foi cancelado'); } } }
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); }
function appthemes_get_order($order_id) { return APP_Order_Factory::retrieve($order_id); }
public function test_upgrade_order() { $order = new APP_Draft_Order(); $order->set_description('Draft'); $order->set_gateway('paypal'); $order->set_currency('EUR'); // We need an existing order that can be connected to $real_order = APP_Order_Factory::create(); $status = $order->add_item('test', 5, $real_order->get_id()); $new_real_order = APP_Draft_Order::upgrade($order); $this->assertEquals('Draft', $new_real_order->get_description()); $this->assertEquals('paypal', $new_real_order->get_gateway()); $this->assertEquals('EUR', $new_real_order->get_currency()); $this->assertCount(1, $new_real_order->get_items()); $this->assertEquals(5, $new_real_order->get_total()); }
/** * 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)); } }