Michael
Michael

Reputation: 784

Paypal Adaptive Chained Payments - Sender's amount is primary receiver's amount not the total amount. How to fix?

I'm developing a service where the sender pays an amount, 95% of which goes to one receiver and 5% to the other. (e.g., $100 paid, $95 less fees to primary and $5 to secondary.) In this example, the sender is seeing $95 as his amount to pay and not $100 and I'm not understanding why.

Here is where the amounts are set in an array corresponding to another array of Paypal e-mail addresses.

$receiverAmountArray = array(
        .5*$backing_amount,
        .95*$backing_amount
        );

The second e-mail address is set to primary. The receiver of the largest amount has to be primary.

$receiverPrimaryArray = array(
        'false',
        'true'
        );

CallPay (from Paypal's library) is called:

$resArray = CallPay ($actionType, $cancelUrl, $returnUrl, $currencyCode, $receiverEmailArray,
                        $receiverAmountArray, $receiverPrimaryArray, $receiverInvoiceIdArray,
                        $feesPayer, $ipnNotificationUrl, $memo, $pin, $preapprovalKey,
                        $reverseAllParallelPaymentsOnError, $senderEmail, $trackingId
);

Here is the CallPay function. Sorry for length:

function CallPay( $actionType, $cancelUrl, $returnUrl, $currencyCode, $receiverEmailArray, $receiverAmountArray,
                        $receiverPrimaryArray, $receiverInvoiceIdArray, $feesPayer, $ipnNotificationUrl,
                        $memo, $pin, $preapprovalKey, $reverseAllParallelPaymentsOnError, $senderEmail, $trackingId )
    {
        /* Gather the information to make the Pay call.
            The variable nvpstr holds the name value pairs
        */

        // required fields
        $nvpstr = "actionType=" . urlencode($actionType) . "&currencyCode=" . urlencode($currencyCode);
        $nvpstr .= "&returnUrl=" . urlencode($returnUrl) . "&cancelUrl=" . urlencode($cancelUrl);

        if (0 != count($receiverAmountArray))
        {
            reset($receiverAmountArray);
            while (list($key, $value) = each($receiverAmountArray))
            {
                if ("" != $value)
                {
                    $nvpstr .= "&receiverList.receiver(" . $key . ").amount=" . urlencode($value);
                }
            }
        }

        if (0 != count($receiverEmailArray))
        {
            reset($receiverEmailArray);
            while (list($key, $value) = each($receiverEmailArray))
            {
                if ("" != $value)
                {
                    $nvpstr .= "&receiverList.receiver(" . $key . ").email=" . urlencode($value);
                }
            }
        }

        if (0 != count($receiverPrimaryArray))
        {
            reset($receiverPrimaryArray);
            while (list($key, $value) = each($receiverPrimaryArray))
            {
                if ("" != $value)
                {
                    $nvpstr = $nvpstr . "&receiverList.receiver(" . $key . ").primary=" . urlencode($value);
                }
            }
        }

        if (0 != count($receiverInvoiceIdArray))
        {
            reset($receiverInvoiceIdArray);
            while (list($key, $value) = each($receiverInvoiceIdArray))
            {
                if ("" != $value)
                {
                    $nvpstr = $nvpstr . "&receiverList.receiver(" . $key . ").invoiceId=" . urlencode($value);
                }
            }
        }

        // optional fields
        if ("" != $feesPayer)
        {
            $nvpstr .= "&feesPayer=" . urlencode($feesPayer);
        }

        if ("" != $ipnNotificationUrl)
        {
            $nvpstr .= "&ipnNotificationUrl=" . urlencode($ipnNotificationUrl);
        }

        if ("" != $memo)
        {
            $nvpstr .= "&memo=" . urlencode($memo);
        }

        if ("" != $pin)
        {
            $nvpstr .= "&pin=" . urlencode($pin);
        }

        if ("" != $preapprovalKey)
        {
            $nvpstr .= "&preapprovalKey=" . urlencode($preapprovalKey);
        }

        if ("" != $reverseAllParallelPaymentsOnError)
        {
            $nvpstr .= "&reverseAllParallelPaymentsOnError=" . urlencode($reverseAllParallelPaymentsOnError);
        }

        if ("" != $senderEmail)
        {
            $nvpstr .= "&senderEmail=" . urlencode($senderEmail);
        }

        if ("" != $trackingId)
        {
            $nvpstr .= "&trackingId=" . urlencode($trackingId);
        }

        /* Make the Pay call to PayPal */
        $resArray = hash_call("Pay", $nvpstr);

        /* Return the response array */
        return $resArray;
    }

Here's the value of $nvpstr right before the call. Is it possible that Paypal is just making the payment amount the primary payment? That doesn't make sense in the context of chained payments.

actionType=PAY¤cyCode=USD&returnUrl=https%3A%2F%2F.com%2Fview_profile.php&cancelUrl=https%3A%2F%2Fexamplefunding.com%2Fview_profile.php&receiverList.receiver(0).amount=95&receiverList.receiver(1).amount=5&receiverList.receiver(0).email=recip_1334204171_biz%40example.com&receiverList.receiver(1).email=example_1334201682_biz%40example.com&receiverList.receiver(0).primary=true&receiverList.receiver(1).primary=false&receiverList.receiver(0).invoiceId=5c4e2902cbe484a0db37284f0144994c&receiverList.receiver(1).invoiceId=6f3d8ce65d1a59b41f8822ba6129ea58&feesPayer=PRIMARYRECEIVER&memo=New+Draft+Lines+-+ExampleFunding.com&senderEmail=paypal_1334201496_per%40example.com&trackingId=mqN8SSgIq

Upvotes: 1

Views: 2338

Answers (2)

Michael
Michael

Reputation: 784

According to Paypal's Adaptive Payments Documentation:

In a chained payment, the sender pays the primary receiver an amount, from which the primary receiver pays secondary receivers. The sender only knows about the primary receiver, not the secondary receivers.

Therefore, this is working as intended. In order to pay 5% of the total amount to the secondary receiver, I must change this:

$receiverAmountArray = array(
        .05*$backing_amount,
        .95*$backing_amount
        );

to this:

$receiverAmountArray = array(
        .05*$backing_amount,
        $backing_amount
        );

It was my mistake to think that the total amount was the sum of the individual receiver amounts in the array.

Upvotes: 3

Scott.N
Scott.N

Reputation: 172

example: total_amount = 100;

if we set receiverList.receiver(0).primary=true then receiverList.receiver(0).amount = total_amount;

and receiverList.receiver(1).amount=95%*total_amount

Upvotes: 0

Related Questions