Charita Bemis
Quite often, when designing websites, web developers have to solve the problem of integrating a website with a payment system. One of the most famous electronic payment systems is PayPal, which allows you to make payments all over the world. It is not surprising that this solution is in great demand in the development of web projects. However, in the process of integrating PayPal into the site, many developers sometimes miss certain points.
Today we will share our experience of integrating a website with the PayPal system and tell you how to set up and track accepting payments from any user to your PayPal account and how to set up sending credited funds to the system’s users.
Integration of payment for goods and services via Paypal
To integrate payment via PayPal, you can put the standard button generated in your Paypal account. When you click on it, the user is immediately transferred to the PayPal website to make a payment. In most cases, this is enough. However, this option does not guarantee that the user will actually do something, and the result can be tracked only within the PayPal account, which is inconvenient.
So, let’s create a simple HTML form with many fields. All fields can be of type hidden with strictly specified values. In doing so, pay attention to their exact names:
Required fields:
amount – the amount of the transfer;
cmd – type of translation;
charset – encoding of communication between the system and Paypal. Strictly utf-8;
business – E-mail from the Paypal account of the seller;
currency_code – currency code in international format. Not all currencies are supported;
return – the absolute URL to which the user will be redirected when they click the return to site button after payment;
cancel – return is the absolute URL that the user will be redirected to when they click the return button when canceling the payment.
Optional fields (but recommended):
undefined_quantity – quantity of purchased goods;
item_name – transaction name
notify url – is the absolute URL to which a notification from Paypal will be sent about the result of the operation. An optional field, but without it you cannot find out the result of the operation;
custom – is a simple field that can contain up to 100 characters of service information. It will return as it is, along with a notification to notify_url. It can be used to transfer, for example, the internal ID of the user operating;
rm – responsible for the method with which the user will be returned to the site (POST or GET).
IPN notifications
Let’s imagine that a user of your site made a payment. With a slight delay, just a few seconds, the PayPal server will send an IPN notification to the script with the result of the operation, if the notify_url field is used. Those. the specified URL will receive data on the payment made in the form of an associative POST array. If the message is not delivered (server response is not 200), then the message will be resent until a 200 response is received. After each unsuccessful notification, the time between retries will double. The maximum number of attempts is 15.
When performing a transfer, the required field is the currency code currency_code. The account to which the transfer is made can use a different currency. In this case, the recipient is obliged to choose what to do with this payment:
1. Accept with conversion into the currency of the current account at the current rate.
2. Accept with the creation of an additional account with the payment currency.
3. Decline the payment.
Due to this feature, the IPN notification will receive the Pending status, not Completed, and the transaction itself will âhangâ until the payee selects one of the options in their own PayPal account. If you choose the second option, all similar transactions will go through without problems, including those previously executed.
There is a nuance – in the case of this action, PayPal does not send an IPN notification of the completion of the operation. You can get around this by storing the ID of all PayPal transactions on the site side and, if necessary, checking their current status through the API.
After completing the configuration of IPN notifications, the next step is to send the credited funds to the system users. This can be implemented in various ways.