Friday, June 5, 2015

Easy way to transfer payment from one account to another using STRIPE in php

Transfer payment from one account to another using STRIPE:

This is done by the following way:
1. Deduct the amount from customer using main account of Stripe.
2. Add amount to the merchant using the same main Stripe account.
For this you will be in need of a Stripe testing/working account.
Firstly Register yourself at Stripe.com
and add stripe in your project it will generate a key & configure it in your account
Then Deduct money from any account using this

Stripe_Charge::create(array(
  "amount" => 600,
  "currency" => "usd",
   "card" => array(
    "number" => "4242424242424242",
    "exp_month" => 10,
    "exp_year" => 2015,
    "cvc" => "314"
  ),
  "metadata" => array("order_id" => "6735")
));

It will deduct $6 using this card and will be add to Stripe Account.
Now pay amount to merchant account using this
            $bank_acc = Stripe_Token::create(array( "bank_account" => array( "country" => "US", "routing_number" => "bank_routing_number", "account_number" => "bank_account_no" ) ));
            $recipient = Stripe_Recipient::create(array( "name" => "name", "type" => "individual", "bank_account"=>$bank_acc->id ));
            $payment =  Stripe_Transfer::create(array( "amount" => '600', "currency" => "usd", "recipient" => $recipient->id, "description" => "Transfer for test@example.com" ));
It will add $6 to merchant account.

Thanks

Friday, May 29, 2015

How to get Latitude & Longitude using zipcode in php?

Get Latitude & Longitude:

It is a very simple way to get latitude & longitude using zipcode in php.
For this you have to use google api's.
Here is a function for doing this:
public function getLatLng($zip)
    {
        $request_url = "http://maps.googleapis.com/maps/api/geocode/xml?address=$zip&sensor=true";
        $xml = simplexml_load_file($request_url) or die("url not loading");
        $status = $xml->status;
        $lat = $lng = 0;
        if ($status == "OK") {
            $lat = $xml->result->geometry->location->lat;
            $lng = $xml->result->geometry->location->lng;
        }
        $loc = array('lat' => $lat, 'lng' => $lng);
        return $loc;
    }
Here $zip is a zipcode variable. It will return a array consisting of latitude & longitude.
Thanks.

Friday, May 22, 2015

Easy & secure way to do digital signature on any online document in php

Easy way for Digital Signature:

For easily digital signature on any online document you have to do some following steps:

1. Create an account on Hellosign.com . Due to this you'll get an API Key.

2. After creating an account create a test app from here. . Due to this you'll get a client id.

Now using this install its package in your project.

Now write this code in your php file.

        require_once 'vendor/autoload.php';
        $client = new HelloSign\Client('YOUR_API_KEY');
        $request = new HelloSign\SignatureRequest;
        $request->enableTestMode();
        $request->setSubject('SUBJECT_NAME');
        $request->setMessage('SUBJECT_MESSAGE');
        $request->addSigner('YOUR_EMAIL', 'Me');
        $request->addFile('PATH_OF_FILE');

        $client_id = 'YOUR_CLIENT_ID';
        $embedded_request = new HelloSign\EmbeddedSignatureRequest($request, $client_id);
        $response = $client->createEmbeddedSignatureRequest($embedded_request);
        $signature = $response->signatures[0]->signature_id;
        $response = $client->getEmbeddedSignUrl($signature);
 

<script type="text/javascript" src="//s3.amazonaws.com/cdn.hellofax.com/js/embedded.js"></script>
<script type="text/javascript">
    window.onload = function() {
    HelloSign.init("YOUR_CLIENT_ID");
    HelloSign.open({
        url: "<?php echo $response->sign_url; ?>",
        allowCancel: true,
        messageListener: function (eventData) {
            alert("HelloSign event received");
        }
    });
    }
</script>

Run this file and see the magic.

Thanks


Friday, May 15, 2015

How to access any behavior function in humhub (Developed in Yii Framework) ?

Access behavior function in humhub:

For access any behavior function we have to create a behavior function on our file in which we direct set its class.

By adding the SpaceControllerBehavior you are able to access current space in your controllers.
Make sure you always pass the current space guid (sguid) in your urls.

When using the method createContainerUrl (provided by SpaceControllerBehavior or UserControllerBehavior) the
current space or user guid is automatically added to urls.

    public function behaviors()
    {
        return array(
            'SpaceControllerBehavior' => array(
                'class' => 'application.modules_core.space.behaviors.SpaceControllerBehavior',
            ),
        );
    }

    public function actionTest() {
        $currentSpace = $this->getSpace();
       
        $this->redirect($this->createContainerUrl('test2'));
       
    }

    public function actionTest2() {
        $currentSpace = $this->getSpace();
    }


Thanks

Friday, May 8, 2015

Easy & Secure client side form validation using jquery validation plugin.

Jquery Validation Plugin:

This is very easy and secure method for client side form validation using validation plugin.

For this you have to include these three jquery validation libraries.

1. First
2. Second
3. Third

After this in your <script> you will add this:


<script>
    $(document).ready(function () {
        $('#myForm').validate({
            ignore: [],
            rules: {
                filename: {
                    required: true,
                    extension: 'docx|doc|gif|jpg|jpeg|png|pdf'                }
              },
            submitHandler: function(form) {
                $('#myForm')[0].submit();
                return false;
            }
        });
    });
</script>

<form method="post" action="/create2" id="myForm" enctype="multipart/form-data">
 <input type="file" name="filename" class="form-control"/>
 <label for="filename" class="error" style="display:none;color:red">This field is required</label> 
 <input type="submit" class="btn btn-primary" id="submit" name="submit" value="submit">
</form>

This will validate your file as required & its extension format.
 Also, you can add filesize in it according to your need.

Thanks

Friday, April 17, 2015

How to save a form in Yii Framework

Save Form in Yii Framework:

Create a create.php in view part & add this :

<?php
$form = $this->beginWidget('CActiveForm', array(
    'id' => 'space-create-form',
    'enableAjaxValidation' => false,
    'htmlOptions' => array('enctype' => 'multipart/form-data'),
));
?>
<div class="form-group">
    <label><?php echo Yii::t('SpaceModule.views_create_create', 'Project Name'); ?></label>
    <?php print $form->textField($model, 'name', array('class' => 'form-control', 'placeholder' => Yii::t('SpaceModule.views_create_create', 'project titan'))); ?>
    <?php echo $form->error($model, 'name'); ?>
</div>
<div class="form-group">
    <label><?php echo Yii::t('SpaceModule.views_create_create', 'Business Founded'); ?></label>
    <?php print $form->textField($model, 'business', array('class' => 'form-control', 'placeholder' => Yii::t('SpaceModule.views_create_create', 'business founded'))); ?>
</div>
<?php
echo HHtml::ajaxButton(Yii::t('SpaceModule.views_create_create', 'Create'), array('//space/create/create'), array(
    'type' => 'POST',
    'beforeSend' => 'function(){ setModalLoader(); }',
    'success' => 'function(html){ $("#globalModal").html(html); }',
), array('class' => 'btn btn-primary', 'id' => 'space-create-submit-button'));
?>


In your Create Controller:

public function actionCreate()
{
if (!Yii::app()->user->canCreateSpace()) {
    throw new CHttpException(400, 'You are not allowed to create spaces!');
}
$model = new Space('edit');

// Ajax Validation
if (isset($_POST['ajax']) && $_POST['ajax'] === 'space-create-form') {
    echo CActiveForm::validate($model);
    Yii::app()->end();
}

if (isset($_POST['Space'])) {

    $_POST['Space'] = Yii::app()->input->stripClean($_POST['Space']);

    $model->attributes = $_POST['Space'];
    if ($model->validate() && $model->save()) {

        // Save in this user variable, that the workspace was new created
        Yii::app()->user->setState('ws', 'created');
        // Redirect to the new created Space
        $this->htmlRedirect($model->getUrl());
    }
}

$this->renderPartial('create', array('model' => $model), false, true);
}


In your space modal:

Firstly add your attributes in attributeLabels() function

public function attributeLabels()
{
    return array(
        'name' => Yii::t('SpaceModule.models_Space', 'Name'),
        'business' => Yii::t('SpaceModule.models_Space', 'Business Founded'),
)};


Also, add in your rules();

public function rules()
{
    $rules = array();
    if ($this->scenario == 'edit') {
        $rules = array(
            array('name,business', 'safe'),
        );
        }
        return $rules;
   }



*You must have to add in your rules(), Otherwise it will show xss errors.

Thanks

Friday, April 10, 2015

How to redirect of any url in Nginx to any another IP address of Apache2 server with same URL(proxy & reverse proxy pass)?

Redirect nginx url to apache2 ip address:

I have a website xyz.com on nginx server & any another website  xxx.xxx.xxx.xxx on apache2 server. Now i want to proxy pass xyz.com/hello to my ip address & also reverse proxy from my ip address. So, that my ip address will show on "xyz.com/hello"  this url.

For this:

Add in your nginx configuration:

location /hello {
                    proxy_pass http://xxx.xxx.xxx.xxx;
                  }


This will directly redirect  xyz.com/hello & xyz.com/hello/ to ip address xxx.xxx.xxx.xxx

Now come to apache2 configuration:

In case of wordpress set your .htaccess file

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>


Also, set in wordpress admin panel's setting

WordPress Address (URL) :  http://xxx.xxx.xxx.xxx
Site Address (URL) : http://xyz.com/hello

Or  you can do it with any another way if you are not using wordpress or any another CMS.

Now your apache2 website xxx.xxx.xxx.xxx will be work on this url http://xyz.com/hello

Thanks.