├── GNU-AGPL-3.0.txt
├── README.textile
├── activerecord
├── libraries
│ └── PayPal_IPN.php
└── models
│ ├── ipn_log_model.php
│ └── ipn_order_model.php
├── common
├── config
│ └── paypal_ipn.php
├── controllers
│ ├── example-no-notification.php
│ └── example-smarty-notification-email.php
├── sql
│ └── create_mysql_tables.sql
└── views
│ └── templates
│ └── confirmation_email.tpl
└── doctrine1.2
├── libraries
└── PayPal_IPN.php
└── models
├── IpnLog.php
├── IpnOrder.php
├── IpnOrderItem.php
└── generated
├── BaseIpnLog.php
├── BaseIpnOrderItems.php
└── BaseIpnOrders.php
/GNU-AGPL-3.0.txt:
--------------------------------------------------------------------------------
1 | GNU AFFERO GENERAL PUBLIC LICENSE
2 | Version 3, 19 November 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU Affero General Public License is a free, copyleft license for
11 | software and other kinds of works, specifically designed to ensure
12 | cooperation with the community in the case of network server software.
13 |
14 | The licenses for most software and other practical works are designed
15 | to take away your freedom to share and change the works. By contrast,
16 | our General Public Licenses are intended to guarantee your freedom to
17 | share and change all versions of a program--to make sure it remains free
18 | software for all its users.
19 |
20 | When we speak of free software, we are referring to freedom, not
21 | price. Our General Public Licenses are designed to make sure that you
22 | have the freedom to distribute copies of free software (and charge for
23 | them if you wish), that you receive source code or can get it if you
24 | want it, that you can change the software or use pieces of it in new
25 | free programs, and that you know you can do these things.
26 |
27 | Developers that use our General Public Licenses protect your rights
28 | with two steps: (1) assert copyright on the software, and (2) offer
29 | you this License which gives you legal permission to copy, distribute
30 | and/or modify the software.
31 |
32 | A secondary benefit of defending all users' freedom is that
33 | improvements made in alternate versions of the program, if they
34 | receive widespread use, become available for other developers to
35 | incorporate. Many developers of free software are heartened and
36 | encouraged by the resulting cooperation. However, in the case of
37 | software used on network servers, this result may fail to come about.
38 | The GNU General Public License permits making a modified version and
39 | letting the public access it on a server without ever releasing its
40 | source code to the public.
41 |
42 | The GNU Affero General Public License is designed specifically to
43 | ensure that, in such cases, the modified source code becomes available
44 | to the community. It requires the operator of a network server to
45 | provide the source code of the modified version running there to the
46 | users of that server. Therefore, public use of a modified version, on
47 | a publicly accessible server, gives the public access to the source
48 | code of the modified version.
49 |
50 | An older license, called the Affero General Public License and
51 | published by Affero, was designed to accomplish similar goals. This is
52 | a different license, not a version of the Affero GPL, but Affero has
53 | released a new version of the Affero GPL which permits relicensing under
54 | this license.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | TERMS AND CONDITIONS
60 |
61 | 0. Definitions.
62 |
63 | "This License" refers to version 3 of the GNU Affero General Public License.
64 |
65 | "Copyright" also means copyright-like laws that apply to other kinds of
66 | works, such as semiconductor masks.
67 |
68 | "The Program" refers to any copyrightable work licensed under this
69 | License. Each licensee is addressed as "you". "Licensees" and
70 | "recipients" may be individuals or organizations.
71 |
72 | To "modify" a work means to copy from or adapt all or part of the work
73 | in a fashion requiring copyright permission, other than the making of an
74 | exact copy. The resulting work is called a "modified version" of the
75 | earlier work or a work "based on" the earlier work.
76 |
77 | A "covered work" means either the unmodified Program or a work based
78 | on the Program.
79 |
80 | To "propagate" a work means to do anything with it that, without
81 | permission, would make you directly or secondarily liable for
82 | infringement under applicable copyright law, except executing it on a
83 | computer or modifying a private copy. Propagation includes copying,
84 | distribution (with or without modification), making available to the
85 | public, and in some countries other activities as well.
86 |
87 | To "convey" a work means any kind of propagation that enables other
88 | parties to make or receive copies. Mere interaction with a user through
89 | a computer network, with no transfer of a copy, is not conveying.
90 |
91 | An interactive user interface displays "Appropriate Legal Notices"
92 | to the extent that it includes a convenient and prominently visible
93 | feature that (1) displays an appropriate copyright notice, and (2)
94 | tells the user that there is no warranty for the work (except to the
95 | extent that warranties are provided), that licensees may convey the
96 | work under this License, and how to view a copy of this License. If
97 | the interface presents a list of user commands or options, such as a
98 | menu, a prominent item in the list meets this criterion.
99 |
100 | 1. Source Code.
101 |
102 | The "source code" for a work means the preferred form of the work
103 | for making modifications to it. "Object code" means any non-source
104 | form of a work.
105 |
106 | A "Standard Interface" means an interface that either is an official
107 | standard defined by a recognized standards body, or, in the case of
108 | interfaces specified for a particular programming language, one that
109 | is widely used among developers working in that language.
110 |
111 | The "System Libraries" of an executable work include anything, other
112 | than the work as a whole, that (a) is included in the normal form of
113 | packaging a Major Component, but which is not part of that Major
114 | Component, and (b) serves only to enable use of the work with that
115 | Major Component, or to implement a Standard Interface for which an
116 | implementation is available to the public in source code form. A
117 | "Major Component", in this context, means a major essential component
118 | (kernel, window system, and so on) of the specific operating system
119 | (if any) on which the executable work runs, or a compiler used to
120 | produce the work, or an object code interpreter used to run it.
121 |
122 | The "Corresponding Source" for a work in object code form means all
123 | the source code needed to generate, install, and (for an executable
124 | work) run the object code and to modify the work, including scripts to
125 | control those activities. However, it does not include the work's
126 | System Libraries, or general-purpose tools or generally available free
127 | programs which are used unmodified in performing those activities but
128 | which are not part of the work. For example, Corresponding Source
129 | includes interface definition files associated with source files for
130 | the work, and the source code for shared libraries and dynamically
131 | linked subprograms that the work is specifically designed to require,
132 | such as by intimate data communication or control flow between those
133 | subprograms and other parts of the work.
134 |
135 | The Corresponding Source need not include anything that users
136 | can regenerate automatically from other parts of the Corresponding
137 | Source.
138 |
139 | The Corresponding Source for a work in source code form is that
140 | same work.
141 |
142 | 2. Basic Permissions.
143 |
144 | All rights granted under this License are granted for the term of
145 | copyright on the Program, and are irrevocable provided the stated
146 | conditions are met. This License explicitly affirms your unlimited
147 | permission to run the unmodified Program. The output from running a
148 | covered work is covered by this License only if the output, given its
149 | content, constitutes a covered work. This License acknowledges your
150 | rights of fair use or other equivalent, as provided by copyright law.
151 |
152 | You may make, run and propagate covered works that you do not
153 | convey, without conditions so long as your license otherwise remains
154 | in force. You may convey covered works to others for the sole purpose
155 | of having them make modifications exclusively for you, or provide you
156 | with facilities for running those works, provided that you comply with
157 | the terms of this License in conveying all material for which you do
158 | not control copyright. Those thus making or running the covered works
159 | for you must do so exclusively on your behalf, under your direction
160 | and control, on terms that prohibit them from making any copies of
161 | your copyrighted material outside their relationship with you.
162 |
163 | Conveying under any other circumstances is permitted solely under
164 | the conditions stated below. Sublicensing is not allowed; section 10
165 | makes it unnecessary.
166 |
167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
168 |
169 | No covered work shall be deemed part of an effective technological
170 | measure under any applicable law fulfilling obligations under article
171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
172 | similar laws prohibiting or restricting circumvention of such
173 | measures.
174 |
175 | When you convey a covered work, you waive any legal power to forbid
176 | circumvention of technological measures to the extent such circumvention
177 | is effected by exercising rights under this License with respect to
178 | the covered work, and you disclaim any intention to limit operation or
179 | modification of the work as a means of enforcing, against the work's
180 | users, your or third parties' legal rights to forbid circumvention of
181 | technological measures.
182 |
183 | 4. Conveying Verbatim Copies.
184 |
185 | You may convey verbatim copies of the Program's source code as you
186 | receive it, in any medium, provided that you conspicuously and
187 | appropriately publish on each copy an appropriate copyright notice;
188 | keep intact all notices stating that this License and any
189 | non-permissive terms added in accord with section 7 apply to the code;
190 | keep intact all notices of the absence of any warranty; and give all
191 | recipients a copy of this License along with the Program.
192 |
193 | You may charge any price or no price for each copy that you convey,
194 | and you may offer support or warranty protection for a fee.
195 |
196 | 5. Conveying Modified Source Versions.
197 |
198 | You may convey a work based on the Program, or the modifications to
199 | produce it from the Program, in the form of source code under the
200 | terms of section 4, provided that you also meet all of these conditions:
201 |
202 | a) The work must carry prominent notices stating that you modified
203 | it, and giving a relevant date.
204 |
205 | b) The work must carry prominent notices stating that it is
206 | released under this License and any conditions added under section
207 | 7. This requirement modifies the requirement in section 4 to
208 | "keep intact all notices".
209 |
210 | c) You must license the entire work, as a whole, under this
211 | License to anyone who comes into possession of a copy. This
212 | License will therefore apply, along with any applicable section 7
213 | additional terms, to the whole of the work, and all its parts,
214 | regardless of how they are packaged. This License gives no
215 | permission to license the work in any other way, but it does not
216 | invalidate such permission if you have separately received it.
217 |
218 | d) If the work has interactive user interfaces, each must display
219 | Appropriate Legal Notices; however, if the Program has interactive
220 | interfaces that do not display Appropriate Legal Notices, your
221 | work need not make them do so.
222 |
223 | A compilation of a covered work with other separate and independent
224 | works, which are not by their nature extensions of the covered work,
225 | and which are not combined with it such as to form a larger program,
226 | in or on a volume of a storage or distribution medium, is called an
227 | "aggregate" if the compilation and its resulting copyright are not
228 | used to limit the access or legal rights of the compilation's users
229 | beyond what the individual works permit. Inclusion of a covered work
230 | in an aggregate does not cause this License to apply to the other
231 | parts of the aggregate.
232 |
233 | 6. Conveying Non-Source Forms.
234 |
235 | You may convey a covered work in object code form under the terms
236 | of sections 4 and 5, provided that you also convey the
237 | machine-readable Corresponding Source under the terms of this License,
238 | in one of these ways:
239 |
240 | a) Convey the object code in, or embodied in, a physical product
241 | (including a physical distribution medium), accompanied by the
242 | Corresponding Source fixed on a durable physical medium
243 | customarily used for software interchange.
244 |
245 | b) Convey the object code in, or embodied in, a physical product
246 | (including a physical distribution medium), accompanied by a
247 | written offer, valid for at least three years and valid for as
248 | long as you offer spare parts or customer support for that product
249 | model, to give anyone who possesses the object code either (1) a
250 | copy of the Corresponding Source for all the software in the
251 | product that is covered by this License, on a durable physical
252 | medium customarily used for software interchange, for a price no
253 | more than your reasonable cost of physically performing this
254 | conveying of source, or (2) access to copy the
255 | Corresponding Source from a network server at no charge.
256 |
257 | c) Convey individual copies of the object code with a copy of the
258 | written offer to provide the Corresponding Source. This
259 | alternative is allowed only occasionally and noncommercially, and
260 | only if you received the object code with such an offer, in accord
261 | with subsection 6b.
262 |
263 | d) Convey the object code by offering access from a designated
264 | place (gratis or for a charge), and offer equivalent access to the
265 | Corresponding Source in the same way through the same place at no
266 | further charge. You need not require recipients to copy the
267 | Corresponding Source along with the object code. If the place to
268 | copy the object code is a network server, the Corresponding Source
269 | may be on a different server (operated by you or a third party)
270 | that supports equivalent copying facilities, provided you maintain
271 | clear directions next to the object code saying where to find the
272 | Corresponding Source. Regardless of what server hosts the
273 | Corresponding Source, you remain obligated to ensure that it is
274 | available for as long as needed to satisfy these requirements.
275 |
276 | e) Convey the object code using peer-to-peer transmission, provided
277 | you inform other peers where the object code and Corresponding
278 | Source of the work are being offered to the general public at no
279 | charge under subsection 6d.
280 |
281 | A separable portion of the object code, whose source code is excluded
282 | from the Corresponding Source as a System Library, need not be
283 | included in conveying the object code work.
284 |
285 | A "User Product" is either (1) a "consumer product", which means any
286 | tangible personal property which is normally used for personal, family,
287 | or household purposes, or (2) anything designed or sold for incorporation
288 | into a dwelling. In determining whether a product is a consumer product,
289 | doubtful cases shall be resolved in favor of coverage. For a particular
290 | product received by a particular user, "normally used" refers to a
291 | typical or common use of that class of product, regardless of the status
292 | of the particular user or of the way in which the particular user
293 | actually uses, or expects or is expected to use, the product. A product
294 | is a consumer product regardless of whether the product has substantial
295 | commercial, industrial or non-consumer uses, unless such uses represent
296 | the only significant mode of use of the product.
297 |
298 | "Installation Information" for a User Product means any methods,
299 | procedures, authorization keys, or other information required to install
300 | and execute modified versions of a covered work in that User Product from
301 | a modified version of its Corresponding Source. The information must
302 | suffice to ensure that the continued functioning of the modified object
303 | code is in no case prevented or interfered with solely because
304 | modification has been made.
305 |
306 | If you convey an object code work under this section in, or with, or
307 | specifically for use in, a User Product, and the conveying occurs as
308 | part of a transaction in which the right of possession and use of the
309 | User Product is transferred to the recipient in perpetuity or for a
310 | fixed term (regardless of how the transaction is characterized), the
311 | Corresponding Source conveyed under this section must be accompanied
312 | by the Installation Information. But this requirement does not apply
313 | if neither you nor any third party retains the ability to install
314 | modified object code on the User Product (for example, the work has
315 | been installed in ROM).
316 |
317 | The requirement to provide Installation Information does not include a
318 | requirement to continue to provide support service, warranty, or updates
319 | for a work that has been modified or installed by the recipient, or for
320 | the User Product in which it has been modified or installed. Access to a
321 | network may be denied when the modification itself materially and
322 | adversely affects the operation of the network or violates the rules and
323 | protocols for communication across the network.
324 |
325 | Corresponding Source conveyed, and Installation Information provided,
326 | in accord with this section must be in a format that is publicly
327 | documented (and with an implementation available to the public in
328 | source code form), and must require no special password or key for
329 | unpacking, reading or copying.
330 |
331 | 7. Additional Terms.
332 |
333 | "Additional permissions" are terms that supplement the terms of this
334 | License by making exceptions from one or more of its conditions.
335 | Additional permissions that are applicable to the entire Program shall
336 | be treated as though they were included in this License, to the extent
337 | that they are valid under applicable law. If additional permissions
338 | apply only to part of the Program, that part may be used separately
339 | under those permissions, but the entire Program remains governed by
340 | this License without regard to the additional permissions.
341 |
342 | When you convey a copy of a covered work, you may at your option
343 | remove any additional permissions from that copy, or from any part of
344 | it. (Additional permissions may be written to require their own
345 | removal in certain cases when you modify the work.) You may place
346 | additional permissions on material, added by you to a covered work,
347 | for which you have or can give appropriate copyright permission.
348 |
349 | Notwithstanding any other provision of this License, for material you
350 | add to a covered work, you may (if authorized by the copyright holders of
351 | that material) supplement the terms of this License with terms:
352 |
353 | a) Disclaiming warranty or limiting liability differently from the
354 | terms of sections 15 and 16 of this License; or
355 |
356 | b) Requiring preservation of specified reasonable legal notices or
357 | author attributions in that material or in the Appropriate Legal
358 | Notices displayed by works containing it; or
359 |
360 | c) Prohibiting misrepresentation of the origin of that material, or
361 | requiring that modified versions of such material be marked in
362 | reasonable ways as different from the original version; or
363 |
364 | d) Limiting the use for publicity purposes of names of licensors or
365 | authors of the material; or
366 |
367 | e) Declining to grant rights under trademark law for use of some
368 | trade names, trademarks, or service marks; or
369 |
370 | f) Requiring indemnification of licensors and authors of that
371 | material by anyone who conveys the material (or modified versions of
372 | it) with contractual assumptions of liability to the recipient, for
373 | any liability that these contractual assumptions directly impose on
374 | those licensors and authors.
375 |
376 | All other non-permissive additional terms are considered "further
377 | restrictions" within the meaning of section 10. If the Program as you
378 | received it, or any part of it, contains a notice stating that it is
379 | governed by this License along with a term that is a further
380 | restriction, you may remove that term. If a license document contains
381 | a further restriction but permits relicensing or conveying under this
382 | License, you may add to a covered work material governed by the terms
383 | of that license document, provided that the further restriction does
384 | not survive such relicensing or conveying.
385 |
386 | If you add terms to a covered work in accord with this section, you
387 | must place, in the relevant source files, a statement of the
388 | additional terms that apply to those files, or a notice indicating
389 | where to find the applicable terms.
390 |
391 | Additional terms, permissive or non-permissive, may be stated in the
392 | form of a separately written license, or stated as exceptions;
393 | the above requirements apply either way.
394 |
395 | 8. Termination.
396 |
397 | You may not propagate or modify a covered work except as expressly
398 | provided under this License. Any attempt otherwise to propagate or
399 | modify it is void, and will automatically terminate your rights under
400 | this License (including any patent licenses granted under the third
401 | paragraph of section 11).
402 |
403 | However, if you cease all violation of this License, then your
404 | license from a particular copyright holder is reinstated (a)
405 | provisionally, unless and until the copyright holder explicitly and
406 | finally terminates your license, and (b) permanently, if the copyright
407 | holder fails to notify you of the violation by some reasonable means
408 | prior to 60 days after the cessation.
409 |
410 | Moreover, your license from a particular copyright holder is
411 | reinstated permanently if the copyright holder notifies you of the
412 | violation by some reasonable means, this is the first time you have
413 | received notice of violation of this License (for any work) from that
414 | copyright holder, and you cure the violation prior to 30 days after
415 | your receipt of the notice.
416 |
417 | Termination of your rights under this section does not terminate the
418 | licenses of parties who have received copies or rights from you under
419 | this License. If your rights have been terminated and not permanently
420 | reinstated, you do not qualify to receive new licenses for the same
421 | material under section 10.
422 |
423 | 9. Acceptance Not Required for Having Copies.
424 |
425 | You are not required to accept this License in order to receive or
426 | run a copy of the Program. Ancillary propagation of a covered work
427 | occurring solely as a consequence of using peer-to-peer transmission
428 | to receive a copy likewise does not require acceptance. However,
429 | nothing other than this License grants you permission to propagate or
430 | modify any covered work. These actions infringe copyright if you do
431 | not accept this License. Therefore, by modifying or propagating a
432 | covered work, you indicate your acceptance of this License to do so.
433 |
434 | 10. Automatic Licensing of Downstream Recipients.
435 |
436 | Each time you convey a covered work, the recipient automatically
437 | receives a license from the original licensors, to run, modify and
438 | propagate that work, subject to this License. You are not responsible
439 | for enforcing compliance by third parties with this License.
440 |
441 | An "entity transaction" is a transaction transferring control of an
442 | organization, or substantially all assets of one, or subdividing an
443 | organization, or merging organizations. If propagation of a covered
444 | work results from an entity transaction, each party to that
445 | transaction who receives a copy of the work also receives whatever
446 | licenses to the work the party's predecessor in interest had or could
447 | give under the previous paragraph, plus a right to possession of the
448 | Corresponding Source of the work from the predecessor in interest, if
449 | the predecessor has it or can get it with reasonable efforts.
450 |
451 | You may not impose any further restrictions on the exercise of the
452 | rights granted or affirmed under this License. For example, you may
453 | not impose a license fee, royalty, or other charge for exercise of
454 | rights granted under this License, and you may not initiate litigation
455 | (including a cross-claim or counterclaim in a lawsuit) alleging that
456 | any patent claim is infringed by making, using, selling, offering for
457 | sale, or importing the Program or any portion of it.
458 |
459 | 11. Patents.
460 |
461 | A "contributor" is a copyright holder who authorizes use under this
462 | License of the Program or a work on which the Program is based. The
463 | work thus licensed is called the contributor's "contributor version".
464 |
465 | A contributor's "essential patent claims" are all patent claims
466 | owned or controlled by the contributor, whether already acquired or
467 | hereafter acquired, that would be infringed by some manner, permitted
468 | by this License, of making, using, or selling its contributor version,
469 | but do not include claims that would be infringed only as a
470 | consequence of further modification of the contributor version. For
471 | purposes of this definition, "control" includes the right to grant
472 | patent sublicenses in a manner consistent with the requirements of
473 | this License.
474 |
475 | Each contributor grants you a non-exclusive, worldwide, royalty-free
476 | patent license under the contributor's essential patent claims, to
477 | make, use, sell, offer for sale, import and otherwise run, modify and
478 | propagate the contents of its contributor version.
479 |
480 | In the following three paragraphs, a "patent license" is any express
481 | agreement or commitment, however denominated, not to enforce a patent
482 | (such as an express permission to practice a patent or covenant not to
483 | sue for patent infringement). To "grant" such a patent license to a
484 | party means to make such an agreement or commitment not to enforce a
485 | patent against the party.
486 |
487 | If you convey a covered work, knowingly relying on a patent license,
488 | and the Corresponding Source of the work is not available for anyone
489 | to copy, free of charge and under the terms of this License, through a
490 | publicly available network server or other readily accessible means,
491 | then you must either (1) cause the Corresponding Source to be so
492 | available, or (2) arrange to deprive yourself of the benefit of the
493 | patent license for this particular work, or (3) arrange, in a manner
494 | consistent with the requirements of this License, to extend the patent
495 | license to downstream recipients. "Knowingly relying" means you have
496 | actual knowledge that, but for the patent license, your conveying the
497 | covered work in a country, or your recipient's use of the covered work
498 | in a country, would infringe one or more identifiable patents in that
499 | country that you have reason to believe are valid.
500 |
501 | If, pursuant to or in connection with a single transaction or
502 | arrangement, you convey, or propagate by procuring conveyance of, a
503 | covered work, and grant a patent license to some of the parties
504 | receiving the covered work authorizing them to use, propagate, modify
505 | or convey a specific copy of the covered work, then the patent license
506 | you grant is automatically extended to all recipients of the covered
507 | work and works based on it.
508 |
509 | A patent license is "discriminatory" if it does not include within
510 | the scope of its coverage, prohibits the exercise of, or is
511 | conditioned on the non-exercise of one or more of the rights that are
512 | specifically granted under this License. You may not convey a covered
513 | work if you are a party to an arrangement with a third party that is
514 | in the business of distributing software, under which you make payment
515 | to the third party based on the extent of your activity of conveying
516 | the work, and under which the third party grants, to any of the
517 | parties who would receive the covered work from you, a discriminatory
518 | patent license (a) in connection with copies of the covered work
519 | conveyed by you (or copies made from those copies), or (b) primarily
520 | for and in connection with specific products or compilations that
521 | contain the covered work, unless you entered into that arrangement,
522 | or that patent license was granted, prior to 28 March 2007.
523 |
524 | Nothing in this License shall be construed as excluding or limiting
525 | any implied license or other defenses to infringement that may
526 | otherwise be available to you under applicable patent law.
527 |
528 | 12. No Surrender of Others' Freedom.
529 |
530 | If conditions are imposed on you (whether by court order, agreement or
531 | otherwise) that contradict the conditions of this License, they do not
532 | excuse you from the conditions of this License. If you cannot convey a
533 | covered work so as to satisfy simultaneously your obligations under this
534 | License and any other pertinent obligations, then as a consequence you may
535 | not convey it at all. For example, if you agree to terms that obligate you
536 | to collect a royalty for further conveying from those to whom you convey
537 | the Program, the only way you could satisfy both those terms and this
538 | License would be to refrain entirely from conveying the Program.
539 |
540 | 13. Remote Network Interaction; Use with the GNU General Public License.
541 |
542 | Notwithstanding any other provision of this License, if you modify the
543 | Program, your modified version must prominently offer all users
544 | interacting with it remotely through a computer network (if your version
545 | supports such interaction) an opportunity to receive the Corresponding
546 | Source of your version by providing access to the Corresponding Source
547 | from a network server at no charge, through some standard or customary
548 | means of facilitating copying of software. This Corresponding Source
549 | shall include the Corresponding Source for any work covered by version 3
550 | of the GNU General Public License that is incorporated pursuant to the
551 | following paragraph.
552 |
553 | Notwithstanding any other provision of this License, you have
554 | permission to link or combine any covered work with a work licensed
555 | under version 3 of the GNU General Public License into a single
556 | combined work, and to convey the resulting work. The terms of this
557 | License will continue to apply to the part which is the covered work,
558 | but the work with which it is combined will remain governed by version
559 | 3 of the GNU General Public License.
560 |
561 | 14. Revised Versions of this License.
562 |
563 | The Free Software Foundation may publish revised and/or new versions of
564 | the GNU Affero General Public License from time to time. Such new versions
565 | will be similar in spirit to the present version, but may differ in detail to
566 | address new problems or concerns.
567 |
568 | Each version is given a distinguishing version number. If the
569 | Program specifies that a certain numbered version of the GNU Affero General
570 | Public License "or any later version" applies to it, you have the
571 | option of following the terms and conditions either of that numbered
572 | version or of any later version published by the Free Software
573 | Foundation. If the Program does not specify a version number of the
574 | GNU Affero General Public License, you may choose any version ever published
575 | by the Free Software Foundation.
576 |
577 | If the Program specifies that a proxy can decide which future
578 | versions of the GNU Affero General Public License can be used, that proxy's
579 | public statement of acceptance of a version permanently authorizes you
580 | to choose that version for the Program.
581 |
582 | Later license versions may give you additional or different
583 | permissions. However, no additional obligations are imposed on any
584 | author or copyright holder as a result of your choosing to follow a
585 | later version.
586 |
587 | 15. Disclaimer of Warranty.
588 |
589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
597 |
598 | 16. Limitation of Liability.
599 |
600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
608 | SUCH DAMAGES.
609 |
610 | 17. Interpretation of Sections 15 and 16.
611 |
612 | If the disclaimer of warranty and limitation of liability provided
613 | above cannot be given local legal effect according to their terms,
614 | reviewing courts shall apply local law that most closely approximates
615 | an absolute waiver of all civil liability in connection with the
616 | Program, unless a warranty or assumption of liability accompanies a
617 | copy of the Program in return for a fee.
618 |
619 | END OF TERMS AND CONDITIONS
620 |
621 | How to Apply These Terms to Your New Programs
622 |
623 | If you develop a new program, and you want it to be of the greatest
624 | possible use to the public, the best way to achieve this is to make it
625 | free software which everyone can redistribute and change under these terms.
626 |
627 | To do so, attach the following notices to the program. It is safest
628 | to attach them to the start of each source file to most effectively
629 | state the exclusion of warranty; and each file should have at least
630 | the "copyright" line and a pointer to where the full notice is found.
631 |
632 |
633 | Copyright (C)
634 |
635 | This program is free software: you can redistribute it and/or modify
636 | it under the terms of the GNU Affero General Public License as published by
637 | the Free Software Foundation, either version 3 of the License, or
638 | (at your option) any later version.
639 |
640 | This program is distributed in the hope that it will be useful,
641 | but WITHOUT ANY WARRANTY; without even the implied warranty of
642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
643 | GNU Affero General Public License for more details.
644 |
645 | You should have received a copy of the GNU Affero General Public License
646 | along with this program. If not, see .
647 |
648 | Also add information on how to contact you by electronic and paper mail.
649 |
650 | If your software can interact with users remotely through a computer
651 | network, you should also make sure that it provides a way for users to
652 | get its source. For example, if your program is a web application, its
653 | interface could display a "Source" link that leads users to an archive
654 | of the code. There are many ways you could offer source, and different
655 | solutions will be better for different programs; see section 13 for the
656 | specific requirements.
657 |
658 | You should also get your employer (if you work as a programmer) or school,
659 | if any, to sign a "copyright disclaimer" for the program, if necessary.
660 | For more information on this, and how to apply and follow the GNU AGPL, see
661 | .
662 |
663 |
--------------------------------------------------------------------------------
/README.textile:
--------------------------------------------------------------------------------
1 | h1. codeigniter-paypal-ipn
2 |
3 | h2. Overview
4 |
5 | codeigniter-paypal-ipn is a CodeIgniter library for working with the PayPal IPN (Instant
6 | Payment Notification) service. The library acts as a listener for the PayPal IPN service
7 | and logs the orders to your database using either Doctrine or CodeIgniter active record.
8 |
9 |
10 | This library is also available for Symfony2 - please see the "symfony2-paypal-ipn":https://github.com/orderly/symfony2-paypal-ipn repo.
11 |
12 | h2. Description
13 |
14 | This library focuses on the "post-payment" workflow, i.e. the processing required once
15 | the payment has been made and PayPal has posted an Instant Payment Notification call to
16 | the IPN listener (aka your CodeIgniter IPN controller).
17 |
18 | This library handles:
19 | * Validating the IPN call
20 | * Logging the IPN call
21 | * Extracting the order and line item information from the IPN call
22 | * Interpreting PayPal's payment status
23 | * Storing the order and line item in the database
24 |
25 | Note that this library currently supports the web_accept and cart transaction types; order
26 | refunds are not currently supported.
27 |
28 | Also note that this library will not work (will return 500 Internal Server Errors) if CodeIgniter's
29 | CSRF protection feature is left enabled. However, in a future version of CodeIgniter
30 | you will be able to enable @csrf_protection@ but whitelist the IPN action - see this "pull
31 | request":https://github.com/EllisLab/CodeIgniter/pull/236 for more details.
32 |
33 | All pre-payment functionality (e.g. posting the checkout information to PayPal) and custom
34 | post-payment workflow (e.g. sending emails) is left as an exercise to the reader.
35 |
36 | h2. Dependencies
37 |
38 | There are two versions supplied: one using CodeIgniter's modified version of the Active
39 | Record Database Pattern, and one using Doctrine (tested with 1.2.3). For the second option
40 | you might find the CodeIgniter guide "Using Doctrine with CodeIgniter":http://codeigniter.com/wiki/Using_Doctrine_with_Code_Igniter/ helpful background.
41 |
42 | h2. Installation
43 |
44 | To create the MySQL tables required by codeigniter-paypal-ipn, run the SQL file found
45 | in the @common/sql@ folder against your db.
46 |
47 | Download all of the remaining files from the @common@ folder and deploy them into your CodeIgniter
48 | installation following the same folder structure as found in GitHub. Then choose between
49 | the @activerecord@ and @doctrine1.2@ folder, and deploy those files into your CodeIgniter
50 | installation as well.
51 |
52 | Please note that two different example controllers are provided: one which performs no
53 | notification following a successful order, and one which sends an order confirmation
54 | email via Smarty. Choose whichever of these example controllers fits your business requirements
55 | best, or create your own custom one (e.g. using a Twig email template instead of a Smarty one).
56 |
57 | Check that csrf_protection in your CodeIgniter is switched off (disclaimer: the author Alex Dean
58 | accepts no responsibility for issues arising from disabling csrf_protection).
59 |
60 | Finally, update your sandbox and production variables as found in @config/paypal_ipn.php@
61 |
62 | h2. Usage
63 |
64 | An example of how to use codeigniter-paypal-ipn can be found in @controllers/example.php@
65 |
66 | h2. Credits
67 |
68 | This library is inspired by:
69 | * Ran Aroussi's "PayPal_Lib for CodeIgniter":http://codeigniter.com/wiki/PayPal_Lib/ (which I used for some time before writing my own)
70 | * Peter Butler's original "PayPal IPN Controller for CakePHP":http://www.studiocanaria.com/articles/paypal_ipn_controller_for_cakephp (for giving me the initial ideas around in-database storage of the orders)
71 | * @webtechnik's "CakePHP-PayPal-IPN Plugin":https://github.com/webtechnick/CakePHP-Paypal-IPN-Plugin (for the tidy configuration settings)
72 |
73 | h2. Disclaimer and Warning
74 |
75 | The author Alex Dean does not accept any liability for any processing errors made by
76 | codeigniter-paypal-ipn, or any financial losses incurred through its use.
77 |
78 | In particular, this library does *not* fulfil the PayPal IPN requirement to _"verify that the
79 | payment amount actually matches what you intend to charge. Although not technically an IPN
80 | issue, if you do not encrypt buttons, it is possible for someone to capture the original
81 | transmission and change the price. Without this check, you could accept a lesser payment
82 | than what you expected."_ (This verification step is out of scope for this library because
83 | it would require integration with your product catalogue.)
84 |
85 | Additionally this library does *not* properly handle refunds. Typically refunds are stored as
86 | a new order line in @ipn_orders@ with a negative balance, but even this is not 100% predicatable.
87 |
88 | And finally the author accepts no liability for the recommendation to disable CodeIgniter's CSRF
89 | protection.
90 |
91 | h2. Copyright
92 |
93 | codeigniter-paypal-ipn is copyright (c) 2011 Alexander Dean, alex@keplarllp.com
94 |
95 | h2. License
96 |
97 | codeigniter-paypal-ipn is free software: you can redistribute it and/or modify it under the
98 | terms of the GNU Affero General Public License as published by the Free Software Foundation,
99 | either version 3 of the License, or (at your option) any later version.
100 |
101 | codeigniter-paypal-ipn is distributed in the hope that it will be useful, but WITHOUT ANY
102 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
103 | PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
104 |
105 | You should have received a copy of the GNU Affero General Public License along with
106 | codeigniter-paypal-ipn. If not, see "http://www.gnu.org/licenses/":http://www.gnu.org/licenses/.
107 |
108 |
109 |
--------------------------------------------------------------------------------
/activerecord/libraries/PayPal_IPN.php:
--------------------------------------------------------------------------------
1 |
57 | * @link https://github.com/orderly/codeigniter-paypal-ipn
58 | * @copyright Copyright (c) 2011 Alex Dean
59 | * @version 0.2
60 | */
61 |
62 | class PayPal_IPN
63 | {
64 | private $_ci; // CodeIgniter instance
65 |
66 | public $ipnData = array(); // Contains the POST values for IPN
67 | public $order = array(); // Contains the fields pertaining to an order
68 | public $orderItems = array(); // Contains the order items within an order
69 | public $orderStatus; // All-important variable: whether the order has been paid for yet or not
70 |
71 | // Configuration constants
72 | private $isLive; // The flag used to indicate we are operating in the live environment
73 | private $ipnURL; // The PayPal IPN URL we're using
74 | private $merchantEmail; // The merchant's email address connected to PayPal
75 |
76 | // Used for logging
77 | private $logID; // The ID of our IpnLog record
78 | private $transactionID; // The transaction ID aka txn_id (from PayPal)
79 | private $transactionType; // The type of transaction (from PayPal)
80 |
81 | // Payment status constants we use, more user-friendly than the PayPal ones
82 | const PAID = 'PAID';
83 | const WAITING = 'WAITING';
84 | const REJECTED = 'REJECTED';
85 |
86 | // Allowed order fields. No point making this static as PHP arrays can always be modified later on anyway.
87 | private $orderFields = array('notify_version', 'verify_sign', 'test_ipn', 'protection_eligibility', 'charset', 'btn_id', 'address_city', 'address_country',
88 | 'address_country_code', 'address_name', 'address_state', 'address_status', 'address_street', 'address_zip', 'first_name',
89 | 'last_name', 'payer_business_name', 'payer_email', 'payer_id', 'payer_status', 'contact_phone', 'residence_country',
90 | 'business', 'receiver_email', 'receiver_id', 'custom', 'invoice', 'memo', 'tax', 'auth_id', 'auth_exp', 'auth_amount', 'auth_status',
91 | 'num_cart_items', 'parent_txn_id', 'payment_date', 'payment_status', 'payment_type', 'pending_reason', 'reason_code',
92 | 'remaining_settle', 'shipping_method', 'shipping', 'transaction_entity', 'txn_id', 'txn_type', 'exchange_rate',
93 | 'mc_currency', 'mc_fee', 'mc_gross', 'mc_handling', 'mc_shipping', 'payment_fee', 'payment_gross', 'settle_amount',
94 | 'settle_currency', 'auction_buyer_id', 'auction_closing_date', 'auction_multi_item', 'for_auction', 'subscr_date',
95 | 'subscr_effective', 'period1', 'period2', 'period3', 'amount1', 'amount2', 'amount3', 'mc_amount1', 'mc_amount2',
96 | 'mc_amount3', 'recurring', 'reattempt', 'retry_at', 'recur_times', 'username', 'password', 'subscr_id', 'case_id',
97 | 'case_type', 'case_creation_date', 'order_status', 'discount', 'shipping_discount', 'ipn_track_id', 'transaction_subject');
98 |
99 | // The constructor. Loads the helpers and configuration files, sets the configuration constants
100 | function __construct()
101 | {
102 | $this->_ci =& get_instance();
103 | $this->_ci->load->config('paypal_ipn'); // The custom configuration file for this library
104 |
105 | // Configuration var
106 | $this->isLive = $this->_ci->config->item('paypal_ipn_use_live_settings');
107 |
108 | // Settings
109 | $settings = $this->_ci->config->item('paypal_ipn_' . (($this->isLive) ? "live" : "sandbox") . '_settings');
110 | $this->ipnURL = $settings['url'];
111 | $this->merchantEmail = $settings['email'];
112 | $this->debug = $settings['debug'];
113 |
114 | // We load the two models here in the constructor because they are used throughout the library
115 | $this->_ci->load->model('Ipn_log_model', 'IPNLog', TRUE);
116 | $this->_ci->load->model('Ipn_order_model', 'IPNOrder', TRUE);
117 | }
118 |
119 | // The key functionality in this library. Extracts the fields from the IPN notification and then
120 | // sends them back to PayPal to make sure that the post is not bogus.
121 | // We also carry out the following validations as per PayPal's guidelines (https://cms.paypal.com/cgi-bin/marketingweb?cmd=_render-content&content_ID=developer/e_howto_admin_IPNIntro):
122 | // - "Verify that you are the intended recipient of the IPN message by checking the email address in the message;
123 | // this handles a situation where another merchant could accidentally or intentionally attempt to use your listener."
124 | // - "Avoid duplicate IPN messages. Check that you have not already processed the transaction identified by the transaction
125 | // ID returned in the IPN message. You may need to store transaction IDs returned by IPN messages in a file or database so
126 | // that you can check for duplicates. If the transaction ID sent by PayPal is a duplicate, you should not process it again."
127 | // Actually PayPal is wrong on this last one - duplicate transaction IDs are fine, PayPal can send multiple different
128 | // messages with the same transaction ID. That's why we store the md5 instead.
129 | public function validateIPN()
130 | {
131 | // Set these all to null
132 | $this->logID = null;
133 | $this->transactionID = null;
134 | $this->transactionType = null;
135 |
136 | // First check that we have post data.
137 | $usingCache = FALSE;
138 | if (!empty($_POST))
139 | {
140 | $ipnDataRaw = $_POST;
141 |
142 | // If we're in debugging mode, then we cache this POST data in the log for potential use later
143 | if ($this->debug)
144 | {
145 | $this->_cacheIPN($ipnDataRaw);
146 | }
147 | }
148 | else
149 | {
150 | // If we're in debug mode, let's try to get the last cached IPN data instead
151 | if ($this->debug)
152 | {
153 | if ($ipnDataRaw = $this->_getCachedIPN())
154 | {
155 | $usingCache = TRUE;
156 | }
157 | else
158 | {
159 | $this->_logTransaction('IPN', 'ERROR', 'No POST data and no cached IPN data');
160 | return FALSE;
161 | }
162 | }
163 | else // Not in debug mode
164 | {
165 | $this->_logTransaction('IPN', 'ERROR', 'No POST data'); // Nulls because we don't have a transaction type or ID yet
166 | return FALSE;
167 | }
168 | }
169 |
170 | // First thing we do is to log this transaction. This way if the script silently fails, there is still a record of the IPN call.
171 | // (If the script succeeds, or another error occurs, then this error message will be overwritten).
172 | $this->_logTransaction('IPN', 'ERROR', 'Script failed silently or is still processing, detail field contains the serialized data from PayPal', serialize($ipnDataRaw));
173 |
174 | // Before doing anything else, let's clean up our post data.
175 | foreach (array_keys($ipnDataRaw) as $field)
176 | {
177 | if (!$usingCache)
178 | {
179 | $value = $this->_ci->input->post($field); // Note that CodeIgniter standardises line returns to \n
180 | // Put line feeds back to \r\n for PayPal otherwise multi-line data will be rejected as INVALID
181 | $ipnDataRaw[$field] = str_replace('\n', '\r\n', $value);
182 | }
183 |
184 | // Let's also store this in this class, turning empty strings back to null to avoid breaking Doctrine later
185 | $this->ipnData[$field] = ($ipnDataRaw[$field] == '') ? null : $ipnDataRaw[$field];
186 | }
187 |
188 | // Let's now set the transaction type and transaction ID, we'll use these for logging.
189 | $this->transactionID = isset($this->ipnData['txn_id']) ? $this->ipnData['txn_id'] : null;
190 | $this->transactionType = isset($this->ipnData['txn_type']) ? $this->ipnData['txn_type'] : null;
191 |
192 | // TODO: which txn_types do we support? Only really web_accept and cart. Sometimes refunds have null txn_type (but we don't really support refunds)
193 |
194 | // Now we need to check that we haven't received this message from PayPal before.
195 | // Luckily we store an md5 hash of each IPN dataset so we can cross-check whether this one is new.
196 | $ipnDataHash = md5(serialize($ipnDataRaw));
197 | if (!$usingCache && $this->_checkForDuplicates($ipnDataHash))
198 | {
199 | $this->_logTransaction('IPN', 'ERROR', 'This is a duplicate call: md5 hash ' . $ipnDataHash . ' already logged');
200 | return FALSE;
201 | }
202 |
203 | // Now we need to ask PayPal to tell us if it sent this notification
204 | $ipnResponse = $this->_postData($this->ipnURL, array_merge(
205 | array('cmd' => '_notify-validate'),
206 | $ipnDataRaw
207 | ));
208 | if ($ipnResponse === FALSE) // Bail out if we have an error.
209 | {
210 | return FALSE;
211 | }
212 |
213 | // Check that PayPal says that the IPN call we received is not invalid
214 | if (stristr('INVALID', $ipnResponse))
215 | {
216 | // Invalid IPN transaction. Check the log for details.
217 | $this->_logTransaction('IPN', 'ERROR', 'PayPal rejected the IPN call as invalid - potentially call was spoofed or was not checked within 30s', $ipnResponse);
218 | return FALSE;
219 | }
220 |
221 | // The IPN transaction is a genuine one - now we need to validate its contents.
222 | // First we check that the receiver email matches our email address.
223 | if ($this->ipnData['receiver_email'] != $this->merchantEmail)
224 | {
225 | $this->_logTransaction('IPN', 'ERROR', 'Receiver email ' . $this->ipnData['receiver_email'] . ' does not match merchant\'s', $ipnResponse);
226 | return FALSE;
227 | }
228 |
229 | // Now we check that PayPal and this listener agree on whether this is a test or not
230 | $testIPN = (isset($this->ipnData['test_ipn']) && $this->ipnData['test_ipn'] == 1);
231 | if ($testIPN == $this->isLive)
232 | {
233 | $this->_logTransaction('IPN', 'ERROR', 'Listener\'s environment does not match test_ipn flag ' . $this->ipnData['test_ipn'], $ipnResponse);
234 | return FALSE;
235 | }
236 |
237 | // The final check is of the payment status. We need to surface this
238 | // as a class variable so that the calling code can decide how to respond.
239 | //
240 | // PayPal has various different payment statuses' - we list them below,
241 | // but for simplicity we generalise these into three categories:
242 | // - PAID - meaning the merchant can now dispatch the order
243 | // - WAITING - wait for another update from PayPal with this transaction_id
244 | // - REJECTED - meaning that payment failed and the order should be rejected
245 | // The following page was invaluable in understanding the different PayPal payment
246 | // statuses: http://www.coderprofile.com/networks/discussion-forum/1305/paypal-help-ipn-payment_status
247 | //
248 | // We throw an error if the payment_status code is unrecognised.
249 | switch ($this->ipnData['payment_status'])
250 | {
251 | // TODO: what about 'Canceled_Reversal' status? Maybe need to work with parent_txn_id
252 | // TODO: 'Reversed' doesn't really affect the order - it's a new row which relates to a refund
253 |
254 | case 'Completed': // Order has been paid for
255 | $this->orderStatus = self::PAID;
256 | break;
257 | case 'Pending': // Payment is still waiting to go through
258 | case 'Processed': // Mostly used to indicate that a cheque has been received and is currently going through the verification process
259 | $this->orderStatus = self::WAITING;
260 | break;
261 | case 'Voided': // Bounced or cancelled check
262 | case 'Expired': // Credit card company didn't recognise card
263 | case 'Reversed': // Credit card holder has got the credit card co to reverse the charge
264 | $this->orderStatus = self::REJECTED;
265 | break;
266 | default:
267 | $this->_logTransaction('IPN', 'ERROR', 'Payment status of ' . $this->ipnData['payment_status'] . ' is not recognised', $ipnResponse);
268 | return FALSE;
269 | }
270 |
271 | // Phew! We have a valid IPN transaction, log it.
272 | $this->_logTransaction('IPN', 'SUCCESS', 'Parsing, authentication and validation complete', $ipnResponse);
273 | return true;
274 | }
275 |
276 | // Function to extract the order and order items from the $ipnData
277 | public function extractOrder()
278 | {
279 | // First extract the actual order record itself
280 | foreach ($this->ipnData as $key=>$value)
281 | {
282 | // Only add the field if it's in our whitelist.
283 | // We use a whitelist because PayPal adds new fields to the IPN system
284 | // at random/without warning, and if we don't have a whitelist then
285 | // the database insert/update will then break
286 | if (in_array($key, $this->orderFields))
287 | {
288 | $this->order[$key] = $value;
289 | }
290 | }
291 |
292 | // Let's store the payment status too
293 | $this->order['order_status'] = $this->orderStatus;
294 |
295 | // Now retrieve the line items which belong to this order
296 | $hasCart = ($this->order['txn_type'] == 'cart');
297 | $numItems = $hasCart ? (int)$this->order['num_cart_items'] : 1;
298 |
299 | // Initialise the total before a discount
300 | $totalBeforeDiscount = 0;
301 |
302 | // Loop through each order item (for non-cart there will only be one item)
303 | for ($i = 0; $i < $numItems; $i++)
304 | {
305 | // Suffixes are different depending on whether there are multiple items (a cart) or not
306 | $suffix = $hasCart ? ($i + 1) : '';
307 | $suffixUnderscore = $hasCart ? '_' . $suffix : $suffix;
308 |
309 | // Now build the order item
310 | $this->orderItems[$i] = array();
311 |
312 | // The following are always set
313 | $this->orderItems[$i]['item_name'] = $this->ipnData['item_name' . $suffix];
314 | $this->orderItems[$i]['item_number'] = $this->ipnData['item_number' . $suffix];
315 | $this->orderItems[$i]['quantity'] = $this->ipnData['quantity' . $suffix];
316 | $this->orderItems[$i]['mc_gross'] = $this->ipnData['mc_gross' . $suffixUnderscore]; // Note the trailing underscore. PayPal oddity
317 | $this->orderItems[$i]['cost_per_item'] = floatval($this->ipnData['mc_gross' . $suffixUnderscore]) / intval($this->ipnData['quantity' . $suffix]); // Should be fine because quantity can never be 0
318 |
319 | // Update the total before the discount was applied
320 | $totalBeforeDiscount += $this->orderItems[$i]['mc_gross'];
321 |
322 | // The following are not always set on each item, so need to be careful
323 | $this->orderItems[$i]['mc_handling'] = isset($this->ipnData['mc_handling' . $suffix]) ? $this->ipnData['mc_handling' . $suffix] : null;
324 | $this->orderItems[$i]['mc_shipping'] = isset($this->ipnData['mc_shipping' . $suffix]) ? $this->ipnData['mc_shipping' . $suffix] : null;
325 | $this->orderItems[$i]['tax'] = isset($this->ipnData['tax' . $suffix]) ? $this->ipnData['tax' . $suffix] : null;
326 |
327 | // Set the order item options if any
328 | // $count = 7 because PayPal allows you to set a maximum of 7 options per item
329 | // Reference: https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_html_Appx_websitestandard_htmlvariables
330 | for ($ii = 1, $count = 7; $ii < $count; $ii++)
331 | {
332 | $this->orderItems[$i]['option_name_'.$ii] = isset($this->ipnData['option_name'.$ii.'_'.$suffix]) ? $this->ipnData['option_name'.$ii.'_'.$suffix] : null;
333 | $this->orderItems[$i]['option_selection_'.$ii] = isset($this->ipnData['option_selection'.$ii.'_'.$suffix]) ? $this->ipnData['option_selection'.$ii.'_'.$suffix] : null;
334 | }
335 | }
336 |
337 | // And calculate the discount, as it's useful to add this into emails etc
338 | $this->order['discount'] = $totalBeforeDiscount - $this->order['mc_gross'];
339 | }
340 |
341 | // Ugly function to deal with the fact that a lot of people don't have curl or similar setup.
342 | // If you do have curl setup in PHP, and @philsturgeon's cURL library for CodeIgniter installed,
343 | // you can replace the contents of this function with:
344 | // $this->_ci->load->library('curl');
345 | // $response = $this->_ci->curl->simple_post($url, $postData);
346 | // // Error logging
347 | // return $response;
348 | function _postData($url, $postData)
349 | {
350 | // Put the postData into a string
351 | $postString = '';
352 | foreach ($postData as $field=>$value)
353 | {
354 | $postString .= $field . '=' . urlencode(stripslashes($value)) . '&'; // Trailing & at end of post string is forgivable
355 | }
356 |
357 | $parsedURL = parse_url($url);
358 |
359 | // fsockopen is a bit odd - it just takes the host without the scheme - unless you want to use
360 | // ssl, in which case you need to use ssl://, not http://
361 | $ipnURL = ($parsedURL['scheme'] == "https") ? "ssl://" . $parsedURL['host'] : $parsedURL['host'];
362 | // Likewise, if using ssl, then need to change port from 80 to 443
363 | $ipnPort = ($parsedURL['scheme'] == "https") ? 443 : 80;
364 | $fp = fsockopen($ipnURL, $ipnPort, $errorNumber, $errorString, 30);
365 |
366 | // Log and return if we have an error
367 | if (!$fp)
368 | {
369 | $this->_logTransaction("IPN", "ERROR", "fsockopen error number $errorNumber: $errorString connecting to " . $parsedURL['host'] . " on port " . $ipnPort);
370 | return FALSE;
371 | }
372 |
373 | fputs($fp, "POST $parsedURL[path] HTTP/1.1\r\n");
374 | fputs($fp, "Host: $parsedURL[host]\r\n");
375 | fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
376 | fputs($fp, "Content-length: " . strlen($postString) . "\r\n");
377 | fputs($fp, "Connection: close\r\n\r\n");
378 | fputs($fp, $postString . "\r\n\r\n");
379 |
380 | $response = '';
381 | while (!feof($fp))
382 | {
383 | $response .= fgets($fp, 1024);
384 | }
385 | fclose($fp); // Close connection
386 |
387 | if (strlen($response) == 0)
388 | {
389 | $this->_logTransaction("IPN", "ERROR", "Response from PayPal was empty");
390 | return FALSE;
391 | }
392 |
393 | return $response;
394 | }
395 |
396 | /* Code below this point is all ORM-specific. In this version, it uses the standard CodeIgniter ActiveRecord pattern */
397 |
398 | // Save an IPN record (insert/update depending on if there is an existing row or not)
399 | // CI ActiveRecord version
400 | function _cacheIPN($ipnDataRaw)
401 | {
402 | // Save the cache
403 | $this->_ci->IPNLog->saveCache($ipnDataRaw);
404 | }
405 |
406 | // Retrieve the cached IPN record if there is one, false if there isn't
407 | // CI ActiveRecord version
408 | function _getCachedIPN()
409 | {
410 | // Save the cache
411 | if (!($cache = $this->_ci->IPNLog->getCache()))
412 | {
413 | return FALSE;
414 | }
415 | else
416 | {
417 | return unserialize($cache->detail);
418 | }
419 | }
420 |
421 | // Check for a duplicate IPN call using the md5 hash
422 | // CI ActiveRecord version
423 | function _checkForDuplicates($hash)
424 | {
425 | // Return the IPN record if we can find one
426 | return $this->_ci->IPNLog->getOneByHash($hash);
427 | }
428 |
429 | // Function to persist the order and the order items to the database.
430 | // Note is that an order may already exist in the system, and this IPN
431 | // call is just to update the record - e.g. changing its payment status.
432 | // CI ActiveRecord version
433 | public function saveOrder()
434 | {
435 | // Save the order
436 | $this->_ci->IPNOrder->saveOrder($this->order, $this->orderItems, $this->ipnData['txn_id']);
437 | }
438 |
439 | // The transaction logger. Currently tracks:
440 | // - Successful and failed calls by the PayPal IPN
441 | // - Successful and failed calls by one or more third-party APIs
442 | // - (In sandbox mode) Caches the last transaction fields so we can run the IPN script directly
443 | // CI ActiveRecord version
444 | function _logTransaction($listenerName, $transactionStatus, $transactionMessage, $ipnResponse = null)
445 | {
446 | // Populate the IPN log record
447 | $ipnLog = array();
448 | $ipnLog['listener_name'] = $listenerName;
449 | $ipnLog['transaction_type'] = $this->transactionType;
450 | $ipnLog['transaction_id'] = $this->transactionID;
451 | $ipnLog['status'] = $transactionStatus;
452 | $ipnLog['message'] = $transactionMessage;
453 | $ipnLog['ipn_data_hash'] = md5(serialize($this->ipnData));
454 |
455 | // We also log the ipnResponse and the ipnData if we have an error and/or are in the sandbox (test) environment.
456 | if ($transactionStatus == 'ERROR' || !$this->isLive)
457 | {
458 | $detailJSON = array();
459 | $detailJSON['ipn_data'] = $this->ipnData;
460 | $detailJSON['ipn_response'] = $ipnResponse;
461 | $ipnLog['detail'] = json_encode($detailJSON);
462 | } else {
463 | $ipnLog['detail'] = null; // Turn it back to null (as it might have been set previously)
464 | }
465 |
466 | // Finally save down the log record.
467 | $insertID = $this->_ci->IPNLog->saveLog($ipnLog, $this->logID);
468 |
469 | // Save the log ID for next time if we need to
470 | if (!is_null($insertID))
471 | {
472 | $this->logID = $insertID;
473 | }
474 | }
475 | }
--------------------------------------------------------------------------------
/activerecord/models/ipn_log_model.php:
--------------------------------------------------------------------------------
1 | .
24 | */
25 |
26 | class Ipn_log_model extends CI_Model
27 | {
28 | // Holds the query for the cache
29 | private $cacheQuery = array();
30 |
31 | // Table name is a constant
32 | const LOG_TABLE = 'ipn_log';
33 |
34 | // Standard constructor
35 | function __construct()
36 | {
37 | parent::__construct();
38 |
39 | // Define once how we access the cache record
40 | $this->cacheQuery = array('listener_name' => 'IPN',
41 | 'transaction_type' => 'cache');
42 | }
43 |
44 | // Retrieve the IPN cache row from the IPN log (if there is one)
45 | function getCache()
46 | {
47 | $query = $this->db->get_where(self::LOG_TABLE, $this->cacheQuery);
48 | return $query->row();
49 | }
50 |
51 | // Retrieve an IPN log record as identified by its IPN data hash
52 | function getOneByHash($hash)
53 | {
54 | $query = $this->db->get_where(self::LOG_TABLE, array('ipn_data_hash' => $hash));
55 | return $query->row();
56 | }
57 |
58 | // Store the IPN cache row in the IPN log (updating the existing cache record if there is one)
59 | function saveCache($ipnDataRaw)
60 | {
61 | // Define the cache record to populate
62 | $cacheRecord = $this->cacheQuery;
63 | $cacheRecord['detail'] = serialize($ipnDataRaw);
64 |
65 | // Now run the insert/update
66 | $this->_upsert($cacheRecord, $this->cacheQuery);
67 | }
68 |
69 | // Store a row in the IPN log
70 | function saveLog($logRecord, $logID)
71 | {
72 | // Define the query to determine whether to update or insert
73 | $logQuery = (is_null($logID)) ? null : array('id' => $logID);
74 |
75 | // Now run the insert/update, returning the ID
76 | return $this->_upsert($logRecord, $logQuery);
77 | }
78 |
79 | // Helper function to insert or update depending on whether the relevant row exists already
80 | function _upsert($record, $query = null)
81 | {
82 | // Check if the record exists already, using the supplied query
83 | $exists = FALSE;
84 | if (!is_null($query))
85 | {
86 | $existingRecord = $this->db->get_where(self::LOG_TABLE, $query, 1, 0);
87 | if ($existingRecord->num_rows() > 0)
88 | {
89 | $exists = TRUE;
90 | }
91 | }
92 |
93 | // Set the update/insert date
94 | $upsertTime = date('Y-m-d H:i:s');
95 | $record['updated_at'] = $upsertTime; // All inserts/updates set the updated_at time
96 |
97 | // If it exists, then update
98 | $retVal = null;
99 | if ($exists)
100 | {
101 | $this->db->update(self::LOG_TABLE, $record, $query);
102 | }
103 | // Otherwise let's insert
104 | else
105 | {
106 | $record['created_at'] = $upsertTime; // All inserts need a created_at time too
107 | $this->db->insert(self::LOG_TABLE, $record);
108 | $retVal = $this->db->insert_id();
109 | }
110 |
111 | return $retVal; // Return the ID for an insert or null for an update
112 | }
113 | }
--------------------------------------------------------------------------------
/activerecord/models/ipn_order_model.php:
--------------------------------------------------------------------------------
1 | .
24 | */
25 |
26 | class Ipn_order_model extends CI_Model
27 | {
28 | // Define the order and order items table names
29 | const ORDER_TABLE = 'ipn_orders';
30 | const ORDER_ITEM_TABLE = 'ipn_order_items';
31 |
32 | // Standard constructor
33 | function __construct()
34 | {
35 | parent::__construct();
36 | }
37 |
38 | // Save the order, performing an insert or update as appropriate
39 | function saveOrder($order, $orderItems, $transactionID)
40 | {
41 | // Define the transaction query once
42 | $orderQuery = array('txn_id' => $transactionID);
43 |
44 | // Check the transaction ID to see if the order needs an insert or update
45 | $existingOrder = $this->db->get_where(self::ORDER_TABLE, $orderQuery, 1, 0);
46 |
47 | // Set the update/insert date
48 | $upsertTime = date('Y-m-d H:i:s');
49 | $order['updated_at'] = $upsertTime; // All inserts/updates set the updated_at time
50 |
51 | // If it exists, get the ID and do an update
52 | if ($existingOrder->num_rows() > 0)
53 | {
54 | $orderID = $existingOrder->row()->id; // Grab the ID
55 | $this->db->update(self::ORDER_TABLE, $order, $orderQuery); // Do the update
56 | }
57 | // Else do an insert and then get the ID
58 | else
59 | {
60 | $order['created_at'] = $upsertTime; // A new order needs a created_at time too
61 | $this->db->insert(self::ORDER_TABLE, $order);
62 | $orderID = $this->db->insert_id();
63 | }
64 |
65 | // Now let's save the order's line items
66 | foreach ($orderItems as $item)
67 | {
68 | // Define the order item query
69 | $orderItemQuery = array(
70 | 'item_name' => $item['item_name'],
71 | 'item_number' => $item['item_number'],
72 | 'order_id' => $orderID
73 | );
74 |
75 | // Add the order ID and datestamp into the item to update/insert
76 | $item['order_id'] = $orderID;
77 | $item['updated_at'] = $upsertTime;
78 |
79 | // Now try to retrieve the order item
80 | $existingOrderItem = $this->db->get_where(self::ORDER_ITEM_TABLE, $orderItemQuery, 1, 0);
81 |
82 | // If the order item exists, update
83 | if ($existingOrderItem->num_rows() > 0)
84 | {
85 | $this->db->update(self::ORDER_ITEM_TABLE, $item, $orderItemQuery);
86 | }
87 | // Else insert the order item
88 | else
89 | {
90 | $item['created_at'] = $upsertTime; // Insert needs a created_at time as well
91 | $this->db->insert(self::ORDER_ITEM_TABLE, $item);
92 | }
93 | }
94 | }
95 | }
--------------------------------------------------------------------------------
/common/config/paypal_ipn.php:
--------------------------------------------------------------------------------
1 | .
24 | */
25 |
26 | // Set this to TRUE or FALSE
27 | $config['paypal_ipn_use_live_settings'] = FALSE;
28 |
29 | // Constants for the live environment
30 | $config['paypal_ipn_live_settings'] = array(
31 | 'email' => 'sales@CHANGEME.com', // Your merchant email address
32 | 'url' => 'https://www.paypal.com/cgi-bin/webscr', // PayPal's IPN handler for validating the data
33 | 'debug' => FALSE // Whether we want debugging enabled (see below for explanation...)
34 | );
35 | // Debugging simply caches the latest PayPal IPN post data into the database, and retrieves it if
36 | // validateIPN is called without post data. This is useful for directly trying a validateIPN call from
37 | // the controller.
38 |
39 | // Constants for the sandbox environment
40 | $config['paypal_ipn_sandbox_settings'] = array(
41 | 'email' => 'system_CHANGEME_biz@CHANGEME.com',
42 | 'url' => 'https://www.sandbox.paypal.com/cgi-bin/webscr',
43 | 'debug' => TRUE
44 | );
45 |
46 | /* End of file paypal_ipn.php */
47 | /* Location: ./system/application/config/paypal_ipn.php */
48 |
--------------------------------------------------------------------------------
/common/controllers/example-no-notification.php:
--------------------------------------------------------------------------------
1 | .
22 | */
23 |
24 | class ExampleNoNotification extends Controller {
25 |
26 | // To handle the IPN post made by PayPal (uses the Paypal_Lib library).
27 | function ipn()
28 | {
29 | $this->load->library('PayPal_IPN'); // Load the library
30 |
31 | // Try to get the IPN data.
32 | if ($this->paypal_ipn->validateIPN())
33 | {
34 | // Succeeded, now let's extract the order
35 | $this->paypal_ipn->extractOrder();
36 |
37 | // And we save the order now (persist and extract are separate because you might only want to persist the order in certain circumstances).
38 | $this->paypal_ipn->saveOrder();
39 |
40 | // Now let's check what the payment status is and act accordingly
41 | if ($this->paypal_ipn->orderStatus == PayPal_IPN::PAID)
42 | {
43 | /* HEALTH WARNING:
44 | *
45 | * Please note that this PAID block does nothing. In other words, this controller will not respond to a successful order
46 | * with any notification such as email or similar. You will have to identify paid orders by checking your database.
47 | *
48 | * If you want to send email notifications on successful receipt of an order, please see the alternative, Smarty template-
49 | * based example controller: example-smarty-email-notification.php
50 | */
51 | }
52 | }
53 | else // Just redirect to the root URL
54 | {
55 | $this->load->helper('url');
56 | redirect('/', 'refresh');
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/common/controllers/example-smarty-notification-email.php:
--------------------------------------------------------------------------------
1 | .
23 | */
24 |
25 | class ExampleSmartyEmailNotification extends Controller {
26 |
27 | // To handle the IPN post made by PayPal (uses the Paypal_Lib library).
28 | function ipn()
29 | {
30 | $this->load->library('PayPal_IPN'); // Load the library
31 |
32 | // Try to get the IPN data.
33 | if ($this->paypal_ipn->validateIPN())
34 | {
35 | // Succeeded, now let's extract the order
36 | $this->paypal_ipn->extractOrder();
37 |
38 | // And we save the order now (persist and extract are separate because you might only want to persist the order in certain circumstances).
39 | $this->paypal_ipn->saveOrder();
40 |
41 | // Now let's check what the payment status is and act accordingly
42 | if ($this->paypal_ipn->orderStatus == PayPal_IPN::PAID)
43 | {
44 | /* HEATH WARNING:
45 | *
46 | * You'll have to create your own email template using Smarty, Twig or similar for this to work.
47 | * If you do not have this, then the code below will cause your Paypal IPN responses to fail
48 | * with 500 errors without your knowledge.
49 | */
50 |
51 | // Configure to send HTML emails.
52 | $this->load->library('email');
53 | $mail_config['mailtype'] = 'html';
54 | $this->email->initialize($mail_config);
55 |
56 | // Prepare the variables to populate the email template:
57 | $data = $this->paypal_ipn->order;
58 | $data['items'] = $this->paypal_ipn->orderItems;
59 |
60 | // Now construct the email
61 | $emailBody = $this->smarty->view('confirmation_email.tpl', $data, TRUE); // You'll have to create your own email template using Smarty, Twig or similar
62 |
63 | // Finish configuring email contents and send.
64 | $this->email->to($data['payer_email'], ($data['first_name'] . ' ' . $data['last_name']));
65 | $this->email->bcc('sales@CHANGEME.com');
66 | $this->email->from('support@CHANGEME.com', 'CHANGEME');
67 | $this->email->subject('Order confirmation');
68 | $this->email->message($emailBody);
69 | $this->email->send();
70 | }
71 | }
72 | else // Just redirect to the root URL
73 | {
74 | $this->load->helper('url');
75 | redirect('/', 'refresh');
76 | }
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/common/sql/create_mysql_tables.sql:
--------------------------------------------------------------------------------
1 | /**
2 | * create_mysql_tables.sql is a MySQL script to drop and re-create the three tables which
3 | * codeigniter-paypal-ipn depends on:
4 | * - ipn_log tracks all interactions with PayPal's IPN service
5 | * - ipn_orders is used to record each order
6 | * - ipn_order_items records the line items which belong to each order
7 | *
8 | * This file is copyright (c) 2011 Alexander Dean, github@keplarllp.com
9 | *
10 | * This file is part of codeigniter-paypal-ipn
11 | *
12 | * codeigniter-paypal-ipn is free software: you can redistribute it and/or modify it under the
13 | * terms of the GNU Affero General Public License as published by the Free Software Foundation,
14 | * either version 3 of the License, or (at your option) any later version.
15 | *
16 | * codeigniter-paypal-ipn is distributed in the hope that it will be useful, but WITHOUT ANY
17 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
18 | * PURPOSE. See the GNU Affero General Public License for more details.
19 | *
20 | * You should have received a copy of the GNU Affero General Public License along with
21 | * codeigniter-paypal-ipn. If not, see .
22 | */
23 |
24 | DROP TABLE IF EXISTS `ipn_log`;
25 |
26 | CREATE TABLE `ipn_log` (
27 | `id` INT NOT NULL AUTO_INCREMENT,
28 | listener_name varchar(3) default NULL COMMENT 'Either IPN or API',
29 | transaction_type varchar(16) default NULL COMMENT 'The type of call being made to the listener',
30 | transaction_id varchar(19) default NULL COMMENT 'The unique transaction ID generated by PayPal',
31 | status varchar(16) default NULL COMMENT 'The status of the call',
32 | message varchar(512) default NULL COMMENT 'Explanation of the call status',
33 | ipn_data_hash varchar(32) default NULL COMMENT 'MD5 hash of the IPN post data',
34 | detail text default NULL COMMENT 'Detail text (potentially JSON) on this call',
35 | created_at DATETIME NOT NULL,
36 | updated_at DATETIME NOT NULL,
37 | PRIMARY KEY (id)
38 | ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
39 |
40 | DROP TABLE IF EXISTS `ipn_orders`;
41 |
42 | CREATE TABLE `ipn_orders` (
43 | `id` INT NOT NULL AUTO_INCREMENT,
44 | notify_version varchar(64) default NULL COMMENT 'IPN Version Number',
45 | verify_sign varchar(127) default NULL COMMENT 'Encrypted string used to verify the authenticityof the tansaction',
46 | test_ipn int(11) default NULL,
47 | protection_eligibility varchar(24) default NULL COMMENT 'Which type of seller protection the buyer is protected by',
48 | charset varchar(127) default NULL COMMENT 'Character set used by PayPal',
49 | btn_id varchar(40) default NULL COMMENT 'The PayPal buy button clicked',
50 | address_city varchar(40) default NULL COMMENT 'City of customers address',
51 | address_country varchar(64) default NULL COMMENT 'Country of customers address',
52 | address_country_code varchar(2) default NULL COMMENT 'Two character ISO 3166 country code',
53 | address_name varchar(128) default NULL COMMENT 'Name used with address (included when customer provides a Gift address)',
54 | address_state varchar(40) default NULL COMMENT 'State of customer address',
55 | address_status varchar(20) default NULL COMMENT 'confirmed/unconfirmed',
56 | address_street varchar(200) default NULL COMMENT 'Customer''s street address',
57 | address_zip varchar(20) default NULL COMMENT 'Zip code of customer''s address',
58 | first_name varchar(64) default NULL COMMENT 'Customer''s first name',
59 | last_name varchar(64) default NULL COMMENT 'Customer''s last name',
60 | payer_business_name varchar(127) default NULL COMMENT 'Customer''s company name, if customer represents a business',
61 | payer_email varchar(127) default NULL COMMENT 'Customer''s primary email address. Use this email to provide any credits',
62 | payer_id varchar(13) default NULL COMMENT 'Unique customer ID.',
63 | payer_status varchar(20) default NULL COMMENT 'verified/unverified',
64 | contact_phone varchar(20) default NULL COMMENT 'Customer''s telephone number.',
65 | residence_country varchar(2) default NULL COMMENT 'Two-Character ISO 3166 country code',
66 | business varchar(127) default NULL COMMENT 'Email address or account ID of the payment recipient (that is, the merchant). Equivalent to the values of receiver_email (If payment is sent to primary account) and business set in the Website Payment HTML.',
67 | receiver_email varchar(127) default NULL COMMENT 'Primary email address of the payment recipient (that is, the merchant). If the payment is sent to a non-primary email address on your PayPal account, the receiver_email is still your primary email.',
68 | receiver_id varchar(13) default NULL COMMENT 'Unique account ID of the payment recipient (i.e., the merchant). This is the same as the recipients referral ID.',
69 | custom varchar(255) default NULL COMMENT 'Custom value as passed by you, the merchant. These are pass-through variables that are never presented to your customer.',
70 | invoice varchar(127) default NULL COMMENT 'Pass through variable you can use to identify your invoice number for this purchase. If omitted, no variable is passed back.',
71 | memo varchar(255) default NULL COMMENT 'Memo as entered by your customer in PayPal Website Payments note field.',
72 | tax decimal(10,2) default NULL COMMENT 'Amount of tax charged on payment',
73 | auth_id varchar(19) default NULL COMMENT 'Authorization identification number',
74 | auth_exp varchar(28) default NULL COMMENT 'Authorization expiration date and time, in the following format: HH:MM:SS DD Mmm YY, YYYY PST',
75 | auth_amount int(11) default NULL COMMENT 'Authorization amount',
76 | auth_status varchar(20) default NULL COMMENT 'Status of authorization',
77 | num_cart_items int(11) default NULL COMMENT 'If this is a PayPal shopping cart transaction, number of items in the cart',
78 | parent_txn_id varchar(19) default NULL COMMENT 'In the case of a refund, reversal, or cancelled reversal, this variable contains the txn_id of the original transaction, while txn_id contains a new ID for the new transaction.',
79 | payment_date varchar(28) default NULL COMMENT 'Time/date stamp generated by PayPal, in the following format: HH:MM:SS DD Mmm YY, YYYY PST',
80 | payment_status varchar(20) default NULL COMMENT 'Payment status of the payment',
81 | payment_type varchar(10) default NULL COMMENT 'echeck/instant',
82 | pending_reason varchar(20) default NULL COMMENT 'This variable is only set if payment_status=pending',
83 | reason_code varchar(20) default NULL COMMENT 'This variable is only set if payment_status=reversed',
84 | remaining_settle int(11) default NULL COMMENT 'Remaining amount that can be captured with Authorization and Capture',
85 | shipping_method varchar(64) default NULL COMMENT 'The name of a shipping method from the shipping calculations section of the merchants account profile. The buyer selected the named shipping method for this transaction',
86 | shipping decimal(10,2) default NULL COMMENT 'Shipping charges associated with this transaction. Format unsigned, no currency symbol, two decimal places',
87 | transaction_entity varchar(20) default NULL COMMENT 'Authorization and capture transaction entity',
88 | txn_id varchar(19) default NULL COMMENT 'A unique transaction ID generated by PayPal',
89 | txn_type varchar(20) default NULL COMMENT 'cart/express_checkout/send-money/virtual-terminal/web-accept',
90 | exchange_rate decimal(10,2) default NULL COMMENT 'Exchange rate used if a currency conversion occured',
91 | mc_currency varchar(3) default NULL COMMENT 'Three character country code. For payment IPN notifications, this is the currency of the payment, for non-payment subscription IPN notifications, this is the currency of the subscription.',
92 | mc_fee decimal(10,2) default NULL COMMENT 'Transaction fee associated with the payment, mc_gross minus mc_fee equals the amount deposited into the receiver_email account. Equivalent to payment_fee for USD payments. If this amount is negative, it signifies a refund or reversal, and either ofthose p',
93 | mc_gross decimal(10,2) default NULL COMMENT 'Full amount of the customer''s payment',
94 | mc_handling decimal(10,2) default NULL COMMENT 'Total handling charge associated with the transaction',
95 | mc_shipping decimal(10,2) default NULL COMMENT 'Total shipping amount associated with the transaction',
96 | payment_fee decimal(10,2) default NULL COMMENT 'USD transaction fee associated with the payment',
97 | payment_gross decimal(10,2) default NULL COMMENT 'Full USD amount of the customers payment transaction, before payment_fee is subtracted',
98 | settle_amount decimal(10,2) default NULL COMMENT 'Amount that is deposited into the account''s primary balance after a currency conversion',
99 | settle_currency varchar(3) default NULL COMMENT 'Currency of settle amount. Three digit currency code',
100 | auction_buyer_id varchar(64) default NULL COMMENT 'The customer''s auction ID.',
101 | auction_closing_date varchar(28) default NULL COMMENT 'The auction''s close date. In the format: HH:MM:SS DD Mmm YY, YYYY PSD',
102 | auction_multi_item int(11) default NULL COMMENT 'The number of items purchased in multi-item auction payments',
103 | for_auction varchar(10) default NULL COMMENT 'This is an auction payment - payments made using Pay for eBay Items or Smart Logos - as well as send money/money request payments with the type eBay items or Auction Goods(non-eBay)',
104 | subscr_date varchar(28) default NULL COMMENT 'Start date or cancellation date depending on whether txn_type is subcr_signup or subscr_cancel',
105 | subscr_effective varchar(28) default NULL COMMENT 'Date when a subscription modification becomes effective',
106 | period1 varchar(10) default NULL COMMENT '(Optional) Trial subscription interval in days, weeks, months, years (example a 4 day interval is 4 D',
107 | period2 varchar(10) default NULL COMMENT '(Optional) Trial period',
108 | period3 varchar(10) default NULL COMMENT 'Regular subscription interval in days, weeks, months, years',
109 | amount1 decimal(10,2) default NULL COMMENT 'Amount of payment for Trial period 1 for USD',
110 | amount2 decimal(10,2) default NULL COMMENT 'Amount of payment for Trial period 2 for USD',
111 | amount3 decimal(10,2) default NULL COMMENT 'Amount of payment for regular subscription period 1 for USD',
112 | mc_amount1 decimal(10,2) default NULL COMMENT 'Amount of payment for trial period 1 regardless of currency',
113 | mc_amount2 decimal(10,2) default NULL COMMENT 'Amount of payment for trial period 2 regardless of currency',
114 | mc_amount3 decimal(10,2) default NULL COMMENT 'Amount of payment for regular subscription period regardless of currency',
115 | recurring varchar(1) default NULL COMMENT 'Indicates whether rate recurs (1 is yes, blank is no)',
116 | reattempt varchar(1) default NULL COMMENT 'Indicates whether reattempts should occur on payment failure (1 is yes, blank is no)',
117 | retry_at varchar(28) default NULL COMMENT 'Date PayPal will retry a failed subscription payment',
118 | recur_times int(11) default NULL COMMENT 'The number of payment installations that will occur at the regular rate',
119 | username varchar(64) default NULL COMMENT '(Optional) Username generated by PayPal and given to subscriber to access the subscription',
120 | password varchar(24) default NULL COMMENT '(Optional) Password generated by PayPal and given to subscriber to access the subscription (Encrypted)',
121 | subscr_id varchar(19) default NULL COMMENT 'ID generated by PayPal for the subscriber',
122 | case_id varchar(28) default NULL COMMENT 'Case identification number',
123 | case_type varchar(28) default NULL COMMENT 'complaint/chargeback',
124 | case_creation_date varchar(28) default NULL COMMENT 'Date/Time the case was registered',
125 | order_status enum('PAID', 'WAITING', 'REJECTED') NULL COMMENT 'Additional variable to make payment_status more actionable',
126 | discount decimal(10,2) default NULL COMMENT 'Additional variable to record the discount made on the order',
127 | shipping_discount decimal(10,2) default NULL COMMENT 'Record the discount made on the shipping',
128 | ipn_track_id varchar(127) default NULL COMMENT 'Internal tracking variable added in April 2011',
129 | transaction_subject varchar(255) default NULL COMMENT 'Describes the product for a button-based purchase',
130 | created_at DATETIME NOT NULL,
131 | updated_at DATETIME NOT NULL,
132 | PRIMARY KEY (id),
133 | CONSTRAINT UniqueTransactionID UNIQUE (`txn_id`)
134 | ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
135 |
136 | DROP TABLE IF EXISTS `ipn_order_items`;
137 |
138 | CREATE TABLE `ipn_order_items` (
139 | `id` INT NOT NULL AUTO_INCREMENT,
140 | `order_id` INT NULL,
141 | item_name varchar(127) default NULL COMMENT 'Item name as passed by you, the merchant. Or, if not passed by you, as entered by your customer. If this is a shopping cart transaction, Paypal will append the number of the item (e.g., item_name_1,item_name_2, and so forth).',
142 | item_number varchar(127) default NULL COMMENT 'Pass-through variable for you to track purchases. It will get passed back to you at the completion of the payment. If omitted, no variable will be passed back to you.',
143 | quantity varchar(127) default NULL COMMENT 'Quantity as entered by your customer or as passed by you, the merchant. If this is a shopping cart transaction, PayPal appends the number of the item (e.g., quantity1,quantity2).',
144 | mc_gross decimal(10,2) default NULL COMMENT 'Full amount of the customer''s payment',
145 | mc_handling decimal(10,2) default NULL COMMENT 'Total handling charge associated with the transaction',
146 | mc_shipping decimal(10,2) default NULL COMMENT 'Total shipping amount associated with the transaction',
147 | tax decimal(10,2) default NULL COMMENT 'Amount of tax charged on payment',
148 | cost_per_item decimal(10,2) default NULL COMMENT 'Cost of an individual item',
149 | option_name_1 varchar(64) default NULL COMMENT 'Option 1 name as requested by you',
150 | option_selection_1 varchar(200) default NULL COMMENT 'Option 1 choice as entered by your customer',
151 | option_name_2 varchar(64) default NULL COMMENT 'Option 2 name as requested by you',
152 | option_selection_2 varchar(200) default NULL COMMENT 'Option 2 choice as entered by your customer',
153 | option_name_3 varchar(64) default NULL COMMENT 'Option 3 name as requested by you',
154 | option_selection_3 varchar(200) default NULL COMMENT 'Option 3 choice as entered by your customer',
155 | option_name_4 varchar(64) default NULL COMMENT 'Option 4 name as requested by you',
156 | option_selection_4 varchar(200) default NULL COMMENT 'Option 4 choice as entered by your customer',
157 | option_name_5 varchar(64) default NULL COMMENT 'Option 5 name as requested by you',
158 | option_selection_5 varchar(200) default NULL COMMENT 'Option 5 choice as entered by your customer',
159 | option_name_6 varchar(64) default NULL COMMENT 'Option 6 name as requested by you',
160 | option_selection_6 varchar(200) default NULL COMMENT 'Option 6 choice as entered by your customer',
161 | option_name_7 varchar(64) default NULL COMMENT 'Option 7 name as requested by you',
162 | option_selection_7 varchar(200) default NULL COMMENT 'Option 7 choice as entered by your customer',
163 | created_at DATETIME NOT NULL,
164 | updated_at DATETIME NOT NULL,
165 | PRIMARY KEY (id),
166 | FOREIGN KEY (`order_id`) REFERENCES ipn_orders(`id`)
167 | ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
168 |
--------------------------------------------------------------------------------
/common/views/templates/confirmation_email.tpl:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
Thank you for your CHANGEME purchase
11 |
This is a confirmation email. Your order has been received and will be dispatched within CHANGEME business day.