Tag Archives: paypal

simple paypal with add entry in backend


<!-- Paypal form -->
<?php $pageURL = "http://localhost/sublimesourcery/treasure-trove/"; ?>
<!--<form action="https://www.paypal.com/cgi-bin/webscr" method="post">-->
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="raviradadiya.ommune-facilitator@gmail.com">
<input type="hidden" name="item_name" value="Donation">
<input type="hidden" name="item_number" value="1">
<input type="hidden" name="amount" value="1">

<input type="hidden" name="rm" value="2">
<input type="hidden" name="custom" value="" id="customval">

<input type="hidden" name="no_shipping" value="0">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="lc" value="AU">
<input type="hidden" name="bn" value="PP-BuyNowBF">
<input type="hidden" name="return" value="<?php echo $pageURL; ?>">
<input type="submit" value="Pay with PayPal!">
</form>
<!-- End Paypal form -->

<?php
if(!empty($_POST)){

global $wpdb;
$player_name = $_POST['first_name'];
$payer_email = $_POST['payer_email'];
$payment_gross = $_POST['payment_gross'];
$payment_date = $_POST['payment_date'];
$payer_id = $_POST['payer_id'];

$wpdb->insert(
'wp_paypal',
array(
'name' => $player_name,
'player_id' =>$payer_id,
'email' =>  $payer_email,
'amount' => $payment_gross,
'payment_date' => $payment_date
),
array(
'%s',
'%s',
'%s',
'%s',
)
);

//echo '<pre>';
//print_r($_POST);
/*$paypal_str = array($player_name, $payer_email, $payment_gross, $payment_date, $payer_id);
echo '<pre>';
print_r($paypal_str);

//$comma_separated = implode(",", $paypal_str);
//echo $comma_separated; // lastname,email,phone
global $wpdb;
$wpdb->insert(
'wp_paypal',
array(
'name' =>  $paypal_str[0],
'email' => $paypal_str[1],
'amount' => $paypal_str[2],
'player_id' => $paypal_str[3],
'date' => $paypal_str[4],
)
);*/
}

/* For Displayind data in backend */
functions.php


add_action('admin_menu', 'my_menu_pages');
function my_menu_pages(){
add_menu_page('Members', 'Members', 'manage_options', 'my-menu', 'my_menu_output', 'dashicons-groups' );
//add_submenu_page('my-menu', 'Submenu Page Title', 'Whatever You Want', 'manage_options', 'my-menu' );
}
function my_menu_output(){
echo '<h2>All Membrs</h2>';
global $wpdb;
$retrieve_data = $wpdb->get_results( "SELECT * FROM wp_paypal" );
echo '<table border=1 class="table table-striped"><tr><th>Name</th><th>Email</th><th>Amount</th><th>Player id</th><th>Payment Date</th></tr>';
foreach ($retrieve_data as $retrieved_data){
echo '<tr><td>'. $retrieved_data->name.'</td>';
echo '<td>'.$retrieved_data->email.'</td>';
echo '<td>'. $retrieved_data->amount.'</td>';
echo '<td>'. $retrieved_data->player_id.'</td>';
echo '<td>'. $retrieved_data->payment_date.'</td>';
}
echo '</table>';
}

Advertisements

Paypal Integration with custom fields

Description:

1) Create simple user form

2) Create simple paypal form

3) paypal form auto submit on user form submit (Using Ajax Trigger)

4) User and User meta create in database when user make payment successfully and return on website. (Admin User and Created user get username and password via email address).

5) Paypal Account for Sandbox(Test) and Business Managed from themeoptions.

membership.php (pagetemplate)


if(!empty($_POST)){
//echo "<pre>";
//print_r($_POST);

$paypal_payer_id = $_POST['payer_id'];
$paypal_payment_gross = $_POST['payment_gross'];
$paypal_payer_email = $_POST['payer_email'];
$paypal_payment_date = $_POST['payment_date'];
$paypal_custom = $_POST['custom'];
$data_explode = explode(",",$paypal_custom);

$mname = $data_explode[0];
$maddress = $data_explode[1];
$mphone = $data_explode[2];
$memail = $data_explode[3];
$muname = $data_explode[4];
$mpass = $data_explode[5];

$data_explode = array(
'user_email' => $data_explode[3],
'user_login' => $data_explode[4],
'user_pass' =>  $data_explode[5],
);

$user_id = wp_insert_user($data_explode);

update_user_meta($user_id, 'm_name', $mname);
update_user_meta($user_id, 'm_address', $maddress);
update_user_meta($user_id, 'm_phone_num', $mphone);

update_user_meta($user_id, 'paypal_payer_id', $paypal_payer_id);
update_user_meta($user_id, 'paypal_payment_gross', $paypal_payment_gross);
update_user_meta($user_id, 'paypal_payer_email', $paypal_payer_email);
update_user_meta($user_id, 'paypal_payment_date', $paypal_payment_date);

$blogusers = get_users( 'role=administrator');
$user_email=array();
foreach ( $blogusers as $user ) {
$user_email[]=$user->user_email;
}
$from_email=implode(",",$user_email);

$to = array($memail,$from_email);
//$urllink = "http://steve.seomonastery.com/wp-admin"; //get_page_link(54);
$subject = 'Your Admin Password';
$body = 'Your User name is: <b>' . $muname . '</b> </br>
Your Password is: <b>' . $mpass . '</b></br>';
wp_mail($to, $subject, $body);

}?>

<form id="ajaxform_member" action="ajaxform_member" method="post">
<table class="signup-tbl">
<tr>
<td><label for="mname">Name:</label></td>
<td><input type="text" required id="mname" name="mname"></td>
</tr>
<tr>
<td><label for="maddress">Address:</label></td>
<td><input type="text" name="maddress" id="maddress" required></td>
</tr>
<tr>
<td><label for="mphone_num">Phone Number:</label></td>
<td><input type="text" name="mphone_num" id="mphone_num" required></td>
</tr>
<tr>
<td><label for="memail">Email:</label></td>
<td><input type="email" name="memail" id="memail" required></td>
</tr>
<tr>
<td><label for="muname">User Name:</label></td>
<td><input type="text" name="muname" id="muname" required></td>
</tr>
<tr>
<td><label for="mpass">Password:</label></td>
<td><input type="password" name="mpass" id="mpass" required></td>
</tr>
</table>
<input class="signup-tbl-btn" id="form-ajax-submit" type="button" value="Paypal Ckeckout " name="mregister">
<p class="status"></p>
</form>

<!-- <form action="https://www.paypal.com/cgi-bin/webscr" method="post" id="point_buy"> -->
<!-- <form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" id="point_buy"> -->
<form action="<?php if($medics_options['paypalac']== 'YES') { echo 'https://www.paypal.com/cgi-bin/webscr'; } else { echo 'https://www.sandbox.paypal.com/cgi-bin/webscr'; } ?>" method="post" id="point_buy">

<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="
<?php if($medics_options['paypalac'] == 'YES') {  echo sanitize_email($medics_options['paypal_email']); } else { echo sanitize_email($medics_options['paypal_business_email']); }?>">

<input type="hidden" name="amount" id="amount" value="<?php if(!empty($medics_options['paypal_amount'])) { echo esc_attr($medics_options['paypal_amount']); } ?>" >

<input type="hidden" name="rm" value="2">
<input type="hidden" name="custom" id="paypal_custom" value="" />

<input type="hidden" name="no_shipping" value="0">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="lc" value="AU">
<input type="hidden" name="bn" value="PP-BuyNowBF">
<input type="hidden" name="return" value="<?php echo get_permalink(115); ?>" />

<br /><br />
<input class="paypal" type="image" src="https://www.paypal.com/en_US/i/btn/btn_xpressCheckout.gif" style="width:auto; height:auto; border:0;" alt="PayPal" />

ajax-signup.js


jQuery(document).ready(function($) {
$("#form-ajax-submit").click(function(){
//validation
var mname = $("#mname").val();
var maddress = $("#maddress").val();
var mphone_num = $("#mphone_num").val();
var memail = $("#memail").val();
var muname = $("#muname").val();
var mpass = $("#mpass").val();

if($("#mname").val() == "" ){
alert('Enter Name');
$("#mname").focus();
return false;
}
if($("#maddress").val() == "" ){
alert('Enter Address');
$("#maddress").focus();
return false;
}
if($("#mphone_num").val() == "" ){
alert('Enter Phone Number');
$("#mphone_num").focus();
return false;
}
if($("#memail").val() == "" ){
alert('Enter Email');
$("#memail").focus();
return false;
}
if($("#muname").val() == "" ){
alert('Enter User Name');
$("#muname").focus();
return false;
}
if($("#mpass").val() == "" ){
alert('Enter Password');
$("#mpass").focus();
return false;
}
$.ajax({
type: 'POST',
dataType: 'json',
url: ajax_signup_object.ajaxurl,
data: {
'action': 'member', //calls wp_ajax_nopriv_ajaxsignup
'mname': $('#mname').val(),
'maddress': $('#maddress').val(),
'mphone_num': $('#mphone_num').val(),
'memail': $('#memail').val(),
'muname': $('#muname').val(),
'mpass': $('#mpass').val(),
},
success: function (response) {
$('#paypal_custom').val(response.data);
$(".paypal").trigger("click");
}
});
});
});

Theme-options.php


<div class="ft-control">
<div class="explain"><?php _e( 'Select Youre Paypal Account.', 'medics' ) ?></div>
<?php if(empty($medics_options['paypalac'])) $medics_options['paypalac']='NO'; ?>
<input type="radio"  name="medics_theme_options[paypalac]" <?php if($medics_options['paypalac']== 'YES') { ?> checked="checked" <?php } ?> value="YES"/>Business Account
<input type="radio"  name="medics_theme_options[paypalac]" <?php if($medics_options['paypalac']== 'NO') { ?> checked="checked" <?php } ?> value="NO"/>Sendbox Account
</div>
<div class="ft-control">
<div class="explain"><?php _e( 'Enter Youre Paypal Business Email Asddress here.', 'medics' ) ?></div>
<input type="text" id="paypal_business_email" class="of-input" name="medics_theme_options[paypal_business_email]" size="32"  value="<?php if(!empty($medics_options['paypal_business_email'])) { echo sanitize_email($medics_options['paypal_business_email']); } ?>">
</div>
<div class="ft-control">
<div class="explain"><?php _e( 'Enter Youre Paypal Test Email Asddress here.', 'medics' ) ?></div>
<input type="text" id="paypal_email" class="of-input" name="medics_theme_options[paypal_email]" size="32"  value="<?php if(!empty($medics_options['paypal_email'])) { echo sanitize_email($medics_options['paypal_email']); } ?>">
</div>
<div class="ft-control">
<div class="explain"><?php _e( 'Enter Youre Product Amount here.', 'medics' ) ?></div>
<input type="number" id="paypal_amount" class="of-input" name="medics_theme_options[paypal_amount]" size="32"  value="<?php if(!empty($medics_options['paypal_amount'])) { echo esc_attr($medics_options['paypal_amount']); } ?>">
</div>

Submit two form by one button and redirect with jQuery Ajax

&lt;/pre&gt;
&lt;form id=&quot;ajaxform_member&quot; action=&quot;&quot; method=&quot;post&quot;&gt;
&lt;table class=&quot;signup-tbl&quot;&gt;
&lt;tr&gt;
&lt;td&gt;&lt;label for=&quot;mname&quot;&gt;Name:&lt;/label&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type=&quot;text&quot; required=&quot;&quot; id=&quot;mname&quot; name=&quot;mname&quot;&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;label for=&quot;maddress&quot;&gt;Address:&lt;/label&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;maddress&quot; id=&quot;maddress&quot; required&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;label for=&quot;mphone_num&quot;&gt;Phone Number:&lt;/label&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;mphone_num&quot; id=&quot;mphone_num&quot; required&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;label for=&quot;memail&quot;&gt;Email:&lt;/label&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type=&quot;email&quot; name=&quot;memail&quot; id=&quot;memail&quot; required&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;label for=&quot;muname&quot;&gt;User Name:&lt;/label&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;muname&quot; id=&quot;muname&quot; required&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;label for=&quot;mpass&quot;&gt;Password:&lt;/label&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type=&quot;password&quot; name=&quot;mpass&quot; id=&quot;mpass&quot; required&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;input  class=&quot;signup-tbl-btn&quot; id=&quot;form-ajax-submit&quot; type=&quot;submit&quot; value=&quot;Membership Register&quot;  name=&quot;mregister&quot;&gt;
&lt;p class=&quot;status&quot;&gt;&lt;/p&gt;
&lt;/form&gt;

&lt;form action=&quot;https://www.sandbox.paypal.com/cgi-bin/webscr&quot; method=&quot;post&quot;&gt;
&lt;input type=&quot;hidden&quot; name=&quot;business&quot; value=&quot;raviradadiya.ommune-facilitator@gmail.com&quot; /&gt;
&lt;input type=&quot;hidden&quot; name=&quot;cmd&quot; value=&quot;_xclick-subscriptions&quot; /&gt;
&lt;!-- Instant Payment Notification &amp; Return Page Details --&gt;
&lt;input type=&quot;hidden&quot; name=&quot;notify_url&quot; value=&quot;http://localhost/JobInterviewGuide/?s2member_paypal_notify=1&quot; /&gt;
&lt;input type=&quot;hidden&quot; name=&quot;cancel_return&quot; value=&quot;http://localhost/JobInterviewGuide/&quot; /&gt;
&lt;input type=&quot;hidden&quot; name=&quot;return&quot; value=&quot;http://localhost/JobInterviewGuide/?s2member_paypal_return=1&quot; /&gt;
&lt;input type=&quot;hidden&quot; name=&quot;rm&quot; value=&quot;2&quot; /&gt;
&lt;!-- Configures Basic Checkout Fields --&gt;
&lt;input type=&quot;hidden&quot; name=&quot;lc&quot; value=&quot;&quot; /&gt;
&lt;input type=&quot;hidden&quot; name=&quot;no_shipping&quot; value=&quot;1&quot; /&gt;
&lt;input type=&quot;hidden&quot; name=&quot;no_note&quot; value=&quot;1&quot; /&gt;
&lt;input type=&quot;hidden&quot; name=&quot;custom&quot; value=&quot;localhost&quot; /&gt;
&lt;input type=&quot;hidden&quot; name=&quot;currency_code&quot; value=&quot;USD&quot; /&gt;
&lt;input type=&quot;hidden&quot; name=&quot;page_style&quot; value=&quot;paypal&quot; /&gt;
&lt;input type=&quot;hidden&quot; name=&quot;charset&quot; value=&quot;utf-8&quot; /&gt;
&lt;input type=&quot;hidden&quot; name=&quot;item_name&quot; value=&quot;Bronze Member / description and pricing details here.&quot; /&gt;
&lt;input type=&quot;hidden&quot; name=&quot;item_number&quot; value=&quot;1&quot; /&gt;
&lt;!-- Configures s2Member's Unique Invoice ID/Code  --&gt;
&lt;input type=&quot;hidden&quot; name=&quot;invoice&quot; value=&quot;&lt;?php echo S2MEMBER_VALUE_FOR_PP_INV(); ?&gt;&quot; /&gt;
&lt;!-- Identifies/Updates An Existing User/Member (when/if applicable)  --&gt;
&lt;input type=&quot;hidden&quot; name=&quot;on0&quot; value=&quot;&lt;?php echo S2MEMBER_CURRENT_USER_VALUE_FOR_PP_ON0; ?&gt;&quot; /&gt;
&lt;input type=&quot;hidden&quot; name=&quot;os0&quot; value=&quot;&lt;?php echo S2MEMBER_CURRENT_USER_VALUE_FOR_PP_OS0; ?&gt;&quot; /&gt;
&lt;!-- Identifies The Customer's IP Address For Tracking --&gt;
&lt;input type=&quot;hidden&quot; name=&quot;on1&quot; value=&quot;&lt;?php echo S2MEMBER_CURRENT_USER_VALUE_FOR_PP_ON1; ?&gt;&quot; /&gt;
&lt;input type=&quot;hidden&quot; name=&quot;os1&quot; value=&quot;&lt;?php echo S2MEMBER_CURRENT_USER_VALUE_FOR_PP_OS1; ?&gt;&quot; /&gt;
&lt;!-- Controls Modify Behavior At PayPal Checkout --&gt;
&lt;input type=&quot;hidden&quot; name=&quot;modify&quot; value=&quot;0&quot; /&gt;
&lt;!-- Customizes Prices, Payments &amp; Billing Cycle --&gt;
&lt;!--&lt;input type=&quot;hidden&quot; name=&quot;amount&quot; value=&quot;0.01&quot; /&gt;--&gt;
&lt;input type=&quot;hidden&quot; name=&quot;src&quot; value=&quot;1&quot; /&gt;
&lt;input type=&quot;hidden&quot; name=&quot;srt&quot; value=&quot;&quot; /&gt;
&lt;input type=&quot;hidden&quot; name=&quot;sra&quot; value=&quot;1&quot; /&gt;
&lt;!--&lt;input type=&quot;hidden&quot; name=&quot;a1&quot; value=&quot;0&quot; /&gt;--&gt;
&lt;!--&lt;input type=&quot;hidden&quot; name=&quot;p1&quot; value=&quot;0&quot; /&gt;--&gt;
&lt;!--&lt;input type=&quot;hidden&quot; name=&quot;t1&quot; value=&quot;D&quot; /&gt;--&gt;
&lt;input type=&quot;hidden&quot; name=&quot;a3&quot; value=&quot;0.01&quot; /&gt;
&lt;input type=&quot;hidden&quot; name=&quot;p3&quot; value=&quot;1&quot; /&gt;
&lt;input type=&quot;hidden&quot; name=&quot;t3&quot; value=&quot;M&quot; /&gt;
&lt;!-- Displays The PayPal Image Button --&gt;
&lt;input class=&quot;paypal&quot;  type=&quot;submit&quot; src=&quot;https://www.paypal.com/en_US/i/btn/btn_xpressCheckout.gif&quot; style=&quot;width:auto; height:auto; border:0;&quot; alt=&quot;PayPal&quot; /&gt;
&lt;/form&gt;
&lt;pre&gt;

ajax.signup.js

&lt;/pre&gt;
jQuery(document).ready(function($) {
// Perform AJAX send mail and create user on form submit
$('form#ajaxform_member').on('submit', function(e){
$('form#ajaxform_member p.status').show().text(ajax_signup_object.loadingmessage);
$.ajax({
type: 'POST',
dataType: 'json',
url: ajax_signup_object.ajaxurl,
data: {
'action': 'member', //calls wp_ajax_nopriv_ajaxsignup
'mname': $('form#ajaxform_member #mname').val(),
'maddress': $('form#ajaxform_member #maddress').val(),
'mphone_num': $('form#ajaxform_member #mphone_num').val(),
'memail': $('form#ajaxform_member #memail').val(),
'muname': $('form#ajaxform_member #muname').val(),
'mpass': $('form#ajaxform_member #mpass').val(),
},
success: function (response) {
//window.location.href='http://localhost/JobInterviewGuide/paypal.php';
}
});
e.preventDefault();
});
$(&quot;.paypal&quot;).click(function(){
alert(&quot;The paragraph was clicked.&quot;);
$(&quot;#form-ajax-submit&quot;).trigger(&quot;click&quot;);
//$(&quot;paypal&quot;).trigger(&quot;click&quot;);
});
});
&lt;pre&gt;

Simple Paypal Integration

</pre>
<?php
if ($_SERVER["SERVER_PORT"] != "80")
{
$pageURL .= "http://".$_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
}
else
{
$pageURL .= "http://".$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
?>
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" id="point_buy">

<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="saloni.ommune-facilitator@gmail.com">

<input type="hidden" name="amount" id="amount" value="100" >

<input type="hidden" name="rm" value="2">
<input type="hidden" name="custom" value="" id="customval">

<input type="hidden" name="no_shipping" value="0">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="lc" value="AU">
<input type="hidden" name="bn" value="PP-BuyNowBF">
<input type="hidden" name="return" value="<?php echo $pageURL ?>">

<br /><br />
<input type="submit" value="Pay with PayPal!">

<?php
if(!empty($_POST)){
echo "<pre>";
print_r($_POST); }?>
<pre>
%d bloggers like this: