예제 #1
0
 public function order_step()
 {
     $form_errors = array();
     $transaction_errors = array();
     $pay_first = get_awpcp_option('pay-before-place-ad');
     $skip_payment_term_selection = false;
     $payments = awpcp_payments_api();
     $_payment_terms = $payments->get_payment_terms();
     // validate submitted data and set relevant transaction attributes
     if (!empty($_POST)) {
         $transaction = $this->get_transaction(true);
         if ($transaction->is_new()) {
             $payments->set_transaction_status_to_open($transaction, $transaction_errors);
         }
         $skip_payment_term_selection = $transaction->get('skip-payment-term-selection');
         $user = awpcp_post_param('user', intval($transaction->user_id));
         $category = awpcp_post_param('category', $transaction->get('category', 0));
         if ($skip_payment_term_selection) {
             $payment_terms = null;
             $term = $payments->get_transaction_payment_term($transaction);
             $payment_type = $transaction->get('payment-term-payment-type');
         } else {
             $payment_terms = new AWPCP_PaymentTermsTable($_payment_terms, $transaction->get('payment-term'));
             $term = $payment_terms->get_payment_term($payment_type, $selected);
         }
         $this->validate_order(compact('user', 'category', 'term'), $form_errors);
         if (empty($form_errors) && empty($transaction_errors)) {
             $transaction->user_id = $user;
             $transaction->set('category', $category);
             if (!$skip_payment_term_selection) {
                 $transaction->set('payment-term', $selected);
                 $transaction->set('payment-term-type', $term->type);
                 $transaction->set('payment-term-id', $term->id);
                 $transaction->set('payment-term-payment-type', $payment_type);
                 $transaction->remove_all_items();
                 $payment_terms->set_transaction_item($transaction);
                 // process transaction to grab Credit Plan information
                 $payments->set_transaction_credit_plan($transaction);
             }
         }
         // Ignore errors if category and user parameters were not sent. This
         // happens every time someone tries to place an Ad starting in the
         // Buy Subscription page.
         if ($skip_payment_term_selection && !isset($_POST['category'])) {
             unset($form_errors['category']);
         }
         if ($skip_payment_term_selection && !isset($_POST['user'])) {
             unset($form_errors['user']);
         }
         // let other parts of the plugin know a transaction is being processed
         $payments->process_transaction($transaction);
     } else {
         $transaction = null;
         $payment_terms = new AWPCP_PaymentTermsTable($_payment_terms);
         $user = wp_get_current_user()->ID;
         $category = 0;
         $term = null;
     }
     // are we done here? what next?
     if ($category > 0 && !is_null($term)) {
         if (empty($form_errors) && empty($transaction_errors)) {
             $payments->set_transaction_status_to_ready_to_checkout($transaction, $transaction_errors);
             if ($pay_first && empty($transaction_errors)) {
                 return $this->checkout_step();
             } else {
                 if (empty($transaction_errors)) {
                     return $this->details_step();
                 }
             }
         }
     }
     // display initial form and show errors, if any
     $messages = $this->messages;
     if (awpcp_current_user_is_admin()) {
         $messages[] = __("You are logged in as an administrator. Any payment steps will be skipped.", "AWPCP");
     }
     $params = array('page' => $this, 'payments' => $payments, 'table' => $payment_terms, 'transaction' => $transaction, 'skip_payment_term_selection' => $skip_payment_term_selection, 'categories' => awpcp_get_categories(), 'form' => compact('category', 'user'), 'messages' => $messages, 'form_errors' => $form_errors, 'transaction_errors' => $transaction_errors);
     $template = AWPCP_DIR . '/frontend/templates/page-place-ad-order-step.tpl.php';
     return $this->render($template, $params);
 }
예제 #2
0
 public function order_step()
 {
     $ad = $this->page->get_ad();
     $transaction = $this->page->get_transaction(true);
     $payments = awpcp_payments_api();
     $fee = $payments->get_ad_payment_term($ad);
     $form_errors = array();
     $transaction_errors = array();
     // verify pre-conditions
     if ($transaction->is_new()) {
         $payments->set_transaction_status_to_open($transaction, $transaction_errors);
     }
     // validate submitted data and prepare transaction
     $payment_terms = new AWPCP_PaymentTermsTable(array($fee->type => array($fee)), $transaction->get('payment-term'));
     if (awpcp_current_user_is_admin() || !$payments->payment_term_requires_payment($fee)) {
         $term = $fee;
         $transaction->set('payment-term-type', $term->type);
         $transaction->set('payment-term-id', $term->id);
         $transaction->set('ad-id', $ad->ad_id);
         $transaction->remove_all_items();
         $payment_terms->set_transaction_item($transaction, $term);
     } else {
         $term = $payments->get_transaction_payment_term($transaction);
         if (!empty($_POST)) {
             $term = $payment_terms->get_payment_term($payment_type, $selected);
             $this->validate_order(compact('term', 'fee'), $form_errors);
             if (empty($form_errors)) {
                 $transaction->set('payment-term', $selected);
                 $transaction->set('payment-term-type', $term->type);
                 $transaction->set('payment-term-id', $term->id);
                 $transaction->set('ad-id', $ad->ad_id);
                 $transaction->remove_all_items();
                 $payment_terms->set_transaction_item($transaction);
                 // process transaction to grab Credit Plan information
                 $payments->set_transaction_credit_plan($transaction);
             }
         }
     }
     // let other parts of the plugin know a transaction is being processed
     $payments->process_transaction($transaction);
     // if everything is fine move onto the next step
     if (!is_null($term)) {
         $payments->set_transaction_status_to_ready_to_checkout($transaction, $transaction_errors);
         if (empty($transaction_errors)) {
             return $this->checkout_step();
         }
     }
     // otherwise display the order form to grab information and show any errors
     $messages = $this->messages;
     if (awpcp_current_user_is_admin()) {
         $messages[] = __("You are logged in as an administrator. Any payment steps will be skipped.", "AWPCP");
     }
     $params = array('payments' => $payments, 'transaction' => $transaction, 'table' => $payment_terms, 'messages' => $messages, 'form_errors' => $form_errors, 'transaction_errors' => $transaction_errors);
     $template = AWPCP_DIR . '/frontend/templates/page-renew-ad-order-step.tpl.php';
     return $this->page->render($template, $params);
 }