Hack Forums
[PHP] Paypal auto-purchase example using the paypal IPN - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Web Development (https://hackforums.net/forumdisplay.php?fid=183)
+---- Thread: [PHP] Paypal auto-purchase example using the paypal IPN (/showthread.php?tid=5717501)



Paypal auto-purchase example using the paypal IPN - d4ne - Sep 14, 2017

Deleted not usefull. Deleted not usefull. Deleted not usefull.

[warn]


* - Ceanko - Sep 14, 2017

From a functional standpoint I strongly discourage using this library. There are many better systems already built. Reinventing the wheel for an extremely simple PayPal IPN that doesn't even support payment management (token -> API), etc.
Furthermore, I don't see any easy flexibility with your library, which could be a huge point for using it.

Here's the recommendation:
  • If you're going to release a library for an API, don't "hardcode" the results. An "event" closure based system should work much better,
    for the release, your system is based on providing easy-to-use automatic product payment, and management; a whole register/login system isn't required.
Good luck in the future though, good start overall.

Here's an example usage of a library I've made in the past:
PHP Code

<?php 
    
/**
     * Manage PayPal IPN requests.
     *
     * @return \Illuminate\Http\Response 
     */
    
public function ipn(Request $request) {
        
$IPN = new PayPalIPN();
        
$listener = &$IPN->setListener(file_get_contents('php://input'));

        
$listener->onVerified(function (Event $event) {
            
//Request has been verified by PayPal.
            
$data = $event->getData();
        });

        
$listener->onInvalid(function (Event $event) {
            
//Request was invalid or forged.
        
});

        
//Trigger verification.
        
$verified = $IPN->verify();

        return 
response('', 200);
    } 

Edit: looking through some more of the code I'd like to add that your styling is horrible; learn the language.


* - d4ne - Sep 14, 2017

(Sep 14, 2017 03:18 PM)Ceanko Wrote:  From a functional standpoint I strongly discourage using this library. There are many better systems already built. Reinventing the wheel for an extremely simple PayPal IPN that doesn't even support payment management (token -> API), etc.
Furthermore, I don't see any easy flexibility with your library, which could be a huge point for using it.

Here's the recommendation:
  • If you're going to release a library for an API, don't "hardcode" the results. An "event" closure based system should work much better,
    for the release, your system is based on providing easy-to-use automatic product payment, and management; a whole register/login system isn't required.
Good luck in the future though, good start overall.

Here's an example usage of a library I've made in the past:
PHP Code

<?php 
    
/**
     * Manage PayPal IPN requests.
     *
     * @return \Illuminate\Http\Response 
     */
    
public function ipn(Request $request) {
        
$IPN = new PayPalIPN();
        
$listener = &$IPN->setListener(file_get_contents('php://input'));

        
$listener->onVerified(function (Event $event) {
            
//Request has been verified by PayPal.
            
$data = $event->getData();
        });

        
$listener->onInvalid(function (Event $event) {
            
//Request was invalid or forged.
        
});

        
//Trigger verification.
        
$verified = $IPN->verify();

        return 
response('', 200);
    } 

Edit: looking through some more of the code I'd like to add that your styling is horrible; learn the language.

No I won't release anything. It's a simple example which was coded in an hour to show people a example since it was posted often here lately.


* - Pim Fortuyn - Sep 19, 2017

Why don't you use the proper paypal lib to create payments instead of doing what you're doing with the html buttons. Also you're not checking if the payment value is even correct in the IPN. People can edit the price with f12 and pay 1 cents and still receive the product.


* - Eagle 95 - Sep 21, 2017

Do not edit out the content of your threads.

Warned and post suspended for a week.