/var/www/hkosl.com/nick/codeigniter/application/libraries/paypal/Paypal_payflow.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 
/**
 *     Angell EYE PayPal PayFlow CodeIgniter Library
 *    An open source PHP library written to easily work with PayPal's PayFlow API's
 *
 *  Copyright © 2014  Andrew K. Angell
 *    Email:  andrew@angelleye.com
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>
 *
 * @package            Angell_EYE_PayPal_PayFlow_Class_Library
 * @author            Andrew K. Angell
 * @copyright        Copyright © 2014 Angell EYE, LLC
 * @link            http://www.angelleye.com
 * @since            Version 2.42
 * @updated            01.19.2014
 * @filesource
 */

require_once('Paypal_pro.php');
class 
PayPal_PayFlow extends PayPal_Pro
{
    
/**
     * Constructor
     *
     * @access    public
     * @param    array    config preferences
     * @return    void
     */
    
function __construct($DataArray)
    {
        
parent::__construct($DataArray);
    
        
$this->APIVendor = isset($DataArray['APIVendor']) ? $DataArray['APIVendor'] : '';
        
$this->APIPartner = isset($DataArray['APIPartner']) ? $DataArray['APIPartner'] : '';
        
$this->Verbosity = isset($DataArray['Verbosity']) ? $DataArray['Verbosity'] : 'HIGH';
    
        if(
$this->Sandbox)
        {
            
$this->APIEndPoint 'https://pilot-payflowpro.paypal.com';
        }
        else
        {
            
$this->APIEndPoint 'https://payflowpro.paypal.com';
        }
    
        
$this->NVPCredentials 'BUTTONSOURCE['.strlen($this->APIButtonSource).']='.$this->APIButtonSource.'&VERBOSITY['.strlen($this->Verbosity).']='.$this->Verbosity.'&USER['.strlen($this->APIUsername).']='.$this->APIUsername.'&VENDOR['.strlen($this->APIVendor).']='.$this->APIVendor.'&PARTNER['.strlen($this->APIPartner).']='.$this->APIPartner.'&PWD['.strlen($this->APIPassword).']='.$this->APIPassword;
    
        
$this->TransactionStateCodes = array(
                
'1' => 'Error',
                
'6' => 'Settlement Pending',
                
'7' => 'Settlement in Progress',
                
'8' => 'Settlement Completed Successfully',
                
'11' => 'Settlement Failed',
                
'14' => 'Settlement Incomplete'
        
);
    }
    
    
/*
     * GetTransactionStateCodeMessage
    *
    * @access public
    * @param number
    * @return string
    */
    
function GetTransactionStateCodeMessage($Code)
    {
        return 
$this -> TransactionStateCodes[$Code];
    }
    
    
/*
     * CURLRequest
    *
    * @access public
    * @param string Request
    * @return string
    */
    
function CURLRequest($Request ""$APIName ""$APIOperation "")
    {
    
        
$unique_id date('ymd-H').rand(1000,9999);
    
        
$headers[] = "Content-Type: text/namevalue"//or text/xml if using XMLPay.
        
$headers[] = "Content-Length : " strlen ($Request);  // Length of data to be passed
        
$headers[] = "X-VPS-Timeout: 45";
        
$headers[] = "X-VPS-Request-ID:" $unique_id;
    
        
$curl curl_init();
        
curl_setopt($curlCURLOPT_HTTPHEADER$headers);
        
curl_setopt($curlCURLOPT_HEADER1);
        
curl_setopt($curlCURLOPT_VERBOSE1);
        
curl_setopt($curlCURLOPT_FOLLOWLOCATION0);
        
curl_setopt($curlCURLOPT_SSL_VERIFYHOST2);
        
curl_setopt($curlCURLOPT_SSL_VERIFYPEERFALSE);
        
curl_setopt($curlCURLOPT_FORBID_REUSEtrue);
        
curl_setopt($curlCURLOPT_TIMEOUT90);
        
curl_setopt($curlCURLOPT_URL$this->APIEndPoint);
        
curl_setopt($curlCURLOPT_RETURNTRANSFER1);
        
curl_setopt($curlCURLOPT_POST1);
        
curl_setopt($curlCURLOPT_POSTFIELDS$Request);
    
        
// Try to submit the transaction up to 3 times with 5 second delay.  This can be used
        // in case of network issues.  The idea here is since you are posting via HTTPS there
        // could be general network issues, so try a few times before you tell customer there
        // is an issue.
        
$i=1;
        while (
$i++ <= 3)
        {
            
$Response curl_exec($curl);
            
$headers curl_getinfo($curl);
    
            if (
$headers['http_code'] != 200) {
                
sleep(5);  // Let's wait 5 seconds to see if its a temporary network issue.
            
}
            else if (
$headers['http_code'] == 200)
            {
                
// we got a good response, drop out of loop.
                
break;
            }
        }
    
        
curl_close($curl);
    
        return 
$Response;
    }
    
    
    
/**
     * Convert an NVP string to an array with URL decoded values
     *
     * @access    public
     * @param    string    NVP string
     * @return    array
     */
    
function NVPToArray($NVPString)
    {
        
$proArray = array();
        
parse_str($NVPString,$proArray);
        return 
$proArray;
    }
    
    
/*
     * ProcessTransaction
    *
    * @access public
    * @param array request parameters
    * @return array
    */
    
function ProcessTransaction($DataArray)
    {
        
$NVPRequest $this->NVPCredentials;
    
        foreach(
$DataArray as $DataArrayVar => $DataArrayVal)
        {
            if(
$DataArrayVal != '')
            {
                
$NVPRequest .= '&'.strtoupper($DataArrayVar).'['.strlen($DataArrayVal).']='.$DataArrayVal;
            }
        }
    
        
$NVPResponse $this->CURLRequest($NVPRequest);
        
$NVPResponse strstr($NVPResponse,"RESULT");
        
$NVPResponseArray $this->NVPToArray($NVPResponse);
    
        
$NVPResponseArray['RAWREQUEST'] = $NVPRequest;
        
$NVPResponseArray['RAWRESPONSE'] = $NVPResponse;
    
        return 
$NVPResponseArray;
    }
}