PayPal API script.
In the offered file three functions for remote work with PayPal payments are realized, for instance, in the admin area of your site.
PayPal API
PayPal payment system offers possibility to obtain information about payments, to arrange for payment and so on. It is realized via posting a name-value pair string over an HTTPS connection to PayPal’s server and then processing the response, which is also a name-value pair string. To be able to use this functionality you are to get API username, API password and API signature in the features of your PayPal account.
Script ‘index.php’
Providential constants
At the beginning of script’s work following constants are defined:
API_USER, API_PASSWORD, API_SIGNATURE – here API of your account’s number is indicated which was described above.
API_URL – url to which post requests should be sent. Place here https://api-3t. paypal.com/nvp (or https://api-3t.sandbox.paypal.com/nvp for testing your site)
PayPalSearch
Function of the latest transactions search in the indicated period of time.
Parameters: $period – possible values: ['day', 'week', 'month', 'year']
Result of the work: massive containing information about payments (if it is blank, it means that there weren’t any payments in the indicated period of time) or error text in case of error.
PayPalRefund
Carries out complete cancellation of transaction.
Parameters: $txn_id – ID of transaction
Result of the work: reply from PayPal server. If it returns Refunded string, it means that transaction has been Refunded successfully.
PayPalDetails
Returns information about transaction.
Parameters: $txn_id – ID of transaction
Result of the work: massive containing information about the transaction indicated or error text in case of error.
Conclusion
Basing on the functions presented you can organize convenient work with PayPal payments without visiting PayPal site at all. You can also create functions of your own using the given ones as an example. You can find additional information in the documentation attached or on the official PayPal site: https://www.paypal.com/IntegrationCenter/ic_home.html



