Codeigniter - digital goods paypal library subscription response null - php

I am working on a subscription system web, I am using Paypal Digital Goods Classes (https://github.com/thenbrent/paypal-digital-goods), and made a custom library called paypal2
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Paypal2
{
public function DatosPaypal($arreglo = array(), $produccion)
{
if (count($arreglo)>0)
{
$idCliente = $arreglo['idcliente'];
$descripcion = $arreglo['descripcion'];
$precio = $arreglo['precio'];
$pagado = $arreglo['pagado'];
$cancelado = $arreglo['cancelado'];
$notificar = $arreglo['notificar'];
$moneda = $arreglo['moneda'];
$usuario = $arreglo['usuario'];
$clave = $arreglo['clave'];
$llave = $arreglo['llave'];
if (!class_exists('PayPal_Digital_Goods',false))
{
require_once APPPATH.'third_party/paypal/paypal-digital-goods.class.php';
if ($produccion == true) {
PayPal_Digital_Goods_Configuration::environment( 'live' );
}
PayPal_Digital_Goods_Configuration::username( $usuario );
PayPal_Digital_Goods_Configuration::password( $clave );
PayPal_Digital_Goods_Configuration::signature( $llave );
PayPal_Digital_Goods_Configuration::return_url( $pagado );
PayPal_Digital_Goods_Configuration::cancel_url( $cancelado );
PayPal_Digital_Goods_Configuration::notify_url( $notificar );
PayPal_Digital_Goods_Configuration::currency( $moneda ); // 3 char character code, must be one of the values here: https://developer.paypal.com/docs/classic/api/currency_codes/
if (!class_exists('PayPal_Subscription', false))
{
require_once APPPATH.'third_party/paypal/paypal-subscription.class.php';
$subscription_details = array(
'description' => $descripcion,
'initial_amount' => $precio,
'amount' => $precio,
'period' => 'Month',
'frequency' => '1',
'total_cycles' => '0',
'user_id' => $idCliente
);
$paypal_subscription = new PayPal_Subscription( $subscription_details );
$respuesta = $paypal_subscription;
return $respuesta;
}
}
}
else
{
return "ERROR";
}
}
}
And here is the controller functions that made the payment possible
function AjaxPagoSubscripcion($plan) //<-Works great
{
$this->load->library('paypal2');
$this->load->model('Usuarios_model');
$this->config->load('PayPal2');
$arreglo = $this->Usuarios_model->DatosPagoSubscripcion($plan);
$PaypalObject = $this->paypal2->DatosPaypal($arreglo, $this->config->config['PPproduction_mode']);
$this->config->set_item('PayPalObject', $PaypalObject);
$data['PayPal'] = $PaypalObject->print_buy_button();
$this->load->view('usuarios/pruebas');
}
function pagos2() //<-Don't know how to get the paypal response or migrate Paypal object
{
$allvariables = get_defined_vars();
$data["Variables"] = $allvariables;
$this->load->view('paypal/pagado');
}
It works great until the subsciption/payment is done, I don't know how to get the paypal response or to migrate the paypal object between controllers, any help would be really appreciated.
UPDATE
I made some changes, and some progress, but now it gives me this error
( ! ) Fatal error: Uncaught exception 'Exception' with message 'Calling PayPal with action CreateRecurringPaymentsProfile has Failed: Profile description is invalid' in G:\wamp\www\serviciosycomprasx\application\third_party\paypal\paypal-digital-goods.class.php on line 224
( ! ) Exception: Calling PayPal with action CreateRecurringPaymentsProfile has Failed: Profile description is invalid in G:\wamp\www\serviciosycomprasx\application\third_party\paypal\paypal-digital-goods.class.php on line 224
And here is the controller which accepts the payment (where the erro triggers obvious :D )
public function pagado($plan)
{
$this->load->library('paypal2');
$this->load->model('Usuarios_model');
$this->config->load('PayPal2');
$arreglo = $this->Usuarios_model->DatosPagoSubscripcion($plan);
//echo $arreglo->precio;
//echo "<pre>",print_r($arreglo),"</pre>"; exit();
$PaypalObject = $this->paypal2->DatosPaypal($arreglo, $this->config->config['PPproduction_mode']);
$prueba = $PaypalObject->start_subscription();
echo "<pre>",print_r($prueba),"</pre>"; exit();
//$data['PayPal'] = $prueba;
//$data['main_content'] = 'paypal/pagado';
//$this->load->view('includes/'.$this->config->config["tema"].'/template' , $data);
}

I finally did it, using the code inside the views, is not how is to be done, but worked finally

Related

Google Task API PHP: Setting the TaskList ID & "Invalid task list ID" error

I'm trying to loop through task lists in order to generate a list of tasks using the Google Task PHP library.
I have:
Done all the credential stuff & can call the API
I can get task lists
A list of tasks for the respective task list output correctly using the ids generated from the point above & the tasklist parameter in Task API explorer
Where I'm stuck:
I'm not sure if I'm calling the 1) wrong method or 2) passing the wrong parameter to get a list of tasks for a respective tasklist id.
My code:
function getGcalTasks(){
$client = $this->getGcalTaskClient();
try {
$service = new Google_Service_Tasks($client);
$optParamLists = array(
'maxResults' => 10,
);
$result_lists = $service->tasklists->listTasklists($optParamLists);
if (
is_array($result_lists->getItems())
&& count($result_lists->getItems())
) {
foreach ($result_lists->getItems() as $tasklist) {
$taskListId = trim($tasklist->getId());
$taskListTitle = trim($tasklist->getTitle());
if(
$taskListId
){
$optParamsTasks = array(
// I've tried all of the below and still get: "Invalid task list ID",
'id' => $taskListId,
'kind' => 'tasks#taskList',
'title' => $taskListTitle,
//'tasklist' => $taskListId,
//'taskList' => $taskListId,
//'tasklistId' => $taskListId,
//'listName' => $taskListTitle,
);
$result_tasks = $service->tasks->listTasks($optParamsTasks);
}
}
}
} catch (Exception $e) {
log_message('error',$e->getMessage());
}
}
Welp, I took a look a few minutes later and realized that listTasks() only accepts one parameter, the id. The code below is working for me:
function getGcalTasks(){
$client = $this->getGcalTaskClient();
$tasks = array();
try {
$service = new Google_Service_Tasks($client);
$optParamLists = array(
'maxResults' => 10,
);
$result_lists = $service->tasklists->listTasklists($optParamLists);
if (
is_array($result_lists->getItems())
&& count($result_lists->getItems())
) {
foreach ($result_lists->getItems() as $tasklist) {
$taskListId = trim($tasklist->getId());
$taskListTitle = trim($tasklist->getTitle());
if(
$taskListId
){
$optParamsTasks = array(
'tasklist' => $taskListId,
);
$result_tasks = $service->tasks->listTasks($taskListId);
$tasks[] = $result_tasks->getItems();
}
}
return $tasks;
}
} catch (Exception $e) {
log_message('error',$e->getMessage());
}
}

Codeigniter Get New Generated Username From Model To Controller

I have been struggling on this issue for a very long time and I still do not have any idea how to get this working.
Currently I need to show my new generated username from Model to Controller. But I can't seem to call it. Below is my code:
Model formval_callbacks.php :
public function _username_check( $user_name )
{
$this->db->select('user_name');
$this->db->like('user_name', $user_name);
$this->db->order_by('user_date', 'desc');
$this->db->limit(1);
$query = $this->db->get('users');
if ($query->num_rows() > 0)
{
$row = $query->row();
$db_username = $row->user_name;
$username_counter = preg_match("/".$user_name."(\d+)/", $db_username, $matches) ? (int)$matches[1] : NULL;
$username_counter++;
return $user_name.$username_counter;
}else{
$username_counter = 1;
return $user_name.$username_counter;
}
}
Model user_model.php :
public function create_user( $role, $insert_array = array() )
{
// The form validation class doesn't allow for multiple config files, so we do it the old fashion way
$this->config->load( 'form_validation/administration/create_user/create_' . $role );
$this->validation_rules = config_item( $role . '_creation_rules' );
// If the data is already validated, there's no reason to do it again
if( ! empty( $insert_array ) OR $this->validate() === TRUE )
{
// Prepare user_data array for insert into user table
$user_data = array(
'user_name' => ( isset( $insert_array['user_name'] ) ) ? $insert_array['user_name'] : set_value('user_name'),
'user_pass' => ( isset( $insert_array['user_pass'] ) ) ? $insert_array['user_pass'] : set_value('user_pass'),
'user_email' => ( isset( $insert_array['user_email'] ) ) ? $insert_array['user_email'] : set_value('user_email')
);
// User level derived directly from the role argument
$user_data['user_level'] = $this->authentication->levels[$role];
// If we are using form validation for the user creation
if( empty( $insert_array ) )
{
// Remove some user_data elements from _field_data array as prep for insert into profile table
$this->form_validation->unset_field_data( array(
'user_name',
'user_pass',
'user_email'
));
// Create array of profile data
foreach( $this->form_validation->get_field_data() as $k => $v )
{
$profile_data[$k] = $v['postdata'];
}
// Unset all data for set_value(), so we can create another user
$this->kill_set_value();
}
// If we are not using form validation for the user creation
else
{
// Remove some insert_array elements as prep for insert into profile table
unset( $insert_array['user_name'] );
unset( $insert_array['user_pass'] );
unset( $insert_array['user_email'] );
// Profile data is insert array
$profile_data = $insert_array;
}
// Encrypt any sensitive data
if( isset( $profile_data['license_number'] ) )
{
$this->load->library('encrypt');
$profile_data['license_number'] = $this->encrypt->encode( $profile_data['license_number'] );
}
// Create a random user id if not already set
$random_unique_int = $this->get_unused_id();
// Generate random user salt
$user_salt = $this->authentication->random_salt();
// Perform transaction
$this->db->trans_start();
$user_data['user_id'] = $random_unique_int;
$user_data['user_pass'] = $this->authentication->hash_passwd( $user_data['user_pass'], $user_salt );
$user_data['user_salt'] = $user_salt;
$user_data['user_date'] = time();
$user_data['user_modified'] = time();
// Insert data in user table
$this->db->set($user_data)
->insert( config_item('user_table'));
$profile_data['user_id'] = $random_unique_int;
// Insert data in profile table
$this->db->set($profile_data)
->insert( config_item( $role . '_profiles_table'));
// Complete transaction
$this->db->trans_complete();
// Verify transaction was successful
if( $this->db->trans_status() !== FALSE )
{
// Load var to confirm user inserted into database
$this->load->vars( array( 'user_created' => 1 ) );
}
return TRUE;
}
return FALSE;
}
Controller register.php :
public function index()
{
// Load resources
$this->load->library('csrf');
$this->load->model('registration_model');
$reg_mode = $this->registration_model->get_reg_mode();
// Check to see if there was a registration submission
if( $this->csrf->token_match )
{
// If mode #1, registration allows for instant user creation without verification or approval.
if( $reg_mode == 1 )
{
$_POST['user_level'] = 1;
$this->load->model('user_model');
$this->user_model->create_user( 'customer', array() );
$this->load->model('formval_callbacks');
$view_data['new_username'] = $this->formval_callbacks->_username_check();
}
}
// If for some reason the user is already logged in
$this->is_logged_in();
// Send registration mode to view
$view_data['reg_mode'] = $reg_mode;
// Ouput alert-bar message if cookies not enabled
$this->check_cookies_enabled();
$data = array(
'title' => WEBSITE_NAME . ' - Account Registration',
'content' => $this->load->view( 'public/register/registration_form', $view_data, TRUE ),
// Load the show password script
'javascripts' => array(
'js/jquery.passwordToggle-1.1.js',
'js/jquery.char-limiter-3.0.0.js',
'js/default-char-limiters.js'
),
// Use the show password script
'extra_head' => '
<script>
$(document).ready(function(){
$("#show-password").passwordToggle({target:"#user_pass"});
});
</script>
'
);
$this->load->view( $this->template, $data );
}
There is an error for this line because I never put in any parameters :
$view_data['new_username'] = $this->formval_callbacks->_username_check();
What should I do if I just want to get the new generated username without putting in the parameter?
Also, is it better to get the new generated username from formval_callback.php or user_model.php in this function :
if( $this->db->trans_status() !== FALSE )
Hope you guys can help me out here.

codeigniter - calling two functions from same controller one after the other, second function fails

This one's got me stuck!
I have two functions in a controller which can be called from a menu independantly and they work fine.
I want to call them in a month end routine (in the same controller), one after the other; the first function works fine and returns to the calling function, the second function is called but fails because the load of the $model variable fails.
Here is the code for the month end routine,
function month_end_routines()
{
// create stock inventory valuation report in excel format
$export_excel = 1;
$this -> inventory_summary($export_excel);
// create negative stock
$export_excel = 1;
$this -> inventory_negative_stock($export_excel);
echo 'debug 2';
// reset rolling inventory indicator
$this -> load->model('Item');
$this -> load->library('../controllers/items');
$this -> items->reset_rolling();
}
Here is the code for the first function called inventory_summary,
function inventory_summary($export_excel=0, $create_PO=0, $set_NM=0, $set_SM=0)
{
// load appropriate models and libraries
$this -> load->model('reports/Inventory_summary');
$this -> load->library('../controllers/items');
// set variables
$model = $this->Inventory_summary;
$tabular_data = array();
$edit_file = 'items/view/';
$width = $this->items->get_form_width();
$stock_total = 0;
// get all items
$report_data = $model->getData(array());
foreach($report_data as $row)
{
$stock_value = $row['cost_price'] * $row['quantity'];
$stock_total = $stock_total + $stock_value;
// set up the item_number to handle blanks
if ($row['item_number'] == NULL) {$row['item_number'] = $this->lang->line('common_edit');}
$tabular_data[] = array (
$row['category'],
anchor (
$edit_file.$row['item_id'].'/width:'.$width,
$row['item_number'],
array('class'=>'thickbox','title'=>$this->lang->line('items_update'))
),
$row['reorder_policy'],
$row['name'],
$row['cost_price'],
$row['quantity'],
$stock_value,
$stock_total
);
}
$today_date = date('d/m/Y; H:i:s', time());
$data = array (
"title" => $this->lang->line('reports_inventory_summary_report'),
"subtitle" => ' - '.$today_date.' '.$this->lang->line('common_for').' '.$this->db->database.'.',
"headers" => $model->getDataColumns(),
"data" => $tabular_data,
"summary_data" => $model->getSummaryData(array()),
"export_excel" => $export_excel
);
if ($export_excel == 1)
{
$this->load->model('Common_routines');
$this->Common_routines->create_csv($data);
}
else
{
$this->load->view("reports/tabular", $data);
}
return;
.. and here is the code for the second function,
function inventory_negative_stock($export_excel=0, $create_PO=0, $set_NM=0, $set_SM=0)
{
echo 'debug 1.5';
$this -> load->model('reports/Inventory_negative_stock');
$this -> load->library('../controllers/items');
echo 'debug 1.6';
$model = $this->Inventory_negative_stock;
var_dump($model);
$tabular_data = array();
$edit_file = 'items/view/';
$width = $this->items->get_form_width();
echo 'debug 1.7';
$report_data = $model->getData(array());
echo 'debug 1.8';
foreach($report_data as $row)
{
// set up the item_number to handle blanks
if ($row['item_number'] == NULL) {$row['item_number'] = $this->lang->line('common_edit');}
// load each line to the output array
$tabular_data[] = array(
$row['category'],
anchor (
$edit_file.$row['item_id'].'/width:'.$width,
$row['item_number'],
array('class'=>'thickbox','title'=>$this->lang->line('items_update'))
),
$row['name'],
$row['cost_price'],
$row['quantity']
);
}
// load data array for display
$today_date = date('d/m/Y; H:i:s', time());
$data = array (
"title" => $this->lang->line('reports_negative_stock'),
"subtitle" => ' - '.$today_date.' '.$this->lang->line('common_for').' '.$this->db->database.'.',
"headers" => $model->getDataColumns(),
"data" => $tabular_data,
"summary_data" => $model->getSummaryData(array()),
"export_excel" => $export_excel
);
if ($export_excel == 1)
{
$this->load->model('Common_routines');
$this->Common_routines->create_csv($data);
}
else
{
$this->load->view("reports/tabular", $data);
}
return;
}
This line is failing
$model=$this->Inventory_negative_stock;
In the first function $model is loaded correctly. In the second it isn't.
It does not matter in which order these functions are called; $model always fails to load in the second function called.
Any help would be great and thanks in advance. I hope I've given enough code; if you need more information let me know.
As requested, here is the code in Inventory_negative_stock,
<?php
require_once("report.php");
class Inventory_negative_stock extends Report
{
function __construct()
{
parent::__construct();
}
public function getDataColumns()
{
return array (
$this->lang->line('reports_category'),
$this->lang->line('reports_item_number'),
$this->lang->line('reports_item_name'),
$this->lang->line('reports_cost_price'),
$this->lang->line('reports_count')
);
}
public function getData(array $inputs)
{
$this->db->select('category, name, cost_price, quantity, reorder_level, reorder_quantity, item_id, item_number');
$this->db->from('items');
$this->db->where("quantity < 0 and deleted = 0");
$this->db->order_by('category, name');
return $this->db->get()->result_array();
}
public function getSummaryData(array $inputs)
{
return array();
}
}
?>

Assigning gid to new user in joomla 1.5

I've created several new child groups under registered users and when I create a new user from the backend, everything works fine. When trying to create an account on the frontend the system is giving them the gid of the parent group (registered users). I would like to know if you can pass the gid to joomla. Here's the script I'm using that's not working. Many thanks!
// Begin create user
global $mainframe;
JFactory::getLanguage()->load('com_user');
$this->execPieceByName('ff_InitLib');
$user = clone(JFactory::getUser());
$pathway =& $mainframe->getPathway();
$config =& JFactory::getConfig();
$authorize =& JFactory::getACL();
$document =& JFactory::getDocument();
// If user registration is not allowed, show 403 not authorized.
$usersConfig = &JComponentHelper::getParams( 'com_users' );
if ($usersConfig->get('allowUserRegistration') == '0') {
echo '<script>alert("Access forbidden");history.go(-1);</script>';
return;
} else {
// Initialize new usertype setting
$newUsertype = $usersConfig->get( 'new_usertype' );
if (!$newUsertype) {
$newUsertype = 'Free User';
}
// Bind the post array to the user object
$post = array(
'name' => ff_getSubmit('ownerName'),
'username' => ff_getSubmit('ownerEmail'),
'email' => ff_getSubmit('ownerEmail'),
'password' => ff_getSubmit('password'),
'password2' => ff_getSubmit('password'),
'task' => 'register_save',
'id' => '0',
'gid' => ff_getSubmit('101'),
);
if (!$user->bind( $post, 'usertype' )) {
echo '<script>alert("'.addslashes($user- >getError()).'");history.go(-1);</script>';
return;
} else {
// Set some initial user values
$user->set('id', 0);
$user->set('usertype', 'Free User');
$user->set('gid', $authorize->get_group_id( '', $newUsertype, 'ARO' ));
$date =& JFactory::getDate();
$user->set('registerDate', $date->toMySQL());
// If user activation is turned on, we need to set the activation information
$useractivation = $usersConfig->get( 'useractivation' );
if ($useractivation == '1')
{
jimport('joomla.user.helper');
$user->set('activation', JUtility::getHash( JUserHelper::genRandomPassword()) );
$user->set('block', '1');
}
// If there was an error with registration, set the message and display form
if ( !$user->save() )
{
echo '<script>alert("'.addslashes(JText::_( $user->getError())).'");history.go(-1);</script>';
return;
} else {
$db =& JFactory::getDBO();
$name = $user->get('name');
$email = $user->get('email');
$username = $user->get('username');
JFactory::getDBO()->setQuery("Update #__facileforms_records Set user_id = '".$user->get('id')."',
username = ".JFactory::getDBO()->Quote($username).", user_full_name = ".JFactory::getDBO()->Quote($name)." Where id = '".$this->record_id."'");
JFactory::getDBO()->query();
}
}
}
[SOLVED] Assigning gid to new user in joomla 1.5
I figured it out. If anyone else looking for an answer to this questions, just replace this line of code:
$user->set('gid', $authorize->get_group_id( '', $newUsertype, 'ARO' ));
with
$user->set('gid', 'your gid#);

PayPal IPN with CodeIgniter

I am trying to implement a membership subscription service on a website built in CodeIgniter. I wish to use PayPal to manage payments, and am having a very hard time implementing this.
What I am trying to achieve is:
User fills in a membership form with
personal details
User selects a
subscription option (1 of 8 choices - each different price) and submits form
User is sent to PayPal to pay
User is returned to site upon successful payment and personal details are stored in database which creates user account (membership).
There is also the addition of form validation, I use the form_validation helper in CodeIgniter, but this needs to be done before PayPal payment can commence.
I have attempted to implement the PayPal_Lib from Ran Aroussi, but I feel it has not enough clear documentation or guidance on it. Any implemented examples or advice would be much appreciated.
Lucas
I found Ran's library a little hard to use too so I've written a replacement - which also has the benefit of performing more checks on the transaction, and logging the IPN call and the order details in your database. Here's the library on GitHub, I hope you find it useful:
https://github.com/orderly/codeigniter-paypal-ipn
Below is the unmodified code that i used with Ran's library.
Hope it helps.
<?php
/**
* PayPal_Lib Controller Class (Paypal IPN Class)
*
* Paypal controller that provides functionality to the creation for PayPal forms,
* submissions, success and cancel requests, as well as IPN responses.
*
* The class requires the use of the PayPal_Lib library and config files.
*
* #package CodeIgniter
* #subpackage Libraries
* #category Commerce
* #author Ran Aroussi <ran#aroussi.com>
* #copyright Copyright (c) 2006, http://aroussi.com/ci/
*
*/
class Paypal extends Controller
{
function Paypal()
{
parent::Controller();
$this->load->library('Paypal_Lib');
}
function index()
{
$this->form();
}
function form()
{
$this->paypal_lib->add_field('business', 'herrka_1245670546_biz#pandorascode.com');
$this->paypal_lib->add_field('return', site_url('paypal/success') );
$this->paypal_lib->add_field('cancel_return', site_url('paypal/cancel') );
$this->paypal_lib->add_field('notify_url', site_url('paypal/ipn') ); // <-- IPN url
$this->paypal_lib->add_field('custom', '470874552'); // <-- Verify return
$this->paypal_lib->add_field('item_name', 'Paypal Test Transaction');
$this->paypal_lib->add_field('item_number', '5');
$this->paypal_lib->add_field('amount', '9.95');
// if you want an image button use this:
$this->paypal_lib->image('button_03.gif');
// otherwise, don't write anything or (if you want to
// change the default button text), write this:
// $this->paypal_lib->button('Click to Pay!');
$data['paypal_form'] = $this->paypal_lib->paypal_form();
$this->load->view('paypal/form', $data);
}
function cancel()
{
$this->load->view('paypal/cancel');
}
function success()
{
//$data['pp_info'] = $this->input->post();
$data['pp_info'] = $_POST; //FIX?
$this->load->view('paypal/success', $data);
}
function ipn()
{
$ipn_valid = $this->paypal_lib->validate_ipn();
if ( $ipn_valid == TRUE )
{
/**
Log IPN
TODO: bunu daha guzel gozukecek sekilde yapayim ilerde.
**/
date_default_timezone_set('Europe/Istanbul');
$this->load->helper('date');
$raw = '';
foreach ($this->paypal_lib->ipn_data as $key=>$value)
{
$raw .= "\n$key: $value";
}
$this->load->model('model_paypal');
$data_ipn['user_id'] = $this->paypal_lib->ipn_data['custom']; /* get USER_ID from custom field. */
$data_ipn['txn_id'] = $this->paypal_lib->ipn_data['txn_id'];
$data_ipn['payment_status'] = $this->paypal_lib->ipn_data['payment_status'];
$data_ipn['mc_gross'] = $this->paypal_lib->ipn_data['mc_gross'];
$data_ipn['mc_fee'] = $this->paypal_lib->ipn_data['mc_fee'];
$data_ipn['mc_currency'] = $this->paypal_lib->ipn_data['mc_currency'];
$data_ipn['item_number'] = $this->paypal_lib->ipn_data['item_number'];
$data_ipn['datetime'] = mdate( "%Y-%m-%d %H:%i:%s" );
$data_ipn['status'] = IPN_ENTRY_AWAITING;
$data_ipn['raw'] = $raw;
$this->model_paypal->ipn_entry_add ( $data_ipn );
$ipn_payment_status = $this->paypal_lib->ipn_data['payment_status'];
if ( strtolower($ipn_payment_status) == 'pending' )
{
log_message('debug', 'payment status TAMAM');
$this->load->model('model_user_premium');
$ipn_item_number = $this->paypal_lib->ipn_data['item_number'];
$item_info = $this->model_user_premium->Premium_item_info ( $ipn_item_number );
$ipn_mc_gross = $this->paypal_lib->ipn_data['mc_gross'];
log_message('debug', 'Item fee: '. $item_info['item_fee'] );
if ( $item_info['item_fee'] == $ipn_mc_gross )
{
log_message('debug', 'fee ile gross TAMAM');
$data_account['user_id'] = $data_ipn['user_id'];
$data_account['type'] = $item_info['item_type'];
$data_account['date_expire'] = date("Y-m-d", mktime(0, 0, 0, date("m") + $item_info['date_extender'], date("d"), date("y") ) );
log_message('debug', 'UserID: '. $data_account['user_id'] );
log_message('debug', 'Type:'. $data_account['type'] );
log_message('debug', 'Expire:'. $data_account['date_expire'] );
$this->model_user_premium->Premium_membership_change( $data_ipn['user_id'], $data_account );
}
else
{
//TODO: report eksik transaction.
}
}
}
elseif ( $ipn_valid == FALSE )
{
$this->load->library('email');
$this->email->to( 'demo#demo.com' );
$this->email->subject('IPN - FAILED');
$this->email->from( 'notify#bulusturx.com', 'PAYPAL' );
$this->email->message('or 4 life');
$this->email->send();
}
}
function ipn_list()
{
//TODO: admin check
$this->load->helper('form');
$this->load->model('model_theme');
switch ( $_SERVER['REQUEST_METHOD'] )
{
case 'GET':
/* Theme System with Reference Variable ( first param ) */
$this->model_theme->Theme_returnThemeInfo( $data, 'paypal' );
$this->load->view( $data['theme_folder_vault'] . 'master-ipn_list', $data );
break;
case 'POST':
$this->load->model('model_paypal');
$user_id = $this->input->post('user_id');
$txn_id = $this->input->post('txn_id');
$list_ipn = $this->model_paypal->ipn_entry_list ( $user_id, $txn_id );
echo '<pre>';
print_r( $list_ipn );
echo '</pre>';
break;
default:
break;
}
}
function ipn_test()
{
$this->load->model('model_user_premium');
$data_account['user_id'] = 123;
$data_account['type'] = 4;
$data_account['date_expire'] = date("Y-m-d", mktime(0, 0, 0, date("m") + 12, date("d"), date("y") ) );
echo '<pre>';
print_r( $data_account );
echo '</pre>';
$this->model_user_premium->Premium_membership_change( 123, $data_account );
}
}
?>
Here's a paypal library from Jamie Rumbelow that I've been using with minor tweaks:
http://bitbucket.org/jamierumbelow/codeigniter-paypal/src

Categories