Sh3ll
OdayForums


Server : LiteSpeed
System : Linux premium84.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64
User : claqxcrl ( 523)
PHP Version : 8.1.32
Disable Function : NONE
Directory :  /home/claqxcrl/confenda.com/wp-content/themes/beevent/functions/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/claqxcrl/confenda.com/wp-content/themes/beevent/functions/payment-actions.php
<?php
defined( 'ABSPATH' ) or wp_die();

/**
 * Payment action class for paystack
 */
function beevent_paystack_action() {
	if ( ! empty ( $_POST['tprice'] ) && ! empty ( $_POST['fname'] ) && ! empty ( $_POST['lname'] ) && ! empty ( $_POST['phone'] ) && ! empty ( $_POST['uemail'] ) ) {
		$TotalPrice  = sanitize_text_field( $_POST['tprice'] );
		$ActualPrice = sanitize_text_field( $_POST['price'] );
		$Quantity    = sanitize_text_field( $_POST['quantity'] );
		$iname       = sanitize_text_field( $_POST['iname'] );
		$fname       = sanitize_text_field( $_POST['fname'] );
		$lname       = sanitize_text_field( $_POST['lname'] );
		$phone       = sanitize_text_field( $_POST['phone'] );
		$uemail      = sanitize_text_field( $_POST['uemail'] );
		$address     = sanitize_text_field( $_POST['address'] );
		$Token       = sanitize_text_field( $_POST['token'] );
		$itemno      = sanitize_text_field( $_POST['itemno'] );
		$method      = sanitize_text_field( $_POST['method'] );
		$ename       = sanitize_text_field( $_POST['ename'] );
		$Shipping    = $TotalPrice - $ActualPrice;

		$singleTicketPrice = $ActualPrice/$Quantity;

		if ( is_user_logged_in() ) {
			$user_ID = get_current_user_id();
			$user    = get_userdata( $user_ID );
			$user_email = ! empty ( $user->user_email ) ? $user->user_email : '';

			if ( empty ( $fname  ) ) {
				$fname = ! empty ( $user->first_name ) ? $user->first_name : '';
			}
			if ( empty ( $lname  ) ) {
				$lname = ! empty ( $user->last_name ) ? $user->last_name : '';
			}
		}

		$currency_symbol  = get_option( 'cart_currency_symbol' );
		$defaultCurrency  = get_option( 'cart_payment_currency' );
	    $item_total	      = $singleTicketPrice * $Quantity;
		$product_details .= "Event name :- " . $ename . "\n";
		$product_details .= "Item name :- " . $iname . "\n";
		$product_details .= "Payment Method :- " . $method . "\n";
		$product_details .= $singleTicketPrice . " x " . $Quantity . " = " . $currency_symbol . wpspsc_number_format_price( $item_total ) . "\n";

		if ( $method == 'stripe' ) {
			$method = 'Stripe';

			require_once('stripe-php/init.php');

			$cardno = sanitize_text_field( $_POST['cardno'] );
			$month  = sanitize_text_field( $_POST['month'] );
			$year   = sanitize_text_field( $_POST['year'] );
			$cvc    = sanitize_text_field( $_POST['cvc'] );

			global $beevent_options;
			$stripeskey = isset( $beevent_options['stripe_secrit_key'] ) ? $beevent_options['stripe_secrit_key'] : '';
			$stripepkey = isset( $beevent_options['stripe_pubishable_key'] ) ? $beevent_options['stripe_pubishable_key'] : '';

			//set stripe secret key and publishable key
		    $stripe = array(
		      "secret_key"      => $stripeskey,
		      "publishable_key" => $stripepkey
		    );    
			
		    \Stripe\Stripe::setApiKey($stripe['secret_key']); 

		    //add customer to stripe
		    $customer = \Stripe\Customer::create(array(
				'name'        => $fname.' '.$lname,
				'description' => $product_details,
		        'email'       => $uemail,
		        'source'      => $Token,
				'address'     => ''
		    ));  

		    // details for which payment performed
		    $payDetails = \Stripe\Charge::create(array(
		        'customer'    => $customer->id,
		        'amount'      => $TotalPrice,
		        'currency'    => $defaultCurrency,
		        'description' => $iname,
		    ));   
			
		    // get payment details
		    $paymenyResponse = $payDetails->jsonSerialize();

		     // check whether the payment is successful
		    if ( $paymenyResponse['amount_refunded'] == 0 && empty( $paymenyResponse['failure_code'] ) && $paymenyResponse['paid'] == 1 && $paymenyResponse['captured'] == 1 ) {
		       //if order inserted successfully
		       if ( $paymentStatus == 'succeeded' ) {
		            $paymentMessage = "The payment was successful.";
		       } else{
		          wp_send_json( array( 'status' => 'error', 'message' => esc_html__( 'Payment failed', 'beevent' ) ) );
		       }
		    } else{
		        wp_send_json( array( 'status' => 'error', 'message' => esc_html__( 'Payment failed', 'beevent' ) ) );
		    }

		} elseif ( $method == 'paystack' ) {
			$method = 'Paystack';
		}

		$wpsc_order = array(
		    'post_title'   => 'WPSC Cart Order for '.$iname,
		    'post_type'    => 'wpsc_cart_orders',
		    'post_content' => '',
		    'post_status'  => 'publish',
	    );
	    $post_id = wp_insert_post( $wpsc_order );

	    update_post_meta( $post_id, 'wpspsc_items_ordered', $product_details );
	    update_post_meta( $post_id, 'wpsc_email_address', $uemail );
	    update_post_meta( $post_id, 'wpsc_shipping_amount', $Shipping );
	    update_post_meta( $post_id, 'wpsc_total_amount', $TotalPrice );
	    update_post_meta( $post_id, 'wpsc_ipaddress', $_SERVER['REMOTE_ADDR'] );
	    update_post_meta( $post_id, 'wpsc_address', $address );
	    update_post_meta( $post_id, 'wpspsc_phone', $phone );
	    update_post_meta( $post_id, 'wpsc_order_status', 'Paid' );
	    update_post_meta( $post_id, 'wpsc_txn_id', $Token );
	    update_post_meta( $post_id, 'wpsc_first_name', $fname );
	    update_post_meta( $post_id, 'wpsc_last_name', $lname );
	    update_post_meta( $post_id, 'wpsc_event_name', $ename );

	    if ( isset($_SESSION['simpleCart']) && !empty($_SESSION['simpleCart'] ) ) {
            update_post_meta( $post_id, 'wpsc_cart_items', $_SESSION['simpleCart']);
        }

	    if ( ! empty ( $post_id ) ) {

	    	$args				       = array();
			$args[ 'product_details' ] = $product_details;
			$args[ 'order_id' ]		   = $post_id;
			$args[ 'coupon_code' ]	   = '';
			$args[ 'address' ]		   = $address;
			$args[ 'payer_email' ]	   = $uemail;

			$ipn_data                  = array();
			$ipn_data['first_name']    = $fname;
			$ipn_data['last_name']     = $lname;
			$ipn_data['txn_id']        = $Token;
			$ipn_data['contact_phone'] = $phone;

			$cart_items	  = array();
			$current_item = array(
				'item_number'  => $itemno,
				'item_name'	   => $iname,
				'quantity'	   => $Quantity,
				'mc_gross'	   => $TotalPrice,
				'mc_currency'  => $currency_symbol,
		    );
		    array_push( $cart_items, $current_item );

			$from_email	          = get_option( 'wpspc_buyer_from_email' );
			$subject	          = get_option( 'wpspc_buyer_email_subj' );
			$subject	          = wpspc_apply_dynamic_tags_on_email( $subject, $ipn_data, $args );
			$body			      = get_option( 'wpspc_buyer_email_body' );
			$args[ 'email_body' ] = $body;
			$body			      = wpspc_apply_dynamic_tags_on_email( $body, $ipn_data, $args );
			$body                 = apply_filters( 'wspsc_buyer_notification_email_body', $body, $ipn_data, $cart_items );

			$headers = 'From: ' . $from_email . "\r\n";
			if ( ! empty( $uemail ) ) {
			    if ( get_option( 'wpspc_send_buyer_email' ) ) {
					if(in_array('beevent-post-type/beevent-post-type.php', apply_filters('active_plugins', get_option('active_plugins')))){
						olomo_olomo_wp_mail( $uemail, $subject, $body, $headers );
						update_post_meta( $post_id, 'wpsc_buyer_email_sent', 'Email sent to: ' . $uemail );
					}
			    }
			}
			$notify_email		  = get_option( 'wpspc_notify_email_address' );
			$seller_email_subject = get_option( 'wpspc_seller_email_subj' );
			$seller_email_subject = wpspc_apply_dynamic_tags_on_email( $seller_email_subject, $ipn_data, $args );

			$seller_email_body	  = get_option( 'wpspc_seller_email_body' );
			$args[ 'email_body' ] = $seller_email_body;
			$seller_email_body	  = wpspc_apply_dynamic_tags_on_email( $seller_email_body, $$ipn_data, $args );
			$seller_email_body    = apply_filters( 'wspsc_seller_notification_email_body', $seller_email_body, $ipn_data, $cart_items );

			if ( ! empty( $notify_email ) ) {
			    if ( get_option( 'wpspc_send_seller_email' ) ) {
					if(in_array('beevent-post-type/beevent-post-type.php', apply_filters('active_plugins', get_option('active_plugins')))){
						olomo_olomo_wp_mail( $notify_email, $seller_email_subject, $seller_email_body, $headers );
					}
			    }
			}

			$returnurl = get_option( 'cart_return_from_paypal_url' );
			$returnurl = add_query_arg( 
			        		array( 
			        			'eid' => $post_id 
			        		),
			        		$returnurl
			        	);
	    	$return    = array(
	            'status'    => 'success',
	            'message'   => esc_html__( 'Your payment is successfull', 'beevent' ),
	            'returnurl' => $returnurl
	        );
	    }

	} else {

		if ( empty ( $_POST['fname'] ) ) {
			$message = esc_html__( 'Please enter first name', 'beevent' );
		} elseif ( empty ( $_POST['lname'] ) ) {
			$message = esc_html__( 'Please enter last name', 'beevent' );
		} elseif ( empty ( $_POST['phone'] ) ) {
			$message = esc_html__( 'Please enter phone number', 'beevent' );
		} elseif ( empty ( $_POST['uemail'] ) ) {
			$message = esc_html__( 'Please enter your email', 'beevent' );
		} else {
			$message = esc_html__( 'Something went wrong!', 'beevent' );
		}

        $return  = array(
            'status'  => 'error',
            'message' => $message,
        );
    }
    wp_send_json( $return );
    wp_die();
}
/* Action for Paystack payment */
add_action( 'wp_ajax_nopriv_beevent_save_paystack', 'beevent_paystack_action' );
add_action( 'wp_ajax_beevent_save_paystack', 'beevent_paystack_action' );

function beevent_stripe_action() {
	
}

function beevent_payfast_action() {
	
}

ZeroDay Forums Mini