place_order();
} else {
$featured_listing_settings = get_option( 'acadp_featured_listing_settings' );
// Enqueue style dependencies
wp_enqueue_style( ACADP_PLUGIN_NAME );
// Enqueue script dependencies
if( wp_script_is( ACADP_PLUGIN_NAME.'-bootstrap', 'registered' ) ) {
wp_enqueue_script( ACADP_PLUGIN_NAME.'-bootstrap' );
}
wp_enqueue_script( ACADP_PLUGIN_NAME );
// ...
ob_start();
include( acadp_get_template( "payments/acadp-public-checkout-display.php" ) );
return ob_get_clean();
}
} else {
return ''.__( 'Sorry, something went wrong.', 'advanced-classifieds-and-directory-pro' ).'';
}
}
/**
* Create Orders. Send emails to site and listing owners
* when order placed.
*
* @since 1.0.0
* @access private
*/
private function place_order() {
$post_id = (int) $_POST['post_id'];
// place order
$new_order = array(
'post_title' => sprintf( __( '[Order] Listing #%d' ), $post_id ),
'post_status' => 'publish',
'post_author' => get_current_user_id(),
'post_type' => 'acadp_payments'
);
$order_id = wp_insert_post( $new_order );
if( $order_id ) {
// save meta fields
update_post_meta( $order_id, 'listing_id', $post_id );
update_post_meta( $order_id, 'featured', 1 );
$featured_listing_settings = get_option( 'acadp_featured_listing_settings' );
$amount = $featured_listing_settings['price'];
update_post_meta( $order_id, 'amount', $amount );
$gateway = sanitize_key( $_POST['payment_gateway'] );
update_post_meta( $order_id, 'payment_gateway', $gateway );
update_post_meta( $order_id, 'payment_status', 'created' );
// send email to site admin after order placed successfully
acadp_email_admin_order_created( $post_id, $order_id );
// process payment
if( 'offline' == $gateway ) {
update_post_meta( $order_id, 'transaction_id', wp_generate_password( 12, false ) );
acadp_email_listing_owner_order_created_offline( $post_id, $order_id );
$redirect_url = acadp_get_payment_receipt_page_link( $order_id );
wp_redirect( $redirect_url );
} else {
acadp_email_listing_owner_order_created( $post_id, $order_id );
// executes the action hook named 'acadp_process_payment'
do_action( 'acadp_process_'.$gateway.'_payment', $order_id );
}
exit();
}
}
/**
* Process the shortcode [acadp_payment_receipt].
*
* @since 1.0.0
* @access public
*/
public function run_shortcode_payment_receipt() {
if( ! is_user_logged_in() ) {
return wp_login_form();
}
$shortcode = 'acadp_payment_receipt';
if( $order_id = get_query_var('acadp_order') ) {
$featured_listing_settings = get_option( 'acadp_featured_listing_settings' );
// Enqueue style dependencies
wp_enqueue_style( ACADP_PLUGIN_NAME );
// Enqueue script dependencies
if( wp_script_is( ACADP_PLUGIN_NAME.'-bootstrap', 'registered' ) ) {
wp_enqueue_script( ACADP_PLUGIN_NAME.'-bootstrap' );
}
wp_enqueue_script( ACADP_PLUGIN_NAME );
// ...
$order = get_post( $order_id );
$post_meta = get_post_meta( $order_id );
ob_start();
include( acadp_get_template( "payments/acadp-public-payment-receipt-display.php" ) );
return ob_get_clean();
} else {
return ''.__( 'Sorry, something went wrong.', 'advanced-classifieds-and-directory-pro' ).'';
}
}
/**
* Process the shortcode [acadp_payment_history].
*
* @since 1.0.0
* @access public
*/
public function run_shortcode_payment_history() {
if( ! is_user_logged_in() ) {
return wp_login_form();
}
if( ! acadp_current_user_can('edit_acadp_listings') ) {
return ''.__( 'You do not have sufficient permissions to access this page.', 'advanced-classifieds-and-directory-pro' ).'';
}
$shortcode = 'acadp_payment_history';
$listings_settings = get_option( 'acadp_listings_settings' );
// Enqueue style dependencies
wp_enqueue_style( ACADP_PLUGIN_NAME );
// Enqueue script dependencies
if( wp_script_is( ACADP_PLUGIN_NAME.'-bootstrap', 'registered' ) ) {
wp_enqueue_script( ACADP_PLUGIN_NAME.'-bootstrap' );
}
wp_enqueue_script( ACADP_PLUGIN_NAME );
// Define the query
$paged = ( get_query_var('paged') ) ? absint( get_query_var('paged') ) : 1;
$args = array(
'post_type' => 'acadp_payments',
'posts_per_page' => isset( $listings_settings['listings_per_page'] ) ? $listings_settings['listings_per_page'] : 10,
'paged' => $paged,
'author' => get_current_user_id(),
);
$acadp_query = new WP_Query( $args );
// Start the Loop
global $post;
// Process output
if( $acadp_query->have_posts() ) {
ob_start();
include( acadp_get_template( "payments/acadp-public-payment-history-display.php" ) );
wp_reset_postdata(); // Use reset postdata to restore orginal query
return ob_get_clean();
} else {
return ''.__( 'No Results Found.', 'advanced-classifieds-and-directory-pro' ).'';
}
}
}