Search

Bhavesh M Khanpara

PHp Developer with 5+ Years Experience

Properties of the Relational tables


It's My World - Anisur Rahman

Relational tables have six properties:
1. Values are atomic.
2. Column values are of the same kind.
3. Each row is unique.
4. The sequence of columns is insignificant.
5. The sequence of rows is insignificant.
6. Each column must have a unique name.

View original post

Difference between DELETE and TRUNCATE


It's My World - Anisur Rahman

  • Truncate cannot be rolled back while Delete can be.
  • Truncate keeps the lock on table while Delete keeps the lock on each row.
  • Truncate resets the counter of the Identity column while Delete doesn’t do so.
  • Trigger is not fired in Truncate while it happens in Delete.

View original post

How to Create A Simple Web-based Chat Application


Dynamically adding inputs with jQuery


Div's And Don'ts

Today I’ll be teaching you on how to add dynamic inputs using jQuery.  This is perfect for when you’re building a web app or some kind of form and are unsure of how many inputs a certain form will need.  The perfect solution is to allow the user to add as many input boxes as needed.  This is very useful for cataloging systems.  For example if you have someone adding items into a catalog it would be much easier for them to add a bunch at once without having to reload the page.

You can view the live demo of what we will be creating by clicking the link below.

Live Demo: http://lukebro.com/tutorial/dynamicinput

For our small application we will be creating a “Add Stock” form which will allow use to add as many different stock options as we want so we only have to submit the form once.  This tutorial…

View original post 1,068 more words

Send mail with Mandrill API


Here I am going to explain you mandrill API setup and avoid your mail form spam folder.Please follow the below steps.

1) Create your account with mandrill.https://mandrillapp.com

2) Find out your API key.

3) Try to setup your API key in below code

<?php
require 'Mandrill.php';

try {
 $mandrill = new Mandrill('Your-API-KEY');
 $message = array(
 'html' => '<p>Example HTML content</p>',
 'text' => 'Example text content',
 'subject' => 'example subject',
 'from_email' => 'bhavesh561988@gmail.com',
 'from_name' => 'bhaveshkhanpara ',
 'to' => array(
 array(
 'email' => 'To@gmail.com',
 'name' => 'To Name',
 'type' => 'to'
 )
 ),
 'headers' => array('Reply-To' => 'reply@gmail.com')
 );
 $async = false;
 $result = $mandrill->messages->send($message, $async);
 print_r($result);
} catch(Mandrill_Error $e) {
 // Mandrill errors are thrown as exceptions
 echo 'A mandrill error occurred: ' . get_class($e) . ' - ' . $e->getMessage();
 // A mandrill error occurred: Mandrill_Unknown_Subaccount - No subaccount exists with the id 'customer-123'
 throw $e;
}
?>




For more details find the source code here https://github.com/bhavesh561988/mandrill

Language and Emoji Unicode Decode


This code and function will help in displaying special characters in different language and Emoji/Smilly to show properly on webpage,

$data = (object)array(
"html" => " &",
"arabic" => "العربية al-ʿarabiyyah, IPA: [æl ʕɑrɑˈbijjɐ], or عربي ʿarabī",
"hebrew" => "עִבְרִית, Ivrit",
"chinese" => "汉语/漢語 Hanyu; 华语/華語 Huáyǔ; 中文 Zhōngwén",
"korean" => "한국어/조선말",
"japanese" => "日本語 Nihongo",
"umlauts" => "äüöãáàß",
"escaped" => "\u65e5\u672c\u8a9e",
"emoji" => json_decode('"\u263a \ue415\ue056\ue057\ue414\ue405\ue106\ue418 \ud83d\ude04\ud83d\ude0a\ud83d\ude03\ud83d\ude09\ud83d\ude0d\ud83d\ude18"'),
);

header(“Content-Type: text/plain; charset=UTF-8”);

print title(“php: print_r(data)”).”\n”.print_r($data,true).”\n\n”;

print title(“php: json_encode(data)”).”\n”.($json = json_encode($data)).”\nstrlen: “.strlen($json).”\n\n\n”;

print title(“php: json_encode_unicode(data)”).”\n”.($json = json_encode_unicode($data)).”\nstrlen: “.strlen($json).”\n\n\n”;

print title(“php: print_r(json_decode(json_encode_unicode(data)))”).”\n”.print_r(json_decode(json_encode_unicode($data)),true).”\n\n”;

print title(“php: data == json_decode(json_encode_unicode(data))”).”\n”.print_r($data == json_decode(json_encode_unicode($data)),true).”\n\n”;

function json_encode_unicode($data) {
if (defined(‘JSON_UNESCAPED_UNICODE’)) {
return json_encode($data, JSON_UNESCAPED_UNICODE);
}
return preg_replace_callback(‘/(?<!\\\\)\\\\u([0-9a-f]{4})/i’,
function ($m) {
$d = pack(“H*”, $m[1]);
$r = mb_convert_encoding($d, “UTF8”, “UTF-16BE”);
return $r!==”?” && $r!==”” ? $r : $m[0];
}, json_encode($data)
);
}

 

Remove index.php from url in codeignitor


<IfModule mod_rewrite.c>

Options +FollowSymLinks -Indexes
RewriteEngine on

# NOTICE: If you get a 404 play with combinations of the following commented out lines
#AllowOverride All
#RewriteBase /

# Restrict your site to only one domain
#RewriteCond %{HTTP_HOST} !^www\.
#RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

<IfModule mod_php5.c>
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

<IfModule !mod_php5.c>
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

</IfModule>

#prevent access to htaccess file
<Files .htaccess>
order allow,deny
deny from all
</Files>

#disable directory browsing
Options All -Indexes
IndexIgnore *

knowledge base


paypal :-

PayPal Recurring Payments IPN Samples

PHP Learning :-

http://ldopensource.wordpress.com/2012/08/18/php-mysql-experienced-interview-questions-and-answers/
http://deepakc-webdevelopment.blogspot.in/2012/05/php-interview-questions-and-answers-for.html
http://ldopensource.wordpress.com/2012/08/18/php-mysql-experienced-interview-questions-and-answers/

Advanced PHP Interview Questions

http://architects.dzone.com/articles/should-your-static-go-static

PHP Basics – PHP Certification Exam Series [1]

How To Optimize Your Site With HTTP Caching

http://www.rajamm.info/

MySql :-

http://zetcode.com/databases/mysqltutorial/storageengines/
http://a4academics.com/interview-questions/53-database-and-sql/397-top-100-database-sql-interview-questions-and-answers-examples-queries

Understanding JOINs in MySQL and Other Relational Databases

JQuery :-

http://www.codeproject.com/Articles/618484/Latest-jQuery-interview-questions-and-answers

Find the latitude and longitude of address using Geocoding API example

socketo :-

http://socketo.me/docs/flow

Simple Chat Using WebSocket and PHP Socket

Zend f2 :-

http://zf2.readthedocs.org/en/latest/getting-started-with-zend-studio/the-application.html

Zend Framework 2 – Simple Web Application – CRUD using Ajax Tutorial

http://www.1stwebdesigner.com/tutorials/zend-framework-first-steps/

Express checkout Paypal Recurring


Hello friends ,here i have share a paypal express checkout lib .I hope it will be help you for development of payment module
Copy and paset this class in CI lib folder

STEP :- 1


class Paypal_Recurring
{
private $_api_username;
private $_api_password;
private $_api_signature;
private $_api_endpoint;
private $_api_version;

public function __construct($param){
$env_type = ‘sandbox’;
$this->_api_username = urlencode($param[0]);
$this->_api_password = urlencode($param[1]);
$this->_api_signature = urlencode($param[2]);
$this->_api_version = ‘75.0’;
if ($env_type === “sandbox”){
$this->_api_endpoint = “https://api-3t.sandbox.paypal.com/nvp&#8221;;
}else{
$this->_api_endpoint = “https://api-3t.paypal.com/nvp&#8221;;
}
}

private function paypal_recurring_http_post($method, $nvp_params){

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $this->_api_endpoint);
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POST, 1);

$nvp_request = “METHOD=” . $method . “&VERSION=” . $this->_api_version . “&PWD=” . $this->_api_password . “&USER=” . $this->_api_username . “&SIGNATURE=” . $this->_api_signature . $nvp_params;
curl_setopt($curl, CURLOPT_POSTFIELDS, $nvp_request);

$response = curl_exec($curl);

if (!$response) {
return false;
}

/**
* Prepare response.
**/
$response_attributs = explode(“&”, $response);
$response_parsed_attributs = array();

foreach ($response_attributs as $cur_atr) {
$tmp_atr = explode(“=”, $cur_atr);
if (count($tmp_atr) == 2) {
$response_parsed_attributs[urldecode($tmp_atr[0])] = urldecode($tmp_atr[1]);
}
}

if (!isset($response_parsed_attributs[‘ACK’])) {
return false;
}
return $response_parsed_attributs;
}

/**
* Enter description here…
*
* @param array $data
* @return unknown
*/
public function paypal_recurring_create_profile(array $data){
$_errors = array();
$nvp_params = array();

/**
*Recurring Payments Profile Details Fields
**/

if (array_key_exists(‘SUBSCRIBERNAME’, $data)){
$nvp_params[‘SUBSCRIBERNAME’] = urlencode($data[‘SUBSCRIBERNAME’]);
}

if (array_key_exists(‘PROFILESTARTDATE’, $data)) {
$nvp_params[‘PROFILESTARTDATE’] = urlencode($data[‘PROFILESTARTDATE’]);
}
else {
$_errors[‘PROFILESTARTDATE’] = ‘PROFILESTARTDATE is required parameter’;
}
if (array_key_exists(‘PROFILEREFERENCE’, $data)){
$nvp_params[‘PROFILEREFERENCE’] = urlencode($data[‘PROFILEREFERENCE’]);
}

if (array_key_exists(‘PAYMENTREQUEST_0_CUSTOM’, $data)){
$nvp_params[‘PAYMENTREQUEST_0_CUSTOM’] = urlencode($data[‘PAYMENTREQUEST_0_CUSTOM’]);
}

/**
* Schedule Details Fields
**/

if (array_key_exists(‘DESC’, $data)){
$nvp_params[‘DESC’] = urlencode($data[‘DESC’]);
}else{
$_errors[‘DESC’] = ‘DESC is required parameter’;
}
if (array_key_exists(‘MAXFAILEDPAYMENTS’, $data) && (int) $data[‘MAXFAILEDPAYMENTS’] > 0){
$nvp_params[‘MAXFAILEDPAYMENTS’] = (int) $data[‘PROFILEREFERENCE’];
}
if (array_key_exists(‘AUTOBILLOUTAMT’, $data)){
$nvp_params[‘AUTOBILLOUTAMT’] = $data[‘AUTOBILLOUTAMT’];
}

if (array_key_exists(‘RETURNURL’, $data)){
$nvp_params[‘RETURNURL’] = $data[‘RETURNURL’];
}

/**
* Billing Period Details Fields
**/

if (array_key_exists(‘BILLINGPERIOD’, $data)){
$nvp_params[‘BILLINGPERIOD’] = urlencode($data[‘BILLINGPERIOD’]);
}else{
$_errors[‘BILLINGPERIOD’] = ‘BILLINGPERIOD is required parameter’;
}

if (array_key_exists(‘BILLINGFREQUENCY’, $data)){
$nvp_params[‘BILLINGFREQUENCY’] = (int) $data[‘BILLINGFREQUENCY’];
}else{
$_errors[‘BILLINGFREQUENCY’] = ‘BILLINGFREQUENCY is required parameter’;
}

if (array_key_exists(‘TOTALBILLINGCYCLES’, $data)){
$nvp_params[‘TOTALBILLINGCYCLES’] = (int) $data[‘TOTALBILLINGCYCLES’];
}

if (array_key_exists(‘AMT’, $data)){
$nvp_params[‘AMT’] = (float) $data[‘AMT’];
}else{
$_errors[‘AMT’] = ‘AMT is required parameter’;
}

if (array_key_exists(‘TRIALBILLINGPERIOD’, $data)){
$nvp_params[‘TRIALBILLINGPERIOD’] = urlencode($data[‘TRIALBILLINGPERIOD’]);
}

if (array_key_exists(‘TRIALBILLINGFREQUENCY’, $data)){
$nvp_params[‘TRIALBILLINGFREQUENCY’] = (int) $data[‘TRIALBILLINGFREQUENCY’];
}

if (array_key_exists(‘TRIALTOTALBILLINGCYCLES’, $data)){
$nvp_params[‘TRIALTOTALBILLINGCYCLES’] = (int) $data[‘TRIALTOTALBILLINGCYCLES’];
}

if (array_key_exists(‘TRIALAMT’, $data)){
$nvp_params[‘TRIALAMT’] = (float) $data[‘TRIALAMT’];
}

if (array_key_exists(‘CURRENCYCODE’, $data)){
$nvp_params[‘CURRENCYCODE’] = urlencode($data[‘CURRENCYCODE’]);
}else{
$_errors[‘CURRENCYCODE’] = ‘CURRENCYCODE is required parameter’;
}

if (array_key_exists(‘SHIPPINGAMT’, $data)){
$nvp_params[‘SHIPPINGAMT’] = (float) $data[‘SHIPPINGAMT’];
}

if (array_key_exists(‘TAXAMT’, $data)){
$nvp_params[‘TAXAMT’] = (float) $data[‘TAXAMT’];
}
/**
*Actvation Details Fields
**/

if (array_key_exists(‘INITAMT’, $data)){
$nvp_params[‘INITAMT’] = (float) $data[‘INITAMT’];
}

if (array_key_exists(‘FAILEDINITAMTACTION’, $data)){
$nvp_params[‘FAILEDINITAMTACTION’] = urlencode($data[‘FAILEDINITAMTACTION’]);
}

/**
* Ship To Address Fields
**/
if (array_key_exists(‘SHIPTONAME’, $data)){
$nvp_params[‘SHIPTONAME’] = urlencode($data[‘SHIPTONAME’]);
}

if (array_key_exists(‘SHIPTOSTREET’, $data)){
$nvp_params[‘SHIPTOSTREET’] = urlencode($data[‘SHIPTOSTREET’]);
}

if (array_key_exists(‘SHIPTOSTREET2’, $data)){
$nvp_params[‘SHIPTOSTREET2’] = urlencode($data[‘SHIPTOSTREET2’]);
}

if (array_key_exists(‘SHIPTOCITY’, $data)){
$nvp_params[‘SHIPTOCITY’] = urlencode($data[‘SHIPTOCITY’]);
}

if (array_key_exists(‘SHIPTOSTATE’, $data)){
$nvp_params[‘SHIPTOSTATE’] = urlencode($data[‘SHIPTOSTATE’]);
}

if (array_key_exists(‘SHIPTOZIP’, $data)){
$nvp_params[‘SHIPTOZIP’] = urlencode($data[‘SHIPTOZIP’]);
}

if (array_key_exists(‘SHIPTOCOUNTRY’, $data)){
$nvp_params[‘SHIPTOCOUNTRY’] = urlencode($data[‘SHIPTOCOUNTRY’]);
}

if (array_key_exists(‘SHIPTOPHONENUM’, $data)){
$nvp_params[‘SHIPTOPHONENUM’] = urlencode($data[‘SHIPTOPHONENUM’]);
}

/**
*Credit Card Details Fields
**/

if (array_key_exists(‘CREDITCARDTYPE’, $data)){
$nvp_params[‘CREDITCARDTYPE’] = urlencode($data[‘CREDITCARDTYPE’]);
}

if (array_key_exists(‘ACCT’, $data)){
$nvp_params[‘ACCT’] = urlencode($data[‘ACCT’]);
}else{
$_errors[‘ACCT’] = ‘ACCT is required parameter’;
}

if (array_key_exists(‘EXPDATE’, $data)){
$nvp_params[‘EXPDATE’] = urlencode($data[‘EXPDATE’]);
}

if (array_key_exists(‘CVV2’, $data)){
$nvp_params[‘CVV2’] = urlencode($data[‘CVV2’]);
}

if (array_key_exists(‘STARTDATE’, $data)){
$nvp_params[‘STARTDATE’] = urlencode($data[‘STARTDATE’]);
}

if (array_key_exists(‘ISSUENUMBER’, $data)){
$nvp_params[‘ISSUENUMBER’] = urlencode($data[‘ISSUENUMBER’]);
}

/**
*Payer Information Fields
**/

if (array_key_exists(‘EMAIL’, $data)){
$nvp_params[‘EMAIL’] = urlencode($data[‘EMAIL’]);
}

if (array_key_exists(‘PAYERID’, $data)){
$nvp_params[‘PAYERID’] = urlencode($data[‘PAYERID’]);
}

if (array_key_exists(‘PAYERSTATUS’, $data)){
$nvp_params[‘PAYERSTATUS’] = urlencode($data[‘PAYERSTATUS’]);
}

if (array_key_exists(‘COUNTRYCODE’, $data)){
$nvp_params[‘COUNTRYCODE’] = urlencode($data[‘COUNTRYCODE’]);
}

if (array_key_exists(‘BUSINESS’, $data)){
$nvp_params[‘BUSINESS’] = urlencode($data[‘BUSINESS’]);
}

/**
*Payer Name Fields
**/
if (array_key_exists(‘SALUTATION’, $data)){
$nvp_params[‘SALUTATION’] = urlencode($data[‘SALUTATION’]);
}

if (array_key_exists(‘FIRSTNAME’, $data)){
$nvp_params[‘FIRSTNAME’] = urlencode($data[‘FIRSTNAME’]);
}

if (array_key_exists(‘MIDDLENAME’, $data)){
$nvp_params[‘MIDDLENAME’] = urlencode($data[‘MIDDLENAME’]);
}

if (array_key_exists(‘LASTNAME’, $data)){
$nvp_params[‘LASTNAME’] = urlencode($data[‘LASTNAME’]);
}

if (array_key_exists(‘SUFFIX’, $data)){
$nvp_params[‘SUFFIX’] = urlencode($data[‘SUFFIX’]);
}

/**
*Address Fields
**/

if (array_key_exists(‘STREET’, $data)){
$nvp_params[‘STREET’] = urlencode($data[‘STREET’]);
}

if (array_key_exists(‘STREET2’, $data)){
$nvp_params[‘STREET2’] = urlencode($data[‘STREET2’]);
}

if (array_key_exists(‘CITY’, $data)){
$nvp_params[‘CITY’] = urlencode($data[‘CITY’]);
}

if (array_key_exists(‘STATE’, $data)){
$nvp_params[‘STATE’] = urlencode($data[‘STATE’]);
}

if (array_key_exists(‘ZIP’, $data)){
$nvp_params[‘ZIP’] = urlencode($data[‘ZIP’]);
}

if (array_key_exists(‘COUNTRY’, $data)){
$nvp_params[‘COUNTRY’] = urlencode($data[‘COUNTRY’]);
}

/* Custom filed*/
/*if (array_key_exists(‘CUSTOM’, $data)){
$nvp_params[‘CUSTOM’] = urlencode($data[‘CUSTOM’]);
}*/

/**
*Payment Details Item Fields
**/

if (isset($data[‘ITEMS’]) && is_array($data[‘ITEMS’])){
for ($i = 0; $i < count($data[‘ITEMS’]); $i++){ if (is_array($data[‘ITEMS’][$i])) { if (array_key_exists(‘L_PAYMENTREQUEST_n_ITEMCATEGORY’, $data[‘ITEMS’][$i])){ $nvp_params[‘L_PAYMENTREQUEST_n_ITEMCATEGORY’ . $i] = urlencode($data[‘ITEMS’][$i][‘L_PAYMENTREQUEST_n_ITEMCATEGORY’]); } if (array_key_exists(‘L_PAYMENTREQUEST_n_NAME’, $data[‘ITEMS’][$i])){ $nvp_params[‘L_PAYMENTREQUEST_n_NAME’ . $i] = urlencode($data[‘ITEMS’][$i][‘L_PAYMENTREQUEST_n_NAME’]); } if (array_key_exists(‘L_PAYMENTREQUEST_n_DESC’, $data[‘ITEMS’][$i])){ $nvp_params[‘L_PAYMENTREQUEST_n_DESC’ . $i] = urlencode($data[‘ITEMS’][$i][‘L_PAYMENTREQUEST_n_DESC’]); } if (array_key_exists(‘L_PAYMENTREQUEST_n_AMT’, $data[‘ITEMS’][$i])){ $nvp_params[‘L_PAYMENTREQUEST_n_AMT’ . $i] = (float) $data[‘ITEMS’][$i][‘L_PAYMENTREQUEST_n_AMT’]; } if (array_key_exists(‘L_PAYMENTREQUEST_n_NUMBER’, $data[‘ITEMS’][$i])){ $nvp_params[‘L_PAYMENTREQUEST_n_NUMBER’ . $i] = urlencode($data[‘ITEMS’][$i][‘L_PAYMENTREQUEST_n_NUMBER’]); } if (array_key_exists(‘L_PAYMENTREQUEST_n_QTY’, $data[‘ITEMS’][$i])){ $nvp_params[‘L_PAYMENTREQUEST_n_QTY’ . $i] = (int) $data[‘ITEMS’][$i][‘L_PAYMENTREQUEST_n_QTY’]; } if (array_key_exists(‘L_PAYMENTREQUEST_n_TAXAMT’, $data[‘ITEMS’][$i])){ $nvp_params[‘L_PAYMENTREQUEST_n_TAXAMT’ . $i] = (float) $data[‘ITEMS’][$i][‘L_PAYMENTREQUEST_n_TAXAMT’]; } } } } if (sizeof($_errors) > 0) {
$_errors[‘has_errors’] = true;
return $_errors;
}

$request_param = ”;

foreach ($nvp_params as $index => $value){
$request_param.=’&’ . $index . ‘=’ . $value;
}
return $this->paypal_recurring_http_post(‘CreateRecurringPaymentsProfile’, $request_param);
}
/**
* Enter description here…
*
* @param unknown_type $profile_id
* @return unknown
*/
public function paypal_recurring_get_profile_details($profile_id){
$request_param = ‘&PROFILEID=’ . urlencode($profile_id);
$result = $this->paypal_recurring_http_post(‘GetRecurringPaymentsProfileDetails’, $request_param);
return $result;
}
/**
* Enter description here…
*
* @param unknown_type $profile_id
* @param unknown_type $action
* @param unknown_type $note
* @return unknown
*/
public function paypal_recurring_manage_profile_status($profile_id, $action, $note = ”){
$request_param = ‘&PROFILEID=’ . urlencode($profile_id) . ‘&ACTION=’ . $action;
if ($note)
$request_param.=’&NOTE=’ . urlencode($note);
$result = $this->paypal_recurring_http_post(‘ManageRecurringPaymentsProfileStatus’, $request_param);
return $result;
}

/**
* Enter description here…
*
* @param unknown_type $profile_id
* @param unknown_type $data
* @return unknown
*/
public function paypal_recurring_update_profile($profile_id, $data){
$nvp_params = array();

/**
* Recurring Payments Profile Details Fields
**/

$nvp_params[‘PROFILEID’] = urlencode($profile_id);

if (array_key_exists(‘NOTE’, $data)){
$nvp_params[‘NOTE’] = urlencode($data[‘NOTE’]);
}

if (array_key_exists(‘SUBSCRIBERNAME’, $data)){
$nvp_params[‘SUBSCRIBERNAME’] = urlencode($data[‘SUBSCRIBERNAME’]);
}

if (array_key_exists(‘PROFILESTARTDATE’, $data)){
$nvp_params[‘PROFILESTARTDATE’] = urlencode($data[‘PROFILESTARTDATE’]);
}

if (array_key_exists(‘PROFILEREFERENCE’, $data)){
$nvp_params[‘PROFILEREFERENCE’] = urlencode($data[‘PROFILEREFERENCE’]);
}

if (array_key_exists(‘ADDITIONALBILLINGCYCLES’, $data)){
$nvp_params[‘ADDITIONALBILLINGCYCLES’] = (int) $data[‘PROFILEREFERENCE’];
}

if (array_key_exists(‘OUTSTANDINGAMT’, $data)){
$nvp_params[‘OUTSTANDINGAMT’] = (float) $data[‘OUTSTANDINGAMT’];
}

if (array_key_exists(‘DESC’, $data) && strlen($data[‘DESC’] > 0)){
$nvp_params[‘DESC’] = urlencode($data[‘DESC’]);
}

if (array_key_exists(‘MAXFAILEDPAYMENTS’, $data) && (int) $data[‘MAXFAILEDPAYMENTS’] > 0){
$nvp_params[‘MAXFAILEDPAYMENTS’] = (int) $data[‘PROFILEREFERENCE’];
}

if (array_key_exists(‘AUTOBILLOUTAMT’, $data)){
$nvp_params[‘AUTOBILLOUTAMT’] = $data[‘AUTOBILLOUTAMT’];
}

if (array_key_exists(‘TOTALBILLINGCYCLES’, $data)){
$nvp_params[‘TOTALBILLINGCYCLES’] = (int) $data[‘TOTALBILLINGCYCLES’];
}

if (array_key_exists(‘AMT’, $data)){
$nvp_params[‘AMT’] = (float) $data[‘AMT’];
}
else{
$_errors[‘AMT’] = ‘AMT is required parameter’;
}

if (array_key_exists(‘TRIALBILLINGPERIOD’, $data)){
$nvp_params[‘TRIALBILLINGPERIOD’] = urlencode($data[‘TRIALBILLINGPERIOD’]);
}

if (array_key_exists(‘TRIALBILLINGFREQUENCY’, $data)){
$nvp_params[‘TRIALBILLINGFREQUENCY’] = (int) $data[‘TRIALBILLINGFREQUENCY’];
}

if (array_key_exists(‘TRIALTOTALBILLINGCYCLES’, $data)){
$nvp_params[‘TRIALTOTALBILLINGCYCLES’] = (int) $data[‘TRIALTOTALBILLINGCYCLES’];
}

if (array_key_exists(‘TRIALAMT’, $data)){
$nvp_params[‘TRIALAMT’] = (float) $data[‘TRIALAMT’];
}

if (array_key_exists(‘CURRENCYCODE’, $data)){
$nvp_params[‘CURRENCYCODE’] = urlencode($data[‘CURRENCYCODE’]);
}else{
$_errors[‘CURRENCYCODE’] = ‘CURRENCYCODE is required parameter’;
}

if (array_key_exists(‘SHIPPINGAMT’, $data)){
$nvp_params[‘SHIPPINGAMT’] = (float) $data[‘SHIPPINGAMT’];
}

if (array_key_exists(‘TAXAMT’, $data)){
$nvp_params[‘TAXAMT’] = (float) $data[‘TAXAMT’];
}

/**
* Actvation Details Fields
*/

if (array_key_exists(‘INITAMT’, $data)){
$nvp_params[‘INITAMT’] = (float) $data[‘INITAMT’];
}

if (array_key_exists(‘FAILEDINITAMTACTION’, $data)){
$nvp_params[‘FAILEDINITAMTACTION’] = urlencode($data[‘FAILEDINITAMTACTION’]);
}

/**
* Ship To Address Fields
**/

if (array_key_exists(‘SHIPTONAME’, $data)){
$nvp_params[‘SHIPTONAME’] = urlencode($data[‘SHIPTONAME’]);
}

if (array_key_exists(‘SHIPTOSTREET’, $data)){
$nvp_params[‘SHIPTOSTREET’] = urlencode($data[‘SHIPTOSTREET’]);
}

if (array_key_exists(‘SHIPTOSTREET2’, $data)){
$nvp_params[‘SHIPTOSTREET2’] = urlencode($data[‘SHIPTOSTREET2’]);
}

if (array_key_exists(‘SHIPTOCITY’, $data)){
$nvp_params[‘SHIPTOCITY’] = urlencode($data[‘SHIPTOCITY’]);
}

if (array_key_exists(‘SHIPTOSTATE’, $data)){
$nvp_params[‘SHIPTOSTATE’] = urlencode($data[‘SHIPTOSTATE’]);
}

if (array_key_exists(‘SHIPTOZIP’, $data)){
$nvp_params[‘SHIPTOZIP’] = urlencode($data[‘SHIPTOZIP’]);
}

if (array_key_exists(‘SHIPTOCOUNTRY’, $data)){
$nvp_params[‘SHIPTOCOUNTRY’] = urlencode($data[‘SHIPTOCOUNTRY’]);
}

if (array_key_exists(‘SHIPTOPHONENUM’, $data)) {
$nvp_params[‘SHIPTOPHONENUM’] = urlencode($data[‘SHIPTOPHONENUM’]);
}

/**
* Credit Card Details Fields
**/
if (array_key_exists(‘CREDITCARDTYPE’, $data)){
$nvp_params[‘CREDITCARDTYPE’] = urlencode($data[‘CREDITCARDTYPE’]);
}

if (array_key_exists(‘ACCT’, $data)){
$nvp_params[‘ACCT’] = urlencode($data[‘ACCT’]);
}else{
$_errors[‘ACCT’] = ‘ACCT is required parameter’;
}

if (array_key_exists(‘EXPDATE’, $data)){
$nvp_params[‘EXPDATE’] = urlencode($data[‘EXPDATE’]);
}

if (array_key_exists(‘CVV2’, $data)) {
$nvp_params[‘CVV2’] = urlencode($data[‘CVV2’]);
}

if (array_key_exists(‘STARTDATE’, $data)){
$nvp_params[‘STARTDATE’] = urlencode($data[‘STARTDATE’]);
}

if (array_key_exists(‘ISSUENUMBER’, $data)){
$nvp_params[‘ISSUENUMBER’] = urlencode($data[‘ISSUENUMBER’]);
}

/**
* Payer Information Fields
**/

if (array_key_exists(‘EMAIL’, $data)){
$nvp_params[‘EMAIL’] = urlencode($data[‘EMAIL’]);
}

if (array_key_exists(‘FIRSTNAME’, $data)){
$nvp_params[‘FIRSTNAME’] = urlencode($data[‘FIRSTNAME’]);
}

if (array_key_exists(‘MIDDLENAME’, $data)){
$nvp_params[‘MIDDLENAME’] = urlencode($data[‘MIDDLENAME’]);
}

if (array_key_exists(‘LASTNAME’, $data)){
$nvp_params[‘LASTNAME’] = urlencode($data[‘LASTNAME’]);
}

if (array_key_exists(‘STREET’, $data)){
$nvp_params[‘STREET’] = urlencode($data[‘STREET’]);
}

if (array_key_exists(‘STREET2’, $data)){
$nvp_params[‘STREET2’] = urlencode($data[‘STREET2’]);
}

if (array_key_exists(‘CITY’, $data)){
$nvp_params[‘CITY’] = urlencode($data[‘CITY’]);
}

if (array_key_exists(‘STATE’, $data)){
$nvp_params[‘STATE’] = urlencode($data[‘STATE’]);
}

if (array_key_exists(‘ZIP’, $data)){
$nvp_params[‘ZIP’] = urlencode($data[‘ZIP’]);
}

if (array_key_exists(‘COUNTRY’, $data)){
$nvp_params[‘COUNTRY’] = urlencode($data[‘COUNTRY’]);
}
$request_param = ”;
foreach ($nvp_params as $index => $value){
$request_param.=’&’ . $index . ‘=’ . $value;
}
return $this->paypal_recurring_http_post(‘UpdateRecurringPaymentsProfile’, $request_param);

}
}

STEP :-2

Now make your controller for doing payment pricess and get responces and manage with your business logic.


class Pr extends CI_Controller {

function __construct() {
parent::__construct();
$this->load->helper(array(‘form’, ‘url’));
$this->load->model(‘commonmodel’);
$param = array(‘username’,’password’,’key’);
$this->load->library(‘Paypal_Recurring’,$param,’pr’);

}

/* Default Method*/
function index(){
redirect(base_url().’dopayment/’);
}

/* Method for Start Recurring Payment*/
function dopayment(){
$plan_info = $this->session->userdata(‘upgrade_plan_details’);
$userInfo = $this->commonmodel->get_item_by_iUserId(‘user’,$this->session->userdata(‘Id’));
$plan_payment_info = $this->commonmodel->get_item_by_iUserId(‘plan_payment’,$this->session->userdata(‘Id’));

$profile_start_date = date(“Y-m-d H:i:s”);
$billing_period = ‘Day’;
$billing_frequency = ‘1’;
$totalbillingcycles = 0;
$desc = $plan_info[‘desc’];
$amount = $plan_info[‘usprice’];
$currency_code = ‘USD’;
$card_type = $this->input->post(‘CCtype’);;
$credit_card_number = $this->input->post(‘CCNo’);
$exp_date = $this->input->post(‘CCExpiresMonth’).$this->input->post(‘CCExpiresYear’);
$cvv2 = $this->input->post(‘cvv2’);
$billing_email = $this->session->userdata(‘business_email’);
$last_name = $userInfo->vLastName;
$first_name = $userInfo->vFirstName;;

$data = array();
$data[‘PROFILESTARTDATE’] = $profile_start_date; // Profile start date
$data[‘DESC’] = $desc; //Description

//Billing Period Details Fields
$data[‘BILLINGPERIOD’] = $billing_period; //Billing period
$data[‘BILLINGFREQUENCY’] = $billing_frequency;
$data[‘TOTALBILLINGCYCLES’] = $totalbillingcycles; //$plan_duration;
$data[‘AMT’] = $amount; //amount
$data[‘INITAMT’] = $amount; //amount
$data[‘CURRENCYCODE’] = $currency_code; //currency code

//Credit Card Details Fields
$data[‘CREDITCARDTYPE’] = $card_type; // card type
$data[‘ACCT’] = $credit_card_number; //credit card number
$data[‘EXPDATE’] = $exp_date; //exp date
$data[‘CVV2’] = $cvv2; //cvv2

//Payer Information Fields
$data[‘EMAIL’] = $billing_email; //Email id of user
$data[‘FIRSTNAME’] = $first_name;
$data[‘LASTNAME’] = $last_name;
$data[‘BUSINESS’] = ‘BusinessName’;

//call method for Create Profile
$paypal_recurring_profileId = ”;
$paypal_recurring_transactionid = ”;
$paypal_recurring_ack_status = ”;

if($userInfo->recurring_profile_id != ” && !(empty($userInfo->recurring_profile_id))){
$createProfile= $this->pr->paypal_recurring_manage_profile_status($userInfo->recurring_profile_id,’Suspend’,’Suspend’);
$createProfile= $this->pr->paypal_recurring_create_profile($data);
} else {
$createProfile= $this->pr->paypal_recurring_create_profile($data);
}

/* set data in varible */
$paypal_recurring_profileId = @$createProfile[‘PROFILEID’];
if(isset($createProfile[‘TRANSACTIONID’])){
$paypal_recurring_transactionid = @$createProfile[‘TRANSACTIONID’];
}else{
$paypal_recurring_transactionid = @$createProfile[‘PROFILEID’];
}
$paypal_recurring_ack_status = @$createProfile[‘ACK’];

@$iPlanPeriod = ’28’;
@$dPlanStartDate = date(‘Y-m-d H:i:s’);
@$dPlanExpiryDate = date(“Y-m-d H:i:s”,strtotime(“+28 day”, strtotime(@$dPlanStartDate)));
@$eSubscription_mode = ‘Inactive’;

if($paypal_recurring_ack_status == ‘Success’){
@$eSubscription_mode = ‘Active’;
$BuisnessData = array(
‘iPlanId’ => $plan_info[‘id’],
‘iPlanPeriod’ => $iPlanPeriod,
‘dPlanStartDate’ => $dPlanStartDate,
‘dPlanExpiryDate’ => $dPlanExpiryDate,
‘eSubscription_mode’ => $eSubscription_mode,
);
$this->db->set($BuisnessData);
$this->db->where(‘iUserId’,$this->session->userdata(‘Id’));
$this->db->update(‘business’);

//Load bayur data using profile Id
$getBuyerDetails = $this->pr->paypal_recurring_get_profile_details($paypal_recurring_profileId);
/*Update plan_payment table*/
$planTabledata = array(
‘iUserId’ => $this->session->userdata(‘Id’),
‘iTrans_id’ => @$paypal_recurring_transactionid,
‘fAmount’ => $getBuyerDetails[‘AMT’],
‘eCurrency’ => $getBuyerDetails[‘CURRENCYCODE’],
‘dCreated’ => date(‘Y-m-d’),
‘eStatus’ => ‘Active’
);
$this->commonmodel->insert(‘plan_payment’,$planTabledata);

/*update user table */
$userTabledata = array(‘recurring_profile_id’=> $getBuyerDetails[‘PROFILEID’]);
$this->commonmodel->update_by_iUserId(‘user’,$this->session->userdata(‘Id’),$userTabledata);
$this->session->set_flashdata(‘paypal_success_message’, “Business plan upgrade process completed successfuly !”);
redirect(‘manageProfile’);
} else {
$this->session->set_flashdata(‘paypal_success_message’, “oops something went wrong error a server error occurred..Try again later”);
redirect(‘manageProfile’);
}
}
}

NOTE :- 

– if you are working with IPN then you don’t get any custom param in Paypal Express checkout

– You have to store Profile id in database and then work with that Id as a Particular User

– When Profile is created you have to manege userdata in your controller and save it in user table ,When second call is occur and Your IPN call at that time you got Profile id so you can manage by all the database operation  by that ID

– TXN_TYPE :- 

  • recurring_payment -When 2nd recurring call is called
  • recurring_payment_profile_created -First time when you subscribe

Create a free website or blog at WordPress.com.

Up ↑