Ankit Agrawal, Author at Codeexecute

Fetch facebook profile data using javascript

fetch Facebook profile data

Facebook is the most popular social networking site. Facebook provides graph api to get data  . We can fetch Facebook profile data using JavaScript also.

<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({
appId : 'Your Facebook App Id',
cookie : true,
xfbml : true,
version : 'v2.8'
});
};

(function(d, s, id)
{
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "https://connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

function fbLoginFunction()
{
FB.login(function(response) {
if (response.authResponse)
{
FB.api('/me', 'get', { fields: 'id,name,gender,hometown,email' }, function(response) {
console.log(response);
});
} else {
alert("Login attempt failed!");
}
}, { scope: 'email,user_birthday,user_location,user_hometown,public_profile' });
}
</script>
<a href="javascript:void(0);" onclick="fbLoginFunction();" class="btn btn-primary btn-xl rounded-pill mt-5">Login</a>
 

Create custom helper in laravel 5

Laravel support inbuilt helper functionality that we can use in our web application. Please follow the following easy steps to create your own custom helper.

  • First create a folder Helpers in your app directory
  • Now create a file CustomHelper.php in this helpers folder
  • Open newly created file and write the following code
namespace App\Helpers;

class CustomHelper
{
    public static function myCustomFunction()
    {
        echo "hello world";
    }
}
  • Open config/app.php and set aliases for you cutsom helper
'aliases' => [
.
.
.
.
.
'CustomHelper' => App\Helpers\CustomHelper::class

  ],
  • Now ou can use your custom helper’s function in your controller like this
 \CustomHelper::myCustomFunction();
 

Stripe payment gateway integration in php

Stripe is one of the best payment gateways for online transactions. It allows credits cards directly through websites to your stripe account.

Create a file name config.php and write some configuration


<?php
require_once('your stripe library path/stripe.php');

define("STRIPE_MODE", "test"); //live

define('STRIPE_SECRET_KEY', "Your test stripe secret key");
define('STRIPE_PUBLISH_KEY', "Your test stripe publish key");

if(STRIPE_MODE == "live")
{
	define('STRIPE_SECRET_KEY', "Your live stripe secret key");
	define('STRIPE_PUBLISH_KEY', "Your live stripe publish key");
}


Stripe::setApiKey(STRIPE_SECRET_KEY);


?>

Create a new file name form.php and write following code


<?php require_once('config.php'); ?>

<?php

$aAmount = your amount*100; // you need to multiple your usd amount to 100 for stripe api

if(isset($_POST['stripeToken']) && isset($_POST['stripeEmail']))
{	
	$aToken  = $_POST['stripeToken'];
	$aEmail  = $_POST['stripeEmail'];
	$aCustomer = Stripe_Customer::create(array(
		'email' => $aEmail,
		'source'  => $aToken
	));


	$aCharge = Stripe_Charge::create(array(
		'customer' => $aCustomer->id,
		'amount'   => $aAmount,
		'currency' => 'usd'
	));

	// Add your code for further development
}	

?>	

<form action="" method="post">
  <script src="https://checkout.stripe.com/checkout.js" class="stripe-button" data-key="stripe publish key" data-description="Add your payment description" data-amount="amount*100" data-locale="auto"></script>
</form>

Download Stripe Library

 

Useful shortcodes for woocommerce plugin

Woo-commerce is an open source WordPress plugin to build own online store. Woo-commerce is the more popular eCommerce solution.It comes with many shortcodes that help to expand functionality

My Account Page

[woocommerce_my_account]

Cart Page

[woocommerce_cart]

Checkout Page

[woocommerce_checkout]

Products Display

[featured_products]
[sale_products] 
[best_selling_products] 
[recent_products]
[product_attribute]
[top_rated_products]

Add to cart

[add_to_cart id="product id"]

For more details click here

 

Send email using gmail in CodeIgniter

You can send email using gmail by using below code.


$this->load->library('email');

$aConfig = array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'Your gmail email',
'smtp_pass' => 'Your gmail password',
'mailtype' => 'html',
'charset' => 'utf-8'
);
$this->email->initialize($aConfig);
$this->email->set_mailtype("html");
$this->email->from('Your from email', 'Your from name');
$this->email->to("Your receiver email");
$this->email->bcc("Your bcc email"); // optional
$this->email->subject("Your email subject");
$this->email->message("Your email body");
if($this->email->send())
{
	echo "email sent";
}
else
{
	echo "email not sent";
}