Tuesday, June 24, 2008

Paypal Reporting API - PHP code

Most of the websites use paypal processor for their online payments.Transaction details and various reports can be checked from Paypal Manager interface. The same reports can be generated using API calls(reporting xml api).We can generate reports using PHP as follows.

Library needed

1. Curl

Common Parameters for all API calls

All the API call require payal account information.So we can save these details in an array as follows.




Common Functions

The following functions are common for all API calls.












Steps to generate Custom Reports

1.The parameters needed for generating a custom report are 'start_date' and 'end_date'.So we can save the parameters in an array as follows.



2.Now we can run the report request as follows.



Here the second parametes is the name of the report.To generate another report we just need to change the report name and give the corresponding parameters in the parameter array.Remeber to give parameter names as keys of parameter array.

3.We will get reportId if the above Api call is successful.We can parse the response from above call and get reportId as follows.



4. Request for the results.



5.Now we can get all the fields in the report.



We can arrange the field names in an array using the function GenerateFieldArray().



6.Finally we can get data for our report.



Now we just need to display it in a report format.

5 comments:

Paul said...

This post was really helpful. Thank you very much for posting this, it helped me get a nice jump on my own program.

Tyera said...

Many many thanks for posting this!

Chris said...

Thanks for this tutorial. I'm wondering if you could help me figure out why runReportRequests for CustomReport or saved templates fail with error code 105 (A system error has occurred). My code works for runReportRequests for DailyActivityReport. I can also create a new template (createTemplateRequest) and get templates details (runTemplateRequest).

Tilotiti said...

Posting code in JPEG format ? Really ?

Unknown said...

I try to use your code. But it failed, return nothing.
Just show the following message
Excepting thrown: