PHP Developer

Tuesday, 3 October 2017

Pay with PayPal and get transaction Detail using simple HTML Form

Pay with PayPal and get transaction Detail using simple HTML Form



<?php

if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['invoice_payment']) && !empty($_POST['invoice_payment'])) {
    //$paypal_email = 'sanjay@gmail.com.com';  //DUMMY
    $paypal_email = 'sunil@gmail.com.com';    //LIVE
 
    $return_url = site_url().'/pay-by-paypal/?type=pay_now&invoiceno='.$_GET['invoiceno'].'&paystatus=completed';
    $cancel_url = site_url().'/pay-by-paypal/?type=pay_now&invoiceno='.$_GET['invoiceno'].'&paystatus=canceled';
    $notify_url = '';

    $item_name = 'Pay for Invoice id : '.$_GET['invoiceno'];
    $item_amount = $total_amount;
    $querystring = '';

    // Firstly Append paypal account to querystring
    $querystring .= "?business=".urlencode($paypal_email)."&";

    // Append amount& currency (£) to quersytring so it cannot be edited in html

    //The item name and amount can be brought in dynamically by querying the $_POST['item_number'] variable.
    $querystring .= "item_name=".urlencode($item_name)."&";
    $querystring .= "amount=".urlencode($item_amount)."&";

    //loop for posted values and append to querystring
    foreach($_POST as $key => $value){
            $value = urlencode(stripslashes($value));
            $querystring .= "$key=$value&";
    }

    // Append paypal return addresses
    $querystring .= "return=".urlencode(stripslashes($return_url))."&";
    $querystring .= "cancel_return=".urlencode(stripslashes($cancel_url))."&";
    $querystring .= "notify_url=".urlencode($notify_url);

    // Append querystring with custom field
    //$querystring .= "&custom=".USERID;

    // Redirect to paypal IPN
    //header('location:https://www.sandbox.paypal.com/cgi-bin/webscr'.$querystring);   // Dummy Sandbox paypal Payment
    header('location:https://www.paypal.com/cgi-bin/webscr'.$querystring);  //Live Paypal Payment
    exit();
} ?>
<?php
$item_number = mt_rand(100000000000000,999999999999999);
$invoiceno = 9087786546;
$current_userid = get_current_user_id();
?>
<form class="paypal" action="" method="post" id="paypal_form">
    <input type="hidden" name="cmd" value="_xclick" />
    <input type="hidden" name="no_note" value="1" />
    <input type="hidden" name="lc" value="US" />
    <input type="hidden" name="currency_code" value="USD" />
    <input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynow_LG.gif:NonHostedGuest" />
    <input type="hidden" name="first_name" value="Sunil"  />
    <input type="hidden" name="last_name" value="Sharma"  />
    <input type="hidden" name="payer_email" value="sunil.sharma@gmail.com"  />  <!-- PayPal ID -->
    <input type="hidden" name="paid_by" value="<?php echo $current_userid;?>"  />
    <input type="hidden" name="paid_to" value="<?php echo $writer_id;?>"  />
    <input type="hidden" name="pay_for_invoiceid" value="<?php echo $invoiceno;?>"  />
    <input type="hidden" name="invoice_payment" value="writer_invoice"  />
    <input type="hidden" name="item_number" value="<?php echo $item_number;?>" / >
    <input type='hidden' name='rm' value='2'>
    <input type="submit" name="submit" class="paypal_paynow" value="PAY NOW"/>
</form>


And get response on return URL "$return_url" using $_REQUEST

Thursday, 31 August 2017

Add Event on Google And Outlook Calendar

Add Event on Google And Outlook Calendar


<?php
function google_outlook_calender_event($from_name, $from_address, $to_name, $to_address, $startTime, $endTime, $subject, $description, $location, $title){

    $domain = 'google.com';

    //Create Email Headers
    $mime_boundary = "----Meeting Booking----".MD5(TIME());

    $headers = "From: ".$from_name." <".$from_address.">\n";
    $headers .= "Reply-To: ".$from_name." <".$from_address.">\n";
    $headers .= "MIME-Version: 1.0\n";
    $headers .= "Content-Type: multipart/alternative; boundary=\"$mime_boundary\"\n";
    $headers .= "Content-class: urn:content-classes:calendarmessage\n";
    
    //Create Email Body (HTML)
    $message = "--$mime_boundary\r\n";
    $message .= "Content-Type: text/html; charset=UTF-8\n";
    $message .= "Content-Transfer-Encoding: 8bit\n\n";
    $message .= "<html>\n";
    $message .= "<body>\n";
    $message .= '<p>Dear '.$to_name.',</p>';
    $message .= '<p>'.$description.'</p>';
    $message .= "</body>\n";
    $message .= "</html>\n";
    $message .= "--$mime_boundary\r\n";
    
    date_default_timezone_set('America/Denver');

    $ical = 'BEGIN:VCALENDAR' . "\r\n" .
    'PRODID:-//Microsoft Corporation//Outlook 10.0 MIMEDIR//EN' . "\r\n" .
    'VERSION:2.0' . "\r\n" .
    'METHOD:REQUEST' . "\r\n" .
    'BEGIN:VTIMEZONE' . "\r\n" .
    'TZID:America/Denver Time' . "\r\n" .
    'BEGIN:STANDARD' . "\r\n" .
    'DTSTART:20170701T000000' . "\r\n" .
    'RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=1SU;BYMONTH=11' . "\r\n" .
    'TZOFFSETFROM:-0300' . "\r\n" .
    'TZOFFSETTO:-0400' . "\r\n" .
    'TZNAME:EST' . "\r\n" .
    'END:STANDARD' . "\r\n" .
    'BEGIN:DAYLIGHT' . "\r\n" .
    'DTSTART:20170701T000000' . "\r\n" .
    'RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=2SU;BYMONTH=3' . "\r\n" .
    'TZOFFSETFROM:-0800' . "\r\n" .
    'TZOFFSETTO:-0700' . "\r\n" .
    'TZNAME:EDST' . "\r\n" .
    'END:DAYLIGHT' . "\r\n" .
    'END:VTIMEZONE' . "\r\n" .
    'BEGIN:VEVENT' . "\r\n" .
    'ORGANIZER;CN="'.$from_name.'":MAILTO:'.$from_address. "\r\n" .
    'ATTENDEE;CN="'.$to_name.'";ROLE=REQ-PARTICIPANT;RSVP=TRUE:MAILTO:'.$to_address. "\r\n" .
    'LAST-MODIFIED:' . date("YmdTHis") . "\r\n" .
    'UID:'.date("Ymd\THis", strtotime($startTime)).rand()."@".$domain."\r\n" .
    'DTSTAMP:20170905T000000' . "\r\n" .
    //'DTSTART;TZID="America/Denver Time":'.date("YmdTHis", strtotime($startTime)). "\r\n" .
    //'DTEND;TZID="America/Denver Time":'.date("YmdTHis", strtotime($endTime)). "\r\n" .
            
    'DTSTART;TZID="America/Denver Time":'.date("Ymd\THis", strtotime($startTime)). "\r\n" .
    'DTEND;TZID="America/Denver Time":'.date("Ymd\THis", strtotime($endTime)). "\r\n" .
    
    //'DTSTART;TZID="America/Denver Time":20170906T000000' . "\r\n" .
    //'DTEND;TZID="America/Denver Time":20170907T000000' . "\r\n" . 
    
    //'DTSTART;TZID="America/New_York Time":20170905' . "\r\n" .  //For Full Day Event on Google
    //'DTEND;TZID="America/New_York Time":20170905' . "\r\n" .    //For full day event on Google
    'TRANSP:OPAQUE'. "\r\n" .
    'SEQUENCE:1'. "\r\n" .
    'SUMMARY:' . $title . '\n' .
    'LOCATION:' . $location . "\r\n" .
    'CLASS:PUBLIC'. "\r\n" .
    'PRIORITY:5'. "\r\n" .
    'BEGIN:VALARM' . "\r\n" .
    'TRIGGER:-PT15M' . "\r\n" .
    'ACTION:DISPLAY' . "\r\n" .
    'DESCRIPTION:Reminder' . "\r\n" .
    'END:VALARM' . "\r\n" .
    'END:VEVENT'. "\r\n" .
    'END:VCALENDAR'. "\r\n";
    $message .= 'Content-Type: text/calendar;name="meeting.ics";method=REQUEST'."\n";
    $message .= "Content-Transfer-Encoding: 8bit\n\n";
    $message .= $ical;

    $mailsent = mail($to_address, $subject, $message, $headers);
    
    return ($mailsent)?(true):(false);
}


$from_name = "Admin";
$from_address = "sunil.sharma27783@gmail.com";
$to_name = "Sunil";        
//$to_address = "sunilsharma.it7@gmail.com";
$to_address = "sunilsharma.it7@outlook.com";
$startTime = "13-09-2017";
$endTime = "14-09-2017";
$subject = "Post Due Date Event";        
$description = 'This is my custom Description. Link <a href="#">CONTENT LINK</a>';        
$location = "";
$title = 'Courtney: ACL Repair Washington DC';

google_outlook_calender_event($from_name, $from_address, $to_name, $to_address, $startTime, $endTime, $subject, $description, $location, $title);

?>

Thursday, 10 August 2017

Custom Code to create Captcha

Custom Code to create Captcha :- 



<html>
   <head>
<script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
   </head>
   <body>
      <form method="post" action="http://astro-global.blogspot.in/" onsubmit="return checkform(this);">
         <!-- START CAPTCHA -->
         <br>
         <div class="capbox">
            <div id="CaptchaDiv"></div>
            <div class="capbox-inner">
               Type the above number:<br>
               <input type="hidden" id="txtCaptcha">
               <input type="text" name="CaptchaInput" id="CaptchaInput" size="15"><br>
            </div>
         </div>
         <br><br>
         <!-- END CAPTCHA -->
<button type="button" class="refresh_captcha" onclick="refresh_captcha();" title="Refresh Captcha Code"><img src="https://cdn3.iconfinder.com/data/icons/faticons/32/sync-01-128.png"></button>
         <input type="submit" value="Test Captcha">
      </form>
      <script type="text/javascript">
jQuery( document ).ready(function() {
refresh_captcha();
});
         // Captcha Script
       
function checkform(theform){
var why = "";

if(theform.CaptchaInput.value == ""){
why += "- Please Enter CAPTCHA Code.\n";
}
if(theform.CaptchaInput.value != ""){
if(ValidCaptcha(theform.CaptchaInput.value) == false){
why += "- The CAPTCHA Code Does Not Match.\n";
}
}
if(why != ""){
alert(why);
return false;
}
}

function refresh_captcha(){
var a = Math.ceil(Math.random() * 9)+ '';
var b = Math.ceil(Math.random() * 9)+ '';
var c = Math.ceil(Math.random() * 9)+ '';
var d = Math.ceil(Math.random() * 9)+ '';
var e = Math.ceil(Math.random() * 9)+ '';
var f = Math.ceil(Math.random() * 9)+ '';
var g = Math.ceil(Math.random() * 9)+ '';

var code = a + b + c + d + e + f + g;
jQuery("#CaptchaDiv").html(code);
jQuery("#txtCaptcha").val(code);
//document.getElementById("txtCaptcha").value = code;
//document.getElementById("CaptchaDiv").innerHTML = code;
}
       
       
       
         // Validate input against the generated number
         function ValidCaptcha(){
var str1 = removeSpaces(document.getElementById('txtCaptcha').value);
var str2 = removeSpaces(document.getElementById('CaptchaInput').value);
if (str1 == str2){
return true;
}else{
return false;
}
         }
       
         // Remove the spaces from the entered and generated code
         function removeSpaces(string){
         return string.split(' ').join('');
         }
      </script>
      <style>
         .capbox {
         background-color: #92D433;
         border: #B3E272 0px solid;
         border-width: 0px 12px 0px 0px;
         display: inline-block;
         *display: inline; zoom: 1; /* FOR IE7-8 */
         padding: 8px 40px 8px 8px;
         }
         .capbox-inner {
         font: bold 11px arial, sans-serif;
         color: #000000;
         background-color: #DBF3BA;
         margin: 5px auto 0px auto;
         padding: 3px;
         -moz-border-radius: 4px;
         -webkit-border-radius: 4px;
         border-radius: 4px;
         }
         #CaptchaDiv {
         font: bold 17px verdana, arial, sans-serif;
         font-style: italic;
         color: #000000;
         background-color: #FFFFFF;
         padding: 4px;
         -moz-border-radius: 4px;
         -webkit-border-radius: 4px;
         border-radius: 4px;
         }
         #CaptchaInput { margin: 1px 0px 1px 0px; width: 135px; }
button.refresh_captcha {
padding: 0;
border: none;
background: transparent;
/* width: 20px; */
cursor: pointer;
}
button.refresh_captcha img {
width: 30px;
height: 30px;
}
      </style>
   </body>
</html>

Thursday, 20 July 2017

How to get transaction details in notify_url page in paypal

How to get transaction details in notify_url page in paypal


<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="POST" name="_xclick" id="paypal_form">
   <input type="hidden" name="upload" value="1" />
   <input type="hidden" name="cmd" value="_xclick" />
   <!-- The business email address, where you want to receive the payment -->
   <!--<input type="hidden" name="business" value="yesidealpayment@gmail.com" />-->
   <input type="hidden" name="business" value="sunil@rudrainnovatives.com" />
   <!-- The customer email address -->
   <input type="hidden" name="item_name_1" value="Invoice payment" />
   <input type="hidden" name="amount_1" value="2" />
   <!--<input type="hidden" name="currency_code" value="AUD" />-->
   <input type="hidden" name="currency_code" value="USD" />
   <input type="hidden" name="amount" value="2" /> 
   <!-- Where you want to return after PayPal Payment -->
   <input type="hidden" name="return" value="http://localhost/paypals/response.php" />
   <!-- A back-end notification send to the specific page after successful payment  -->
   <!--<input type="hidden" name="notify_url" value="http://yes-i-deal.com.au/test/paypal.php" />-->
   <input type="hidden" name="notify_url" value="http://localhost/paypals/response.php" />
   <!-- Where you want to return after cancel the PayPal Payment  -->
   <input type="hidden" name="cancel_return" value="http://localhost/paypals/response.php" />
   <input type="hidden" name="custom" value="25" />  
   <input type="image" name="submit"   src="http://localhost/paypals/themes/green/images/Buy-Now-Button.png" />
</form>



In my notify_url page I am getting values as : 

<?php
echo "<pre>";
print_r($_REQUEST);
echo "<pre>";
?>

Wednesday, 28 September 2016

Codeignetor Code


https://drive.google.com/open?id=0B4i05RJ0-BFRZXhEWTVzWVBHblk

Thursday, 15 September 2016

Wordpress Custom Category Template WIth Custom Pagination

Wordpress Custom Category Template WIth Custom Pagination


1) Create new file for custom taxonomy and upload in wordpress theme taxonomy-(taxonomy-name).php
    Example : Id Taxonomy name is "vacancies_uts". Then file name is "taxonomy-vacancies_uts.php".


2) Add this code in functions.php file for pagination anywhere in website

 
<?php
/************ Pagination Function START *************/
function wp_pagination() {
    global $wp_query;
    $big = 12345678;
    $page_format = paginate_links( array(
        'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
        'format' => '?paged=%#%',
        'current' => max( 1, get_query_var('paged') ),
        'total' => $wp_query->max_num_pages,
        'type'  => 'array'
    ) );
    if( is_array($page_format) ) {
        $paged = ( get_query_var('paged') == 0 ) ? 1 : get_query_var('paged');
        echo '<div><ul>';
        echo '<li><span>'. $paged . ' of ' . $wp_query->max_num_pages .'</span></li>';
        foreach ( $page_format as $page ) {
                echo "<li>$page</li>";
        }
       echo '</ul></div>';
    }
}
/************ Pagination Function END *************/
?>
   
3) Add below code in "taxonomy-vacancies_uts.php" and upload in activated theme.

<?php
/**
 * The template for displaying all pages.
 *
*/


get_header(); ?>
<?php

$queried_object = get_queried_object();
$term_id = $queried_object->term_id;
$term_name = $queried_object->name;
?>
<div id="content" class="content" role="main">

<?php
$today = date('m/d/Y');
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

query_posts(array(
//'posts_per_page' => 2,
'post_type' => 'vacancies', //Post Type
'post_status' => 'publish', //Post Status
'tax_query' => array(
    array(
        'taxonomy' => 'vacancies_uts', //Texonomy Name
        'field' => 'id',
        'terms' => $term_id
    )
),
'meta_query' => array(
    array(
        'key' => 'last_date',  //Meta Field name for compare
        'value' => $today,     //Meta Field Value compare with this value
        'compare' => '>='
    )
),
'paged' => $paged
)
);
?>
<?php if ( have_posts() ) : ?>
<div class="cat_heading"><div class="cat_name"><?php echo $term_name;?></div></div>
<table class="vacancies_tables">
<?php while ( have_posts() ) : the_post(); ?>
    <?php $vacancies_elgible = get_the_terms( get_the_ID(), 'vacancies_elgible' );?>
    <tr>
        <td class="vac_title" data-label="Exam"><a href="<?php echo get_the_permalink();?>"><?php echo get_the_title();?></a></td>
        <td class="detail_link" data-label="Details"><a class="home_viewmore" href="<?php echo get_the_permalink();?>">View More</a></td>
    </tr>
<?php endwhile; ?>
</table>
<div class="custom_pagination"><?php wp_pagination(); ?></div>
<?php else : ?>

<?php //get_template_part( 'no-results', 'page' ); ?>
<?php echo "Sorry, no vacancies available under this Category."; ?>

<?php endif;?>

</div><!-- #content -->

<?php get_footer(); ?>

Tuesday, 13 September 2016

Image Mapping


Image Mapping means more than one link add on single image on different image locations.

And best website for image mapping is https://www.image-map.net/