PayPal PHP SDK Class Library

PayPal PHP SDK Class Library

Released 6 years ago , Last update 2 years ago

Easily integrate PayPal API web services for Payments Pro, Adaptive Payments, Adaptive Accounts, Invoicing, Permissions, or PayFlow into any PHP project.

Questions & Comments


Or enter your name and Email
  • O Ozzie 4 years ago
    Hello Andrew, Much gratitude to you for sharing your work with us. *bow* I am using the pay api operation and was able to successfully make a call using the sandbox accounts. It seems there is a requirement for a secondary receiver for it to work. How can i disable the secondary receiver requirement and leave only the primary receiver? Is there a setting within the adaptive class? Or is that not an option? Im a bit confused because according to paypal: The Adaptive Payments API uses the Pay operation to make payments between a sender and one or more receivers of that payment. https://developer.paypal.com/docs/classic/adaptive-payments/gs_AdaptivePayments/ Thanks!
    • Andrew Angell Publisher 4 years ago
      Sounds like you've got a single receiver on the request but you left it set as primary. If you have a primary receiver it expects a secondary receiver. Just get rid of the primary=>true (simply remove the true value) and that should do it for you.
    • O Ozzie 4 years ago
      That was it. Thank you for your work and a swift response to my question. All the best, Ozzie
  • A Arda 4 years ago
    Hello Andrew, Firstly, thanks for the awesome class and maintaining this! I've been using since CodeIgniter days, and I'll be using this now in Laravel 4, since you've added composer support on GitHub. In my project, I'll be using Express Checkout, Auth/Capture model, but I couldn't find any example in your examples folder for Auth/Capture. Could you please provide this? https://github.com/angelleye/paypal-php-library/tree/master/samples Or am I missing it? I've already checked callbacks for express checkout. (I am already following your GitHub repo to catch up, if that'd help you) Thank again, Best Regards,
    • Andrew Angell Publisher 4 years ago
      Glad to hear you've been using it for awhile and like it. Thanks! For Express Checkout Authorization you'll use the regular EC calls: SetExpressCheckout, GetExpressCheckoutDetails, DoExpressCheckoutPayment. You'll just set the PaymentAction to Authorization instead of Sale. Those are available in the samples folder, although I believe GECD is tied into the DoExpressCheckoutPayment.php sample. For the capture you would use DoCapture. I don't have a sample for that setup, but there is a template for it in the templates directory: https://github.com/angelleye/paypal-php-library/blob/master/templates/DoCapture.php It works exactly like all the other samples/templates. Just need to fill in the array data for the request.
    • A Arda 4 years ago
      Hey Andrew, Thanks for the fast reply, much appreciated! I totally ignored the templates folder while checking for i-don't-know-why :) I have some similar questions, I hope you can help me: 1. There is this "refund capture" method in GitHub paypal/rest-api-sdk-php. I couldn't find it in your templates. Should the refund() work also for refunding the captures ? 2. How about voiding authorization(s)? Does your void() method exactly for this purpose? 3. (not really related to a code question, just asking for ideas if you have any idea(s) :) ) To totally refund, is voiding unprocessed authorizations and refunding captures suffice? Thanks again for your time, Best Regards,
    • Andrew Angell Publisher 4 years ago
      The REST API is completely separate from the Classic API, which is what my library works in. I really haven't done much with their REST API myself, although, I do plan to build it into this library at some point. Right now it offers nothing we can't do in the Classic API, and in fact it pales in comparison to what Classic provides right now. The Classic API refund calls (which are in my library) would be DoRefund or Refund. Refund is for Adaptive Payments and DoRefund is for Express Checkout, Standard, or Payments Pro. For voiding auths with my library you would use DoVoid. An authorization is not a completed transaction, so a refund is obsolete here. Voiding the auth would simply kill it so it could not be captured in the future and would release any held funds back to the payer account. On a Sale transaction or an Authorization that has been Captured, you would use DoRefund (or Refund in Adaptive Payments) to reverse the payment.
  • MV Manmohit Verma 4 years ago
    I am getting following error : Parse error: syntax error, unexpected T_FUNCTION, expecting ')' in /home/content/68/8460168/html/wp-content/themes/eStore/autoload.php on line 7 I am using payflow ( PayFlowTransaction.php ) Please help me...
    • Andrew Angell Publisher 4 years ago
      Looks like a problem with your autoload.php..?? Did you check line 7 in that file for a missing ) ?
  • PG Phil Gale 4 years ago
    Wow thanks for this, seems to be exactly what I was looking for!
    • Andrew Angell Publisher 4 years ago
      I'm glad to hear it. Let me know if you have any questions when you get going.
  • M momo 4 years ago
    how to use in mass payment paypal ? ( goto www.mysite.com/Masspay.php , my money will pay to many paypal account ? ) and how to setting to use paypal live not sandbox ?
    • Andrew Angell Publisher 4 years ago
      Do you have the library setup with your own credentials and working? You can test it by running the GetBalance sample. Once that's working with your account you're good to go. Then you just need to open up the MassPay.php template file and fill in the parameters accordingly. You'll build your receivers in the MassPay request within a loop using whatever source you have available.
  • PM perera malinda 5 years ago
    Thanks..how to use this code digital download website.
    • Andrew Angell Publisher 5 years ago
      I'm not sure I understand what you're asking. Are you talking about Express Checkout for Digital Goods?
  • JH Jerry Harrison 6 years ago
    Hi there, So far great plugin I have a couple of questions and some help with paypal.class.php itself. First off I noticed on some of the lines the arrays were reference different variables or keys. I so far have only noticed on a couple of lines - ln 3647 ... $XMLRequest .= $PaymentPeriod != '' ? '' . $Memo . '' : ''; The var $Memo needs to be changed to $PaymentPeriod $XMLRequest .= $PaymentPeriod != '' ? '' . $PaymentPeriod . '' : ''; ln 3652 $XMLRequest .= $SenderEmail != '' ? '' . $PinType . '' : ''; TO $XMLRequest .= $SenderEmail != '' ? '' . $SenderEmail . '' : ''; And finally Line 3613 $ClientDetailsFields = isset($DataArray['ClientDetailsFields']) ? $DataArray['ClientDetails'] : array(); should be $ClientDetailsFields = isset($DataArray['ClientDetailsFields']) ? $DataArray['ClientDetailsFields'] : array(); ----------------------------------------------------------------------------- Hope that helps further the development of this handy lib! Like I mentioned I do have some questions (I would normally head over to a forum or stack overflow but hope you might have more guidance). I'm helping out building a crowd funding type platform and I was wondering if you had any suggestions - api call wise - in what is the correct process to carryout such a project. I honestly could find and good help on PayPal's forums or their code samples (not much for adaptive). I kinda have to narrowed down to this, but I could be extremely off. 1) I know i need to perform a Preapproval request (good example in your plugin) -- save the Preapproval Key in the db 2) Get some details on the Preapproval request via PreapprovalDetails to verify data 3) when time comes and if the goal was met run a chained pay action and listen for ipn Is this correct or are there other steps/precautions I should be taking? Thank you for your library and your help! -- Jerry PS. any thoughts on opening a Github?
    • Andrew Angell Publisher 6 years ago
      Thanks for the feedback. I think I've gotten most of those things fixed in my local copy. Been meaning to add a few more features and get the next version posted. Sounds like you've got a good handle on things. I think the flow you've outlined is exactly what you should be doing. I do plan on releasing this on Github. If not with this next version, probably the one after that.
  • C ClementBoudon 6 years ago
    Hi, I notice one little mistake in your paypal.class.php file : On line 3615, function Preapproval($DataArray), if $DataArray['ClientDetailsFields'] is set, you don't use 'ClientDetailsFields' but 'ClientDetails' as value of $ClientDetailsFields. Just by replacing $DataArray['ClientDetails'] by $DataArray['ClientDetailsFields'], everything's going fine. By the way, thanks for your work, it's so helpfull.
    • Andrew Angell Publisher 6 years ago
      Thanks, nice catch. I've got it fixed so it'll be on the next release, which will most likely be a Github repo. Glad you've found it useful!
    • C ClementBoudon 6 years ago
      Hi, I notice one more mistake : in paypal.class.php, on line 3019, If $PreapprovalKey != '', you don't use $PreapprovalKey as value for xml parameter "preapprovalKey", nut $Pin. By replacing $Pin by $PreapprovalKey, everything works fine. The error I used to have was : "Invalid request parameter: preapprovalKey with value". Regards, Clement.
    • Andrew Angell Publisher 6 years ago
      Ah, yes, thanks again. I can't believe nobody, including myself, has run into that yet.
  • ZW Zachary Walsh 6 years ago
    Hi Andrew, Just a quick question on error handling. Is there an easy way to display the error messages sent back from PayPal? If a payment fails for whatever reason, (primarily in the case of user input errors) I'd like the customer to be able to see where there has been an error. This api class is great, very helpful!
    • Andrew Angell Publisher 6 years ago
      The result will always include an ERRORS array that you can use to display messages however you want. There is also a basic DisplayErrors() method included in the class that will simply write them out with line breaks between each line. $PayPal->DisplayErrors($PayPalResult['ERRORS']);
    • ZW Zachary Walsh 6 years ago
      Excellent, thank you. I played with that DisplayErrors function but wasn't providing the correct argument. Works like a charm!
  • S seamedia 6 years ago
    Hi Angel, I added initamt, but seems to be it is not charging initally and just create the recuring profile. When create recrring profile, it will not charge initially ? or what I need to add to a do initial payment ? Thanks in advance Prajosh
    • Andrew Angell Publisher 6 years ago
      Hi Prajosh, If you add initial amount it will indeed charge that amount right away. It's actually outside of the profile itself, though. So then depending on what you set the start date of the profile to you could have 2 payments coming through right away...one would be the "initial payment" and the other would be the first of the recurring payments. Can you send me a sample of what you're working with? I'll take a look and help you find the problem.
    • S seamedia 6 years ago
      HI Angel, Thanks for quick reply: I am using same time code from your script: $DaysTimestamp = strtotime('now'); $Mo = date('m', $DaysTimestamp); $Day = date('d', $DaysTimestamp); $Year = date('Y', $DaysTimestamp); $StartDateGMT = $Year . '-' . $Mo . '-' . $Day . 'T00:00:00\Z'; sample code: $sandbox, 'APIUsername' => $api_username, 'APIPassword' => $api_password, 'APISignature' => $api_signature); $PayPal = new PayPal($PayPalConfig); $CRPPFields = array( 'token' => '', // Token returned from PayPal SetExpressCheckout. Can also use token returned from SetCustomerBillingAgreement. ); $DaysTimestamp = strtotime('now'); $Mo = date('m', $DaysTimestamp); $Day = date('d', $DaysTimestamp); $Year = date('Y', $DaysTimestamp); $StartDateGMT = $Year . '-' . $Mo . '-' . $Day . 'T00:00:00\Z'; $start_time = strtotime(date('m/d/Y')); $start_date = date('Y-m-d\T00:00:00\Z',$start_time); $name=$firstName." ".$lastName; $ProfileDetails = array( 'subscribername' => $name, // Full name of the person receiving the product or service paid for by the recurring payment. 32 char max. 'profilestartdate' => $start_date, // Required. The date when the billing for this profiile begins. Must be a valid date in UTC/GMT format. 'profilereference' => $customer_id // The merchant's own unique invoice number or reference ID. 127 char max. ); $ScheduleDetails = array( 'desc' => 'Recurring', // Required. Description of the recurring payment. This field must match the corresponding billing agreement description included in SetExpressCheckout. 'maxfailedpayments' => '2', // The number of scheduled payment periods that can fail before the profile is automatically suspended. 'autobillamt' => 'AddToNextBilling' // This field indiciates whether you would like PayPal to automatically bill the outstanding balance amount in the next billing cycle. Values can be: NoAutoBill or AddToNextBilling ); $BillingPeriod = array( 'trialbillingperiod' => '', 'trialbillingfrequency' => '', 'trialtotalbillingcycles' => '', 'trialamt' => '', 'billingperiod' => $recuring_type, // Required. Unit for billing during this subscription period. One of the following: Day, Week, SemiMonth, Month, Year 'billingfrequency' => '1', // Required. Number of billing periods that make up one billing cycle. The combination of billing freq. and billing period must be less than or equal to one year. 'totalbillingcycles' => '0', // the number of billing cycles for the payment period (regular or trial). For trial period it must be greater than 0. For regular payments 0 means indefinite...until canceled. 'amt' => $paymentAmount, // Required. Billing amount for each billing cycle during the payment period. This does not include shipping and tax. 'currencycode' => 'USD', // Required. Three-letter currency code. 'shippingamt' => '', // Shipping amount for each billing cycle during the payment period. 'taxamt' => '' // Tax amount for each billing cycle during the payment period. ); $ActivationDetails = array( 'initamt' => '', // Initial non-recurring payment amount due immediatly upon profile creation. Use an initial amount for enrolment or set-up fees. 'failedinitamtaction' => '', // By default, PayPal will suspend the pending profile in the event that the initial payment fails. You can override this. Values are: ContinueOnFailure or CancelOnFailure ); $CCDetails = array( 'creditcardtype' => $creditCardType, // Required. Type of credit card. Visa, MasterCard, Discover, Amex, Maestro, Solo. If Maestro or Solo, the currency code must be GBP. In addition, either start date or issue number must be specified. 'acct' => $creditCardNumber, // Required. Credit card number. No spaces or punctuation. 'expdate' => $padDateMonth.$expDateYear, // Required. Credit card expiration date. Format is MMYYYY 'cvv2' => $cvv2Number, // Requirements determined by your PayPal account settings. Security digits for credit card. 'startdate' => '', // Month and year that Maestro or Solo card was issued. MMYYYY 'issuenumber' => '' // Issue number of Maestro or Solo card. Two numeric digits max. ); $PayerInfo = array( 'email' => $email, // Email address of payer. 'payerid' => $customer_id, // Unique PayPal customer ID for payer. 'payerstatus' => '', // Status of payer. Values are verified or unverified 'countrycode' => '', // Payer's country of residence in the form of the two letter code. 'business' => '' // Payer's business name. ); $PayerName = array( 'salutation' => '', // Payer's salutation. 20 char max. 'firstname' => $first_name, // Payer's first name. 25 char max. 'middlename' => '', // Payer's middle name. 25 char max. 'lastname' => $lastName, // Payer's last name. 25 char max. 'suffix' => '' // Payer's suffix. 12 char max. ); $BillingAddress = array( 'street' => $address1, // Required. First street address. 'street2' => '', // Second street address. 'city' => $city, // Required. Name of City. 'state' => $state, // Required. Name of State or Province. 'countrycode' => '', // Required. Country code. 'zip' => $card_zip, // Required. Postal code of payer. 'phonenum' => '' // Phone Number of payer. 20 char max. ); $ShippingAddress = array( 'shiptoname' => '', // Required if shipping is included. Person's name associated with this address. 32 char max. 'shiptostreet' => '', // Required if shipping is included. First street address. 100 char max. 'shiptostreet2' => '', // Second street address. 100 char max. 'shiptocity' => '', // Required if shipping is included. Name of city. 40 char max. 'shiptostate' => '', // Required if shipping is included. Name of state or province. 40 char max. 'shiptozip' => '', // Required if shipping is included. Postal code of shipping address. 20 char max. 'shiptocountrycode' => '', // Required if shipping is included. Country code of shipping address. 2 char max. 'shiptophonenum' => '' // Phone number for shipping address. 20 char max. ); $PayPalRequestData = array( 'ProfileDetails' => $ProfileDetails, 'ScheduleDetails' => $ScheduleDetails, 'BillingPeriod' => $BillingPeriod, 'CCDetails' => $CCDetails, 'PayerInfo' => $PayerInfo, 'PayerName' => $PayerName ); $PayPalResult = $PayPal->CreateRecurringPaymentsProfile($PayPalRequestData); echo '
      ';
      print_r($PayPalResult);
      exit;
      ?>
    • Andrew Angell Publisher 6 years ago
      I meant for you to email me an attachment of your current file, but that works. The $ActivationDetails array includes both INITAMT and FAILEDINITAMTACTION and you've got both of those blank. Those are the fields you need to use in order to charge an initial amount.
    • S seamedia 6 years ago
      Hi Andrew, Thanks for quick reply, I can see recurring profile created, but credit card not charged yet. do u know why ? Thanks Prajosh
    • Andrew Angell Publisher 6 years ago
      Are you still talking about the INITAMT or just the first payment of the profile? If you're still talking about the INITAMT, then again, you need to make sure you've included those parameters in your request. If you're just talking about the first payment from the profile itself, assuming you set "today" as the start date, then sometimes the first payment can lag a little bit, especially on the PayPal sandbox. You should see it come through before too long, although, I've seen it take as long as 6 - 8 hours on the sandbox sometimes. As long as your profile is created correctly you can look in there and see when the next payment date is expected and as long it still shows "today" you know it'll be coming soon. The live server is typically much quicker and you'll see the first payment hit at the same time the profile is created in most cases. Really, the sandbox is usually pretty good about that, too, but it does get delayed at times.
    • S seamedia 6 years ago
      Hi Andrew, I am trying to do Recuring payment thru express checkout, Initially I tried SetCustomerBillingAgreement, but getting below error: [L_ERRORCODE0] => 10004 [L_SHORTMESSAGE0] => Transaction refused because of an invalid argument. See additional error messages for details. Any idea ? Thanks Prajosh Hi Andrew, Yes it is charged now. Thanks for quick reply. Thanks Prajosh
You need to log-in or create an account
  • Create an account
  • Log-in
Please use your real name.
Activation link will be sent to this address.
Minimum 8 characters
Enter your password again

Clicking this button confirms you read and agreed to the terms of use and privacy policy.

X

Save your watchlist

Fill your details below to receive project updates from your watch list - including new versions, price changes and discounts.

I agree to the terms of use and privacy policy.