Beispiel #1
0
function actionConfirm()
{
    global $configuration;
    $errors = array();
    if ($_SESSION['Creditcard']['CardType'] == 'Paypal') {
        $result = sendPaypalRequest();
        if (is_array($result)) {
            update_order('status', 'Refused');
        } else {
            $token = $result;
            update_order('token', $token);
            clean_order();
            $paypalUrl = $configuration['paypal']['paypalUrl'] . '/webscr&cmd=_express-checkout&useraction=commit&token=' . $token;
            header('Location: ' . $paypalUrl);
            exit;
        }
    } else {
        $guid = $_SESSION['uid'];
        if (!isset($_SESSION['orderWaiting'])) {
            $_SESSION['orderWaiting'] = true;
            update_order('status', 'Waiting');
            $result = sendCreditRequest();
            if (is_array($result)) {
                update_order('status', 'Refused');
            } else {
                $transactionId = $result;
                $_SESSION['transaction_id'] = $transactionId;
                update_order('transaction_id', $transactionId);
                update_order('status', 'Completed');
            }
        } else {
            $result[] = 'Transaction Treated';
        }
    }
    if (is_array($result)) {
        $_SESSION['orderWaiting'] = true;
    }
    return $result;
}
Beispiel #2
0
function dt_paypal_listener() {

	if( isset( $_GET['action'] ) ) {
		switch ( $_GET['action'] ) {

			case 'dt_paypal_cancel':
				$arg = array('action','res');
				delete_option($_GET['res']);
				#$url = remove_query_arg( $args ,home_url() );
				$url = dt_get_page_permalink_by_its_template('tpl-reservation.php');
				$url = remove_query_arg( $args ,$url );
				$url = add_query_arg( array( 'action' => 'error' ) , $url );
				wp_safe_redirect($url);
				exit;
			break;

			case 'dt_paypal_retrun':

				$reservation = get_option($_REQUEST['res']);

				$staff = explode("_",$_REQUEST['res']);
				$staff_name = get_the_title($staff[4]);
				$service_name = get_the_title($reservation['service']);
				$start = new DateTime($reservation['start']);
				$end = new DateTime($reservation['end']);
				$date = date_format($start, "Y/m/d");
				$time = date_format($start,"g:i a").' - '.date_format($end,"g:i a");

				$client_name = get_the_title($reservation['user']);
				$cinfo = get_post_meta( $reservation['user'], "_info",true);
				$cinfo = is_array($cinfo) ? $cinfo : array();
				$client_email = array_key_exists('emailid', $cinfo) ? $cinfo['emailid'] : "";
				$client_phone = array_key_exists('phone', $cinfo) ? $cinfo['phone'] : "";

				#Staff Price
				$sinfo = get_post_meta( $staff[4] , "_info",true);
				$sinfo = is_array($sinfo) ? $sinfo : array();
				$staff_price = array_key_exists("price", $sinfo) ? $sinfo['price'] : 0;
				$staff_price = floatval($staff_price);

				#Service Price
				$serviceinfo = get_post_meta($reservation['service'],'_info',true );
				$serviceinfo = is_array( $serviceinfo ) ? $serviceinfo : array();
				$service_price = array_key_exists("price", $serviceinfo) ? $serviceinfo['price'] : 0;
				$service_price = floatval($service_price);

				$amount = ( ($staff_price+$service_price) > 0 ) ? ( $staff_price+$service_price ) : "";

				$pdata = '&TOKEN='.$_REQUEST['token']
					.'&PAYERID='.$_REQUEST['PayerID']
					.'&PAYMENTACTION='.urlencode( "SALE" )
					.'&AMT='.urlencode($amount);

					//We need to execute the "DoExpressCheckoutPayment" at this point to Receive payment from user.
					$response = sendPaypalRequest('DoExpressCheckoutPayment', $pdata);

				if ( "SUCCESS" == strtoupper( $response["ACK"] ) || "SUCCESSWITHWARNING" == strtoupper( $response["ACK"] ) ) {

					// we can retrieve transaction details using either GetTransactionDetails or GetExpressCheckoutDetails
					// GetTransactionDetails requires a Transaction ID, and GetExpressCheckoutDetails requires Token returned by SetExpressCheckOut
					$response = sendPaypalRequest( 'GetTransactionDetails', "&TRANSACTIONID=" . urlencode( $response["TRANSACTIONID"] ) );

					if ( "SUCCESS" == strtoupper( $response["ACK"] ) || "SUCCESSWITHWARNING" == strtoupper( $response["ACK"] ) ) {

						$array = array(
							'staff_name' => $staff_name,
							'service_name' => $service_name,
							'appointment_id' => $reservation['id'],
							'appointment_time' => $time,
							'appointment_date' => $date,
							'appointment_title' => $reservation['title'],
							'appointment_body' =>  $reservation['body'],
							'client_name' => $client_name,
							'client_phone' => $client_phone,
							'client_email' => $client_email,
							'amount' => $amount,
							'company_logo' => 'Company Logo',
							'company_name' => 'Company Name',
							'company_phone' => 'Company Phone',
							'company_address' => 'Company Address',
							'company_website' => 'Company Website');

						#Staff Mail
						$subject =  dttheme_option('company', 'appointment_notification_to_staff_subject');

						$subject = dt_replace( $subject, $array);

						$message =  dttheme_option('company', 'appointment_notification_to_staff_message' );
						$message = dt_replace( $message, $array);

						dt_send_mail( $sinfo["emailid"], $subject, $message);

						#Customer Mail
						$subject =  dttheme_option('company', 'appointment_notification_to_client_subject');
						$subject = dt_replace( $subject, $array);

						$message =  dttheme_option('company', 'appointment_notification_to_client_message' );
						$message = dt_replace( $message, $array);
						dt_send_mail( $client_email, $subject, $message);

						#Add Payment Details to options table
						$payment_id = str_replace('_dt_reservation_',"_dt_payment_",$_REQUEST['res']);
						$payment_data = array( 
							'date' =>  date('Y-m-d H:i:s'),
							'service' => get_the_title($reservation['service']),
							'type' => 'paypal',
							'customer_id' =>$reservation['user'],
							'token' => $_REQUEST['token'],
							'status' => $response['PAYMENTSTATUS'],
							'transaction_id'=> $response['TRANSACTIONID'],
							'total'=> urldecode( $response['AMT']));
						update_option($payment_id,$payment_data);

						$arg = array('action','res');
						# $url = remove_query_arg( $args ,home_url() );
						$url = dt_get_page_permalink_by_its_template('tpl-reservation.php');
						$url = remove_query_arg( $args ,$url );
						$url = add_query_arg( array( 'action' => 'success' ) , $url );
						wp_safe_redirect($url);
						exit;
					} else {
						throw new Exception( urldecode( $response["L_LONGMESSAGE0"] ) );
					}
				} else {
					throw new Exception( urldecode( $response["L_LONGMESSAGE0"] ) );
				}
			break;
		}
	}
}?>