PageRenderTime 66ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/phpPayPal.php

https://github.com/cmarkell/phpPayPal
PHP | 2319 lines | 1622 code | 301 blank | 396 comment | 71 complexity | 145fdb527f4c2286ab6ac1503de3f225 MD5 | raw file
  1. <?php
  2. /*
  3. Created by Drew Johnston, 2007, drewjoh.com
  4. Please give credit where credit is due. :)
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. Get, Create and Update Recurring Payment Profiles available thanks to Bill Joslin (billjoslin.com)!
  15. */
  16. class phpPayPal {
  17. // ---------------------------
  18. // PRIVATE VARIABLES
  19. // ---------------------------
  20. // NOTE: LIVE and SANDBOX variables are included. Sandbox is enabled by default.
  21. private $sandbox = TRUE;
  22. private $live = FALSE;
  23. public $API_USERNAME = NULL;
  24. public $API_PASSWORD = NULL;
  25. public $API_SIGNATURE = NULL;
  26. private $API_ENDPOINT = NULL;
  27. public $USE_PROXY = NULL;
  28. public $PROXY_HOST = NULL;
  29. public $PROXY_PORT = NULL;
  30. private $PAYPAL_URL = NULL;
  31. public $return_url = NULL;
  32. public $cancel_url = NULL;
  33. public $VERSION = '3.0';
  34. // ----------------------------
  35. // PUBLIC VARIABLES
  36. // ----------------------------
  37. // Array of the response variables from PayPal requests
  38. public $Response;
  39. /* -------------------
  40. ERROR VARIABLES
  41. -------------------
  42. - $Error = an array of PayPal's response to any paypal errors
  43. - All $_error's = are filled for any error that occurs, including PayPal errors
  44. - If a method returns false, the $_error's should be filled with error information
  45. */
  46. // Array of the error response from PayPal - [TIMESTAMP] [CORRELATIONID] [ACK] [L_ERRORCODE0] [L_SHORTMESSAGE0] [L_LONGMESSAGE0] [L_SEVERITYCODE0] [VERSION] [BUILD]
  47. public $Error;
  48. public $_error = false;
  49. public $_error_ack;
  50. public $_error_type;
  51. public $_error_date;
  52. public $_error_code;
  53. public $_error_short_message;
  54. public $_error_long_message;
  55. public $_error_corrective_action;
  56. public $_error_severity_code;
  57. public $_error_version;
  58. public $_error_build;
  59. public $_error_display_message;
  60. /* ----------------------
  61. REQUEST VARIABLES
  62. ----------------------
  63. - All values found in a Request
  64. - Format is $our_variable_name; // PAYPALS_VARIABLE_NAME
  65. */
  66. public $payment_type = 'Sale'; // PAYMENTTYPE
  67. public $email; // EMAIL
  68. public $salutation; // SALUTATION
  69. public $first_name; // FIRSTNAME
  70. public $middle_name; // MIDDLENAME
  71. public $last_name; // LASTNAME
  72. public $suffix; // SUFFIX
  73. public $credit_card_type; // CREDITCARDTYPE --- Visa, MasterCard, Discover, Amex, Switch, Solo
  74. public $credit_card_number; // ACCT
  75. public $expire_date; // EXPDATE - MMYYYY
  76. public $cvv2_code; // CVV2
  77. public $address1; // STREET
  78. public $address2; // STREET2
  79. public $city; // CITY
  80. public $state; // STATE
  81. public $postal_code; // ZIP
  82. public $phone_number; // PHONENUM
  83. public $country_code; // COUNTRYCODE
  84. public $currency_code = "USD"; // CURRENCYCODE
  85. public $ip_address; //IPADDRESS
  86. public $amount_total; // AMT
  87. public $amount_shipping; // SHIPPINGAMT
  88. public $amount_handling; // HANDLINGAMT
  89. public $amount_tax; // TAXAMT
  90. public $amount_sales_tax; // SALESTAX - This is apparently only used with getTransactionDetails, and appears to be the same as amount_tax
  91. public $amount_items; // ITEMAMT
  92. public $amount_max; // MAXAMT
  93. public $amount_fee; // FEEAMT
  94. public $amount_settle; // SETTLEAMT
  95. public $amount_refund_net; // NETREFUNDAMT
  96. public $amount_refund_fee; // FEEREFUNDAMT
  97. public $amount_refund_total; // GROSSREFUNDAMT
  98. public $billing_type;
  99. public $billing_agreement;
  100. public $shipping_name; // SHIPTONAME
  101. public $shipping_address1; // SHIPTOSTREET
  102. public $shipping_address2; // SHIPTOSTREET2
  103. public $shipping_city; // SHIPTOCITY
  104. public $shipping_state; // SHIPTOSTATE
  105. public $shipping_postal_code; // SHIPTOZIP
  106. public $shipping_country_code; // SHIPTOCOUNTRYCODE
  107. public $shipping_country_name;
  108. public $shipping_phone_number; // SHIPTOPHONENUM
  109. public $description; // DESC
  110. public $custom; // CUSTOM
  111. public $invoice_number; // INVNUM
  112. public $note; // NOTE
  113. public $notify_url; // NOTIFYURL
  114. public $require_confirmed_shipping_address; // REQCONFIRMSHIPPING
  115. public $no_shipping; // NOSHIPPING
  116. public $address_override; // ADDROVERRIDE
  117. public $local_code; // LOCALECODE
  118. public $page_style; // PAGESTYLE
  119. public $hdr_image; // HDRIMG
  120. public $hdr_border_color; //HDRBORDERCOLOR
  121. public $hdr_back_color; // HDRBACKCOLOR
  122. public $payflow_color; // PAYFLOWCOLOR
  123. public $channel_type; // CHANNELTYPE
  124. public $solution_type; // SOLUTIONTYPE
  125. public $user_action; // USERACTION
  126. public $return_fmf_details = 0; // RETURNFMFDETAILS - 0 by default
  127. // Variables found in Authorize and Capture
  128. public $authorization_id; // AUTHORIZATIONID
  129. public $complete_type; // COMPLETETYPE
  130. public $soft_descriptor; // SOFTDESCRIPTOR
  131. public $transaction_entity; // TRANSACTIONENTITY
  132. // Variables that are returned to us
  133. public $ack;
  134. public $token; // TOKEN
  135. public $payer_id; // PAYERID
  136. public $payer_status; // PAYERSTATUS
  137. public $payer_business; // PAYERBUSINESS
  138. public $address_owner; // ADDRESSOWNER
  139. public $address_status; // ADDRESSSTATUS
  140. public $address_id;
  141. public $business; // BUSINESS
  142. public $avs_code;
  143. public $cvv2_match;
  144. public $transaction_id; // TRANSACTIONID
  145. public $parent_transaction_id; // PARENTTRANSACTIONID
  146. public $refund_transaction_id; // REFUNDTRANSACTIONID
  147. public $transaction_type; // TRANSACTIONTYPE
  148. public $payment_status; // PAYMENTSTATUS
  149. public $payment_pending_reason; // PENDINGREASON
  150. public $payment_reason_code; // REASONCODE
  151. public $order_time; // ORDERTIME
  152. public $timestamp;
  153. public $exchange_rate; // EXCHANGERATE
  154. public $receipt_id; // RECEIPTID
  155. public $receiver_business; // RECEIVERBUSINESS
  156. public $receiver_email; // RECEIVEREMAIL
  157. public $receiver_id; // RECEIVERID
  158. public $subscription_id; // SUBSCRIPTIONID
  159. public $subscription_date; // SUBSCRIPTIONDATE
  160. public $effective_date; // EFFECTIVEDATE
  161. public $retry_time; // RETRYTIME
  162. public $user_name; // USERNAME
  163. public $password; // PASSWORD
  164. public $recurrences; // RECURRENCES
  165. public $reattempt; // REATTEMPT
  166. public $recurring; // RECURRING
  167. public $period; // PERIOD
  168. public $buyer_id; // BUYERID
  169. public $closing_date; // CLOSINGDATE
  170. public $multi_item; // MULTIITEM
  171. public $refund_type; // REFUNDTYPE
  172. // Other
  173. public $build;
  174. public $version;
  175. public $correlation_id;
  176. /*
  177. This is the Items array, contains KEY => VALUE pairs for NAME => VALUE of items where NAME = name of item variable
  178. Names include: name, number, quantity, amount_tax, amount_total
  179. */
  180. public $ItemsArray;
  181. /* -----------------------
  182. COUNTRY NAMES & CODES
  183. -----------------------
  184. - This is an array of country names and their country codes
  185. - Organized in CODE => NAME format ($countries[COUNTRY_CODE] = COUNTRY_NAME)
  186. - This is purely for informational purposes, the class itself doesn't use these.
  187. - PayPal does use the country CODES when sending address information; can come in very handy then.
  188. - List should include all countries that PayPal accepts payments from.
  189. */
  190. public $countries = array ("US"=>"United States","AL"=>"Albania","DZ"=>"Algeria","AS"=>"American Samoa","AD"=>"Andorra","AI"=>"Anguilla","AG"=>"Antigua and Barbuda","AR"=>"Argentina","AM"=>"Armenia","AW"=>"Aruba","AU"=>"Australia","AT"=>"Austria","AZ"=>"Azerbaijan Republic","BS"=>"Bahamas","BH"=>"Bahrain","BD"=>"Bangladesh","BB"=>"Barbados","BY"=>"Belarus","BE"=>"Belgium","BZ"=>"Belize","BJ"=>"Benin","BM"=>"Bermuda","BO"=>"Bolivia","BA"=>"Bosnia and Herzegovina","BW"=>"Botswana","BR"=>"Brazil","VG"=>"British Virgin Islands","BN"=>"Brunei","BG"=>"Bulgaria","BF"=>"Burkina Faso","KH"=>"Cambodia","CM"=>"Cameroon","CA"=>"Canada","CV"=>"Cape Verde","KY"=>"Cayman Islands","CL"=>"Chile","C2"=>"China","CO"=>"Colombia","CK"=>"Cook Islands","CR"=>"Costa Rica","CI"=>"Cote D'Ivoire","HR"=>"Croatia","CY"=>"Cyprus","CZ"=>"Czech Republic","DK"=>"Denmark","DJ"=>"Djibouti","DM"=>"Dominica","DO"=>"Dominican Republic","TP"=>"East Timor","EC"=>"Ecuador","EG"=>"Egypt","SV"=>"El Salvador","EE"=>"Estonia","FM"=>"Federated States of Micronesia","FJ"=>"Fiji","FI"=>"Finland","FR"=>"France","GF"=>"French Guiana","PF"=>"French Polynesia","GA"=>"Gabon Republic","GE"=>"Georgia","DE"=>"Germany","GH"=>"Ghana","GI"=>"Gibraltar","GR"=>"Greece","GD"=>"Grenada","GP"=>"Guadeloupe","GU"=>"Guam","GT"=>"Guatemala","GN"=>"Guinea","GY"=>"Guyana","HT"=>"Haiti","HN"=>"Honduras","HK"=>"Hong Kong","HU"=>"Hungary","IS"=>"Iceland","IN"=>"India","ID"=>"Indonesia","IE"=>"Ireland","IL"=>"Israel","IT"=>"Italy","JM"=>"Jamaica","JP"=>"Japan","JO"=>"Jordan","KZ"=>"Kazakhstan","KE"=>"Kenya","KW"=>"Kuwait","LA"=>"Laos","LV"=>"Latvia","LB"=>"Lebanon","LS"=>"Lesotho","LT"=>"Lithuania","LU"=>"Luxembourg","MO"=>"Macau","MK"=>"Macedonia","MG"=>"Madagascar","MY"=>"Malaysia","MV"=>"Maldives","ML"=>"Mali","MT"=>"Malta","MH"=>"Marshall Islands","MQ"=>"Martinique","MU"=>"Mauritius","MX"=>"Mexico","MD"=>"Moldova","MN"=>"Mongolia","MS"=>"Montserrat","MA"=>"Morocco","MZ"=>"Mozambique","NA"=>"Namibia","NP"=>"Nepal","NL"=>"Netherlands","AN"=>"Netherlands Antilles","NZ"=>"New Zealand","NI"=>"Nicaragua","MP"=>"Northern Mariana Islands","NO"=>"Norway","OM"=>"Oman","PK"=>"Pakistan","PW"=>"Palau","PS"=>"Palestine","PA"=>"Panama","PG"=>"Papua New Guinea","PY"=>"Paraguay","PE"=>"Peru","PH"=>"Philippines","PL"=>"Poland","PT"=>"Portugal","PR"=>"Puerto Rico","QA"=>"Qatar","RO"=>"Romania","RU"=>"Russia","RW"=>"Rwanda","VC"=>"Saint Vincent and the Grenadines","WS"=>"Samoa","SA"=>"Saudi Arabia","SN"=>"Senegal","CS"=>"Serbia and Montenegro","SC"=>"Seychelles","SG"=>"Singapore","SK"=>"Slovakia","SI"=>"Slovenia","SB"=>"Solomon Islands","ZA"=>"South Africa","KR"=>"South Korea","ES"=>"Spain","LK"=>"Sri Lanka","KN"=>"St. Kitts and Nevis","LC"=>"St. Lucia","SZ"=>"Swaziland","SE"=>"Sweden","CH"=>"Switzerland","TW"=>"Taiwan","TZ"=>"Tanzania","TH"=>"Thailand","TG"=>"Togo","TO"=>"Tonga","TT"=>"Trinidad and Tobago","TN"=>"Tunisia","TR"=>"Turkey","TM"=>"Turkmenistan","TC"=>"Turks and Caicos Islands","UG"=>"Uganda","UA"=>"Ukraine","AE"=>"United Arab Emirates","GB"=>"United Kingdom","UY"=>"Uruguay","UZ"=>"Uzbekistan","VU"=>"Vanuatu","VE"=>"Venezuela","VN"=>"Vietnam","VI"=>"Virgin Islands (USA)","YE"=>"Yemen","ZM"=>"Zambia");
  191. /* --------------------
  192. STATES
  193. --------------------
  194. - States for certain countries, many of these are required formats for PayPal
  195. - Multidimensional array
  196. - $states[COUNTRY_CODE][STATE_CODE] = STATE_NAME
  197. */
  198. public $states = array(
  199. 'US' => array ("AK"=>"AK","AL"=>"AL","AR"=>"AR","AZ"=>"AZ","CA"=>"CA","CO"=>"CO","CT"=>"CT","DC"=>"DC","DE"=>"DE","FL"=>"FL","GA"=>"GA","HI"=>"HI",
  200. "IA"=>"IA","ID"=>"ID","IL"=>"IL","IN"=>"IN","KS"=>"KS","KY"=>"KY","LA"=>"LA","MA"=>"MA","MD"=>"MD","ME"=>"ME","MI"=>"MI","MN"=>"MN",
  201. "MO"=>"MO","MS"=>"MS","MT"=>"MT","NC"=>"NC","ND"=>"ND","NE"=>"NE","NH"=>"NH","NJ"=>"NJ","NM"=>"NM","NV"=>"NV","NY"=>"NY","OH"=>"OH",
  202. "OK"=>"OK","OR"=>"OR","PA"=>"PA","RI"=>"RI","SC"=>"SC","SD"=>"SD","TN"=>"TN","TX"=>"TX","UT"=>"UT","VA"=>"VA","VT"=>"VT","WA"=>"WA",
  203. "WI"=>"WI","WV"=>"WV","WY"=>"WY","AA"=>"AA","AE"=>"AE","AP"=>"AP","AS"=>"AS","FM"=>"FM","GU"=>"GU","MH"=>"MH","MP"=>"MP","PR"=>"PR",
  204. "PW"=>"PW","VI"=>"VI")
  205. ,
  206. 'CA' => array ("AB"=>"Alberta", "BC"=>"British Columbia", "MB"=>"Manitoba", "NB"=>"New Brunswick", "NL"=>"Newfoundland", "NS"=>"Nova Scotia",
  207. "NU"=>"Nunavut", "NT"=>"Northwest Territories", "ON"=>"Ontario", "PE"=>"Prince Edward Island", "QC"=>"Quebec", "SK"=>"Saskatchewan",
  208. "YT"=>"Yukon")
  209. ,
  210. 'AU' => array ("Australian Capital Territory"=>"Australian Capital Territory","New South Wales"=>"New South Wales","Northern Territory"=>"Northern Territory",
  211. "Queensland"=>"Queensland","South Australia"=>"South Australia","Tasmania"=>"Tasmania","Victoria"=>"Victoria","Western Australia"=>"Western Australia")
  212. ,
  213. 'GB' => array ("Aberdeen City"=>"Aberdeen City","Aberdeenshire"=>"Aberdeenshire","Angus"=>"Angus","Antrim"=>"Antrim","Argyll and Bute"=>"Argyll and Bute",
  214. "Armagh"=>"Armagh","Avon"=>"Avon","Bedfordshire"=>"Bedfordshire","Berkshire"=>"Berkshire","Blaenau Gwent"=>"Blaenau Gwent","Borders"=>"Borders",
  215. "Bridgend"=>"Bridgend","Bristol"=>"Bristol","Buckinghamshire"=>"Buckinghamshire","Caerphilly"=>"Caerphilly","Cambridgeshire"=>"Cambridgeshire",
  216. "Cardiff"=>"Cardiff","Carmarthenshire"=>"Carmarthenshire","Ceredigion"=>"Ceredigion","Channel Islands"=>"Channel Islands","Cheshire"=>"Cheshire",
  217. "Clackmannan"=>"Clackmannan","Cleveland"=>"Cleveland","Conwy"=>"Conwy","Cornwall"=>"Cornwall","Cumbria"=>"Cumbria","Denbighshire"=>"Denbighshire",
  218. "Derbyshire"=>"Derbyshire","Devon"=>"Devon","Dorset"=>"Dorset","Down"=>"Down","Dumfries and Galloway"=>"Dumfries and Galloway","Durham"=>"Durham",
  219. "East Ayrshire"=>"East Ayrshire","East Dunbartonshire"=>"East Dunbartonshire","East Lothian"=>"East Lothian","East Renfrewshire"=>"East Renfrewshire",
  220. "East Riding of Yorkshire"=>"East Riding of Yorkshire","East Sussex"=>"East Sussex","Edinburgh City"=>"Edinburgh City","Essex"=>"Essex",
  221. "Falkirk"=>"Falkirk","Fermanagh"=>"Fermanagh","Fife"=>"Fife","Flintshire"=>"Flintshire","Glasgow"=>"Glasgow","Gloucestershire"=>"Gloucestershire",
  222. "Greater Manchester"=>"Greater Manchester","Gwynedd"=>"Gwynedd","Hampshire"=>"Hampshire","Herefordshire"=>"Herefordshire",
  223. "Hertfordshire"=>"Hertfordshire","Highland"=>"Highland","Humberside"=>"Humberside","Inverclyde"=>"Inverclyde","Isle of Anglesey"=>"Isle of Anglesey",
  224. "Isle of Man"=>"Isle of Man","Isle of Wight"=>"Isle of Wight","Isles of Scilly"=>"Isles of Scilly","Kent"=>"Kent","Lancashire"=>"Lancashire",
  225. "Leicestershire"=>"Leicestershire","Lincolnshire"=>"Lincolnshire","London"=>"London","Londonderry"=>"Londonderry","Merseyside"=>"Merseyside",
  226. "Merthyr Tydfil"=>"Merthyr Tydfil","Middlesex"=>"Middlesex","Midlothian"=>"Midlothian","Monmouthshire"=>"Monmouthshire","Moray"=>"Moray",
  227. "Neath Port Talbot"=>"Neath Port Talbot","Newport"=>"Newport","Norfolk"=>"Norfolk","North Ayrshire"=>"North Ayrshire",
  228. "North Lanarkshire"=>"North Lanarkshire","North Yorkshire"=>"North Yorkshire","Northamptonshire"=>"Northamptonshire","Northumberland"=>"Northumberland",
  229. "Nottinghamshire"=>"Nottinghamshire","Orkney"=>"Orkney","Oxfordshire"=>"Oxfordshire","Pembrokeshire"=>"Pembrokeshire",
  230. "Perthshire and Kinross"=>"Perthshire and Kinross","Powys"=>"Powys","Renfrewshire"=>"Renfrewshire","Rhondda Cynon Taff"=>"Rhondda Cynon Taff",
  231. "Rutland"=>"Rutland","Shetland"=>"Shetland","Shropshire"=>"Shropshire","Somerset"=>"Somerset","South Ayrshire"=>"South Ayrshire",
  232. "South Lanarkshire"=>"South Lanarkshire","South Yorkshire"=>"South Yorkshire","Staffordshire"=>"Staffordshire","Stirling"=>"Stirling",
  233. "Suffolk"=>"Suffolk","Surrey"=>"Surrey","Swansea"=>"Swansea","The Vale of Glamorgan"=>"The Vale of Glamorgan","Tofaen"=>"Tofaen",
  234. "Tyne and Wear"=>"Tyne and Wear","Tyrone"=>"Tyrone","Warwickshire"=>"Warwickshire","West Dunbartonshire"=>"West Dunbartonshire",
  235. "West Lothian"=>"West Lothian","West Midlands"=>"West Midlands","West Sussex"=>"West Sussex","West Yorkshire"=>"West Yorkshire",
  236. "Western Isles"=>"Western Isles","Wiltshire"=>"Wiltshire","Worcestershire"=>"Worcestershire","Wrexham"=>"Wrexham")
  237. ,
  238. 'ES' => array ("Alava" => "Alava", "Albacete" => "Albacete", "Alicante" => "Alicante", "Almeria" => "Almeria", "Asturias" => "Asturias",
  239. "Avila" => "Avila", "Badajoz" => "Badajoz", "Barcelona" => "Barcelona", "Burgos" => "Burgos", "Caceres" => "Caceres",
  240. "Cadiz" => "Cadiz", "Cantabria" => "Cantabria", "Castellon" => "Castellon", "Ceuta" => "Ceuta", "Ciudad Real" => "Ciudad Real",
  241. "Cordoba" => "Cordoba", "Cuenca" => "Cuenca", "Guadalajara" => "Guadalajara", "Gerona" => "Gerona", "Granada" => "Granada",
  242. "Guipuzcoa" => "Guipuzcoa", "Huelva" => "Huelva", "Huesca" => "Huesca", "Islas Baleares" => "Islas Baleares", "Jaen" => "Jaen",
  243. "La Coruna" => "La Coruna", "Las Palmas" => "Las Palmas", "La Rioja" => "La Rioja", "Leon" => "Leon", "Lerida" => "Lerida",
  244. "Lugo" => "Lugo", "Madrid" => "Madrid", "Malaga" => "Malaga", "Melilla" => "Melilla", "Murcia" => "Murcia", "Navarra" => "Navarra",
  245. "Orense" => "Orense", "Palencia" => "Palencia", "Pontevedra" => "Pontevedra", "Salamanca" => "Salamanca",
  246. "Santa Cruz de Tenerife" => "Santa Cruz de Tenerife", "Segovia" => "Segovia", "Sevilla" => "Sevilla", "Soria" => "Soria",
  247. "Tarragona" => "Tarragona", "Teruel" => "Teruel", "Toledo" => "Toledo", "Valencia" => "Valencia", "Valladolid" => "Valladolid",
  248. "Vizcaya" => "Vizcaya", "Zamora" => "Zamora", "Zaragoza" => "Zaragoza")
  249. );
  250. // ----------------------------
  251. // Internal Use Varibles
  252. // ----------------------------
  253. /* -----------------------------------------
  254. AVS Response Code Values and Meanings
  255. -----------------------------------------
  256. - $AvsResponseCodesArray[CODE][MESSAGE]
  257. - $AvsResponseCodesArray[CODE][DETAILS]
  258. */
  259. public $AvsResponseCodesArray = array (
  260. 'A' => array('message' => 'Address', 'details' => 'Address Only (no ZIP)'),
  261. 'B' => array('message' => 'International "A"', 'details' => 'Address Only (no ZIP)'),
  262. 'C' => array('message' => 'International "N"', 'details' => 'None - The transaction is declined.'),
  263. 'D' => array('message' => 'International "X"', 'details' => 'Address and Postal Code'),
  264. 'E' => array('message' => 'Not Allowed for MOTO (Internet/Phone) transactions', 'details' => 'Not applicable - The transaction is declined.'),
  265. 'F' => array('message' => 'UK-Specific "X"', 'details' => 'Address and Postal Code'),
  266. 'G' => array('message' => 'Global Unavailable', 'details' => 'Not applicable'),
  267. 'I' => array('message' => 'International Unavailable', 'details' => 'Not applicable'),
  268. 'N' => array('message' => 'No', 'details' => 'None - The transaction is declined.'),
  269. 'P' => array('message' => 'Postal (International "Z")', 'details' => 'Postal Code only (no Address)'),
  270. 'R' => array('message' => 'Retry', 'details' => 'Not Applicable'),
  271. 'S' => array('message' => 'Service Not Supported', 'details' => 'Not Applicable'),
  272. 'U' => array('message' => 'Unavailable', 'details' => 'Not Applicable'),
  273. 'W' => array('message' => 'Whole ZIP', 'details' => 'Nine-digit ZIP code (no Address)'),
  274. 'X' => array('message' => 'Exact Match', 'details' => 'Address and nine-digit ZIP code'),
  275. 'Y' => array('message' => 'Yes', 'details' => 'Address and five-digit ZIP'),
  276. 'Z' => array('message' => 'ZIP', 'details' => 'Five-digit ZIP code (no Address)'),
  277. '' => array('message' => 'Error', 'details' => 'Not Applicable')
  278. );
  279. /* ---------------------------------------
  280. CVV Rsponse Code Values and Meanings
  281. ---------------------------------------
  282. - $CvvResponseCodesArray[CODE][MESSAGE]
  283. - $CvvResponseCodesArray[CODE][DETAILS]
  284. */
  285. public $CvvResponseCodesArray = array (
  286. 'M' => array('message' => 'Match', 'details' => 'CVV2'),
  287. 'N' => array('message' => 'No Match', 'details' => 'None'),
  288. 'P' => array('message' => 'Not Processed', 'details' => 'Not Applicable'),
  289. 'S' => array('message' => 'Service not supported', 'details' => 'Not Applicable'),
  290. 'U' => array('message' => 'Service not available', 'details' => 'Not Applicable'),
  291. 'X' => array('message' => 'No response', 'details' => 'Not Applicable')
  292. );
  293. /* ---------------------------------------
  294. CVV Rsponse Code Values and Meanings for Switch and Solo cards
  295. ---------------------------------------
  296. - TODO: ??
  297. */
  298. /* --------------------------------------------
  299. REQUEST FIELDS ARRAYS
  300. --------------------------------------------
  301. */
  302. public $RequestFieldsArray = array(
  303. 'DoCapture' => array(
  304. 'authorization_id' => array('name' =>'AUTHORIZATIONID', 'required' => 'yes'),
  305. 'amount' => array('name' =>'AMT', 'required' => 'yes'),
  306. 'currency_code' => array('name' =>'CURRENCYCODE', 'required' => 'no'),
  307. 'complete_type' => array('name' =>'COMPLETETYPE', 'required' => 'yes'),
  308. 'invoice_number' => array('name' =>'INVNUM', 'required' => 'no'),
  309. 'note' => array('name' =>'NOTE', 'required' => 'no'),
  310. 'soft_descriptor' => array('name' =>'SOFTDESCRIPTOR', 'required' => 'no')
  311. ),
  312. 'DoAuthorization' => array(
  313. 'transaction_id' => array('name' =>'TRANSACTIONID', 'required' => 'yes'),
  314. 'amount' => array('name' =>'AMT', 'required' => 'yes'),
  315. 'transaction_entity' => array('name' =>'TRANSACTIONENTITY', 'required' => 'no'),
  316. 'currency_code' => array('name' =>'CURRENCYCODE', 'required' => 'no')
  317. ),
  318. 'DoReauthorization' => array(
  319. 'authorization_id' => array('name' =>'AUTHORIZATIONID', 'required' => 'yes'),
  320. 'amount' => array('name' =>'AMT', 'required' => 'yes')
  321. ),
  322. 'DoVoid' => array(
  323. 'authorization_id' => array('name' =>'AUTHORIZATIONID', 'required' => 'yes'),
  324. 'note' => array('name' =>'NOTE', 'required' => 'no')
  325. ),
  326. 'DoDirectPayment' => array(
  327. 'payment_type' => array('name' => 'PAYMENTACTION', 'required' => 'yes'),
  328. 'ip_address' => array('name' => 'IPADDRESS', 'required' => 'yes'),
  329. 'return_fmf_details' => array('name' => 'RETURNFMFDETAILS', 'required' => 'no'),
  330. 'amount_total' => array('name' => 'AMT', 'required' => 'yes'),
  331. 'credit_card_type' => array('name' => 'CREDITCARDTYPE', 'required' => 'yes'),
  332. 'credit_card_number' => array('name' => 'ACCT', 'required' => 'yes'),
  333. 'expire_date' => array('name' => 'EXPDATE', 'required' => 'yes'),
  334. 'first_name' => array('name' => 'FIRSTNAME', 'required' => 'yes'),
  335. 'last_name' => array('name' => 'LASTNAME', 'required' => 'yes'),
  336. 'address1' => array('name' => 'STREET', 'required' => 'no'),
  337. 'address2' => array('name' => 'STREET2', 'required' => 'no'),
  338. 'city' => array('name' => 'CITY', 'required' => 'no'),
  339. 'state' => array('name' => 'STATE', 'required' => 'no'),
  340. 'country_code' => array('name' => 'COUNTRYCODE', 'required' => 'no'),
  341. 'postal_code' => array('name' => 'ZIP', 'required' => 'no'),
  342. 'notify_url' => array('name' => 'NOTIFYURL', 'required' => 'no'),
  343. 'currency_code' => array('name' => 'CURRENCYCODE', 'required' => 'no'),
  344. 'amount_items' => array('name' => 'ITEMAMT', 'required' => 'no'),
  345. 'amount_shipping' => array('name' => 'SHIPPINGAMT', 'required' => 'no'),
  346. 'amount_handling' => array('name' => 'HANDLINGAMT', 'required' => 'no'),
  347. 'amount_tax' => array('name' => 'TAXAMT', 'required' => 'no'),
  348. 'description' => array('name' => 'DESC', 'required' => 'no'),
  349. 'custom' => array('name' => 'CUSTOM', 'required' => 'no'),
  350. 'invoice_number' => array('name' => 'INVNUM', 'required' => 'no'),
  351. 'cvv2_code' => array('name' => 'CVV2', 'required' => 'yes'),
  352. 'start_date' => array('name' => 'STARTDATE', 'required' => 'no'), // For Maestro/Solo cards
  353. 'issue_number' => array('name' => 'ISSUENUMBER', 'required' => 'no'), // For maestro/Solo Cards
  354. 'email' => array('name' => 'EMAIL', 'required' => 'no'),
  355. 'phone_number' => array('name' => 'PHONENUM', 'required' => 'no'),
  356. 'shipping_name' => array('name' => 'SHIPTONAME', 'required' => 'no'),
  357. 'shipping_address1' => array('name' => 'SHIPTOSTREET', 'required' => 'no'),
  358. 'shipping_address2' => array('name' => 'SHIPTOSTREET2', 'required' => 'no'),
  359. 'shipping_city' => array('name' => 'SHIPTOCITY', 'required' => 'no'),
  360. 'shipping_state' => array('name' => 'SHIPTOSTATE', 'required' => 'no'),
  361. 'shipping_postal_code' => array('name' => 'SHIPTOZIP', 'required' => 'no'),
  362. 'shipping_country_code' => array('name' => 'SHIPTOCOUNTRYCODE', 'required' => 'no'),
  363. 'shipping_phone_number' => array('name' => 'SHIPTOPHONENUM', 'required' => 'no')
  364. ),
  365. 'SetExpressCheckout' => array(
  366. 'return_url' => array('name' => 'RETURNURL', 'required' => 'yes'),
  367. 'cancel_url' => array('name' => 'CANCELURL', 'required' => 'yes'),
  368. 'amount_total' => array('name' => 'AMT', 'required' => 'yes'),
  369. 'currency_code' => array('name' => 'CURRENCYCODE', 'required' => 'no'),
  370. 'amount_max' => array('name' => 'MAXAMT', 'required' => 'no'),
  371. 'payment_type' => array('name' => 'PAYMENTACTION', 'required' => 'no'),
  372. 'email' => array('name' => 'EMAIL', 'required' => 'no'),
  373. 'description' => array('name' => 'DESC', 'required' => 'no'),
  374. 'custom' => array('name' => 'CUSTOM', 'required' => 'no'),
  375. 'invoice_number' => array('name' => 'INVNUM', 'required' => 'no'),
  376. 'phone_number' => array('name' => 'PHONENUM', 'required' => 'no'),
  377. 'shipping_name' => array('name' => 'SHIPTONAME', 'required' => 'no'),
  378. 'shipping_address1' => array('name' => 'SHIPTOSTREET', 'required' => 'no'),
  379. 'shipping_address2' => array('name' => 'SHIPTOSTREET2', 'required' => 'no'),
  380. 'shipping_city' => array('name' => 'SHIPTOCITY', 'required' => 'no'),
  381. 'shipping_state' => array('name' => 'SHIPTOSTATE', 'required' => 'no'),
  382. 'shipping_postal_code' => array('name' => 'SHIPTOZIP', 'required' => 'no'),
  383. 'shipping_country_code' => array('name' => 'SHIPTOCOUNTRYCODE', 'required' => 'no'),
  384. 'shipping_phone_number' => array('name' => 'SHIPTOPHONENUM', 'required' => 'no'),
  385. 'require_confirmed_shipping_address' => array('name' => 'REQCONFIRMSHIPPING', 'required' => 'no'),
  386. 'no_shipping' => array('name' => 'NOSHIPPING', 'required' => 'no'),
  387. 'address_override' => array('name' => 'ADDROVERRIDE', 'required' => 'no'),
  388. 'token' => array('name' => 'TOKEN', 'required' => 'no'),
  389. 'locale_code' => array('name' => 'LOCALECODE', 'required' => 'no'),
  390. 'page_style' => array('name' => 'PAGESTYLE', 'required' => 'no'),
  391. 'hdr_img' => array('name' => 'HDRIMG', 'required' => 'no'),
  392. 'hdr_border_color' => array('name' => 'HDRBORDERCOLOR', 'required' => 'no'),
  393. 'hdr_background_color' => array('name' => 'HDRBACKCOLOR', 'required' => 'no'),
  394. 'payflow_color' => array('name' => 'PAYFLOWCOLOR', 'required' => 'no'),
  395. 'user_action' => array('name' => 'USERACTION', 'required' => 'no'),
  396. 'channel_type' => array('name' => 'CHANNELTYPE', 'required' => 'no'),
  397. 'solution_type' => array('name' => 'SOLUTIONTYPE', 'required' => 'no') ,
  398. 'billing_type' => array('name' => 'L_BILLINGTYPE0', 'required' => 'no'),
  399. 'billing_agreement' => array('name' => 'L_BILLINGAGREEMENTDESCRIPTION0', 'required' => 'no')
  400. ),
  401. 'GetExpressCheckoutDetails' => array(
  402. 'token' => array('name' => 'TOKEN', 'required' => 'yes')
  403. ),
  404. 'DoExpressCheckoutPayment' => array(
  405. 'token' => array('name' => 'TOKEN', 'required' => 'yes'),
  406. 'payment_type' => array('name' => 'PAYMENTACTION', 'required' => 'yes'),
  407. 'payer_id' => array('name' => 'PAYERID', 'required' => 'yes'),
  408. 'amount_total' => array('name' => 'AMT', 'required' => 'yes'),
  409. 'description' => array('name' => 'DESC', 'required' => 'no'),
  410. 'custom' => array('name' => 'CUSTOM', 'required' => 'no'),
  411. 'invoice_number' => array('name' => 'INVNUM', 'required' => 'no'),
  412. 'notify_url' => array('name' => 'NOTIFYURL', 'required' => 'no'),
  413. 'amount_items' => array('name' => 'ITEMAMT', 'required' => 'no'),
  414. 'amount_shipping' => array('name' => 'SHIPPINGAMT', 'required' => 'no'),
  415. 'amount_handling' => array('name' => 'HANDLINGAMT', 'required' => 'no'),
  416. 'amount_tax' => array('name' => 'TAXAMT', 'required' => 'no'),
  417. 'currency_code' => array('name' => 'CURRENCYCODE', 'required' => 'no'),
  418. 'shipping_name' => array('name' => 'SHIPTONAME', 'required' => 'no'),
  419. 'shipping_address1' => array('name' => 'SHIPTOSTREET', 'required' => 'no'),
  420. 'shipping_address2' => array('name' => 'SHIPTOSTREET2', 'required' => 'no'),
  421. 'shipping_city' => array('name' => 'SHIPTOCITY', 'required' => 'no'),
  422. 'shipping_state' => array('name' => 'SHIPTOSTATE', 'required' => 'no'),
  423. 'shipping_postal_code' => array('name' => 'SHIPTOZIP', 'required' => 'no'),
  424. 'shipping_country_code' => array('name' => 'SHIPTOCOUNTRYCODE', 'required' => 'no'),
  425. 'shipping_phone_number' => array('name' => 'SHIPTOPHONENUM', 'required' => 'no')
  426. ),
  427. 'GetTransactionDetails' => array(
  428. 'transaction_id' => array('name' => 'TRANSACTIONID', 'required' => 'yes')
  429. ),
  430. 'RefundTransaction' => array(
  431. 'transaction_id' => array('name' => 'TRANSACTIONID', 'required' => 'yes'),
  432. 'refund_type' => array('name' => 'REFUNDTYPE', 'required' => 'yes'),
  433. 'amount_total' => array('name' => 'AMT', 'required' => 'no'),
  434. 'note' => array('name' => 'NOTE', 'required' => 'no'),
  435. ),
  436. 'CreateRecurringPaymentsProfile' => array(
  437. 'token' => array('name' => 'TOKEN', 'required' => 'yes'),
  438. 'payer_id' => array('name' => 'PAYERID', 'required' => 'yes'),
  439. 'email' => array('name' => 'EMAIL', 'required' => 'yes'),
  440. 'country_code' => array('name' => 'COUNTRYCODE', 'required' => 'no'),
  441. 'business' => array('name' => 'BUSINESS', 'required' => 'no'),
  442. 'payer_status' => array('name' => 'PAYERSTATUS', 'required' => 'no'),
  443. 'subscriber_name' => array('name' => 'SUBSCRIBERNAME', 'required' => 'yes'),
  444. 'profile_reference' => array('name' => 'PROFILEREFERENCE', 'required' => 'yes'),
  445. 'credit_card_type' => array('name' => 'CREDITCARDTYPE', 'required' => 'yes'),
  446. 'credit_card_number' => array('name' => 'ACCT', 'required' => 'yes'),
  447. 'expire_date' => array('name' => 'EXPDATE', 'required' => 'yes'),
  448. 'first_name' => array('name' => 'FIRSTNAME', 'required' => 'yes'),
  449. 'last_name' => array('name' => 'LASTNAME', 'required' => 'yes'),
  450. 'address1' => array('name' => 'STREET', 'required' => 'no'),
  451. 'address2' => array('name' => 'STREET2', 'required' => 'no'),
  452. 'city' => array('name' => 'CITY', 'required' => 'no'),
  453. 'state' => array('name' => 'STATE', 'required' => 'no'),
  454. 'country_code' => array('name' => 'COUNTRYCODE', 'required' => 'no'),
  455. 'postal_code' => array('name' => 'ZIP', 'required' => 'no'),
  456. 'shipping_name' => array('name' => 'SHIPTONAME', 'required' => 'no'),
  457. 'shipping_address1' => array('name' => 'SHIPTOSTREET', 'required' => 'no'),
  458. 'shipping_address2' => array('name' => 'SHIPTOSTREET2', 'required' => 'no'),
  459. 'shipping_city' => array('name' => 'SHIPTOCITY', 'required' => 'no'),
  460. 'shipping_state' => array('name' => 'SHIPTOSTATE', 'required' => 'no'),
  461. 'shipping_postal_code' => array('name' => 'SHIPTOZIP', 'required' => 'no'),
  462. 'shipping_country_code' => array('name' => 'SHIPTOCOUNTRYCODE', 'required' => 'no'),
  463. 'shipping_phone_number' => array('name' => 'SHIPTOPHONENUM', 'required' => 'no'),
  464. 'description' => array('name' => 'DESC', 'required' => 'yes'), // You must match the billing agreement var in set Express checkout
  465. 'currency' => array('name' => 'CURRENCYCODE', 'required' => 'yes'),
  466. 'payment_type' => array('name' => 'PAYMENTACTION', 'required' => 'yes'),
  467. 'billing_type' => array('name' => 'L_BILLINGTYPE0', 'required' => 'yes'),
  468. 'billing_agreement' => array('name' => 'L_BILLINGAGREEMENTDESCRIPTION0', 'required' => 'yes'),
  469. 'profile_start_date' => array('name' => 'PROFILESTARTDATE', 'required' => 'yes'),
  470. 'billing_period' => array('name' => 'BILLINGPERIOD', 'required' => 'yes'), // Day Week Month SemiMonth Year
  471. 'billing_frequency' => array('name' => 'BILLINGFREQUENCY', 'required' => 'yes'),
  472. 'billing_amount' => array('name' => 'AMT', 'required' => 'yes'),
  473. 'tax_amount' => array('name' => 'TAXAMT', 'required' => 'yes'),
  474. 'ship_amount' => array('name' => 'SHIPPINGAMT', 'required' => 'yes'),
  475. 'inital_amount' => array('name' => 'INITAMT', 'required' => 'no'),
  476. 'failed_inital_amount' => array('name' => 'FAILEDINITAMTACTION', 'required' => 'no'),
  477. 'billing_total_cycles' => array('name' => 'TOTALBILLINGCYCLES', 'required' => 'no'),
  478. 'trial_billing_period' => array('name' => 'TRIALBILLINGPERIOD', 'required' => 'no'),
  479. 'trial_billing_frequency' => array('name' => 'TRIALBILLINGFREQUENCY', 'required' => 'no'),
  480. 'trial_amount' => array('name' => 'TRIALAMT', 'required' => 'no'),
  481. 'trial_billing_cycle' => array('name' => 'TRIALTOTALBILLINGCYCLES', 'required' => 'no'),
  482. 'max_failed_attempts' => array('name' => 'MAXFAILEDPAYMENTS', 'required' => 'no'),
  483. 'auto_bill_amt' => array('name' => 'AUTOBILLOUTAMT', 'required' => 'no')
  484. ),
  485. 'UpdateRecurringPaymentsProfile' => array(
  486. 'profile_id' => array('name' => 'PROFILEID', 'required' => 'yes'),
  487. 'note' => array('name' => 'NOTE', 'required' => 'no'),
  488. 'description' => array('name' => 'DESC', 'required' => 'no'),
  489. 'subscriber_name' => array('name' => 'SUBSCRIBERNAME', 'required' => 'no'),
  490. 'profile_reference' => array('name' => 'PROFILEREFERENCE', 'required' => 'no'),
  491. 'additional_billing_cycles' => array('name' => 'ADDITIONALBILLINGCYCLES', 'required' => 'no'),
  492. 'amount' => array('name' => 'AMT', 'required' => 'yes'),
  493. 'shipping_amount' => array('name' => 'SHIPPINGAMT', 'required' => 'no'),
  494. 'tax_amount' => array('name' => 'TAXAMT', 'required' => 'no'),
  495. 'outstanding_amount' => array('name' => 'OUTSTANDINGAMT', 'required' => 'no'),
  496. 'auto_bill_out' => array('name' => 'AUTOBILLOUTAMT', 'required' => 'no'),
  497. 'max_failed_payments' => array('name' => 'MAXFAILEDPAYMENTS', 'required' => 'no'),
  498. 'profile_start_date' => array('name' => 'PROFILESTARTDATE' , 'required' => 'no'),
  499. 'ship_to_name' => array('name' => 'SHIPTONAME', 'required' => 'no'),
  500. 'ship_to_street' => array('name' => 'SHIPTOSTREET', 'required' => 'no'),
  501. 'ship_to_street_2' => array('name' => 'SHIPTOSTREET2', 'required' => 'no'),
  502. 'ship_to_city' => array('name' => 'SHIPTOCITY', 'required' => 'no'),
  503. 'ship_to_province' => array('name' => 'SHIPTOSTATE', 'required' => 'no'),
  504. 'ship_to_postal_code' => array('name' => 'SHIPTOZIP', 'required' => 'no'),
  505. 'ship_to_country' => array('name' => 'SHIPTOCOUNTRY', 'required' => 'no'),
  506. 'ship_to_phone_number' => array('name' => 'SHIPTOPHONENUM', 'required' => 'no'),
  507. 'billing_period' => array('name' => 'BILLINGPERIOD', 'required' => 'yes'),
  508. 'billing_frequency' => array('name' => 'BILLINGFREQUENCY', 'required' => 'yes'),
  509. 'total_billing_cycles' => array('name' => 'TOTALBILLINGCYCLES', 'required' => 'no'),
  510. 'trial_billing_period' => array('name' => 'TRIALBILLINGPERIOD', 'required' => 'no'),
  511. 'trial_billing_frequnecy' => array('name' => 'TRIALBILLINGFREQUENCY', 'required' => 'no'),
  512. 'trial_total_cycles' => array('name' => 'TRIALTOTALBILLINGCYCLES', 'required' => 'no'),
  513. 'trial_amount' => array('name' => 'TRIALAMT', 'required' => 'no'),
  514. 'currency' => array('name' => 'CURRENCYCODE', 'required' => 'yes'),
  515. 'shipping_amount' => array('name' => 'SHIPPINGAMT', 'required' => 'no'),
  516. 'tax_amount' => array('name' => 'TAXAMT', 'required' => 'no'),
  517. 'credit_card_type' => array('name' => 'CREDITCARDTYPE', 'required' => 'no'),
  518. 'credit_card_number' => array('name' => 'ACCT', 'required' => 'no'),
  519. 'expiration_date' => array('name' => 'EXPDATE', 'required' => 'no'),
  520. 'cvv2' => array('name' => 'CVV2', 'required' => 'no'),
  521. 'start_date' => array('name' => 'STARTDATE', 'required' => 'no'),
  522. 'email' => array('name' => 'EMAIL', 'required' => 'no'),
  523. 'first_name' => array('name' => 'FIRSTNAME', 'required' => 'no'),
  524. 'last_name' => array('name' => 'LASTNAME', 'required' => 'no'),
  525. 'street' => array('name' => 'STREET', 'required' => 'yes'),
  526. 'street2' => array('name' => 'STREET2', 'required' => 'no'),
  527. 'city' => array('name' => 'CITY', 'required' => 'yes'),
  528. 'province' => array('name' => 'STATE', 'required' => 'yes'),
  529. 'country_code' => array('name' => 'COUNTRYCODE', 'required' => 'yes'),
  530. 'postal_code' => array('name' => 'ZIP', 'required' => 'yes'),
  531. 'phone_number' => array('name' => 'PHONENUM', 'required' => 'no')
  532. ),
  533. 'DoReferenceTransaction' => array(
  534. 'reference_id' => array('name' => 'REFERENCEID', 'required' => 'yes'),
  535. 'payment_type' => array('name' => 'PAYMENTACTION', 'required' => 'yes'),
  536. 'return_fmf_details' => array('name' => 'RETURNFMFDETAILS', 'required' => 'no'),
  537. 'soft_descriptor' => array('name' => 'SOFTDESCRIPTOR', 'required' => 'no'),
  538. 'ship_to_name' => array('name' => 'SHIPTONAME', 'required' => 'no'),
  539. 'ship_to_street' => array('name' => 'SHIPTOSTREET', 'required' => 'no'),
  540. 'ship_to_street_2' => array('name' => 'SHIPTOSTREET2', 'required' => 'no'),
  541. 'ship_to_city' => array('name' => 'SHIPTOCITY', 'required' => 'no'),
  542. 'ship_to_province' => array('name' => 'SHIPTOSTATE', 'required' => 'no'),
  543. 'ship_to_postal_code' => array('name' => 'SHIPTOZIP', 'required' => 'no'),
  544. 'ship_to_country' => array('name' => 'SHIPTOCOUNTRY', 'required' => 'no'),
  545. 'ship_to_phone_number' => array('name' => 'SHIPTOPHONENUM', 'required' => 'no'),
  546. 'billing_period' => array('name' => 'BILLINGPERIOD', 'required' => 'yes'),
  547. 'billing_frequency' => array('name' => 'BILLINGFREQUENCY', 'required' => 'yes'),
  548. 'phone_number' => array('name' => 'PHONENUM', 'required' => 'no'),
  549. 'amount_total' => array('name' => 'AMT', 'required' => 'yes'),
  550. 'currency_code' => array('name' => 'CURRENCYCODE', 'required' => 'no'),
  551. 'amount_items' => array('name' => 'ITEMAMT', 'required' => 'no'),
  552. 'amount_shipping' => array('name' => 'SHIPPINGAMT', 'required' => 'no'),
  553. 'amount_handling' => array('name' => 'HANDLINGAMT', 'required' => 'no'),
  554. 'amount_tax' => array('name' => 'TAXAMT', 'required' => 'no'),
  555. 'description' => array('name' => 'DESC', 'required' => 'no'),
  556. 'custom' => array('name' => 'CUSTOM', 'required' => 'no'),
  557. 'invoice_number' => array('name' => 'INVNUM', 'required' => 'no'),
  558. 'button_source' => array('name' => 'BUTTONSOURCE', 'required' => 'no'),
  559. 'notify_url' => array('name' => 'NOTIFYURL', 'required' => 'no'),
  560. 'credit_card_type' => array('name' => 'CREDITCARDTYPE', 'required' => 'no'),
  561. 'credit_card_number' => array('name' => 'ACCT', 'required' => 'no'),
  562. 'cvv2_code' => array('name' => 'CVV2', 'required' => 'yes'),
  563. 'expire_date' => array('name' => 'EXPDATE', 'required' => 'no'),
  564. 'start_date' => array('name' => 'STARTDATE', 'required' => 'no'), // For Maestro/Solo cards
  565. 'issue_number' => array('name' => 'ISSUENUMBER', 'required' => 'no'), // For maestro/Solo Cards
  566. 'email' => array('name' => 'EMAIL', 'required' => 'no'),
  567. 'first_name' => array('name' => 'FIRSTNAME', 'required' => 'no'),
  568. 'last_name' => array('name' => 'LASTNAME', 'required' => 'no'),
  569. 'address1' => array('name' => 'STREET', 'required' => 'no'),
  570. 'address2' => array('name' => 'STREET2', 'required' => 'no'),
  571. 'city' => array('name' => 'CITY', 'required' => 'no'),
  572. 'state' => array('name' => 'STATE', 'required' => 'no'),
  573. 'country_code' => array('name' => 'COUNTRYCODE', 'required' => 'no'),
  574. 'postal_code' => array('name' => 'ZIP', 'required' => 'no')
  575. )
  576. );
  577. public $ResponseFieldsArray = array(
  578. 'DoCapture' => array(
  579. 'authorization_id' => 'AUTHORIZATIONID',
  580. 'email' => 'EMAIL',
  581. 'payer_id' => 'PAYERID',
  582. 'payer_status' => 'PAYERSTATUS',
  583. 'country_code' => 'COUNTRYCODE',
  584. 'business' => 'BUSINESS',
  585. 'address_status' => 'ADDRESSSTATUS',
  586. 'shipping_name' => 'SHIPTONAME',
  587. 'shipping_address1' => 'SHIPTOSTREET',
  588. 'shipping_address2' => 'SHIPTOSTREET2',
  589. 'shipping_city' => 'SHIPTOCITY',
  590. 'shipping_state' => 'SHIPTOSTATE',
  591. 'shipping_postal_code' => 'SHIPTOZIP',
  592. 'shipping_country_code' => 'SHIPTOCOUNTRYCODE',
  593. 'salutation' => 'SALUTATION',
  594. 'first_name' => 'FIRSTNAME',
  595. 'middle_name' => 'MIDDLENAME',
  596. 'last_name' => 'LASTNAME',
  597. 'suffix' => 'SUFFIX'
  598. ),
  599. 'DoAuthorization' => array(
  600. 'transaction_id' => 'TRANSACTIONID',
  601. 'amount' => 'AMT'
  602. ),
  603. 'DoReauthorization' => array(
  604. 'authorization_id' => 'AUTHORIZATIONID'
  605. ),
  606. 'DoVoid' => array(
  607. 'authorization_id' => 'AUTHORIZATIONID'
  608. ),
  609. 'DoDirectPayment' => array(
  610. 'timestamp' => 'TIMESTAMP',
  611. 'correlation_id' => 'CORRELATIONID',
  612. 'ack' => 'ACK',
  613. 'version' => 'VERSION',
  614. 'build' => 'BUILD',
  615. 'avs_code' => 'AVSCODE',
  616. 'cvv2_match' => 'CVV2MATCH',
  617. 'transaction_id' => 'TRANSACTIONID',
  618. 'amount_total' => 'AMT',
  619. 'currency_code' => 'CURRENCYCODE'
  620. )
  621. ,
  622. 'SetExpressCheckout' => array(
  623. 'timestamp' => 'TIMESTAMP',
  624. 'correlation_id' => 'CORRELATIONID',
  625. 'ack' => 'ACK',
  626. 'version' => 'VERSION',
  627. 'build' => 'BUILD',
  628. 'token' => 'TOKEN'
  629. )
  630. ,
  631. 'DoExpressCheckoutPayment' => array(
  632. 'timestamp' => 'TIMESTAMP',
  633. 'correlation_id' => 'CORRELATIONID',
  634. 'ack' => 'ACK',
  635. 'version' => 'VERSION',
  636. 'build' => 'BUILD',
  637. 'token' => 'TOKEN',
  638. 'transaction_id' => 'TRANSACTIONID',
  639. 'transaction_type' => 'TRANSACTIONTYPE',
  640. 'payment_type' => 'PAYMENTTYPE',
  641. 'order_time' => 'ORDERTIME',
  642. 'amount_total' => 'AMT',
  643. 'currency_code' => 'CURRENCYCODE',
  644. 'amount_fee' => 'FEEAMT',
  645. 'amount_settle' => 'SETTLEAMT',
  646. 'amount_tax' => 'TAXAMT',
  647. 'exchange_rate' => 'EXCHANGERATE',
  648. 'payment_status' => 'PAYMENTSTATUS',
  649. 'payment_pending_reason'=> 'PENDINGREASON',
  650. 'payment_reason_code' => 'REASONCODE'
  651. )
  652. ,
  653. 'GetExpressCheckoutDetails' => array(
  654. 'timestamp' => 'TIMESTAMP',
  655. 'correlation_id' => 'CORRELATIONID',
  656. 'ack' => 'ACK',
  657. 'version' => 'VERSION',
  658. 'build' => 'BUILD',
  659. 'token' => 'TOKEN',
  660. 'email' => 'EMAIL',
  661. 'payer_id' => 'PAYERID',
  662. 'payer_status' => 'PAYERSTATUS',
  663. 'salutation' => 'SALUTATION',
  664. 'first_name' => 'FIRSTNAME',
  665. 'middle_name' => 'MIDDLENAME',
  666. 'last_name' => 'LASTNAME',
  667. 'suffix' => 'SUFFIX',
  668. 'country_code' => 'COUNTRYCODE',
  669. 'business' => 'BUSINESS',
  670. 'shipping_name' => 'SHIPTONAME',
  671. 'shipping_address1' => 'SHIPTOSTREET',
  672. 'shipping_address2' => 'SHIPTOSTREET2',
  673. 'shipping_city' => 'SHIPTOCITY',
  674. 'shipping_state' => 'SHIPTOSTATE',
  675. 'shipping_country_code' => 'SHIPTOCOUNTRYCODE',
  676. 'shipping_country_name' => 'SHIPTOCOUNTRYNAME',
  677. 'shipping_postal_code' => 'SHIPTOZIP',
  678. 'address_id' => 'ADDRESSID', // Is this a returned variable? Some docs say yes, some no
  679. 'address_status' => 'ADDRESSSTATUS',
  680. 'description' => 'DESC',
  681. 'custom' => 'CUSTOM',
  682. 'phone_number' => 'PHONENUM'
  683. )
  684. ,
  685. 'GetTransactionDetails' => array(
  686. 'timestamp' => 'TIMESTAMP',
  687. 'correlation_id' => 'CORRELATIONID',
  688. 'ack' => 'ACK',
  689. 'version' => 'VERSION',
  690. 'build' => 'BUILD',
  691. 'receiver_business' => 'RECEIVERBUSINESS',
  692. 'receiver_email' => 'RECEIVEREMAIL',
  693. 'receiver_id' => 'RECEIVERID',
  694. 'email' => 'EMAIL',
  695. 'payer_id' => 'PAYERID',
  696. 'payer_status' => 'PAYERSTATUS',
  697. 'salutation' => 'SALUTATION',
  698. 'first_name' => 'FIRSTNAME',
  699. 'last_name' => 'LASTNAME',
  700. 'middle_name' => 'MIDDLENAME',
  701. 'suffix' => 'SUFFIX',
  702. 'payer_business' => 'PAYERBUSINESS',
  703. 'country_code' => 'COUNTRYCODE',
  704. 'business' => 'BUSINESS',
  705. 'shipping_name' => 'SHIPTONAME',
  706. 'shipping_address1' => 'SHIPTOSTREET',
  707. 'shipping_address2' => 'SHIPTOSTREET2',
  708. 'shipping_city' => 'SHIPTOCITY',
  709. 'shipping_state' => 'SHIPTOSTATE',
  710. 'shipping_country_code' => 'SHIPTOCOUNTRYCODE',
  711. 'shipping_country_name' => 'SHIPTOCOUNTRYNAME',
  712. 'shipping_postal_code' => 'SHIPTOZIP',
  713. 'address_id' => 'ADDRESSID', // Is this a returned variable? Some docs say yes, some no
  714. 'address_status' => 'ADDRESSSTATUS',
  715. 'address_owner' => 'ADDRESSOWNER',
  716. 'parent_transaction_id' => 'PARENTTRANSACTIONID',
  717. 'transaction_id' => 'TRANSACTIONID',
  718. 'receipt_id' => 'RECEIPTID',
  719. 'transaction_type' => 'TRANSACTIONTYPE',
  720. 'payment_type' => 'PAYMENTTYPE',
  721. 'order_time' => 'ORDERTIME',
  722. 'amount_total' => 'AMT',
  723. 'currency_code' => 'CURRENCYCODE',
  724. 'amount_fee' => 'FEEAMT',
  725. 'amount_settle' => 'SETTLEAMT',
  726. 'amount_tax' => 'TAXAMT',
  727. 'exchange_rate' => 'EXCHANGERATE',
  728. 'payment_status' => 'PAYMENTSTATUS',
  729. 'payment_pending_reason' => 'PENDINGREASON',
  730. 'payment_reason_code' => 'REASONCODE',
  731. 'amount_sales_tax' => 'SALESTAX',
  732. 'invoice_number' => 'INVNUM',
  733. 'note' => 'NOTE',
  734. 'custom' => 'CUSTOM',
  735. 'subscription_id' => 'SUBSCRIPTIONID',
  736. 'subscription_date' => 'SUBSCRIPTIONDATE',
  737. 'effective_date' => 'EFFECTIVEDATE',
  738. 'retry_time' => 'RETRYTIME',
  739. 'user_name' => 'USERNAME',
  740. 'recurrences' => 'RECURRENCES',
  741. 'reattempt' => 'REATTEMPT',
  742. 'recurring' => 'RECURRING',
  743. 'period' => 'PERIOD',
  744. 'buyer_id' => 'BUYERID',
  745. 'closing_date' => 'CLOSINGDATE',
  746. 'multi_item' => 'MULTIITEM'
  747. )
  748. ,
  749. 'RefundTransaction' => array(
  750. 'refund_transaction_id' => 'REFUNDTRANSACTIONID',
  751. 'amount_refund_net' => 'NETFUNDAMT',
  752. 'amount_refund_fee' => 'FEEREFUNDAMT',
  753. 'amount_refund_total' => 'GROSSREFUNDAMT'
  754. ),
  755. 'CreateRecurringPaymentsProfile' => array(
  756. 'profile_id' => 'PROFILEID',
  757. 'status' => 'STATUS'
  758. ),
  759. 'UpdateRecurringPaymentsProfile' => array(
  760. 'profile_id' => 'PROFILEID',
  761. ),
  762. 'GetRecurringPaymentsProfileDetails' => array(
  763. 'profile_id' => 'PROFILEID',
  764. 'status' => 'STATUS',
  765. 'auto_bill_out' => 'AUTOBILLOUTAMT',
  766. 'description' => 'DESC',
  767. 'max_failed_payments' => 'MAXFAILEDPAYMENTS',
  768. 'subcriber_name' => 'SUBSCRIBERNAME',
  769. 'profile_start_date' => 'PROFILESTARTDATE',
  770. 'nest_billing_date' => 'NEXTBILLINGDATE',
  771. 'num_cycles_completed' => 'NUMCYCLESCOMPLETED',
  772. 'num_cycles_remaining' => 'NUMCYCLESREMAINING',
  773. 'outstanding_balance' => 'OUTSTANDINGBALANCE',
  774. 'failed_billing_account'=> 'FAILEDPAYMENTCOUNT',
  775. 'trial_amount_paid' => 'TRIALAMTPAID',
  776. 'regular_amount_paid' => 'REGULARAMTPAID',
  777. 'aggregate_amount' => 'AGGREGATEAMT',
  778. 'aggregate_option_amount' => 'AGGREGATEOPTIONALAMT',
  779. 'final_payment_due_date' => 'FINALPAYMENTDUEDATE',
  780. 'time_stamp' => 'TIMESTAMP',
  781. 'correlation_id' => 'CORRELATIONID',
  782. 'ack' => 'ACK',
  783. 'version' => 'VERSION',
  784. 'build' => 'BUILD',
  785. 'ship_to_street' => 'SHIPTOSTREET',
  786. 'ship_to_street2' => 'SHIPTOSTREET2',
  787. 'ship_to_city' => 'SHIPTOCITY',
  788. 'ship_to_province' => 'SHIPTOSTATE',
  789. 'ship_to_postalcode' => 'SHIPTOZIP',
  790. 'ship_to_country_code' => 'SHIPTOCOUNTRYCODE',
  791. 'ship_to_country' => 'SHIPTOCOUNTRY',
  792. 'ship_to_country_name' => 'SHIPTOCOUNTRYNAME',
  793. 'ship_address_owner' => 'SHIPADDRESSOWNER',
  794. 'ship_address_status' => 'SHIPADDRESSSTATUS',
  795. 'billing_period' => 'BILLINGPERIOD',
  796. 'billing_frequency' => 'BILLINGFREQUENCY',
  797. 'total_biling_cycles' => 'TOTALBILLINGCYCLES',
  798. 'currency' => 'CURRENCYCODE',
  799. 'amount' => 'AMT',
  800. 'shipping_amount' => 'SHIPPINGAMT',
  801. 'tax_amount' => 'TAXAMT',
  802. 'regualar_billing_period' => 'REGULARBILLINGPERIOD',
  803. 'regular_billing_frequency' => 'REGULARBILLINGFREQUENCY',
  804. 'regular_billing_cycles' => 'REGULARTOTALBILLINGCYCLES',
  805. 'regular_currency' => 'REGULARCURRENCYCODE',
  806. 'regular_amount' => 'REGULARAMT',
  807. 'regular_shipping_amount' => 'REGULARSHIPPINGAMT',
  808. 'regular_tax_amount' => 'REGULARTAXAMT',
  809. 'credit_card_num' => 'ACCT',
  810. 'credit_card_type' => 'CREDITCARDTYPE',
  811. 'expiration_date' => 'EXPDATE',
  812. 'email' => 'EMAIL',
  813. 'first_name' => 'FIRSTNAME',
  814. 'last_name' => 'LASTNAME',
  815. 'street' => 'STREET',
  816. 'street2' => 'STREET2',
  817. 'city' => 'CITY',
  818. 'state' => 'STATE',
  819. 'postal_code' => 'ZIP',
  820. 'country_code' => 'COUNTRYCODE',
  821. 'country' => 'COUNTRY',
  822. 'address_owner' => 'ADDRESSOWNER',
  823. 'address_status' => 'ADDRESSSTATUS',
  824. 'payer_status' => 'PAYERSTATUS'
  825. ),
  826. 'DoReferenceTransaction' => array(
  827. 'avs_code' => 'AVSCODE',
  828. 'cvv2_match' => 'AVV2MATCH',
  829. 'billing_agreement_id' => 'BILLINGAGREEMENTID', // Should include filter IDs, but this will have to be done in the function level
  830. 'transaction_id' => 'TRANSACTIONID',
  831. 'transaction_type' => 'TRANSACTIONTYPE',
  832. 'payment_type' => 'PAYMENTTYPE',
  833. 'order_time' => 'ORDERTIME',
  834. 'amount_total' => 'AMT',
  835. 'currency_code' => 'CURRENCYCODE',
  836. 'ammount_fee' => 'FEEAMT',
  837. 'amount_settle' => 'SETTLEAMT',
  838. 'amount_tax' => 'TAXAMT',
  839. 'exchange_rate' => 'EXCHANGERATE',
  840. 'payment_status' => 'PAYMENTSTATUS',
  841. 'pending_reason' => 'PENDINGREASON',
  842. 'reason_code' => 'REASONCODE',
  843. 'protection_eligibility'=> 'PROTECTIONELIGIBILITY',
  844. 'ebay_item_auction_transaction_id' => 'EBAYITEMAUCTIONTXNID',
  845. 'payment_error' => 'PAYMENTERROR'
  846. )
  847. );
  848. // CONSTRUCT
  849. function __construct($sandbox=false)
  850. {
  851. $this->sandbox = $sandbox;
  852. if ($sandbox) $this->live = false;
  853. else $this->live = true;
  854. // SANDBOX SETTINGS
  855. if($this->sandbox):
  856. $this->API_USERNAME = 'sdk-three_api1.sdk.com';
  857. $this->API_PASSWORD = 'QFZCWN5HZM8VBG7Q';
  858. $this->API_SIGNATURE = 'A-IzJhZZjhg29XQ2qnhapuwxIDzyAZQ92FRP5dqBzVesOkzbdUONzmOU';
  859. $this->API_ENDPOINT = 'https://api-3t.sandbox.paypal.com/nvp';
  860. $this->USE_PROXY = FALSE;
  861. $this->PROXY_HOST = '127.0.0.1';
  862. $this->PROXY_PORT = '808';
  863. $this->PAYPAL_URL = 'https://www.sandbox.paypal.com/webscr&cmd=_express-checkout&token=';
  864. $this->return_url = '';
  865. $this->cancel_url = '';
  866. // LIVE SETTINGS
  867. elseif($this->live):
  868. $this->API_USERNAME = '';
  869. $this->API_PASSWORD = '';
  870. $this->API_SIGNATURE = '';
  871. $this->API_ENDPOINT = 'https://api-3t.paypal.com/nvp';
  872. $this->USE_PROXY = FALSE;
  873. $this->PROXY_HOST = '127.0.0.1';
  874. $this->PROXY_PORT = '8080';
  875. $this->PAYPAL_URL = 'https://www.paypal.com/webscr&cmd=_express-checkout&token=';
  876. $this->return_url = '';
  877. $this->cancel_url = '';
  878. $this->VERSION = '3.0';
  879. endif;
  880. }
  881. public function do_capture()
  882. {
  883. // urlencode the needed variables
  884. $this->urlencodeVariables();
  885. /* Construct the request string that will be sent to PayPal.
  886. The variable $nvpstr contains all the variables and is a
  887. name value pair string with & as a delimiter */
  888. $nvpstr = $this->generateNVPString('DoCapture');
  889. // decode the variables incase we still require access to them in our program
  890. $this->urldecodeVariables();
  891. /* Make the API call to PayPal, using API signature.
  892. The API response is stored in an associative array called $this->Response */
  893. $this->Response = $this->hash_call("DoCapture", $nvpstr);
  894. // TODO: Add error handling for the hash_call
  895. /*
  896. *************
  897. if NO SUCCESS
  898. *************
  899. */
  900. if(strtoupper($this->Response["ACK"]) != "SUCCESS" AND strtoupper($this->Response["ACK"]) != "SUCCESSWITHWARNING")
  901. {
  902. $this->Error['TIMESTAMP'] = @$this->Response['TIMESTAMP'];
  903. $this->Error['CORRELATIONID'] = @$this->Response['CORRELATIONID'];
  904. $this->Error['ACK'] = $this->Response['ACK'];
  905. $this->Error['ERRORCODE'] = $this->Response['L_ERRORCODE0'];
  906. $this->Error['SHORTMESSAGE'] = $this->Response['L_SHORTMESSAGE0'];
  907. $this->Error['LONGMESSAGE'] = $this->Response['L_LONGMESSAGE0'];
  908. $this->Error['SEVERITYCODE'] = $this->Response['L_SEVERITYCODE0'];
  909. $this->Error['VERSION'] = @$this->Response['VERSION'];
  910. $this->Error['BUILD'] = @$this->Response['BUILD'];
  911. // TODO: Error codes for AVSCODE and CVV@MATCH
  912. $this->_error = true;
  913. $this->_error_ack = $this->Response['ACK'];
  914. $this->ack = 'Failure';
  915. $this->_error_type = 'paypal';
  916. $this->_error_date = $this->Response['TIMESTAMP'];
  917. $this->_error_code = $this->Response['L_ERRORCODE0'];
  918. $this->_error_short_message = $this->Response['L_SHORTMESSAGE0'];
  919. $this->_error_long_message = $this->Response['L_LONGMESSAGE0'];
  920. $this->_error_severity_code = $this->Response['L_SEVERITYCODE0'];
  921. $this->_error_version = @$this->Response['VERSION'];
  922. $this->_error_build = @$this->Response['BUILD'];
  923. return false;
  924. }
  925. /*
  926. *************
  927. if SUCCESS
  928. *************
  929. */
  930. elseif(strtoupper($this->Response["ACK"]) == 'SUCCESS' OR strtoupper($this->Response["ACK"]) == 'SUCCESSWITHWARNING')
  931. {
  932. /* Take the response variables and put them into the local class variables */
  933. foreach($this->ResponseFieldsArray['DoCapture'] as $key => $value)
  934. $this->$key = $this->Response[$value];
  935. return true;
  936. }
  937. }
  938. public function do_authorization()
  939. {
  940. // urlencode the needed variables
  941. $this->urlencodeVariables();
  942. /* Construct the request string that will be sent to PayPal.
  943. The variable $nvpstr contains all the variables and is a
  944. name value pair string with & as a delimiter */
  945. $nvpstr = $this->generateNVPString('DoAuthorization');
  946. // decode the variables incase we still require access to them in our program
  947. $this->urldecodeVariables();
  948. /* Make the API call to PayPal, using API signature.
  949. The API response is stored in an associative array called $this->Response */
  950. $this->Response = $this->hash_call("DoAuthorization", $nvpstr);
  951. // TODO: Add error handling for the hash_call
  952. /*
  953. *************
  954. if NO SUCCESS
  955. *************
  956. */
  957. if(strtoupper($this->Response["ACK"]) != "SUCCESS" AND strtoupper($this->Response["ACK"]) != "SUCCESSWITHWARNING")
  958. {
  959. $this->Error['TIMESTAMP'] = @$this->Response['TIMESTAMP'];
  960. $this->Error['CORRELATIONID'] = @$this->Response['CORRELATIONID'];
  961. $this->Error['ACK'] = $this->Response['ACK'];
  962. $this->Error['ERRORCODE'] = $this->Response['L_ERRORCODE0'];
  963. $this->Error['SHORTMESSAGE'] = $this->Response['L_SHORTMESSAGE0'];
  964. $this->Error['LONGMESSAGE'] = $this->Response['L_LONGMESSAGE0'];
  965. $this->Error['SEVERITYCODE'] = $this->Response['L_SEVERITYCODE0'];
  966. $this->Error['VERSION'] = @$this->Response['VERSION'];
  967. $this->Error['BUILD'] = @$this->Response['BUILD'];
  968. // TODO: Error codes for AVSCODE and CVV@MATCH
  969. $this->_error = true;
  970. $this->_error_ack = $this->Response['ACK'];
  971. $this->ack = 'Failure';
  972. $this->_error_type = 'paypal';
  973. $this->_error_date = $this->Response['TIMESTAMP'];
  974. $this->_error_code = $this->Response['L_ERRORCODE0'];
  975. $this->_error_short_message = $this->Response['L_SHORTMESSAGE0'];
  976. $this->_error_long_message = $this->Response['L_LONGMESSAGE0'];
  977. $this->_error_severity_code = $this->Response['L_SEVERITYCODE0'];
  978. $this->_error_version = @$this->Response['VERSION'];
  979. $this->_error_build = @$this->Response['BUILD'];
  980. return false;
  981. }
  982. /*
  983. *************
  984. if SUCCESS
  985. *************
  986. */
  987. elseif(strtoupper($this->Response["ACK"]) == 'SUCCESS' OR strtoupper($this->Response["ACK"]) == 'SUCCESSWITHWARNING')
  988. {
  989. /* Take the response variables and put them into the local class variables */
  990. foreach($this->ResponseFieldsArray['DoAuthorization'] as $key => $value)
  991. $this->$key = $this->Response[$value];
  992. return true;
  993. }
  994. }
  995. public function do_reauthorization()
  996. {
  997. // urlencode the needed variables
  998. $this->urlencodeVariables();
  999. /* Construct the request string that will be sent to PayPal.
  1000. The variable $nvpstr contains all the variables and is a
  1001. name value pair string with & as a delimiter */
  1002. $nvpstr = $this->generateNVPString('DoReauthorization');
  1003. // decode the variables incase we still require access to them in our program
  1004. $this->urldecodeVariables();
  1005. /* Make the API call to PayPal, using API signature.
  1006. The API response is stored in an associative array called $this->Response */
  1007. $this->Response = $this->hash_call("DoReauthorization", $nvpstr);
  1008. // TODO: Add error handling for the hash_call
  1009. /*
  1010. *************
  1011. if NO SUCCESS
  1012. *************
  1013. */
  1014. if(strtoupper($this->Response["ACK"]) != "SUCCESS" AND strtoupper($this->Response["ACK"]) != "SUCCESSWITHWARNING")
  1015. {
  1016. $this->Error['TIMESTAMP'] = @$this->Response['TIMESTAMP'];
  1017. $this->Error['CORRELATIONID'] = @$this->Response['CORRELATIONID'];
  1018. $this->Error['ACK'] = $this->Response['ACK'];
  1019. $this->Error['ERRORCODE'] = $this->Response['L_ERRORCODE0'];
  1020. $this->Error['SHORTMESSAGE'] = $this->Response['L_SHORTMESSAGE0'];
  1021. $this->Error['LONGMESSAGE'] = $this->Response['L_LONGMESSAGE0'];
  1022. $this->Error['SEVERITYCODE'] = $this->Response['L_SEVERITYCODE0'];
  1023. $this->Error['VERSION'] = @$this->Response['VERSION'];
  1024. $this->Error['BUILD'] = @$this->Response['BUILD'];
  1025. // TODO: Error codes for AVSCODE and CVV@MATCH
  1026. $this->_error = true;
  1027. $this->_error_ack = $this->Response['ACK'];
  1028. $this->ack = 'Failure';
  1029. $this->_error_type = 'paypal';
  1030. $this->_error_date = $this->Response['TIMESTAMP'];
  1031. $this->_error_code = $this->Response['L_ERRORCODE0'];
  1032. $this->_error_short_message = $this->Response['L_SHORTMESSAGE0'];
  1033. $this->_error_long_message = $this->Response['L_LONGMESSAGE0'];
  1034. $this->_error_severity_code = $this->Response['L_SEVERITYCODE0'];
  1035. $this->_error_version = @$this->Response['VERSION'];
  1036. $this->_error_build = @$this->Response['BUILD'];
  1037. return false;
  1038. }
  1039. /*
  1040. *************
  1041. if SUCCESS
  1042. *************
  1043. */
  1044. elseif(strtoupper($this->Response["ACK"]) == 'SUCCESS' OR strtoupper($this->Response["ACK"]) == 'SUCCESSWITHWARNING')
  1045. {
  1046. /* Take the response variables and put them into the local class variables */
  1047. foreach($this->ResponseFieldsArray['DoReauthorization'] as $key => $value)
  1048. $this->$key = $this->Response[$value];
  1049. return true;
  1050. }
  1051. }
  1052. public function do_void()
  1053. {
  1054. // urlencode the needed variables
  1055. $this->urlencodeVariables();
  1056. /* Construct the request string that will be sent to PayPal.
  1057. The variable $nvpstr contains all the variables and is a
  1058. name value pair string with & as a delimiter */
  1059. $nvpstr = $this->generateNVPString('DoVoid');
  1060. // decode the variables incase we still require access to them in our program
  1061. $this->urldecodeVariables();
  1062. /* Make the API call to PayPal, using API signature.
  1063. The API response is stored in an associative array called $this->Response */
  1064. $this->Response = $this->hash_call("DoVoid", $nvpstr);
  1065. // TODO: Add error handling for the hash_call
  1066. /*
  1067. *************
  1068. if NO SUCCESS
  1069. *************
  1070. */
  1071. if(strtoupper($this->Response["ACK"]) != "SUCCESS" AND strtoupper($this->Response["ACK"]) != "SUCCESSWITHWARNING")
  1072. {
  1073. $this->Error['TIMESTAMP'] = @$this->Response['TIMESTAMP'];
  1074. $this->Error['CORRELATIONID'] = @$this->Response['CORRELATIONID'];
  1075. $this->Error['ACK'] = $this->Response['ACK'];
  1076. $this->Error['ERRORCODE'] = $this->Response['L_ERRORCODE0'];
  1077. $this->Error['SHORTMESSAGE'] = $this->Response['L_SHORTMESSAGE0'];
  1078. $this->Error['LONGMESSAGE'] = $this->Response['L_LONGMESSAGE0'];
  1079. $this->Error['SEVERITYCODE'] = $this->Response['L_SEVERITYCODE0'];
  1080. $this->Error['VERSION'] = @$this->Response['VERSION'];
  1081. $this->Error['BUILD'] = @$this->Response['BUILD'];
  1082. // TODO: Error codes for AVSCODE and CVV@MATCH
  1083. $this->_error = true;
  1084. $this->_error_ack = $this->Response['ACK'];
  1085. $this->ack = 'Failure';
  1086. $this->_error_type = 'paypal';
  1087. $this->_error_date = $this->Response['TIMESTAMP'];
  1088. $this->_error_code = $this->Response['L_ERRORCODE0'];
  1089. $this->_error_short_message = $this->Response['L_SHORTMESSAGE0'];
  1090. $this->_error_long_message = $this->Response['L_LONGMESSAGE0'];
  1091. $this->_error_severity_code = $this->Response['L_SEVERITYCODE0'];
  1092. $this->_error_version = @$this->Response['VERSION'];
  1093. $this->_error_build = @$this->Response['BUILD'];
  1094. return false;
  1095. }
  1096. /*
  1097. *************
  1098. if SUCCESS
  1099. *************
  1100. */
  1101. elseif(strtoupper($this->Response["ACK"]) == 'SUCCESS' OR strtoupper($this->Response["ACK"]) == 'SUCCESSWITHWARNING')
  1102. {
  1103. /* Take the response variables and put them into the local class variables */
  1104. foreach($this->ResponseFieldsArray['DoVoid'] as $key => $value)
  1105. $this->$key = $this->Response[$value];
  1106. return true;
  1107. }
  1108. }
  1109. public function do_direct_payment()
  1110. {
  1111. // urlencode the needed variables
  1112. $this->urlencodeVariables();
  1113. /* Construct the request string that will be sent to PayPal.
  1114. The variable $nvpstr contains all the variables and is a
  1115. name value pair string with & as a delimiter */
  1116. $nvpstr = $this->generateNVPString('DoDirectPayment');
  1117. /* Construct and add any items found in this instance */
  1118. if(!empty($this->ItemsArray))
  1119. {
  1120. // Counter for the total of all the items put together
  1121. $total_items_amount = 0;
  1122. $total_items_tax_amount = 0;
  1123. // Go through the items array
  1124. foreach($this->ItemsArray as $key => $value)
  1125. {
  1126. // Get the array of the current item from the main array
  1127. $current_item = $this->ItemsArray[$key];
  1128. // Add it to the request string
  1129. $nvpstr .= "&L_NAME".$key."=".$current_item['name'].
  1130. "&L_NUMBER".$key."=".$current_item['number'].
  1131. "&L_QTY".$key."=".$current_item['quantity'].
  1132. "&L_TAXAMT".$key."=".$current_item['amount_tax'].
  1133. "&L_AMT".$key."=".$current_item['amount'];
  1134. // Add this item's amount to the total current count
  1135. $total_items_amount += ($current_item['amount'] * $current_item['quantity']);
  1136. $total_items_tax_amount += ($current_item['amount_tax'] * $current_item['quantity']);
  1137. }
  1138. // Set the amount_items for this instance and ITEMAMT added to the request string
  1139. $this->amount_items = $total_items_amount;
  1140. // Add this to our NVP string
  1141. $nvpstr .= "&ITEMAMT=".urlencode($total_items_amount);
  1142. // If our entire tax amount is not set, we will automatically set it based on the items tax amount
  1143. if($this->amount_tax == 0 OR empty($this->amount_tax))
  1144. $nvpstr .= "&TAXAMT=".urlencode($total_items_tax_amount);
  1145. }
  1146. // decode the variables incase we still require access to them in our program
  1147. $this->urldecodeVariables();
  1148. /* Make the API call to PayPal, using API signature.
  1149. The API response is stored in an associative array called $this->Response */
  1150. $this->Response = $this->hash_call("DoDirectPayment", $nvpstr);
  1151. // TODO: Add error handling for the hash_call
  1152. /*
  1153. *************
  1154. if NO SUCCESS
  1155. *************
  1156. */
  1157. if(strtoupper($this->Response["ACK"]) != "SUCCESS" AND strtoupper($this->Response["ACK"]) != "SUCCESSWITHWARNING")
  1158. {
  1159. $this->Error['TIMESTAMP'] = @$this->Response['TIMESTAMP'];
  1160. $this->Error['CORRELATIONID'] = @$this->Response['CORRELATIONID'];
  1161. $this->Error['ACK'] = $this->Response['ACK'];
  1162. $this->Error['ERRORCODE'] = $this->Response['L_ERRORCODE0'];
  1163. $this->Error['SHORTMESSAGE'] = $this->Response['L_SHORTMESSAGE0'];
  1164. $this->Error['LONGMESSAGE'] = $this->Response['L_LONGMESSAGE0'];
  1165. $this->Error['SEVERITYCODE'] = $this->Response['L_SEVERITYCODE0'];
  1166. $this->Error['VERSION'] = @$this->Response['VERSION'];
  1167. $this->Error['BUILD'] = @$this->Response['BUILD'];
  1168. // TODO: Error codes for AVSCODE and CVV@MATCH
  1169. $this->_error = true;
  1170. $this->_error_ack = $this->Response['ACK'];
  1171. $this->ack = 'Failure';
  1172. $this->_error_type = 'paypal';
  1173. $this->_error_date = $this->Response['TIMESTAMP'];
  1174. $this->_error_code = $this->Response['L_ERRORCODE0'];
  1175. $this->_error_short_message = $this->Response['L_SHORTMESSAGE0'];
  1176. $this->_error_long_message = $this->Response['L_LONGMESSAGE0'];
  1177. $this->_error_severity_code = $this->Response['L_SEVERITYCODE0'];
  1178. $this->_error_version = @$this->Response['VERSION'];
  1179. $this->_error_build = @$this->Response['BUILD'];
  1180. return false;
  1181. }
  1182. /*
  1183. *************
  1184. if SUCCESS
  1185. *************
  1186. */
  1187. elseif(strtoupper($this->Response["ACK"]) == 'SUCCESS' OR strtoupper($this->Response["ACK"]) == 'SUCCESSWITHWARNING')
  1188. {
  1189. /* Take the response variables and put them into the local class variables */
  1190. foreach($this->ResponseFieldsArray['DoDirectPayment'] as $key => $value)
  1191. $this->$key = $this->Response[$value];
  1192. return true;
  1193. }
  1194. }
  1195. function set_express_checkout()
  1196. {
  1197. // TODO: Add error handling prior to trying to make PayPal calls. ie: missing amount_total or RETURN_URL
  1198. // urlencode the needed variables
  1199. $this->urlencodeVariables();
  1200. /* Construct the parameter string that describes the PayPal payment
  1201. the varialbes were set in the web form, and the resulting string
  1202. is stored in $nvpstr
  1203. */
  1204. $nvpstr = $this->generateNVPString('SetExpressCheckout');
  1205. // decode the variables incase we still require access to them in our program
  1206. $this->urldecodeVariables();
  1207. /* Make the call to PayPal to set the Express Checkout token
  1208. If the API call succeded, then redirect the buyer to PayPal
  1209. to begin to authorize payment. If an error occured, show the
  1210. resulting errors
  1211. */
  1212. $this->Response = $this->hash_call("SetExpressCheckout", $nvpstr);
  1213. /* Display the API response back to the browser.
  1214. If the response from PayPal was a success, display the response parameters'
  1215. If the response was an error, display the errors received using APIError.php.
  1216. */
  1217. /*
  1218. *************
  1219. if NO SUCCESS
  1220. *************
  1221. */
  1222. if(strtoupper($this->Response["ACK"]) != "SUCCESS")
  1223. {
  1224. $this->Error['TIMESTAMP'] = @$this->Response['TIMESTAMP'];
  1225. $this->Error['CORRELATIONID'] = @$this->Response['CORRELATIONID'];
  1226. $this->Error['ACK'] = $this->Response['ACK'];
  1227. $this->Error['ERRORCODE'] = $this->Response['L_ERRORCODE0'];
  1228. $this->Error['SHORTMESSAGE'] = $this->Response['L_SHORTMESSAGE0'];
  1229. $this->Error['LONGMESSAGE'] = $this->Response['L_LONGMESSAGE0'];
  1230. $this->Error['SEVERITYCODE'] = $this->Response['L_SEVERITYCODE0'];
  1231. $this->Error['VERSION'] = @$this->Response['VERSION'];
  1232. $this->Error['BUILD'] = @$this->Response['BUILD'];
  1233. $this->_error = true;
  1234. $this->_error_ack = $this->Response['ACK'];
  1235. $this->ack = 'Failure';
  1236. $this->_error_type = 'paypal';
  1237. $this->_error_date = $this->Response['TIMESTAMP'];
  1238. $this->_error_code = $this->Response['L_ERRORCODE0'];
  1239. $this->_error_short_message = $this->Response['L_SHORTMESSAGE0'];
  1240. $this->_error_long_message = $this->Response['L_LONGMESSAGE0'];
  1241. $this->_error_severity_code = $this->Response['L_SEVERITYCODE0'];
  1242. $this->_error_version = @$this->Response['VERSION'];
  1243. $this->_error_build = @$this->Response['BUILD'];
  1244. return false;
  1245. /*
  1246. $_SESSION['reshash']=$this->Response;
  1247. $location = "APIError.php";
  1248. header("Location: $location");
  1249. */
  1250. }
  1251. /*
  1252. *************
  1253. if SUCCESS
  1254. *************
  1255. */
  1256. elseif(strtoupper($this->Response["ACK"]) == 'SUCCESS')
  1257. {
  1258. /* Take the response variables and put them into the local class variables */
  1259. foreach($this->ResponseFieldsArray['SetExpressCheckout'] as $key => $value)
  1260. $this->$key = $this->Response[$value];
  1261. return true;
  1262. }
  1263. }
  1264. function set_express_checkout_successful_redirect()
  1265. {
  1266. // Redirect to paypal.com here
  1267. $token = urlencode($this->Response["TOKEN"]);
  1268. $paypal_url = $this->PAYPAL_URL.$token;
  1269. header("Location: ".$paypal_url);
  1270. }
  1271. function get_express_checkout_details()
  1272. {
  1273. // TODO: Add error handling prior to PayPal calls. ie: missing TOKEN
  1274. /* At this point, the buyer has completed in authorizing payment
  1275. at PayPal. The script will now call PayPal with the details
  1276. of the authorization, incuding any shipping information of the
  1277. buyer. Remember, the authorization is not a completed transaction
  1278. at this state - the buyer still needs an additional step to finalize
  1279. the transaction
  1280. */
  1281. /* Build a second API request to PayPal, using the token as the
  1282. ID to get the details on the payment authorization
  1283. */
  1284. /* Construct the parameter string that describes the PayPal payment
  1285. the varialbes were set in the web form, and the resulting string
  1286. is stored in $nvpstr
  1287. */
  1288. $nvpstr = $this->generateNVPString('GetExpressCheckoutDetails');
  1289. /* Make the API call and store the results in an array. If the
  1290. call was a success, show the authorization details, and provide
  1291. an action to complete the payment. If failed, show the error
  1292. */
  1293. $this->Response = $this->hash_call("GetExpressCheckoutDetails", $nvpstr);
  1294. /*
  1295. *************
  1296. if NO SUCCESS
  1297. *************
  1298. */
  1299. if(strtoupper($this->Response["ACK"]) != "SUCCESS")
  1300. {
  1301. $this->Error['TIMESTAMP'] = @$this->Response['TIMESTAMP'];
  1302. $this->Error['CORRELATIONID'] = @$this->Response['CORRELATIONID'];
  1303. $this->Error['ACK'] = $this->Response['ACK'];
  1304. $this->Error['ERRORCODE'] = $this->Response['L_ERRORCODE0'];
  1305. $this->Error['SHORTMESSAGE'] = $this->Response['L_SHORTMESSAGE0'];
  1306. $this->Error['LONGMESSAGE'] = $this->Response['L_LONGMESSAGE0'];
  1307. $this->Error['SEVERITYCODE'] = $this->Response['L_SEVERITYCODE0'];
  1308. $this->Error['VERSION'] = @$this->Response['VERSION'];
  1309. $this->Error['BUILD'] = @$this->Response['BUILD'];
  1310. $this->_error = true;
  1311. $this->_error_ack = $this->Response['ACK'];
  1312. $this->ack = 'Failure';
  1313. $this->_error_type = 'paypal';
  1314. $this->_error_date = $this->Response['TIMESTAMP'];
  1315. $this->_error_code = $this->Response['L_ERRORCODE0'];
  1316. $this->_error_short_message = $this->Response['L_SHORTMESSAGE0'];
  1317. $this->_error_long_message = $this->Response['L_LONGMESSAGE0'];
  1318. $this->_error_severity_code = $this->Response['L_SEVERITYCODE0'];
  1319. $this->_error_version = @$this->Response['VERSION'];
  1320. $this->_error_build = @$this->Response['BUILD'];
  1321. return false;
  1322. }
  1323. /*
  1324. ***********
  1325. if SUCCESS
  1326. ***********
  1327. */
  1328. elseif(strtoupper($this->Response["ACK"]) == 'SUCCESS')
  1329. {
  1330. /*
  1331. Take the response variables and put them into the local class variables
  1332. */
  1333. foreach($this->ResponseFieldsArray['GetExpressCheckoutDetails'] as $key => $value)
  1334. $this->$key = @$this->Response[$value];
  1335. return true;
  1336. }
  1337. }
  1338. function do_express_checkout_payment()
  1339. {
  1340. // TODO: Error checking. ie: we require a token and payer_id here
  1341. // urlencode the needed variables
  1342. $this->urlencodeVariables();
  1343. /* Construct the parameter string that describes the PayPal payment
  1344. the varialbes were set in the web form, and the resulting string
  1345. is stored in $nvpstr
  1346. */
  1347. $nvpstr = $this->generateNVPString('DoExpressCheckoutPayment');
  1348. /* Construct and add any items found in this instance */
  1349. if(!empty($this->ItemsArray))
  1350. {
  1351. // Counter for the total of all the items put together
  1352. $total_items_amount = 0;
  1353. // Go through the items array
  1354. foreach($this->ItemsArray as $key => $value)
  1355. {
  1356. // Get the array of the current item from the main array
  1357. $current_item = $this->ItemsArray[$key];
  1358. // Add it to the request string
  1359. $nvpstr .= "&L_NAME".$key."=".$current_item['name'].
  1360. "&L_NUMBER".$key."=".$current_item['number'].
  1361. "&L_QTY".$key."=".$current_item['quantity'].
  1362. "&L_TAXAMT".$key."=".$current_item['amount_tax'].
  1363. "&L_AMT".$key."=".$current_item['amount'];
  1364. // Add this item's amount to the total current count
  1365. $total_items_amount += ($current_item['amount'] * $current_item['quantity']);
  1366. }
  1367. // Set the amount_items for this instance and ITEMAMT added to the request string
  1368. $this->amount_items = $total_items_amount;
  1369. $nvpstr .= "&ITEMAMT=".$total_items_amount;
  1370. }
  1371. /* Make the call to PayPal to finalize payment
  1372. If an error occured, show the resulting errors
  1373. */
  1374. $this->Response = $this->hash_call("DoExpressCheckoutPayment", $nvpstr);
  1375. // decode the variables incase we still require access to them in our program
  1376. $this->urldecodeVariables();
  1377. /*
  1378. *************
  1379. if NO SUCCESS
  1380. *************
  1381. */
  1382. if(strtoupper($this->Response["ACK"]) != "SUCCESS")
  1383. {
  1384. $this->Error['TIMESTAMP'] = @$this->Response['TIMESTAMP'];
  1385. $this->Error['CORRELATIONID'] = @$this->Response['CORRELATIONID'];
  1386. $this->Error['ACK'] = $this->Response['ACK'];
  1387. $this->Error['ERRORCODE'] = $this->Response['L_ERRORCODE0'];
  1388. $this->Error['SHORTMESSAGE'] = $this->Response['L_SHORTMESSAGE0'];
  1389. $this->Error['LONGMESSAGE'] = $this->Response['L_LONGMESSAGE0'];
  1390. $this->Error['SEVERITYCODE'] = $this->Response['L_SEVERITYCODE0'];
  1391. $this->Error['VERSION'] = @$this->Response['VERSION'];
  1392. $this->Error['BUILD'] = @$this->Response['BUILD'];
  1393. $this->_error = true;
  1394. $this->_error_ack = $this->Response['ACK'];
  1395. $this->ack = 'Failure';
  1396. $this->_error_type = 'paypal';
  1397. $this->_error_date = $this->Response['TIMESTAMP'];
  1398. $this->_error_code = $this->Response['L_ERRORCODE0'];
  1399. $this->_error_short_message = $this->Response['L_SHORTMESSAGE0'];
  1400. $this->_error_long_message = $this->Response['L_LONGMESSAGE0'];
  1401. $this->_error_severity_code = $this->Response['L_SEVERITYCODE0'];
  1402. $this->_error_version = @$this->Response['VERSION'];
  1403. $this->_error_build = @$this->Response['BUILD'];
  1404. return false;
  1405. }
  1406. /*
  1407. *************
  1408. if SUCCESS
  1409. *************
  1410. */
  1411. elseif(strtoupper($this->Response["ACK"]) == 'SUCCESS')
  1412. {
  1413. /*
  1414. Take the response variables and put them into the local class variables
  1415. */
  1416. foreach($this->ResponseFieldsArray['DoExpressCheckoutPayment'] as $key => $value)
  1417. $this->$key = @$this->Response[$value];
  1418. return true;
  1419. }
  1420. }
  1421. function get_transaction_details()
  1422. {
  1423. /* Construct the parameter string that describes the PayPal payment
  1424. the varialbes were set in the web form, and the resulting string
  1425. is stored in $nvpstr
  1426. */
  1427. $nvpstr = $this->generateNVPString('GetTransactionDetails');
  1428. /* Make the API call to PayPal, using API signature.
  1429. The API response is stored in an associative array called $resArray */
  1430. $this->Response = $this->hash_call("GetTransactionDetails", $nvpstr);
  1431. /* Next, collect the API request in the associative array $reqArray
  1432. as well to display back to the browser.
  1433. Normally you wouldnt not need to do this, but its shown for testing */
  1434. /*
  1435. *************
  1436. if NO SUCCESS
  1437. *************
  1438. */
  1439. if(strtoupper($this->Response["ACK"]) != "SUCCESS")
  1440. {
  1441. $this->Error['TIMESTAMP'] = @$this->Response['TIMESTAMP'];
  1442. $this->Error['CORRELATIONID'] = @$this->Response['CORRELATIONID'];
  1443. $this->Error['ACK'] = $this->Response['ACK'];
  1444. $this->Error['ERRORCODE'] = $this->Response['L_ERRORCODE0'];
  1445. $this->Error['SHORTMESSAGE'] = $this->Response['L_SHORTMESSAGE0'];
  1446. $this->Error['LONGMESSAGE'] = $this->Response['L_LONGMESSAGE0'];
  1447. $this->Error['SEVERITYCODE'] = $this->Response['L_SEVERITYCODE0'];
  1448. $this->Error['VERSION'] = @$this->Response['VERSION'];
  1449. $this->Error['BUILD'] = @$this->Response['BUILD'];
  1450. $this->_error = true;
  1451. $this->_error_ack = $this->Response['ACK'];
  1452. $this->ack = 'Failure';
  1453. $this->_error_type = 'paypal';
  1454. $this->_error_date = $this->Response['TIMESTAMP'];
  1455. $this->_error_code = $this->Response['L_ERRORCODE0'];
  1456. $this->_error_short_message = $this->Response['L_SHORTMESSAGE0'];
  1457. $this->_error_long_message = $this->Response['L_LONGMESSAGE0'];
  1458. $this->_error_severity_code = $this->Response['L_SEVERITYCODE0'];
  1459. $this->_error_version = @$this->Response['VERSION'];
  1460. $this->_error_build = @$this->Response['BUILD'];
  1461. return false;
  1462. }
  1463. /*
  1464. *************
  1465. if SUCCESS
  1466. *************
  1467. */
  1468. elseif(strtoupper($this->Response["ACK"]) == 'SUCCESS')
  1469. {
  1470. /* Take the response variables and put them into the local class variables */
  1471. foreach($this->ResponseFieldsArray['GetTransactionDetails'] as $key => $value)
  1472. $this->$key = $this->Response[$value];
  1473. $this->getItems($this->Response);
  1474. return true;
  1475. }
  1476. }
  1477. function refund_transaction()
  1478. {
  1479. /* Construct the parameter string that describes the PayPal payment
  1480. the varialbes were set in the web form, and the resulting string
  1481. is stored in $nvpstr
  1482. */
  1483. $nvpstr = $this->generateNVPString('RefundTransaction');
  1484. /* Make the API call to PayPal, using API signature.
  1485. The API response is stored in an associative array called $resArray */
  1486. $this->Response = $this->hash_call("RefundTransaction", $nvpstr);
  1487. /* Next, collect the API request in the associative array $reqArray
  1488. as well to display back to the browser.
  1489. Normally you wouldnt not need to do this, but its shown for testing */
  1490. /*
  1491. *************
  1492. if NO SUCCESS
  1493. *************
  1494. */
  1495. if(strtoupper($this->Response["ACK"]) != "SUCCESS")
  1496. {
  1497. $this->Error['TIMESTAMP'] = @$this->Response['TIMESTAMP'];
  1498. $this->Error['CORRELATIONID'] = @$this->Response['CORRELATIONID'];
  1499. $this->Error['ACK'] = $this->Response['ACK'];
  1500. $this->Error['ERRORCODE'] = $this->Response['L_ERRORCODE0'];
  1501. $this->Error['SHORTMESSAGE'] = $this->Response['L_SHORTMESSAGE0'];
  1502. $this->Error['LONGMESSAGE'] = $this->Response['L_LONGMESSAGE0'];
  1503. $this->Error['SEVERITYCODE'] = $this->Response['L_SEVERITYCODE0'];
  1504. $this->Error['VERSION'] = @$this->Response['VERSION'];
  1505. $this->Error['BUILD'] = @$this->Response['BUILD'];
  1506. $this->_error = true;
  1507. $this->_error_ack = $this->Response['ACK'];
  1508. $this->ack = 'Failure';
  1509. $this->_error_type = 'paypal';
  1510. $this->_error_date = $this->Response['TIMESTAMP'];
  1511. $this->_error_code = $this->Response['L_ERRORCODE0'];
  1512. $this->_error_short_message = $this->Response['L_SHORTMESSAGE0'];
  1513. $this->_error_long_message = $this->Response['L_LONGMESSAGE0'];
  1514. $this->_error_severity_code = $this->Response['L_SEVERITYCODE0'];
  1515. $this->_error_version = @$this->Response['VERSION'];
  1516. $this->_error_build = @$this->Response['BUILD'];
  1517. return false;
  1518. }
  1519. /*
  1520. *************
  1521. if SUCCESS
  1522. *************
  1523. */
  1524. elseif(strtoupper($this->Response["ACK"]) == 'SUCCESS')
  1525. {
  1526. /* Take the response variables and put them into the local class variables */
  1527. foreach($this->ResponseFieldsArray['RefundTransaction'] as $key => $value)
  1528. $this->$key = $this->Response[$value];
  1529. $this->getItems($this->Response);
  1530. return true;
  1531. }
  1532. }
  1533. function create_recurring_payments_profile()
  1534. {
  1535. $this->urlencodeVariables();
  1536. $nvpstr = $this->generateNVPString('CreateRecurringPaymentsProfile');
  1537. $this->Response = $this->hash_call("CreateRecurringPaymentsProfile", $nvpstr);
  1538. $this->urldecodeVariables();
  1539. if(strtoupper($this->Response["ACK"]) != "SUCCESS")
  1540. {
  1541. $this->Error['TIMESTAMP'] = @$this->Response['TIMESTAMP'];
  1542. $this->Error['CORRELATIONID'] = @$this->Response['CORRELATIONID'];
  1543. $this->Error['ACK'] = $this->Response['ACK'];
  1544. $this->Error['ERRORCODE'] = $this->Response['L_ERRORCODE0'];
  1545. $this->Error['SHORTMESSAGE'] = $this->Response['L_SHORTMESSAGE0'];
  1546. $this->Error['LONGMESSAGE'] = $this->Response['L_LONGMESSAGE0'];
  1547. $this->Error['SEVERITYCODE'] = $this->Response['L_SEVERITYCODE0'];
  1548. $this->Error['VERSION'] = @$this->Response['VERSION'];
  1549. $this->Error['BUILD'] = @$this->Response['BUILD'];
  1550. $this->_error = true;
  1551. $this->_error_ack = $this->Response['ACK'];
  1552. $this->ack = 'Failure';
  1553. $this->_error_type = 'paypal';
  1554. $this->_error_date = $this->Response['TIMESTAMP'];
  1555. $this->_error_code = $this->Response['L_ERRORCODE0'];
  1556. $this->_error_short_message = $this->Response['L_SHORTMESSAGE0'];
  1557. $this->_error_long_message = $this->Response['L_LONGMESSAGE0'];
  1558. $this->_error_severity_code = $this->Response['L_SEVERITYCODE0'];
  1559. $this->_error_version = @$this->Response['VERSION'];
  1560. $this->_error_build = @$this->Response['BUILD'];
  1561. return false;
  1562. }
  1563. elseif(strtoupper($this->Response["ACK"]) == 'SUCCESS')
  1564. {
  1565. /*
  1566. Take the response variables and put them into the local class variables
  1567. */
  1568. foreach($this->ResponseFieldsArray['CreateRecurringPaymentsProfile'] as $key => $value)
  1569. $this->$key = $this->Response[$value];
  1570. return true;
  1571. }
  1572. }
  1573. function get_recurring_payments_profile_details()
  1574. {
  1575. $nvpstr = $this->generateNVPString('GetRecurringPaymentsProfileDetails');
  1576. $this->Response = $this->hash_call("GetRecurringPaymentsProfileDetails", $nvpstr);
  1577. if(strtoupper($this->Response["ACK"]) != "SUCCESS")
  1578. {
  1579. $this->Error['TIMESTAMP'] = @$this->Response['TIMESTAMP'];
  1580. $this->Error['CORRELATIONID'] = @$this->Response['CORRELATIONID'];
  1581. $this->Error['ACK'] = $this->Response['ACK'];
  1582. $this->Error['ERRORCODE'] = $this->Response['L_ERRORCODE0'];
  1583. $this->Error['SHORTMESSAGE'] = $this->Response['L_SHORTMESSAGE0'];
  1584. $this->Error['LONGMESSAGE'] = $this->Response['L_LONGMESSAGE0'];
  1585. $this->Error['SEVERITYCODE'] = $this->Response['L_SEVERITYCODE0'];
  1586. $this->Error['VERSION'] = @$this->Response['VERSION'];
  1587. $this->Error['BUILD'] = @$this->Response['BUILD'];
  1588. $this->_error = true;
  1589. $this->_error_ack = $this->Response['ACK'];
  1590. $this->ack = 'Failure';
  1591. $this->_error_type = 'paypal';
  1592. $this->_error_date = $this->Response['TIMESTAMP'];
  1593. $this->_error_code = $this->Response['L_ERRORCODE0'];
  1594. $this->_error_short_message = $this->Response['L_SHORTMESSAGE0'];
  1595. $this->_error_long_message = $this->Response['L_LONGMESSAGE0'];
  1596. $this->_error_severity_code = $this->Response['L_SEVERITYCODE0'];
  1597. $this->_error_version = @$this->Response['VERSION'];
  1598. $this->_error_build = @$this->Response['BUILD'];
  1599. return false;
  1600. }
  1601. elseif(strtoupper($this->Response["ACK"]) == 'SUCCESS')
  1602. {
  1603. foreach($this->ResponseFieldsArray['GetRecurringPaymentsProfileDetails'] as $key => $value)
  1604. $this->$key = $this->Response[$value];
  1605. $this->getItems($this->Response);
  1606. return true;
  1607. }
  1608. }
  1609. function update_recurring_payments_profile()
  1610. {
  1611. $this->urlencodeVariables();
  1612. $nvpstr = $this->generateNVPString('UpdateRecurringPaymentsProfile');
  1613. $this->urldecodeVariables();
  1614. $this->Response = $this->hash_call("UpdateRecurringPaymentsProfile", $nvpstr);
  1615. if(strtoupper($this->Response["ACK"]) != "SUCCESS")
  1616. {
  1617. $this->Error['TIMESTAMP'] = @$this->Response['TIMESTAMP'];
  1618. $this->Error['CORRELATIONID'] = @$this->Response['CORRELATIONID'];
  1619. $this->Error['ACK'] = $this->Response['ACK'];
  1620. $this->Error['ERRORCODE'] = $this->Response['L_ERRORCODE0'];
  1621. $this->Error['SHORTMESSAGE'] = $this->Response['L_SHORTMESSAGE0'];
  1622. $this->Error['LONGMESSAGE'] = $this->Response['L_LONGMESSAGE0'];
  1623. $this->Error['SEVERITYCODE'] = $this->Response['L_SEVERITYCODE0'];
  1624. $this->Error['VERSION'] = @$this->Response['VERSION'];
  1625. $this->Error['BUILD'] = @$this->Response['BUILD'];
  1626. $this->_error = true;
  1627. $this->_error_ack = $this->Response['ACK'];
  1628. $this->ack = 'Failure';
  1629. $this->_error_type = 'paypal';
  1630. $this->_error_date = $this->Response['TIMESTAMP'];
  1631. $this->_error_code = $this->Response['L_ERRORCODE0'];
  1632. $this->_error_short_message = $this->Response['L_SHORTMESSAGE0'];
  1633. $this->_error_long_message = $this->Response['L_LONGMESSAGE0'];
  1634. $this->_error_severity_code = $this->Response['L_SEVERITYCODE0'];
  1635. $this->_error_version = @$this->Response['VERSION'];
  1636. $this->_error_build = @$this->Response['BUILD'];
  1637. return false;
  1638. }
  1639. elseif(strtoupper($this->Response["ACK"]) == 'SUCCESS')
  1640. {
  1641. foreach($this->ResponseFieldsArray['UpdateRecurringPaymentsProfile'] as $key => $value)
  1642. $this->$key = $this->Response[$value];
  1643. return true;
  1644. }
  1645. }
  1646. public function do_reference_transaction()
  1647. {
  1648. // urlencode the needed variables
  1649. $this->urlencodeVariables();
  1650. /* Construct the request string that will be sent to PayPal.
  1651. The variable $nvpstr contains all the variables and is a
  1652. name value pair string with & as a delimiter */
  1653. $nvpstr = $this->generateNVPString('DoReferenceTransaction');
  1654. /* Construct and add any items found in this instance */
  1655. if(!empty($this->ItemsArray))
  1656. {
  1657. // Counter for the total of all the items put together
  1658. $total_items_amount = 0;
  1659. $total_items_tax_amount = 0;
  1660. // Go through the items array
  1661. foreach($this->ItemsArray as $key => $value)
  1662. {
  1663. // Get the array of the current item from the main array
  1664. $current_item = $this->ItemsArray[$key];
  1665. // Add it to the request string
  1666. $nvpstr .= "&L_NAME".$key."=".$current_item['name'].
  1667. "&L_NUMBER".$key."=".$current_item['number'].
  1668. "&L_QTY".$key."=".$current_item['quantity'].
  1669. "&L_TAXAMT".$key."=".$current_item['amount_tax'].
  1670. "&L_AMT".$key."=".$current_item['amount'];
  1671. // Add this item's amount to the total current count
  1672. $total_items_amount += ($current_item['amount'] * $current_item['quantity']);
  1673. $total_items_tax_amount += ($current_item['amount_tax'] * $current_item['quantity']);
  1674. }
  1675. // Set the amount_items for this instance and ITEMAMT added to the request string
  1676. $this->amount_items = $total_items_amount;
  1677. // Add this to our NVP string
  1678. $nvpstr .= "&ITEMAMT=".urlencode($total_items_amount);
  1679. // If our entire tax amount is not set, we will automatically set it based on the items tax amount
  1680. if($this->amount_tax == 0 OR empty($this->amount_tax))
  1681. $nvpstr .= "&TAXAMT=".urlencode($total_items_tax_amount);
  1682. }
  1683. // decode the variables incase we still require access to them in our program
  1684. $this->urldecodeVariables();
  1685. /* Make the API call to PayPal, using API signature.
  1686. The API response is stored in an associative array called $this->Response */
  1687. $this->Response = $this->hash_call("DoReferenceTransaction", $nvpstr);
  1688. // TODO: Add error handling for the hash_call
  1689. /*
  1690. *************
  1691. if NO SUCCESS
  1692. *************
  1693. */
  1694. if(strtoupper($this->Response["ACK"]) != "SUCCESS" AND strtoupper($this->Response["ACK"]) != "SUCCESSWITHWARNING")
  1695. {
  1696. $this->Error['TIMESTAMP'] = @$this->Response['TIMESTAMP'];
  1697. $this->Error['CORRELATIONID'] = @$this->Response['CORRELATIONID'];
  1698. $this->Error['ACK'] = $this->Response['ACK'];
  1699. $this->Error['ERRORCODE'] = $this->Response['L_ERRORCODE0'];
  1700. $this->Error['SHORTMESSAGE'] = $this->Response['L_SHORTMESSAGE0'];
  1701. $this->Error['LONGMESSAGE'] = $this->Response['L_LONGMESSAGE0'];
  1702. $this->Error['SEVERITYCODE'] = $this->Response['L_SEVERITYCODE0'];
  1703. $this->Error['VERSION'] = @$this->Response['VERSION'];
  1704. $this->Error['BUILD'] = @$this->Response['BUILD'];
  1705. // TODO: Error codes for AVSCODE and CVV@MATCH
  1706. $this->_error = true;
  1707. $this->_error_ack = $this->Response['ACK'];
  1708. $this->ack = 'Failure';
  1709. $this->_error_type = 'paypal';
  1710. $this->_error_date = $this->Response['TIMESTAMP'];
  1711. $this->_error_code = $this->Response['L_ERRORCODE0'];
  1712. $this->_error_short_message = $this->Response['L_SHORTMESSAGE0'];
  1713. $this->_error_long_message = $this->Response['L_LONGMESSAGE0'];
  1714. $this->_error_severity_code = $this->Response['L_SEVERITYCODE0'];
  1715. $this->_error_version = @$this->Response['VERSION'];
  1716. $this->_error_build = @$this->Response['BUILD'];
  1717. return false;
  1718. }
  1719. /*
  1720. *************
  1721. if SUCCESS
  1722. *************
  1723. */
  1724. elseif(strtoupper($this->Response["ACK"]) == 'SUCCESS' OR strtoupper($this->Response["ACK"]) == 'SUCCESSWITHWARNING')
  1725. {
  1726. /* Take the response variables and put them into the local class variables */
  1727. foreach($this->ResponseFieldsArray['DoReferenceTransaction'] as $key => $value)
  1728. $this->$key = $this->Response[$value];
  1729. return true;
  1730. }
  1731. }
  1732. /**
  1733. * hash_call: Function to perform the API call to PayPal using API signature
  1734. * @methodName is name of API method.
  1735. * @nvpStr is nvp string.
  1736. * returns an associtive array containing the response from the server.
  1737. */
  1738. private function hash_call($methodName, $nvpStr)
  1739. {
  1740. //setting the curl parameters.
  1741. $ch = curl_init();
  1742. curl_setopt($ch, CURLOPT_URL,$this->API_ENDPOINT);
  1743. curl_setopt($ch, CURLOPT_VERBOSE, 1);
  1744. //turning off the server and peer verification(TrustManager Concept).
  1745. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  1746. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  1747. curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  1748. curl_setopt($ch, CURLOPT_POST, 1);
  1749. //if USE_PROXY constant set to TRUE in Constants.php, then only proxy will be enabled.
  1750. //Set proxy name to PROXY_HOST and port number to PROXY_PORT in constants.php
  1751. if($this->USE_PROXY)
  1752. curl_setopt ($ch, CURLOPT_PROXY, $this->PROXY_HOST.":".$this->PROXY_PORT);
  1753. //NVPRequest for submitting to server
  1754. $nvpreq = "METHOD=".urlencode($methodName)."&VERSION=".urlencode($this->VERSION)."&PWD=".urlencode($this->API_PASSWORD).
  1755. "&USER=".urlencode($this->API_USERNAME)."&SIGNATURE=".urlencode($this->API_SIGNATURE).$nvpStr;
  1756. //setting the nvpreq as POST FIELD to curl
  1757. curl_setopt($ch,CURLOPT_POSTFIELDS,$nvpreq);
  1758. //getting response from server
  1759. $response = curl_exec($ch);
  1760. //convrting NVPResponse to an Associative Array
  1761. $nvpResArray = $this->deformatNVP($response);
  1762. $nvpReqArray = $this->deformatNVP($nvpreq);
  1763. $_SESSION['nvpReqArray'] = $nvpReqArray;
  1764. /*
  1765. *************
  1766. if NO SUCCESS
  1767. *************
  1768. */
  1769. if (curl_errno($ch))
  1770. {
  1771. // moving to display page to display curl errors
  1772. $_SESSION['curl_error_no'] = curl_errno($ch) ;
  1773. $_SESSION['curl_error_msg'] = curl_error($ch);
  1774. $this->_error = true;
  1775. $this->ack = 'Failure';
  1776. $this->_error_type = 'curl';
  1777. $this->_error_date = date("Y-m-d H:i:s");
  1778. $this->_error_code = curl_errno($ch);
  1779. $this->_error_short_message = 'There was an error trying to contact the PayPal servers. (curl error) See long message for details.';
  1780. $this->_error_long_message = curl_error($ch);
  1781. return false;
  1782. }
  1783. /*
  1784. *************
  1785. if SUCCESS
  1786. *************
  1787. */
  1788. else
  1789. {
  1790. //closing the curl
  1791. curl_close($ch);
  1792. }
  1793. return $nvpResArray;
  1794. }
  1795. /** This function will take NVPString and convert it to an Associative Array and it will decode the response.
  1796. * It is usefull to search for a particular key and displaying arrays.
  1797. * @nvpstr is NVPString.
  1798. * @nvpArray is an Associative Array.
  1799. */
  1800. private function deformatNVP($nvpstr)
  1801. {
  1802. $intial=0;
  1803. $nvpArray = array();
  1804. while(strlen($nvpstr))
  1805. {
  1806. //postion of Key
  1807. $keypos= strpos($nvpstr,'=');
  1808. //position of value
  1809. $valuepos = strpos($nvpstr,'&') ? strpos($nvpstr,'&'): strlen($nvpstr);
  1810. /*getting the Key and Value values and storing in a Associative Array*/
  1811. $keyval=substr($nvpstr,$intial,$keypos);
  1812. $valval=substr($nvpstr,$keypos+1,$valuepos-$keypos-1);
  1813. //decoding the respose
  1814. $nvpArray[urldecode($keyval)] =urldecode( $valval);
  1815. $nvpstr=substr($nvpstr,$valuepos+1,strlen($nvpstr));
  1816. }
  1817. return $nvpArray;
  1818. }
  1819. /* This function will add an item to the itemArray for use in doDirectPayment and doExpressCheckoutPayment */
  1820. public function addItem($name, $number, $quantity, $amount_tax, $amount)
  1821. {
  1822. $new_item = array(
  1823. 'name' => $name,
  1824. 'number' => $number,
  1825. 'quantity' => $quantity,
  1826. 'amount_tax' => $amount_tax,
  1827. 'amount' => $amount);
  1828. $this->ItemsArray[] = $new_item;
  1829. // TODO: Should recalculate and set $this->amount_items after every new item is added. Or is this done on each request?
  1830. }
  1831. private function getItems($passed_response)
  1832. {
  1833. // Clear any current items
  1834. $this->ItemsArray = '';
  1835. // Get the items if there are any
  1836. // Start this off by checking for a first item
  1837. if(!empty($passed_response['L_NAME0']) OR !empty($passed_response['L_NUMBER0']) OR !empty($passed_response['L_QTY0']))
  1838. {
  1839. $i = 0;
  1840. // Start a loop to get all the items (up to 200)
  1841. // We'll break out of it if we stop finding items
  1842. while($i < 200)
  1843. {
  1844. // One of the Name, Number, and Qty fields may be empty, so check all of them
  1845. // and if any of them are filled, then we have an item
  1846. if(!empty($passed_response['L_NAME'.$i]) OR !empty($passed_response['L_NUMBER'.$i]) OR !empty($passed_response['L_QTY'.$i]))
  1847. {
  1848. $new_item = array(
  1849. 'name' => $passed_response['L_NAME'.$i],
  1850. 'number' => $passed_response['L_NUMBER'.$i],
  1851. 'quantity' => $passed_response['L_QTY'.$i],
  1852. 'amount_tax' => $passed_response['L_TAXAMT'.$i],
  1853. 'amount' => $passed_response['L_AMT'.$i]);
  1854. $this->ItemsArray[] = $new_item;
  1855. $i++;
  1856. }
  1857. else
  1858. break;
  1859. } // end while
  1860. } // end if
  1861. } // end function
  1862. private function generateNVPString($type)
  1863. {
  1864. $temp_nvp_str = '';
  1865. // Go through the selected RequestFieldsArray and create the request string based on whether the field is required or filled
  1866. // TODO: return error if required field is empty?
  1867. foreach($this->RequestFieldsArray[$type] as $key => $value)
  1868. {
  1869. if($value['required'] == 'yes')
  1870. $temp_nvp_str .= '&'.$value['name'].'='.$this->$key;
  1871. elseif(!empty($this->$key))
  1872. $temp_nvp_str .= '&'.$value['name'].'='.$this->$key;
  1873. }
  1874. return $temp_nvp_str;
  1875. }
  1876. /* This function encodes all applicable variables for transport to PayPal */
  1877. private function urlencodeVariables()
  1878. {
  1879. // Decode all specified variables
  1880. $this->payment_type = urlencode($this->payment_type);
  1881. $this->email = urlencode($this->email);
  1882. $this->first_name = urlencode($this->first_name);
  1883. $this->last_name = urlencode($this->last_name);
  1884. $this->credit_card_type = urlencode($this->credit_card_type);
  1885. $this->credit_card_number = urlencode($this->credit_card_number);
  1886. // Month must be padded with leading zero
  1887. $this->expire_date = urlencode(str_pad($this->expire_date, 6, '0', STR_PAD_LEFT));
  1888. $this->cvv2_code = urlencode($this->cvv2_code);
  1889. $this->address1 = urlencode($this->address1);
  1890. $this->address2 = urlencode($this->address2);
  1891. $this->city = urlencode($this->city);
  1892. $this->state = urlencode($this->state);
  1893. $this->postal_code = urlencode($this->postal_code);
  1894. $this->country_code = urlencode($this->country_code);
  1895. $this->currency_code = urlencode($this->currency_code);
  1896. $this->ip_address = urlencode($this->ip_address);
  1897. $this->shipping_name = urlencode($this->shipping_name);
  1898. $this->shipping_address1 = urlencode($this->shipping_address1);
  1899. $this->shipping_address2 = urlencode($this->shipping_address2);
  1900. $this->shipping_city = urlencode($this->shipping_city);
  1901. $this->shipping_state = urlencode($this->shipping_state);
  1902. $this->shipping_postal_code = urlencode($this->shipping_postal_code);
  1903. $this->shipping_country_code = urlencode($this->shipping_country_code);
  1904. $this->shipping_phone_number = urlencode($this->shipping_phone_number);
  1905. $this->amount_total = urlencode($this->amount_total);
  1906. $this->amount_shipping = urlencode($this->amount_shipping);
  1907. $this->amount_tax = urlencode($this->amount_tax);
  1908. $this->amount_handling = urlencode($this->amount_handling);
  1909. $this->amount_items = urlencode($this->amount_items);
  1910. $this->token = urlencode($this->token);
  1911. $this->payer_id = urlencode($this->payer_id);
  1912. if(!empty($this->ItemsArray))
  1913. {
  1914. // Go through the items array
  1915. foreach($this->ItemsArray as $key => $value)
  1916. {
  1917. // Get the array of the current item from the main array
  1918. $current_item = $this->ItemsArray[$key];
  1919. // Encode everything
  1920. // TODO: use a foreach loop instead
  1921. $current_item['name'] = urlencode($current_item['name']);
  1922. $current_item['number'] = urlencode($current_item['number']);
  1923. $current_item['quantity'] = urlencode($current_item['quantity']);
  1924. $current_item['amount_tax'] = urlencode($current_item['amount_tax']);
  1925. $current_item['amount'] = urlencode($current_item['amount']);
  1926. // Put the encoded array back in the item array (replaces previous array)
  1927. $this->ItemsArray[$key] = $current_item;
  1928. }
  1929. }
  1930. }
  1931. /* This function Decodes all applicable variables for use in application/database */
  1932. private function urldecodeVariables()
  1933. {
  1934. // Decode all specified variables
  1935. $this->payment_type = urldecode($this->payment_type);
  1936. $this->email = urldecode($this->email);
  1937. $this->first_name = urldecode($this->first_name);
  1938. $this->last_name = urldecode($this->last_name);
  1939. $this->credit_card_type = urldecode($this->credit_card_type);
  1940. $this->credit_card_number = urldecode($this->credit_card_number);
  1941. // Month must be padded with leading zero
  1942. $this->expire_date = urldecode(str_pad($this->expire_date, 6, '0', STR_PAD_LEFT));
  1943. $this->cvv2_code = urldecode($this->cvv2_code);
  1944. $this->address1 = urldecode($this->address1);
  1945. $this->address2 = urldecode($this->address2);
  1946. $this->city = urldecode($this->city);
  1947. $this->state = urldecode($this->state);
  1948. $this->postal_code = urldecode($this->postal_code);
  1949. $this->country_code = urldecode($this->country_code);
  1950. $this->currency_code = urldecode($this->currency_code);
  1951. $this->ip_address = urldecode($this->ip_address);
  1952. $this->shipping_name = urldecode($this->shipping_name);
  1953. $this->shipping_address1 = urldecode($this->shipping_address1);
  1954. $this->shipping_address2 = urldecode($this->shipping_address2);
  1955. $this->shipping_city = urldecode($this->shipping_city);
  1956. $this->shipping_state = urldecode($this->shipping_state);
  1957. $this->shipping_postal_code = urldecode($this->shipping_postal_code);
  1958. $this->shipping_country_code = urldecode($this->shipping_country_code);
  1959. $this->shipping_phone_number = urldecode($this->shipping_phone_number);
  1960. $this->amount_total = urldecode($this->amount_total);
  1961. $this->amount_shipping = urldecode($this->amount_shipping);
  1962. $this->amount_tax = urldecode($this->amount_tax);
  1963. $this->amount_handling = urldecode($this->amount_handling);
  1964. $this->amount_items = urldecode($this->amount_items);
  1965. $this->token = urldecode($this->token);
  1966. $this->payer_id = urldecode($this->payer_id);
  1967. if(!empty($this->ItemsArray))
  1968. {
  1969. // Go through the items array
  1970. foreach($this->ItemsArray as $key => $value)
  1971. {
  1972. // Get the array of the current item from the main array
  1973. $current_item = $this->ItemsArray[$key];
  1974. // Decode everything
  1975. // TODO: use a foreach loop instead
  1976. $current_item['name'] = urldecode($current_item['name']);
  1977. $current_item['number'] = urldecode($current_item['number']);
  1978. $current_item['quantity'] = urldecode($current_item['quantity']);
  1979. $current_item['amount_tax'] = urldecode($current_item['amount_tax']);
  1980. $current_item['amount'] = urldecode($current_item['amount']);
  1981. // Put the decoded array back in the item array (replaces previous array)
  1982. $this->ItemsArray[$key] = $current_item;
  1983. }
  1984. }
  1985. }
  1986. } // END CLASS