Ankit Agrawal, Author at Codeexecute

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";
}
 

Remove public from url in laravel

By using following steps we can remove public from url

  • Rename server.php to index.php at laravel root folder
  • Copy .htaccess file from public folder to root folder and update code mentioned below

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>

RewriteEngine On

# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(css|js|images)/(.*)$ public/$1/$2 [L,NC]
</IfModule>

 

 

Jquery mCustomScrollbar not working with ajax

mCustomScrollbar directly not working with ajax we have to initialize it again while using ajax. Please use following code


jQuery(document).ready(function(){
    jQuery(".your ajax content div").mCustomScrollbar();

    jQuery.ajax({
        url: "your ajax url",
        type: "post",
        data: "your post data",
        success: function(response) {
            jQuery(".your ajax content div").mCustomScrollbar("destroy"); //First we have to destroy
            jQuery(".your ajax content div").html(response);
        },
        complete: function () {
            jQuery(".your ajax content div").mCustomScrollbar();
        }
    });
});