Source for file examples.php

Documentation is available at examples.php

  1. <?php
  2.  
  3. /**
  4.  * List of Examples
  5.  *
  6.  * This file contains an example of how each operation is supposed to be carried out.
  7.  * 
  8.  * I have commented out all the examples, simply uncomment the operations you wish to test
  9.  * 
  10.  * The examples here are presented using fictitious data, to reproduce the results you will have
  11.  * to substitute the equivalent data with those of your own. Thank you.
  12.  * 
  13.  * You are required to sign up for your own API username, password and signature
  14.  * 
  15.  * The examples will be in the following order for all the operations supported by this program:
  16.  * 
  17.  * Simply include the file paypal_base.php and then you can go ahead to select any of the operations available
  18.  * 
  19.  * - DoDirectPayment
  20.  * - SetExpressCheckout
  21.  * - GetExpressCheckoutDetails
  22.  * - DoExpressCheckoutPayment
  23.  * 
  24.  * More of the API operations shall be supported in the subsequent versions of this program
  25.  *  
  26.  * @author Israel Ekpo <perfectvista@users.sourceforge.net>
  27.  * @copyright Copyright 2007, Israel Ekpo
  28.  * @license http://phppaypalpro.sourceforge.net/LICENSE.txt BSD License
  29.  * @version 0.1
  30.  * @package PaypalBase
  31.  * @filesource
  32.  */
  33.  
  34.  
  35. require_once('paypal_base.php');
  36.  
  37. $paymentAction 'Sale';
  38.  
  39. $currencyId 'USD';
  40.  
  41. $salutation 'Mr.';
  42. $fname      'Israel';
  43. $lname      'Ekpo';
  44. $address1   '123 Main Street';
  45. $address2   'Apt 987';
  46. $city       'North Miami Beach';
  47. $state      'FL';
  48. $zip        '33181';
  49. $cc_country 'US';
  50.  
  51. $phone      '3059449455';
  52.  
  53. $cc_type    'Visa';
  54. $cc_number  '4147706547894046';
  55. $cv2        '917';
  56. $exp_month  '12';
  57. $exp_year   '2007';
  58.  
  59. $email       'paypal@example.net';
  60.  
  61. $item_desc   'Cool Sourceforge Software Example';
  62.  
  63. $order_desc  'Purchase from PerfectVista Technologies, Inc';
  64. $custom      'WebPurchase';
  65.  
  66. $invoice     =  date('U');
  67.  
  68. $ip  $_SERVER['REMOTE_ADDR'];
  69.  
  70. $unique_session_id session_id();
  71.  
  72. $item1 40.00;
  73. $item2 20.00;
  74. $item3 30.00;
  75.  
  76. $tax1 7.00;
  77. $tax2 14.00;
  78. $tax3 21.00;
  79.  
  80. $item_total  $item1 $item2 $item3;
  81.  
  82. $tax         $tax1 $tax2 $tax3;    
  83.  
  84. $shipping    25.00;
  85. $handling    75.00;
  86.  
  87. $order_total $item_total $shipping $handling $tax;
  88.  
  89.  
  90. // Setting up the Authentication information
  91. // Such as Username, Password, Signature and Subject
  92.  
  93. $API new WebsitePaymentsPro();
  94.  
  95. $API_USERNAME 'ibb_api1.perfectvista.net';
  96.  
  97. $API_PASSWORD 'RMMP25ATEC3PZJX8';
  98.  
  99. $API_SIGNATURE 'AiPC9BjkCyDFQXbSkoZcgqH3hpacA4EAG6uE6TDmFNlGFx6LWKnsoGLG';
  100.  
  101. $API->prepare($API_USERNAME$API_PASSWORD$API_SIGNATURE);
  102.  
  103. /*
  104. // DoDirectPayment
  105. //==========================================================================================================
  106.  
  107. $Paypal = $API->selectOperation('DoDirectPayment');
  108.  
  109. $Address = PayPalTypes::AddressType($fname . ''. $lname, $address1, $address2, $city, $state, $zip, $cc_country, $phone);
  110.  
  111. $PersonName = PayPalTypes::PersonNameType($salutation, $fname, '', $lname);
  112.  
  113. $PayerInfo = PayPalTypes::PayerInfoType($email, 'israelekpo', 'verified', $PersonName, $cc_country, '', $Address);
  114.  
  115. $CreditCardDetails = PayPalTypes::CreditCardDetailsType($cc_type, $cc_number, $exp_month, $exp_year, $PayerInfo, $cv2);
  116.  
  117. $PaymentDetails = PayPalTypes::PaymentDetailsType($order_total, $item_total, $shipping, $handling, $tax, $order_desc, $custom, $invoice, '', 'http://phppaypalpro.sourceforge.net/ipn_notify.php', $Address);
  118.  
  119. $Paypal->setParams($paymentAction, $PaymentDetails, $CreditCardDetails, $ip, $unique_session_id);
  120.  
  121. $Paypal->addPaymentItem('Perfume for Ladies', 'Item Number 90887', 1, $tax1, $item1, $currencyId);
  122. $Paypal->addPaymentItem('Cologne for Gentlement', 'Item Number 90888', 1, $tax2, $item2, $currencyId);
  123. $Paypal->addPaymentItem('Toys for Kids', 'Item Number 90889', 1, $tax3, $item3, $currencyId);
  124.  
  125. $Paypal->execute();
  126.  
  127. if ($Paypal->success())
  128. {
  129.     $response = $Paypal->getAPIResponse();
  130. }
  131. else 
  132. {
  133.     $response = $Paypal->getAPIException();
  134. }
  135.  
  136.  
  137. var_dump($response);
  138.  
  139.  
  140.  
  141.  
  142. // SetExpressCheckout
  143. // On Success Will return a token with value like EC-7EG51014BE327234S
  144. // Customer should then be redirected by your server to URL like 
  145. // https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-7EG51014BE327234S
  146. // Customer will then enter payment at paypal.com and upon success customer will be sent back to the $ReturnURL
  147. // that you provided in the operation with the tokon and PayerID appended as parameters to the $ReturnURL
  148. //==========================================================================================================
  149.  
  150. $Paypal = $API->selectOperation('SetExpressCheckout');
  151.  
  152. $OrderTotal = 300.00;
  153.  
  154. $ReturnURL = 'http://phppaypalpro.sourceforge.net/return_url.php';
  155.  
  156. $CancelURL = 'http://phppaypalpro.sourceforge.net/cancel_url.php';
  157.  
  158. $PaymentAction = 'Sale'; // or Order
  159.  
  160. $Paypal->setParams($OrderTotal, $ReturnURL, $CancelURL, $PaymentAction);
  161.  
  162. $Paypal->execute();
  163.  
  164. if ($Paypal->success())
  165. {
  166.     var_dump($Paypal->getAPIResponse());
  167. } else 
  168. {
  169.     var_dump($Paypal->getAPIException());
  170.  
  171.  
  172. // GetExpressCheckoutDetails
  173.  
  174. // At the $Return URL get the ExpressCheckoutDetails by calling this operation using the token
  175. // The PayperID will be used in the next step, DoExpressCheckoutPayment
  176. // This operation returns all the details about the person making the payment (name, contact info etc)
  177. //==========================================================================================================
  178.  
  179. $Paypal = $API->selectOperation('GetExpressCheckoutDetails');
  180.  
  181. $Token = $_REQUEST['token'];
  182.  
  183. $Paypal->setParams($Token);
  184.  
  185. $Paypal->execute();
  186.  
  187. if ($Paypal->success())
  188. {
  189.     var_dump($Paypal->getAPIResponse());
  190.     
  191. else 
  192. {
  193.     var_dump($Paypal->getAPIException());
  194.  
  195.  
  196. // DoExpressCheckoutPayment
  197. // The $token and $PayerID are used in this operation to complete the transaction.
  198. // This is where the final Paypal Transaction ID like 4PJ31634YK772325W will be issued.
  199. //==========================================================================================================
  200.   
  201.  
  202. $Paypal = $API->selectOperation('DoExpressCheckoutPayment');
  203.  
  204. $PaymentAction = 'Sale'; // or Order
  205.  
  206. $Token = $_REQUEST['token'];
  207.  
  208. $PayerID = $_REQUEST['PayerID'];
  209.  
  210. $Address = PayPalTypes::AddressType($fname . ''. $lname, $address1, $address2, $city, $state, $zip, $cc_country, $phone);
  211.  
  212. $item_desc   = 'Cool Sourceforge Software';
  213.  
  214. $order_desc  = 'Purchase from PerfectVista Technologies';
  215. $custom      = 'WebPurchase';
  216.  
  217. $invoice     =  date('U');
  218.  
  219. $ip  = $_SERVER['REMOTE_ADDR'];
  220.  
  221. $unique_session_id = session_id();
  222.  
  223. $item1 = 40.00;
  224. $item2 = 20.00;
  225. $item3 = 30.00;
  226.  
  227. $tax1 = 7.00;
  228. $tax2 = 14.00;
  229. $tax3 = 21.00;
  230.  
  231. $item_total  = $item1 + $item2 + $item3;
  232.  
  233. $tax         = $tax1 + $tax2 + $tax3;    
  234.  
  235. $shipping    = 25.00;
  236. $handling    = 75.00;
  237.  
  238. $order_total = $item_total + $shipping + $handling + $tax;
  239.  
  240. $PaymentDetails = PayPalTypes::PaymentDetailsType($order_total, $item_total, $shipping, $handling, $tax, $order_desc, $custom, $invoice, '', 'http://phppaypalpro.sourceforge.net/ipn_notify.php', $Address);
  241.  
  242. $Paypal->setParams($PaymentAction, $Token, $PayerID, $PaymentDetails);
  243.  
  244. $Paypal->addPaymentItem('Perfume for Ladies', 'Item Number 90887', 1, $tax1, $item1, $currencyId);
  245. $Paypal->addPaymentItem('Cologne for Gentlement', 'Item Number 90888', 1, $tax2, $item2, $currencyId);
  246. $Paypal->addPaymentItem('Toys for Kids', 'Item Number 90889', 1, $tax3, $item3, $currencyId);
  247.  
  248.  
  249. $Paypal->execute();
  250.  
  251. if ($Paypal->success())
  252. {
  253.  
  254.     var_dump($Paypal->getAPIResponse());
  255. else 
  256. {
  257.     var_dump($Paypal->getAPIException());
  258. */
  259.  
  260. /*
  261. //
  262. // TransactionSearch
  263. // Searching for a set of Transactions by passing certain criteria to the Paypal Webservice
  264. //==========================================================================================================
  265.  
  266. $Paypal = $API->selectOperation('TransactionSearch');
  267. $StartDate  = strtotime('2006-11-19');
  268. $EndDate    = strtotime('2006-11-25');
  269.  
  270. $PayerEmail = 'sbb@perfectvista.net';
  271. $ReceiverEmail = 'perfectvista@users.sourceforge.net';
  272. $ReceiptID = '2XF249546X016870H'; 
  273. $TransactionID = '8A5447438G757964A'; 
  274. $PayerName = PayPalTypes::PersonNameType($salutation, $fname, '', $lname); 
  275. $AuctionItemNumber = ''; 
  276. $InvoiceID = '9876542'; 
  277. $CardNumber = '4010582588585520';
  278.  
  279. $TransactionClass = 'Sent'; // One of: Received, Masspay, MoneyRequest, 
  280. // OR FundsAdded, FundsWithdrawn, Referral, Fee, Subscription, 
  281. // OR Divdend, BillPay, Refund, CurrencyConversions, BalanceTransfer, Reversal, 
  282. // OR Shipping, BalanceAffecting, Echeck
  283.  
  284. $Amount = '9.35';
  285. $CurrencyCode = 'USD'; 
  286. $Status = 'Success'; // One of: Processing, Success, Denied, Reversed
  287. $currencyID = 'USD';
  288.  
  289. // If the value is an empty string that parameter will be excluded from the search criteria.
  290.  
  291. $Paypal->setParams($StartDate, $EndDate, $PayerEmail, $ReceiverEmail, $ReceiptID, $TransactionID, $PayerName, $AuctionItemNumber, $InvoiceID, $CardNumber, $TransactionClass, $Amount, $CurrencyCode, $Status, $currencyId);
  292.  
  293. $Paypal->execute();
  294.  
  295. if ($Paypal->success())
  296. {
  297.     $response = $Paypal->getAPIResponse();
  298.     
  299. else 
  300. {
  301.     $response = $Paypal->getAPIException();
  302. }
  303.  
  304. echo '<pre>';
  305. var_dump($response);
  306. echo '</pre>';
  307.  
  308. */
  309.  
  310. /*
  311. // GetTransactionDetails
  312. // Retrieves the Transaction Details for a specific transaction by passing certain criteria to the Paypal Webservice.
  313. // The details available here are better than those for the Transaction Search
  314. //==========================================================================================================
  315.  
  316. $Paypal = $API->selectOperation('GetTransactionDetails');
  317.  
  318. $TransactionID = '11A317146P6709549';
  319.  
  320. $Paypal->setParams($TransactionID);
  321.  
  322. $Paypal->execute();
  323.  
  324. if ($Paypal->success())
  325. {
  326.     $response = $Paypal->getAPIResponse();
  327.     
  328. }
  329.  
  330. else 
  331. {
  332.     $response = $Paypal->getAPIException();
  333. }
  334.  
  335. echo "<pre>";
  336. var_dump($response);
  337. echo "</pre>";
  338. */
  339.  
  340. ?>

Documentation generated on Sat, 03 Feb 2007 20:59:00 -0800 by phpDocumentor 1.3.1