Details
Description
Background
When people migrate from WHMCS (or another solution) and they have PayPal Subscriptions active, we instruct them to create a redirect to translate those IPN calls to a URL Blesta can use. For example, we tell people to add the following to their .htaccess file:
Redirect 301 /modules/gateways/callback/paypal.php /callback/gw/1/paypal_payments_standard/
However, a typical IPN URL that is created by Blesta looks something like this:
/callback/gw/1/paypal_payments_standard/?client_id=12345
Note that the client_id is included in the IPN URL. Blesta uses this to match the payment to a particular client based on the internal ID. With these redirected IPN calls, no such client_id is provided.
In the absense of the client_id being provided, Blesta falls back to trying to match the payer_email to a client's email address. However, if there is no match, the payment cannot be recorded. This is common, because clients often pay with a different PayPal email than they sign up with.
Proposed Solution
Update the PayPal Payments Standard gateway to add a textarea field at the bottom, below the "Developer Mode" checkbox. Give it a label of "Payment Mapping (Advanced Use Only)". Add a tooltip that says. "Intended for use with PayPal Subscriptions that were created outside of Blesta. Map payer_email to internal Client ID, 1 per line. For example: email,client-id"
We should be able to store a lot of these under gateway_meta.value as it's a text field.
Then, when we receive an IPN call from PayPal, we do the folowing:
- If the URL contains the client_id, use this as we do currently (no change)
- If the URL does not contain the client_id, try to match the payer_email in the IPN request to a client-id as provided in the mapping data. If it exists, apply the payment.
- Finally, if the client_id is not provided in the IPN URL, and there is no mapping data match for the payer_email, try to match on client email as we do currently.
When saving the mapping data, make sure all payer_emails are unique, display an error if they are not:
Duplicate emails were found in your mapping data, remove duplicates and try again.