private function checkout() { $sticky_info = $this->upgrades_api->get_info($this->listing->get_id()); if ($sticky_info->pending || !$sticky_info->upgradeable || !wpbdp_payments_possible()) { return; } $payment = new WPBDP_Payment(array('listing_id' => $this->listing->get_id())); $payment->add_item('upgrade', $sticky_info->upgrade->cost, _x('Listing upgrade to featured', 'submit', 'WPBDM')); $payment->save(); update_post_meta($this->listing->get_id(), '_wpbdp[sticky]', 'pending'); // FIXME: maybe this should be set automatically when saving the payment? require_once WPBDP_PATH . 'core/view-checkout.php'; $checkout = new WPBDP_Checkout_Page($payment); return $checkout->dispatch(); }
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(); }
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(); }
public function get_latest_payments() { return WPBDP_Payment::find(array('listing_id' => $this->id, '_order' => '-id', '_limit' => 10)); }
/** * @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(); }
public function generate_recurring_payment() { $recurring_item = $this->get_recurring_item(); if (!$recurring_item) { return null; } $rp = new WPBDP_Payment(array('listing_id' => $this->get_listing_id(), 'gateway' => $this->get_gateway(), 'currency_code' => $this->get_currency_code(), 'amount' => 0.0, 'payerinfo' => $this->payerinfo, 'extra_data' => array('recurring_id' => $this->get_data('recurring_id'), 'parent_payment_id' => $this->id))); $rp->add_item('recurring_fee', $recurring_item->amount, $recurring_item->description, $recurring_item->data, $recurring_item->rel_id_1, $recurring_item->rel_id_2); $rp->save(); return $rp; }
/** * @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); }
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']); }