Search code examples
paypalpaypal-ipnpaypal-sandbox

Parallel preapproved paypal payment?


I have parallel payments working on my test server very nicely, i.e. I can send money to more than 1 person at a time in parallel based on the example parallel.php file I downloaded from the developer paypal site.

I also downloaded the preapproval_flow.php file, but in the code, I can't see a variable/array which allows me to set parallel payment receivers, or even a single receiver for that matter.

Is it not possible to preapprove parallel payments with paypal api's?

If it is possible, how do I do it?

With straight forward parallel payments, I can use the following to set the parallel receivers of a payment:

$receiverEmailArray = array(
    'email0',
    'email1',
    'email2',
    'email3',
    'email4',
    'email5',
    'email6',
    'email7',
    'email8',
    'email9'
);

According to cms.paypal.com and x.com, the preappoval_flow has an option called feesPayer, for which the documentation says:

SENDER – Sender pays all fees (for personal, implicit simple/parallel payments; do not use for chained or unilateral payments)

The bold bit, tells me that it's possible to do pre-approved parallel payments, but I can't figure out how to sent the receivers...

Also, on x.com, it says:

Developers and merchants can combine;

  • Parallel and preapproved payments.

Solution

  • The first step in pre-approvals, is on obtaining one from the buyer.

    This pre-approval is not tied to any specific seller, but rather to the API caller, and it allows you to make a Pay API call in the future without the buyer having to confirm it.

    The pre-approval flow is a separate API call from the Payment flow. In it, you specify the total amount you want to pre-approve, the start and end dates that the pre-approval is valid for, and a few other parameters. (See chapter 8 of the Adaptive Payments dev guide for the full spec: https://cms.paypal.com/cms_content/US/en_US/files/developer/PP_AdaptivePayments.pdf )

    In this API call, you redirect the buyer to the PayPal site, where he will approve future payments up to the amount you specified. (e.g. if you specified a total amount of $1000, the buyer can make 20 purchases of $50, or 1 big purchase of $1000)

    Once the buyer approves this, you have a permission to charge him (In the form of a pre-approval token PA-xxxxxxxxxxxxxx, but at this point no money has changed hands.

    Now that you have the token, you can proceed to make the Parallel Payment Pay API call, just like you are doing now, BUT you will specify one additional parameter: preapprovalKey=<The PA key obtained previously>

    (And you also need to make sure that actionType is set to PAY )

    As soon as you make this API call, because PayPal sees that you have already obtained permission from the buyer (in the form of the approved PA-key), it will immediately move the money to the receivers specified. There is no need for the buyer to be redirected to approve this payment, since he has already pre approved it. (See the logic here?)

    So to recap:

    1. Make call to Pre-Approval API, to obtain permission to charge from the buyer
    2. Make call to Pay API (that includes the PA key from step 1) to execute on the permission given