Paypal Payment Gateway For WordPress

Paypal payment gateway processing steps are

  1. Send data form your website to paypal
  2. Paypal process your data and return payment information
  3. Send again payment information to paypal for IPN validation
  4. Paypal again return IPN validated status, if status true then insert payment informationin in your database

Step1: Send data form your website to paypal

Sending data arguments are
$paypal_args = array(
    'cmd' => '_xclick',
    'amount' => 50,
    'business' => 'your paypal email. User will be payment this account',
    'item_name' => 'test',
    'item_number' => 20,
    'email' => 'payer email. who is send money to your business account',
    'no_shipping' => '1',
    'no_note' => '1',
    'currency_code' => 'USD',
    'charset' => 'UTF-8',
    'custom' => json_encode( array( 'user_id' => 1, 'product_id' => 20 ) ),
    'rm' => '2',
    'return' => 'www.example.com/paypal.php',
    'notify_url' => 'www.example.com/success_message',
    'cbt' => sprintf( __( 'Click here to complete the payment on %s', 'wpuf' ), get_bloginfo( 'name' ) )
);

//paypal url
if( sandbox ) {
    $paypal_url = 'https://www.sandbox.paypal.com/webscr/';
} else {
    $paypal_url = 'https://www.paypal.com/webscr/';
}

$paypal_url = $paypal_url . '?' . http_build_query( $paypal_args );

wp_redirect( $paypal_url );<br>exit;

 

Step2: Paypal process your data and return payment information
Step3: Send again payment information to paypal for IPN validation

www.example.com/paypal.php

 // Get recieved values from post data
$ipn_data = (array) stripslashes_deep( $_POST );
$ipn_data['cmd'] = '_notify-validate';

// Send back post vars to paypal
$params = array(
    'body' => $ipn_data,
    'sslverify' => false,
    'timeout' => 30,
    'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ),
);

//paypal url
if( sandbox ) {
    $paypal_url = 'https://www.sandbox.paypal.com/webscr/';
} else {
    $paypal_url = 'https://www.paypal.com/webscr/';
}

$response = wp_remote_post( $paypal_url, $params );

//Step4: Paypal again return IPN validated status, if status true then //insert payment informationin in your database

if ( !is_wp_error( $response ) && $response['response']['code'] >= 200 && $response['response']['code'] < 300 && (strcmp( $response['body'], "VERIFIED" ) == 0) ) {
    return true;
} else {
    return false;
}

 

 

WordPress File Upload Process

This function has created for wordpress file uploading . You can easily upload your file with the help of this function.

function file_upload() {
    $upload = array(
        'name' => $_FILES['file']['name'],
        'type' => $_FILES['file']['type'],
        'tmp_name' => $_FILES['file']['tmp_name'],
        'error' => $_FILES['file']['error'],
        'size' => $_FILES['file']['size']
    );

    header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );

    $attach = handle_upload( $upload );

    if ( $attach['success'] ) {
        echo 'Successfully upload your file';
    } else {
        echo 'Fail to upload your file';
    }
}
function handle_upload( $upload_data ) {

    if ( ! function_exists( 'wp_handle_upload' ) ) {
       require_once( ABSPATH . 'wp-admin/includes/file.php' );
    }

    $uploaded_file = wp_handle_upload( $upload_data, array('test_form' => false) );

    if ( isset( $uploaded_file['file'] ) ) {
        $file_loc = $uploaded_file['file'];
        $file_name = basename( $upload_data['name'] );
        $file_type = wp_check_filetype( $file_name );
        $post_title = preg_replace( '/\.[^.]+$/', '', basename( $file_name ) );

        $attachment = array(
            'post_mime_type' => $file_type['type'],
            'post_title' => $post_title,
            'post_content' => '',
            'post_status' => 'inherit'
        );

        include( ABSPATH . 'wp-admin/includes/image.php' );
        $attach_id = wp_insert_attachment( $attachment, $file_loc );
        $attach_data = wp_generate_attachment_metadata( $attach_id, $file_loc );
        wp_update_attachment_metadata( $attach_id, $attach_data );
        return array('success' => true, 'attach_id' => $attach_id);
    }

    return array('success' => false, 'error' => $uploaded_file['error']);
}

 

WordPress Email Sending Configuration

WordPress email sending configuration for Bcc (Blind carbon copy).  If you want to send Cc (carbon copy) then change the first line as

$type = 'Cc: User <user@example.com>, Another User <anotheruser@example.com>';

Does not use to Bcc or Cc then remove the first line as

$type = 'Bcc: User <user@example.com>, Another User <anotheruser@example.com>';

here if full code

$type = 'Bcc: User <user@example.com>, Another User <anotheruser@example.com>';
$admin_email = get_option( 'admin_email' );
$blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
$reply = 'no-reply@' . preg_replace( '#^www\.#', '', strtolower( $_SERVER['SERVER_NAME'] ) );
$reply_to = "Reply_To: <$reply>";
$content_type = 'Content-Type: text/html';
$charset = 'Charset: UTF-8';
$from = "From: $blogname <$reply>";
$subject = 'test';
$message = 'Hi, how are you?';

$headers = array(
    $type,
    $reply_to,
    $content_type,
    $charset,
    $from
);
wp_mai( $admin_email, $subject, $message, $headers);

 

Drop Down Menu

CSS Design for WordPress Vartical Navigation Menus

<div id="nav_menue">
	<?php wp_nav_menu( array( 'menu' => 'headermemu') ); ?>
</div>
 #nav_menue ul li ul{
    position: absolute;
    display: none;
    top: -1px;
    left: 100%;
    width: 80%;
}
#nav_menue  ul li:hover>ul{
    display: block;
}
#nav_menue ul li{
    position: relative;
    margin-top: 0;
    list-style:none;
}
.parent> a{
    background: url(images/right.gif) no-repeat 97% 50%;
}
#nav_menue ul{
    padding: 0;
    margin: 0;
    list-style-type: none;
    font: bold 13px Verdana;
    list-style: none;
    width: 220px;
}
#nav_menue ul li:first-child{
    border-top: 1px solid #778;
}
#nav_menue ul li a{
    display:block;
    overflow: auto; /*force hasLayout in IE7 */
    color: #535353;
    font-size: 14px;
    text-decoration: none;
    padding: 6px;
    border-bottom: 1px solid #778;
    border-right: 1px solid #778;
    border-left: 1px solid #777788;
    margin-top:0;
}
#nav_menue ul li a:link, #nav_menue ul li a:visited, #nav_menue ul li a:active{
    background-color: #EDEDED; /*background of tabs (default state)*/
}
#nav_menue ul li a:hover{
    background-color: black;
    color: #fff;
}

CSS Design for wordpress Horizontal Navigation menu

<div id="header_nav_menu">
	<?php wp_nav_menu( array( 'menu' => 'headermemu') ); ?>
</div>
#header_nav_menu li a,
#header_nav_menu li {
    display: inline-block;
    text-decoration: none;
}
#header_nav_menu li a {
    border-bottom: 0;
    color: #6a6a6a;
    text-transform: uppercase;
    white-space: nowrap;
}
#header_nav_menu li a:hover {
    color: #000;
}
#header_nav_menu li {
    margin: 0 40px 0 0;
    margin: 0 2.857142857rem 0 0;
    position: relative;
}
#header_nav_menu li ul {
    display: none;
    margin: 0;
    padding: 0;
    position: absolute;
    top: 100%;
    z-index: 1;
}
#header_nav_menu li ul ul {
    top: 0;
    left: 100%;
}
#header_nav_menu ul li:hover > ul {
    border-left: 0;
    display: block;
}
#header_nav_menu li ul li a {
    background: #efefef;
    border-bottom: 1px solid #ededed;
    display: block;
    font-size: 11px;
    font-size: 0.785714286rem;
    line-height: 2.181818182;
    padding: 8px 10px;
    padding: 0.571428571rem 0.714285714rem;
    width: 180px;
    width: 12.85714286rem;
    white-space: normal;
}
#header_nav_menu li ul li a:hover {
    background: #e3e3e3;
    color: #444;
}