paypal integration

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
nga
Forum Commoner
Posts: 46
Joined: Mon Aug 17, 2009 3:05 am

paypal integration

Post by nga »

hello, sorry for posting paypal integration question here. It's php related and paypal forum doesnt have high response rate....

So i want to create a buy now button where i can send userID as a hidden field to paypal and receive it back from paypal IPN (so my code know who made the payment and update my database acordingly immediately after the payment went through without human interference). I'm thinking of populateing userID as an hidden field inside paypal form as a hidden field. However, what hidden field should be used to hold this information so it would come back to me inside paypal IPN message?
pbs
Forum Contributor
Posts: 230
Joined: Fri Nov 07, 2008 5:31 am
Location: Nashik, India
Contact:

Re: paypal integration

Post by pbs »

You can use on0, on1 optional variables to send the values or follow this link

https://cms.paypal.com/us/cgi-bin/?&cmd ... lvariables


Also you can use session to store userid
nga
Forum Commoner
Posts: 46
Joined: Mon Aug 17, 2009 3:05 am

Re: paypal integration

Post by nga »

session variable cant be passed to IPN... I looked into the link you posted, it doesnt say which fields will be posted back to me in IPN... the on1 and on0 will be presented to user which i dont want to happens. Just quitely inside hidden field is good enough
nga
Forum Commoner
Posts: 46
Joined: Mon Aug 17, 2009 3:05 am

Re: paypal integration

Post by nga »

I need the userID in the IPN to update my transaction table accordingly (update if user purchased successfully)
User avatar
kaisellgren
DevNet Resident
Posts: 1675
Joined: Sat Jan 07, 2006 5:52 am
Location: Lahti, Finland.

Re: paypal integration

Post by kaisellgren »

IIRC

Code: Select all

<input type="hidden" name="custom" value="someone@who.pays" />
should do fine.
ramblin54321
Forum Commoner
Posts: 32
Joined: Wed Nov 18, 2009 5:31 am

Re: paypal integration

Post by ramblin54321 »

Hi,
I've tried a whole bunch of different shopping carts and now I have Opencart and Plaincart. The IPN test from the Paypal Sandbox gives a 403 forbidden error even after changing the permissions to 777. Does anyone know how to fix this? I can get a payment to go through but no notifications back.
User avatar
kaisellgren
DevNet Resident
Posts: 1675
Joined: Sat Jan 07, 2006 5:52 am
Location: Lahti, Finland.

Re: paypal integration

Post by kaisellgren »

Does the IPN notification script ever fire up? If it does not, then Paypal IPN bot may not be able to access the file and thus 403 permission denied occurs. Can you access the IPN notification file yourself? I think you can't because the bot doesn't really differ from any other web clients apart from sending different user agents.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: paypal integration

Post by pickle »

Moved to Miscellaneous
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
ramblin54321
Forum Commoner
Posts: 32
Joined: Wed Nov 18, 2009 5:31 am

Re: paypal integration

Post by ramblin54321 »

When you say IPN notification script, is this the file you are talking about? If so, it is in a directory called catalog/payment/pp.standard.php and I can access it in the file manager.

Code: Select all

<?php
class ControllerPaymentPPStandard extends Controller {
    protected function index() {
        $this->data['button_confirm'] = $this->language->get('button_confirm');
        $this->data['button_back'] = $this->language->get('button_back');
 
        if (!$this->config->get('pp_standard_test')) {
            $this->data['action'] = 'https://www.paypal.com/cgi-bin/webscr';
        } else {
            $this->data['action'] = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
        }       
        
        $this->load->model('checkout/order');
        
        $order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
        
        $this->data['business'] = $this->config->get('pp_standard_email');
        $this->data['item_name'] = html_entity_decode($this->config->get('config_store'), ENT_QUOTES, 'UTF-8');             
        $this->data['currency_code'] = $order_info['currency'];
        $this->data['amount'] = $this->currency->format($order_info['total'], $order_info['currency'], $order_info['value'], FALSE);
        $this->data['first_name'] = html_entity_decode($order_info['payment_firstname'], ENT_QUOTES, 'UTF-8');  
        $this->data['last_name'] = html_entity_decode($order_info['payment_lastname'], ENT_QUOTES, 'UTF-8');    
        $this->data['address1'] = html_entity_decode($order_info['payment_address_1'], ENT_QUOTES, 'UTF-8');    
        $this->data['address2'] = html_entity_decode($order_info['payment_address_2'], ENT_QUOTES, 'UTF-8');    
        $this->data['city'] = html_entity_decode($order_info['payment_city'], ENT_QUOTES, 'UTF-8'); 
        $this->data['zip'] = html_entity_decode($order_info['payment_postcode'], ENT_QUOTES, 'UTF-8');  
        $this->data['country'] = $order_info['payment_iso_code_2'];
        $this->data['notify_url'] = $this->url->http('payment/pp_standard/callback');
        $this->data['email'] = $order_info['email'];
        $this->data['invoice'] = $this->session->data['order_id'] . ' - ' . html_entity_decode($order_info['payment_firstname'], ENT_QUOTES, 'UTF-8') . ' ' . html_entity_decode($order_info['payment_lastname'], ENT_QUOTES, 'UTF-8');
        $this->data['lc'] = $this->language->getCode();
        
        if (!$this->config->get('pp_standard_transaction')) {
            $this->data['paymentaction'] = 'authorization';
        } else {
            $this->data['paymentaction'] = 'sale';
        }
        
        $this->data['return'] = $this->url->https('checkout/success');
        
        if ($this->request->get['route'] != 'checkout/guest/confirm') {
            $this->data['cancel_return'] = $this->url->https('checkout/payment');
        } else {
            $this->data['cancel_return'] = $this->url->https('checkout/guest');
        }
        
        $this->load->library('encryption');
        
        $encryption = new Encryption($this->config->get('config_encryption'));
        
        $this->data['custom'] = $encryption->encrypt($this->session->data['order_id']);
        
        if ($this->request->get['route'] != 'checkout/guest/confirm') {
            $this->data['back'] = $this->url->https('checkout/payment');
        } else {
            $this->data['back'] = $this->url->https('checkout/guest');
        }
        
        $this->id = 'payment';
 
        if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/pp_standard.tpl')) {
            $this->template = $this->config->get('config_template') . '/template/payment/pp_standard.tpl';
        } else {
            $this->template = 'default/template/payment/pp_standard.tpl';
        }   
        
        $this->render();    
    }
    
    public function callback() {
        $this->load->library('encryption');
    
        $encryption = new Encryption($this->config->get('config_encryption'));
        
        if (isset($this->request->post['custom'])) {
            $order_id = $encryption->decrypt($this->request->post['custom']);
        } else {
            $order_id = 0;
        }
 
        $this->load->model('checkout/order');
                
        $order_info = $this->model_checkout_order->getOrder($order_id);
        
        if ($order_info) {
            $request = 'cmd=_notify-validate';
        
            foreach ($this->request->post as $key => $value) {
                $request .= '&' . $key . '=' . urlencode(stripslashes(html_entity_decode($value, ENT_QUOTES, 'UTF-8')));
            }
                
            if (extension_loaded('curl')) {
                if (!$this->config->get('pp_standard_test')) {
                    $ch = curl_init('https://www.paypal.com/cgi-bin/webscr');
                } else {
                    $ch = curl_init('https://www.sandbox.paypal.com/cgi-bin/webscr');
                }
 
                curl_setopt($ch, CURLOPT_POST, true);
                curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                curl_setopt($ch, CURLOPT_HEADER, false);
                curl_setopt($ch, CURLOPT_TIMEOUT, 30);
                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        
                $response = curl_exec($ch);
            
                if (strcmp($response, 'VERIFIED') == 0 || $this->request->post['payment_status'] == 'Completed') {
                    $this->model_checkout_order->confirm($order_id, $this->config->get('pp_standard_order_status_id'));
                }
                    
                curl_close($ch);
            } else {
                $header  = 'POST /cgi-bin/webscr HTTP/1.0' . "\r\n";
                $header .= 'Content-Type: application/x-www-form-urlencoded' . "\r\n";
                $header .= 'Content-Length: ' . strlen(utf8_decode($request)) . "\r\n";
                $header .= 'Connection: close'  ."\r\n\r\n";
                
                if (!$this->config->get('pp_standard_test')) {
                    $fp = fsockopen('www.paypal.com', 80, $errno, $errstr, 30);
                } else {
                    $fp = fsockopen('www.sandbox.paypal.com', 80, $errno, $errstr, 30);
                }
            
                if ($fp) {
                    fputs($fp, $header . $request);
                
                    while (!feof($fp)) {
                        $response = fgets($fp, 1024);
                    
                        if (strcmp($response, 'VERIFIED') == 0 || $this->request->post['payment_status'] == 'Completed') {
                            $this->model_checkout_order->confirm($order_id, $this->config->get('pp_standard_order_status_id'));
                        }
                    }
                
                    fclose($fp);
                }
            }
        }
    }
}
?>
User avatar
kaisellgren
DevNet Resident
Posts: 1675
Joined: Sat Jan 07, 2006 5:52 am
Location: Lahti, Finland.

Re: paypal integration

Post by kaisellgren »

That file just defines a class. It won't do anything. You need PayPal to call a script that will actually do something (handle the payment).
Post Reply