Source for file paypal_types.php

Documentation is available at paypal_types.php

  1. <?php
  2.  
  3. /**
  4.  * Preparation of WebService DataTypes
  5.  * 
  6.  * Copyright (C) 2007 Israel Ekpo
  7.  * 
  8.  * Contains the class which has methods that generates a list of datatypes (arrays) used by the webs service.
  9.  * Most of the datatypes are passed to the SoapClient->__soapCall() method as multi-dimensional arrays.
  10.  * 
  11.  * @package PaypalTypes
  12.  * @author Israel Ekpo <israelekpo@sourceforge.net>
  13.  * @copyright Copyright 2007, Israel Ekpo
  14.  * @version 0.1.0
  15.  * @license http://phppaypalpro.sourceforge.net/LICENSE.txt BSD License
  16.  * @filesource
  17.  */
  18.  
  19. /**
  20.  * This class contains the list of all the Data Types used when contacting the Paypal webservice
  21.  * 
  22.  * @package PaypalTypes
  23.  * @author Israel Ekpo <israelekpo@sourceforge.net>
  24.  * @copyright Copyright 2007, Israel Ekpo
  25.  * @license http://phppaypalpro.sourceforge.net/LICENSE.txt BSD License
  26.  * @version 0.1.0
  27.  * @filesource
  28.  */
  29. {   
  30.     /**
  31.      * Formats the Amount according to the BasicAmountType
  32.      *
  33.      * This method creates a classical example of an element that has an attribute.
  34.      * For example <element attribute1='attr1' attribute2='attr2'>value</element>
  35.      * will be created as array('_' => 'value', 'attr1' => 'attribute1', 'attr2' => 'attribute2');
  36.      * 
  37.      * @param string $amount 
  38.      * @param string $currencyID 
  39.      * @usedby PaypalTypes::PaymentDetailsType()
  40.      * @usedby PaypalTypes::PaymentDetailsItemType()
  41.      * @return BasicAmountType 
  42.      */
  43.     static public function BasicAmountType($amount '0.00'$currencyID 'USD')
  44.     {
  45.         $BasicAmountType['_'number_format($amount2);
  46.         $BasicAmountType['currencyID'$currencyID;
  47.         
  48.         return $BasicAmountType;
  49.     }
  50.     
  51.     /**
  52.      * Prepares the AddressType
  53.      * 
  54.      * This method is used to generate the AddressType for Payment information.
  55.      *
  56.      * @param string $Name 
  57.      * @param string $Street1 
  58.      * @param string $Street2 
  59.      * @param string $CityName 
  60.      * @param string $StateOrProvince 
  61.      * @param string $PostalCode 
  62.      * @param string $Country 
  63.      * @param string $Phone 
  64.      * @return AddressType 
  65.      */
  66.     static public function AddressType($Name ''$Street1 ''$Street2 ''$CityName ''$StateOrProvince ''$PostalCode ''$Country ''$Phone '')
  67.     {
  68.         $AddressType['Name'$Name;
  69.         $AddressType['Street1'$Street1;
  70.         $AddressType['Street2'$Street2;
  71.         $AddressType['CityName'$CityName;
  72.         $AddressType['StateOrProvince'$StateOrProvince;
  73.         $AddressType['Country'$Country;
  74.         $AddressType['PostalCode'$PostalCode;
  75.         $AddressType['Phone'$Phone;
  76.         
  77.         return $AddressType;
  78.     }
  79.     
  80.     /**
  81.      * Prepares the PersonNameType
  82.      * 
  83.      * The person name type is used to format the name information for onward inclusion in the SOAP message.
  84.      *
  85.      * @param string $Salutation 
  86.      * @param string $FirstName 
  87.      * @param string $MiddleName 
  88.      * @param string $LastName 
  89.      * @param string $Suffix 
  90.      * @return PersonNameType 
  91.      */
  92.     static public function PersonNameType($Salutation ''$FirstName ''$MiddleName ''$LastName ''$Suffix '')
  93.     {
  94.         if ($Salutation)
  95.         {
  96.             $PersonNameType['Salutation'$Salutation;
  97.         }
  98.         
  99.         $PersonNameType['FirstName'$FirstName;
  100.         
  101.         if ($MiddleName)
  102.         {
  103.             $PersonNameType['MiddleName'$MiddleName;
  104.         }
  105.         
  106.         $PersonNameType['LastName']  $LastName;
  107.         
  108.         if ($Suffix)
  109.         {
  110.             $PersonNameType['Suffix'$Suffix;
  111.         }
  112.         
  113.         return $PersonNameType;
  114.     }
  115.     
  116.     /**
  117.      * Prepares the PayerInfoType
  118.      *
  119.      * The PayerInfoType uses the AddressType and PersonNameType to generate a multi-dimensional array
  120.      * that will in turn be used as part of a SOAP message.
  121.      * 
  122.      * @param EmailAddressType $Payer e.g buyer@gmail.com
  123.      * @param string $PayerID 
  124.      * @param string $PayerStatus verified, unverified
  125.      * @param PersonNameType $PayerName 
  126.      * @param string $PayerCountry 
  127.      * @param string $PayerBusiness 
  128.      * @param AddressType $Address 
  129.      * @param string $ContactPhone 
  130.      * @return PayerInfoType 
  131.      */
  132.     static public function PayerInfoType($Payer ''$PayerID ''$PayerStatus 'verified'$PayerName$PayerCountry'US'$PayerBusiness ''$Address$ContactPhone '')
  133.     {
  134.         $PayerInfoType['Payer'$Payer;
  135.         $PayerInfoType['PayerID'$PayerID;
  136.         $PayerInfoType['PayerStatus'$PayerStatus;
  137.         $PayerInfoType['PayerName'$PayerName;
  138.         $PayerInfoType['PayerCountry'$PayerCountry;
  139.         
  140.         if ($PayerBusiness)
  141.         {
  142.             $PayerInfoType['PayerBusiness'$PayerBusiness;
  143.         }
  144.         
  145.         $PayerInfoType['Address'$Address;
  146.         
  147.         if ($ContactPhone)
  148.         {
  149.             $PayerInfoType['ContactPhone'$ContactPhone;
  150.         }
  151.         
  152.         return $PayerInfoType;
  153.     }
  154.     
  155.     /**
  156.      * Makes the CreditCardDetailsType
  157.      * 
  158.      * This is a very essential data type because it has to be formatted correctly. This method is used to
  159.      * generate an array that is going to be part of the payment details submitted to paypal.
  160.      *
  161.      * @param string $CreditCardType Visa,MasterCard,Amex,Discover,Solo,Switch
  162.      * @param string $CreditCardNumber 
  163.      * @param int $ExpMonth 
  164.      * @param int $ExpYear 
  165.      * @param PayerInfoType $CardOwner 
  166.      * @param string $CVV2 
  167.      * @return CreditCardDetailsType 
  168.      */
  169.     static public function CreditCardDetailsType($CreditCardType$CreditCardNumber$ExpMonth$ExpYear$CardOwner$CVV2 '')
  170.     {
  171.         $CreditCardDetailsType['CreditCardType'$CreditCardType;
  172.         $CreditCardDetailsType['CreditCardNumber'$CreditCardNumber;
  173.         $CreditCardDetailsType['ExpMonth'$ExpMonth;
  174.         $CreditCardDetailsType['ExpYear'$ExpYear;
  175.         $CreditCardDetailsType['CardOwner'$CardOwner;
  176.         
  177.         if($CVV2)
  178.         {
  179.             $CreditCardDetailsType['CVV2'$CVV2;
  180.         }
  181.         
  182.         return $CreditCardDetailsType;
  183.     }
  184.     
  185.     /**
  186.      * Makes PaymentDetailsItemType
  187.      *
  188.      * This generates details about a particular payment item. An array is returned which contains the name, quantity
  189.      * and amound of each item added to the payment.
  190.      * 
  191.      * @param string $Name 
  192.      * @param string $Number 
  193.      * @param integer $Quantity 
  194.      * @param BasicAmountType $Tax 
  195.      * @param BasicAmountType $Amount 
  196.      * @param string $CurrencyID 
  197.      * @return PaymentDetailsItemType 
  198.      */
  199.     static public function PaymentDetailsItemType($Name ''$Number ''$Quantity 1$Tax ''$Amount ''$CurrencyID 'USD')
  200.     {
  201.         $PaymentDetailsItemType['Name'$Name;
  202.         $PaymentDetailsItemType['Number'$Number;
  203.         $PaymentDetailsItemType['Quantity'$Quantity;
  204.         
  205.         if ($Tax)
  206.         {
  207.             $PaymentDetailsItemType['Tax'self::BasicAmountType($Tax$CurrencyID);
  208.         }
  209.         
  210.         if ($Amount)
  211.         {
  212.             $PaymentDetailsItemType['Amount'self::BasicAmountType($Amount$CurrencyID);
  213.         }
  214.         
  215.         return $PaymentDetailsItemType;
  216.     }
  217.     
  218.     /**
  219.      * Creates the PaymentDetailsType
  220.      *
  221.      * This is a critical part of the DoDirectPayment and DoExpressCheckOutPayment operations.
  222.      * The payment details is an overall summary of the payment to be sent to the paypal web service.
  223.      * 
  224.      * @param BasicAmountType $OrderTotal 
  225.      * @param BasicAmountType $ItemTotal 
  226.      * @param BasicAmountType $ShippingTotal 
  227.      * @param BasicAmountType $HandlingTotal 
  228.      * @param BasicAmountType $TaxTotal 
  229.      * @param string $OrderDescription 
  230.      * @param string $Custom 
  231.      * @param string $InvoiceID 
  232.      * @param string $ButtonSource 
  233.      * @param string $NotifyURL Paypal IPN URL
  234.      * @param AddressType $ShipToAddress 
  235.      * @param PaymentDetailsItemType $PaymentDetailsItem 
  236.      * @param string $CurrencyID 
  237.      * @return PaymentDetailsType 
  238.      */
  239.     static public function PaymentDetailsType($OrderTotal$ItemTotal ='0.00'$ShippingTotal '0.00'$HandlingTotal '0.00'$TaxTotal '0.00'$OrderDescription ''$Custom ''$InvoiceID ''$ButtonSource ''$NotifyURL ''$ShipToAddress ''$PaymentDetailsItem array()$CurrencyID'USD')
  240.     {
  241.         $PaymentDetailsType['OrderTotal'self::BasicAmountType($OrderTotal$CurrencyID);
  242.         $PaymentDetailsType['ItemTotal'self::BasicAmountType($ItemTotal$CurrencyID);
  243.         $PaymentDetailsType['ShippingTotal'self::BasicAmountType($ShippingTotal$CurrencyID);
  244.         $PaymentDetailsType['HandlingTotal'self::BasicAmountType($HandlingTotal$CurrencyID);
  245.         $PaymentDetailsType['TaxTotal'self::BasicAmountType($TaxTotal$CurrencyID);
  246.         $PaymentDetailsType['OrderDescription'$OrderDescription;
  247.         $PaymentDetailsType['Custom'$Custom;
  248.         $PaymentDetailsType['InvoiceID'$InvoiceID;
  249.         $PaymentDetailsType['ButtonSource'$ButtonSource;
  250.         $PaymentDetailsType['NotifyURL'$NotifyURL;
  251.         $PaymentDetailsType['ShipToAddress'$ShipToAddress;
  252.         $PaymentDetailsType['PaymentDetailsItem'$PaymentDetailsItem;
  253.  
  254.         return $PaymentDetailsType;
  255.     }
  256.     
  257.     /**
  258.      * Prepares the DoDirectPaymentRequestDetailsType
  259.      *
  260.      * This basically returns a multi-dimensional array with the Payment Action. Credit Card information, User IP
  261.      * address and the merchant's session id.
  262.      * 
  263.      * @param string $PaymentAction This could be a Sale or Order.
  264.      * @param PaymentDetailsType $PaymentDetails 
  265.      * @param CreditCardDetailsType $CreditCard 
  266.      * @param string $IPAddress 
  267.      * @param string $MerchantSessionId 
  268.      * @return DoDirectPaymentRequestDetailsType 
  269.      */
  270.     static public function DoDirectPaymentRequestDetailsType($PaymentAction$PaymentDetails$CreditCard$IPAddress$MerchantSessionId)
  271.     {
  272.         $DoDirectPaymentRequestDetailsType['PaymentAction'$PaymentAction;
  273.         $DoDirectPaymentRequestDetailsType['PaymentDetails'$PaymentDetails;
  274.         $DoDirectPaymentRequestDetailsType['CreditCard'$CreditCard;
  275.         $DoDirectPaymentRequestDetailsType['IPAddress'$IPAddress;
  276.         $DoDirectPaymentRequestDetailsType['MerchantSessionId'$MerchantSessionId;
  277.         
  278.         return $DoDirectPaymentRequestDetailsType;
  279.     }
  280.     
  281.     /**
  282.      * Prepares the SetExpressCheckoutRequestDetailsType
  283.      * 
  284.      * This is an array with the Amount, Return URL, Cancellation URL and Payment Action (Sale or Order)
  285.      *
  286.      * @param BasicAmountType $OrderTotal 
  287.      * @param string $ReturnURL 
  288.      * @param string $CancelURL 
  289.      * @param string $PaymentAction Sale or Order
  290.      * @return SetExpressCheckoutRequestDetailsType 
  291.      */
  292.     static public function SetExpressCheckoutRequestDetailsType($OrderTotal$ReturnURL$CancelURL$PaymentAction$currencyID 'USD')
  293.     {
  294.         $SetExpressCheckoutRequestDetailsType['OrderTotal'self::BasicAmountType($OrderTotal$currencyID);
  295.         $SetExpressCheckoutRequestDetailsType['ReturnURL'$ReturnURL;
  296.         $SetExpressCheckoutRequestDetailsType['CancelURL'$CancelURL;
  297.         $SetExpressCheckoutRequestDetailsType['PaymentAction'$PaymentAction;
  298.         
  299.         return $SetExpressCheckoutRequestDetailsType;
  300.     }
  301.     
  302.     /**
  303.      * Makes the DoExpressCheckoutPaymentRequestDetailsType
  304.      *
  305.      * This returns the Payment action, Token value, Payer ID and Payment details as a multi-dimensional array.
  306.      * 
  307.      * @param string $PaymentAction Order or Sale
  308.      * @param string $Token 
  309.      * @param string $PayerID 
  310.      * @param PaymentDetailsType $PaymentDetails 
  311.      * @return DoExpressCheckoutPaymentRequestDetailsType 
  312.      */
  313.     static public function DoExpressCheckoutPaymentRequestDetailsType($PaymentAction$Token$PayerID$PaymentDetails)
  314.     {
  315.         $DoExpressCheckoutPaymentRequestDetailsType['PaymentAction'$PaymentAction;
  316.         $DoExpressCheckoutPaymentRequestDetailsType['Token'$Token;
  317.         $DoExpressCheckoutPaymentRequestDetailsType['PayerID'$PayerID;
  318.         $DoExpressCheckoutPaymentRequestDetailsType['PaymentDetails'$PaymentDetails;
  319.         
  320.         return $DoExpressCheckoutPaymentRequestDetailsType;
  321.     }
  322.     
  323.     /**
  324.      * Makes the UserIdPasswordType
  325.      *
  326.      * This prepares the authentication message to be passed to paypal. It is an array
  327.      * with the Username, Password and Signature of the user. If the payment is being made on behalf of
  328.      * another account then the username of that account has to be passed as the subject.
  329.      * 
  330.      * @param string $Username 
  331.      * @param string $Password 
  332.      * @param string $Signature 
  333.      * @param string $Subject 
  334.      * @return UserIdPasswordType 
  335.      */
  336.     static public function UserIdPasswordType($Username ''$Password ''$Signature ''$Subject'')
  337.     {
  338.         
  339.        $UserIdPasswordType['Username'$Username;
  340.        $UserIdPasswordType['Password'$Password;
  341.        $UserIdPasswordType['Signature'$Signature;
  342.        
  343.        if ($Subject)
  344.        {
  345.            $UserIdPasswordType['Subject'$Subject;
  346.        }
  347.        
  348.        return $UserIdPasswordType;
  349.     }
  350.     
  351.     /**
  352.      * Returns the date in the ISO 8601 format
  353.      *
  354.      * Generates the ISO 8601 format using the UNIX timestamp supplied. Like 2007-02-02T01:36:06-05:00
  355.      * which is basically the year, month, day, 24-hour format, minutes, seconds and time zone like -05:00 for EST
  356.      * 
  357.      * @param integer $timeStamp the Unix Timestamp
  358.      * @return string 
  359.      */
  360.     static public function dateTimeType($timeStamp 0)
  361.     {
  362.         $timeStamp = (int) $timeStamp;
  363.         
  364.         if (!$timeStamp)
  365.         {
  366.             return date('c');
  367.         }
  368.         else 
  369.         {
  370.             return date('c'$timeStamp);
  371.         }
  372.     }
  373.     
  374.     /**
  375.      * Generates the TransactionSearchRequestType
  376.      * 
  377.      * Prepares a multi-dimensional array to be used in the search.
  378.      *
  379.      * @uses self::dateTimeType
  380.      * @param integer $StartDate UNIXTIMESTAMP
  381.      * @param intefer $EndDate UNIXTIMESTAMP
  382.      * @param string $PayerEmail 
  383.      * @param string $ReceiverEmail 
  384.      * @param string $ReceiptID 
  385.      * @param string $TransactionID 
  386.      * @param string $PayerName 
  387.      * @param string $AuctionItemNumber 
  388.      * @param string $InvoiceID 
  389.      * @param string $CardNumber 
  390.      * @param string $TransactionClass 
  391.      * @param BasicAmountType $Amount 
  392.      * @param string $CurrencyCode 
  393.      * @param string $Status 
  394.      * @return TransactionSearchRequestType 
  395.      */
  396.     static public function TransactionSearchRequestType($StartDate$EndDate 0$PayerEmail ''$ReceiverEmail ''$ReceiptID ''$TransactionID ''$PayerName ''$AuctionItemNumber ''$InvoiceID ''$CardNumber ''$TransactionClass ''$Amount ''$CurrencyCode ''$Status ''$currencyID 'USD')
  397.     {
  398.         $TransactionSearchRequestType['StartDate'self::dateTimeType($StartDate);
  399.         
  400.         if ($EndDate)
  401.         {
  402.             $TransactionSearchRequestType['EndDate'self::dateTimeType($EndDate);
  403.         }
  404.         
  405.         if ($PayerEmail)
  406.         {
  407.             $TransactionSearchRequestType['Payer'$PayerEmail;
  408.         }
  409.         
  410.         if ($ReceiverEmail)
  411.         {
  412.             $TransactionSearchRequestType['Receiver'$ReceiverEmail;
  413.         }
  414.         
  415.         if ($ReceiptID)
  416.         {
  417.             $TransactionSearchRequestType['ReceiptID'$ReceiptID;
  418.         }
  419.                 
  420.         if ($TransactionID)
  421.         {
  422.             $TransactionSearchRequestType['TransactionID'$TransactionID;
  423.         }
  424.         
  425.         if ($PayerName)
  426.         {
  427.             $TransactionSearchRequestType['PayerName'$PayerName;
  428.         }
  429.         
  430.         if ($AuctionItemNumber)
  431.         {
  432.             $TransactionSearchRequestType['AuctionItemNumber'$AuctionItemNumber;
  433.         }
  434.                 
  435.         if ($InvoiceID)
  436.         {
  437.             $TransactionSearchRequestType['InvoiceID'$InvoiceID;
  438.         }
  439.         
  440.         if ($CardNumber)
  441.         {
  442.             $TransactionSearchRequestType['CardNumber'$CardNumber;
  443.         }
  444.         
  445.         if ($TransactionClass)
  446.         {
  447.             $TransactionSearchRequestType['TransactionClass'$TransactionClass
  448.         }
  449.         
  450.         if ($Amount)
  451.         {
  452.             $TransactionSearchRequestType['Amount'self::BasicAmountType($Amount$currencyID);
  453.         }
  454.  
  455.         if ($CurrencyCode)
  456.         {
  457.             $TransactionSearchRequestType['CurrencyCode'$CurrencyCode;
  458.         }
  459.         
  460.         if ($Status)
  461.         {
  462.             $TransactionSearchRequestType['Status'$Status;
  463.         }
  464.         
  465.         return $TransactionSearchRequestType;       
  466.     }
  467. }
  468. ?>

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