Esempio n. 1
0
 public function dispatch()
 {
     if (!$this->payment) {
         $q = isset($_REQUEST['payment']) ? $_REQUEST['payment'] : null;
         if ($q) {
             $q = urldecode(base64_decode($q));
             parse_str($q, $payment_data);
             if (isset($payment_data['payment_id']) && isset($payment_data['verify'])) {
                 // TODO: check 'verify'.
                 $this->payment = WPBDP_Payment::get($payment_data['payment_id']);
             }
         }
     }
     if (!$this->payment) {
         return wpbdp_render_msg(_x('Invalid payment id.', 'payments', 'WPBDM'), 'error');
     }
     $step = 'gateway_selection';
     if ($this->payment->is_rejected() || $this->payment->is_canceled()) {
         $step = 'rejected';
     } elseif (!$this->payment->is_pending()) {
         $step = 'done';
     } else {
         if ($this->payment->get_data('returned')) {
             $step = 'pending_verification';
         } elseif ($this->payment->get_gateway()) {
             $step = 'checkout';
         }
     }
     return call_user_func(array(&$this, $step));
 }
 private function checkout()
 {
     $payment = WPBDP_Payment::get($this->category->payment_id);
     if (!$payment) {
         return wpbdp_render_msg(_x('Invalid renewal state.', 'renewal', 'WPBDM'), 'error');
     }
     require_once WPBDP_PATH . 'core/view-checkout.php';
     $checkout = new WPBDP_Checkout_Page($payment);
     return $checkout->dispatch();
 }
Esempio n. 3
0
 public function ajax_payment_details()
 {
     if (!current_user_can('administrator')) {
         exit;
     }
     global $wpbdp;
     $response = new WPBDP_AJAX_Response();
     $payment = WPBDP_Payment::get(intval($_REQUEST['id']));
     if (!$payment) {
         $response->send_error();
     }
     $response->add('html', wpbdp_render_page(WPBDP_PATH . 'admin/templates/payment-details.tpl.php', array('payment' => $payment, 'invoice' => $wpbdp->payments->render_invoice($payment))));
     $response->send();
 }
Esempio n. 4
0
 public function remove_category($category, $remove_fee = true, $cleanup = false)
 {
     global $wpdb;
     $category_id = intval(is_object($category) ? $category->term_id : $category);
     if ($remove_fee) {
         $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}wpbdp_listing_fees WHERE listing_id = %d AND category_id = %d", $this->id, $category_id));
     }
     $listing_terms = wp_get_post_terms($this->id, WPBDP_CATEGORY_TAX, array('fields' => 'ids'));
     wpbdp_array_remove_value($listing_terms, $category_id);
     wp_set_post_terms($this->id, $listing_terms, WPBDP_CATEGORY_TAX);
     if ($cleanup) {
         // Remove all payment items related to this category.
         $payment_ids = $wpdb->get_col($wpdb->prepare("SELECT p.id FROM {$wpdb->prefix}wpbdp_payments p WHERE p.listing_id = %d AND\n                                                            p.status = %s AND\n                                                            EXISTS( SELECT 1 FROM {$wpdb->prefix}wpbdp_payments_items pi WHERE pi.payment_id = p.id\n                                                            AND pi.item_type IN (%s, %s) AND pi.rel_id_1 = %d)", $this->id, 'pending', 'fee', 'recurring_fee', $category_id));
         foreach ($payment_ids as $pid) {
             $payment = WPBDP_Payment::get($pid);
             $items = $payment->get_items(array('item_type' => array('fee', 'recurring_fee'), 'rel_id_1' => $category_id));
             foreach ($items as &$item) {
                 $payment->delete_item($item);
             }
             $payment->save();
         }
     }
 }
 /**
  * @since 3.4.2
  */
 public function process_generic($action = '')
 {
     if ('postback' != $action) {
         return;
     }
     $jwt = JWT::decode(wpbdp_getv($_REQUEST, 'jwt', ''), wpbdp_get_option('googlewallet-seller-secret'));
     if (!is_object($jwt) || !isset($jwt->request) || !isset($jwt->request->sellerData) || !isset($jwt->response)) {
         die;
     }
     parse_str($jwt->request->sellerData, $data);
     if (!isset($data['payment_id'])) {
         die;
     }
     $payment_id = intval($data['payment_id']);
     $payment = WPBDP_Payment::get($payment_id);
     if ('googlewallet' != $payment->get_gateway()) {
         die;
     }
     if ('SUBSCRIPTION_CANCELED' == $jwt->response->statusCode) {
         $payment->cancel_recurring();
     }
     die;
 }
 protected function step_checkout()
 {
     global $wpbdp;
     if ($this->state->editing) {
         $this->state->advance(false);
         return $this->dispatch();
     }
     $payment = WPBDP_Payment::get($this->state->payment_id);
     if (!$payment) {
         return wpbdp_render_msg(_x('Invalid submit state.', 'submit_state', 'WPBDM'), 'error');
     }
     if ($payment->is_completed()) {
         $this->state->advance(false);
         return $this->dispatch();
     }
     require_once WPBDP_PATH . 'core/view-checkout.php';
     $checkout = new WPBDP_Checkout_Page($payment);
     return $checkout->dispatch();
 }
Esempio n. 7
0
 /**
  * @since 3.5.8
  */
 public function notify_abandoned_payments()
 {
     global $wpdb;
     $threshold = max(1, absint(wpbdp_get_option('payment-abandonment-threshold')));
     $time_for_pending = wpbdp_format_time(strtotime("-{$threshold} hours", current_time('timestamp')), 'mysql');
     $notified = get_option('wpbdp-payment-abandonment-notified', array());
     if (!is_array($notified)) {
         $notified = array();
     }
     // For now, we only notify listings with pending INITIAL payments.
     $to_notify = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wpbdp_payments WHERE status = %s AND tag = %s AND processed_on IS NULL AND created_on < %s ORDER BY created_on", 'pending', 'initial', $time_for_pending));
     foreach ($to_notify as &$data) {
         if (in_array($data->id, $notified)) {
             continue;
         }
         $payment = WPBDP_Payment::get($data->id);
         // Send e-mail.
         $replacements = array('listing' => get_the_title($payment->get_listing_id()), 'link' => sprintf('<a href="%1$s">%1$s</a>', esc_url($payment->get_checkout_url())));
         $email = wpbdp_email_from_template('email-templates-payment-abandoned', $replacements);
         $email->to[] = wpbusdirman_get_the_business_email($payment->get_listing_id());
         $email->template = 'businessdirectory-email';
         $email->send();
         $notified[] = $data->id;
     }
     update_option('wpbdp-payment-abandonment-notified', $notified);
 }
Esempio n. 8
0
 function handle_actions()
 {
     if (!isset($_REQUEST['wpbdmaction']) || !isset($_REQUEST['post'])) {
         return;
     }
     $action = $_REQUEST['wpbdmaction'];
     $posts = is_array($_REQUEST['post']) ? $_REQUEST['post'] : array($_REQUEST['post']);
     $listings_api = wpbdp_listings_api();
     $upgrades_api = wpbdp_listing_upgrades_api();
     if (!current_user_can('administrator')) {
         exit;
     }
     switch ($action) {
         case 'publish':
             foreach ($posts as $post_id) {
                 wp_update_post(array('ID' => $post_id, 'post_status' => 'publish'));
             }
             $this->messages[] = _nx('The listing has been published.', 'The listings have been published.', count($posts), 'admin', 'WPBDM');
             break;
         case 'setaspaid':
             foreach ($posts as $post_id) {
                 $listing = WPBDP_Listing::get($post_id);
                 $listing->mark_as_paid();
             }
             $this->messages[] = _nx('The listing status has been set as paid.', 'The listings status has been set as paid.', count($posts), 'admin', 'WPBDM');
             break;
         case 'changesticky':
             foreach ($posts as $post_id) {
                 $upgrades_api->set_sticky($post_id, wpbdp_getv($_GET, 'u'));
             }
             $this->messages[] = _nx('The listing has been modified.', 'The listings have been modified.', count($posts), 'admin', 'WPBDM');
             break;
         case 'upgradefeatured':
             foreach ($posts as $post_id) {
                 $upgrades_api->set_sticky($post_id, 'sticky', true);
             }
             $this->messages[] = _nx('The listing has been upgraded.', 'The listings have been upgraded.', count($posts), 'admin', 'WPBDM');
             break;
         case 'cancelfeatured':
             foreach ($posts as $post_id) {
                 $upgrades_api->set_sticky($post_id, 'normal');
             }
             $this->messages[] = _nx('The listing has been downgraded.', 'The listings have been downgraded.', count($posts), 'admin', 'WPBDM');
             break;
         case 'approvetransaction':
             $transaction = WPBDP_Payment::get($_GET['transaction_id']);
             $transaction->set_status(WPBDP_Payment::STATUS_COMPLETED, 'admin');
             $transaction->save();
             $this->messages[] = _x('The transaction has been approved.', 'admin', 'WPBDM');
             break;
         case 'rejecttransaction':
             $transaction = WPBDP_Payment::get($_GET['transaction_id']);
             $transaction->set_status(WPBDP_Payment::STATUS_REJECTED, 'admin');
             $transaction->save();
             $this->messages[] = _x('The transaction has been rejected.', 'admin', 'WPBDM');
             break;
         case 'assignfee':
             $listing = WPBDP_Listing::get($posts[0]);
             $listing->add_category($_GET['category_id'], $_GET['fee_id']);
             $this->messages[] = _x('The fee was successfully assigned.', 'admin', 'WPBDM');
             break;
         case 'renewlisting':
             foreach ($posts as $post_id) {
                 $listings_api->auto_renew($post_id);
             }
             $this->messages[] = _nx('Listing was renewed.', 'Listings were renewed.', count($posts), 'admin', 'WPBDM');
             break;
         case 'send-renewal-email':
             $renewal_id = intval($_GET['renewal_id']);
             if ($listings_api->send_renewal_email($renewal_id)) {
                 $this->messages[] = _x('Renewal email sent.', 'admin', 'WPBDM');
             }
             break;
         default:
             do_action('wpbdp_admin_directory_handle_action', $action);
             break;
     }
     $_SERVER['REQUEST_URI'] = remove_query_arg(array('wpbdmaction', 'wpbdmfilter', 'transaction_id', 'category_id', 'fee_id', 'u', 'renewal_id'), $_SERVER['REQUEST_URI']);
 }