Year: 2018

9 Aug

How to create git alias by editing .gitconfig

We can create git aliases simply using the git config command.
Example is
git config --global alias.co checkout

But here, we are discussing another method of managing git aliases by editing the .gitconfig file.

Using git aliases will help you to use shorter commands for various operations.
You can create git aliases by following the below steps.

1) Open your .gitconfig from your home folder.
If you are using vim, you can open it by the below command.

vim /home/[user]/.gitconfig
Replace [user] with your username.
You can use any editor.

2)If you already added your email and name to the config, your .gitconfig
will be like
[user]
email = myemail@domain.com
name = myName

Now we have to add a new section [alias]

After that your .gitconfig will be

[user]
email = myemail@domain.com
name = myName
[alias]

3) Now let’s add one alias.

Instead of typing git status, if you would like to use git st
Then we have to add the below line under [alias].
st = status

Now the new .gitconfig will be like

[user]
email = myemail@domain.com
name = myName
[alias]
st = status

4) If you would like to add more aliases,
You can do as shown below.

[user]
email = myemail@domain.com
name = myName
[alias]
st = status
br = branch
co = checkout
pl = pull origin
ps = push origin
plm = pull origin master
psm = push origin master
coi = checkout integration
cob = checkout -b
lbd = branch -D
rbd = push origin –delete
com = commit -m
mg = merge

9 Aug

Create a bootable USB flash drive from linux terminal

First have a look at the partitions and file systems on the system with this command:
sudo fdisk -l

The drive that you’d like to target might be something like /dev/sdc, /dev/sdd or /dev/sde. You can get the target drive from the fdisk -l command.

Then locate the path of the iso image. Assume that the path of iso image is: /home/user/Downloads/ubuntu-18.04-desktop-amd64.iso
and the path of target drive is: /dev/sdc

Then command to create the bootable USB flash drive is

sudo dd if=/home/user/Downloads/ubuntu-18.04-desktop-amd64.iso of=/dev/sdc status=progress

status=progress will give you the progress report on the terminal.

1 Jul

Stripe alipay module for WHMCS

Stripe payment API integration with WHMCS is easy to do. This article covered payment using stripe with alipay.

1) First let’s create a source using the below code

 $response = \Stripe\Source::create(array(
      "type" => "alipay",
      "currency" => "usd",
      "amount" => $params['amount'] * 100,
      "metadata" => array(  
          "invoiceid" => $invoiceid,
          "userid" => $params['clientdetails']['userid'],
          "order_id" => $invoiceid . "_" . date( "YmdHis" )
      ),
      "redirect" => array(
        "return_url" => $systemUrl . "/modules/gateways/callback/stripe_alipay.php?invoiceid=$invoiceid"
      ),
    ));

2)Then we need to make use of the hook feature of stripe.

Hooks we have to use are
surce.chargeable, charge.succeeded.

From surce.chargeable we have to create charge as

 $charge = \Stripe\Charge::create(array(
        "amount" => $amount,
        "currency" => "usd",
        "source" => $source_id,
    ));

And then from charge.succeeded, We have to add transaction details as shown below.

    $source_meta_data = $event_json->data->object->source;
    $source_id = $event_json->data->object->id;
    $amount = ($event_json->data->object->amount) / (100.00);
    $invoiceid = $source_meta_data->metadata->invoiceid;
    $order_id = $source_meta_data->metadata->order_id;
    $userid = $source_meta_data->metadata->userid;
    $invoiceid = checkCbInvoiceID($invoiceid, "stripe_alipay");
    addInvoicePayment($invoiceid, $source_id, $amount, 0, "stripe_alipay");
    logTransaction("stripe_alipay", json_decode($body, true), "Successful");

This is a high level idea of the gateway module development.
If you would like to develop a stripe module or need more info, please contact from the link
Contact Us.
We will get back to you asap.

7 May

Smarty for WHMCS

In MVC, we always use view to display html contents. If we are not using any template engine, then we have to use php tags in the html page to add dynamic contents.

For example, we can use below code to loop through an array without any template engine.

<?php foreach ($users as $user) : ?>
<div>
    <h2><?php echo $user['name']; ?></h2>
    <p><?php echo $user['company']; ?></p>
</div>
<?php endforeach; ?>

Here we are using php tags to loop through the array. Also we are using php function to print it. WHMCS uses Smarty template engine, and we have to do loop in a different manner with Smarty template engine.

{foreach from=$users item=user}
	<h2>{$user.name}</h2>
	<p>{$user.company}</p>
{/foreach}

This is just an example that shows the difference between Smarty and normal view files. For normal view files, we add .php as extension. But for Smarty files, by default .tpl is the extension of the view files.

Now let’s explore more smarty examples.
Let’s fist create a WHMCS page.

For any custom client area page, we have to add the below content at the top of the page.

<?php

//Let's include whmcs classes
use WHMCS\ClientArea;
use WHMCS\Database\Capsule;

define('CLIENTAREA', true);

require __DIR__ . '/init.php';

$ca = new ClientArea();
$ca->initPage();

Let’s name our custom page as custom_page.php and upload it to the root folder of whmcs.
Now , we have the content required for any client area page on custom_page.php.
Now let’s display some html using the php file.
For that we have to create a tpl file.

Before that, let’s discuss about client area theming.

With whmcs, there are many themes available. For each theme,
there will be different css, images etc. Templates are stored in the folder templates/.
WHMCS has a default client area template with the name ‘six’. So the client area .tpl files are stored in the folder templates/six.

Now, back to our custom_page.php. For this page, we have to create a tpl file to add html contents. Let’s name the tpl file as custom_page.tpl, then it should be uploaded to the folder templates/six.

So our tpl file full path is templates/six/custom_page.tpl

Let’s just add content as

<p>Hello world!!!! </p>

To use the above file as tpl file, we have to define that in custom_page.php

That can be one as

$ca->setTemplate('custom_page');  //it will load the templates/six/custom_page.tpl

if our tpl file name was test.tpl, then we could load that as

$ca->setTemplate('test');  //it will load templates/six/test.tpl

Then to print the content, we have to add below line to the custom_page.php

$ca->output();

So the full custom_page.php is

<?php

//Let's include whmcs classes
use WHMCS\ClientArea;
use WHMCS\Database\Capsule;

define('CLIENTAREA', true);

require __DIR__ . '/init.php';

$ca = new ClientArea();
$ca->initPage();

$ca->setTemplate('custom_page'); 
$ca->output();

And our templates/six/custom_page.tpl content is

<p>Hellow world!!!! </p>

Then browse the url
http://whmcssite.com/custom_page.php

And you will see the html content
Hello world!!!!

Now we know how to display static content using smarty.

Now let’s see how to display dynamic contents using smarty.
For that, now let’s just display the logged in user’s email in the tpl.

We have to add the below code to the php file after the line $ca->initPage();

//get the logged in user id
$loggedin_user_id =  $_SESSION['uid'];
$client = Capsule::table('tblclients')
        ->where('id', '=', $loggedin_user_id)
        ->first();
$ca->assign('client_email', $client->email);

And below code to the tpl

<p>
        Client email is: {$client_email}
</p>

So the trick is, we havee to fetch what ever data to be displayed using a query and then pass that to the
tpl as

$ca->assign('client_email', $client->email);

Then we can just access that from the tpl as {$client_email}

If we were passing the email as

$ca->assign('clientMail', $client->email);

Then we can access it from the tpl as

{$clientMail}

We can do a lot more with smarty, Some of them are explained in the below links.
https://www.smarty.net/docsv2/en/language.function.if.tpl
https://www.smarty.net/docs/en/language.function.foreach.tpl
https://www.smarty.net/docs/en/language.variables.tpl
https://www.smarty.net/docs/en/language.function.include.tpl
https://www.smarty.net/docs/en/language.syntax.variables.tpl

~

31 Mar

Useful Laravel Commands

#Reload the database
php artisan migrate:fresh –seed

#Install new packages and the compile
`composer install` & `npm install`

#Create a seeder file
php artisan make:seeder NewModelSeeder

#Run a single seeder file
php artisan db:seed –class=NewModelSeeder

#Create a model
php artisan make:model MyNewModel

#Create a controller
php artisan make:controller MyNewController –resource

#Create a migration file
php artisan make:migration create_my_new_table –create=my_new_table

#Run migration
php artisan migrate