/
Paypal_lib
203 lines (169 loc) · 5.98 KB
/
Paypal_lib
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* @package CodeIgniter
* @author Romaldy Minaya
* @copyright Copyright (c) 2011, PROTOS.
* @license GLP
* @since Version 1.0
* @version 1.0
*/
// ------------------------------------------------------------------------
/**
* Paypal Class
*
* @package CodeIgniter
* @subpackage Libraries
* @category Payment process
* @author Romaldy Minaya
*
// ------------------------------------------------------------------------
Documentation
This class let you make the payment procces based on paypal API,
effortless and easy.
*1)Use the same documentation about the vars from paypal page. http://bit.ly/j4wRR
*2)Customize the payment procces as you desire.
*3)Build with love.
Implementation
*1)Copy this code in your controller's function
$config['business'] = 'demo@demo.com';
$config['cpp_header_image'] = ''; //Image header url [750 pixels wide by 90 pixels high]
$config['return'] = 'sucess.php';
$config['cancel_return'] = 'shopping.php';
$config['notify_url'] = 'process_payment.php'; //IPN Post
$config['production'] = TRUE; //Its false by default and will use sandbox
$config['discount_rate_cart'] = 20; //This means 20% discount
$config["invoice"] = '843843'; //The invoice id
$this->load->library('paypal',$config);
#$this->paypal->add(<name>,<price>,<quantity>[Default 1],<code>[Optional]);
$this->paypal->add('T-shirt',2.99,6); //First item
$this->paypal->add('Pants',40); //Second item
$this->paypal->add('Blowse',10,10,'B-199-26'); //Third item with code
$this->paypal->pay(); //Proccess the payment
The notify url is where paypal will POST the information of the payment so you
can save that POST directly into your DB and analize as you want.
With $config["invoice"] is how you identify a bill and you can compare,save or update
that value later on your DB.
For test porpuses i do recommend to save the entire POST into your DB and analize if
its working according to your needs before putting it in production mode. EX.
$received_post = print_r($this->input->post(),TRUE);
//Save that variable and analize.
Note: html reference page http://bit.ly/j4wRR
*/
class Paypal {
var $config = Array();
var $production_url = 'https://www.paypal.com/cgi-bin/webscr?';
var $sandbox_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr?';
var $item = 1;
/**
* Constructor
*
* @param string
* @return void
*/
public function __construct($props = array())
{
$this->__initialize($props);
log_message('debug', "Paypal Class Initialized");
}
// --------------------------------------------------------------------
/**
* initialize Paypal preferences
*
* @access public
* @param array
* @return bool
*/
function __initialize($props = array())
{
#Account information
$config["business"] = ''; //Account email or id
$config["cmd"] = '_cart'; //Do not modify
$config["production"] = FALSE;
#Custom variable here we send the billing code-->
$config["custom"] = '';
$config["invoice"] = ''; //Code to identify the bill
#API Configuration-->
$config["upload"] = '1'; //Do not modify
$config["currency_code"] = 'USD'; //http://bit.ly/anciiH
$config["disp_tot"] = 'Y';
#Page Layout -->
$config["cpp_header_image"] = ''; //Image header url [750 pixels wide by 90 pixels high]
$config["cpp_cart_border_color"] = '000'; //The HTML hex code for your principal identifying color
$config["no_note"] = 1; //[0,1] 0 show, 1 hide
#Payment Page Information -->
$config["return"] = ''; //The URL to which PayPal redirects buyers’ browser after they complete their payments.
$config["cancel_return"] = ''; //Specify a URL on your website that displays a “Payment Canceled†page.
$config["notify_url"] = ''; //The URL to which PayPal posts information about the payment (IPN)
$config["rm"] = '2'; //Leave this to get payment information
$config["lc"] = 'EN'; //Languaje [EN,ES]
#Shipping and Misc Information -->
$config["shipping"] = '';
$config["shipping2"] = '';
$config["handling"] = '';
$config["tax"] = '';
$config["discount_amount_cart"] = ''; //Discount amount [9.99]
$config["discount_rate_cart"] = ''; //Discount percentage [15]
#Customer Information -->
$config["first_name"] = '';
$config["last_name"] = '';
$config["address1"] = '';
$config["address2"] = '';
$config["city"] = '';
$config["state"] = '';
$config["zip"] = '';
$config["email"] = '';
$config["night_phone_a"] = '';
$config["night_phone_b"] = '';
$config["night_phone_c"] = '';
/*
* Convert array elements into class variables
*/
if (count($props) > 0)
{
foreach ($props as $key => $val)
{
$config[$key] = $val;
}
}
$this->config = $config;
}
// --------------------------------------------------------------------
/**
* Perform payment process
*
* @access public
* @param array
* @return void
*/
function pay(){
#Convert the array to url encode variables
$vars = http_build_query($this->config);
if($this->config['production'] == TRUE){
header('LOCATION:'.$this->production_url.$vars);
}else{
header('LOCATION:'.$this->sandbox_url.$vars);
}
}
// --------------------------------------------------------------------
/**
* Add a product to the list
*
* @access public
* @param array
* @return void
*/
function add($item_name = '',$item_amount = NULL,$item_qty = NULL,$item_number = NULL){
$this->config['item_name_'.$this->item] = $item_name;
$this->config['amount_'.$this->item] = $item_amount;
$this->config['quantity_'.$this->item] = $item_qty;
$this->config['item_number_'.$this->item] = $item_number;
$this->item++;
}
}
// END Paypal Class
/* End of file Paypal.php */
/* Location: ./application/libraries/Paypal.php */