0

我想向两个收货人付款,即买家以 100 的价格购买商品,收货人 1 得到 90,收货人 2 得到 10。我正在使用链式付款方式。我在接收者 1 的帐户中获得 100,这没问题,但我无法获得接收者 2 的付款。接收者的帐户 ID 已设置,但此处未给出。我做错了什么?谢谢

<?php
require_once('../includes/config.php');
require_once('../includes/paypal.class.php');

$PayPalConfig = array(
                      'Sandbox' => $sandbox,
                      'DeveloperAccountEmail' => $developer_account_email,
                      'ApplicationID' => $application_id,
                      'DeviceID' => $device_id,
                      'IPAddress' => $_SERVER['REMOTE_ADDR'],
                      'APIUsername' => $api_username,
                      'APIPassword' => $api_password,
                      'APISignature' => $api_signature,
                      'APISubject' => $api_subject
                    );

$PayPal = new PayPal_Adaptive($PayPalConfig);

$PayRequestFields = array(
                        'ActionType' => 'PAY_PRIMARY',                              
                        'CancelURL' => $domain.'cancel.php',                        
                        'CurrencyCode' => 'USD',                                
                        'FeesPayer' => 'EACHRECEIVER',                                  
                        'IPNNotificationURL' => '',                         
                        'Memo' => '',                                       
                        'Pin' => '',                                        
                        'PreapprovalKey' => '',                              
                        'ReturnURL' => $domain.'return.php',                                    
                        'ReverseAllParallelPaymentsOnError' => '',          
                        'SenderEmail' => '',                                
                        'TrackingID' => ''                                  
                        );

$ClientDetailsFields = array(
                        'CustomerID' => '',                                 
                        'CustomerType' => '',                               
                        'GeoLocation' => '',                                
                        'Model' => '',                                      
                        'PartnerName' => ''                                 
                        );

$FundingTypes = array('ECHECK', 'BALANCE', 'CREDITCARD');                   

$Receivers = array();
$Receiver = array(
                'Amount' => '100.00',                                           
                'Email' => 'receiver1accountid',                                                
                'InvoiceID' => '',                                          
                'PaymentType' => 'GOODS',                                       
                'PaymentSubType' => '',                                     
                'Phone' => array('CountryCode' => '', 'PhoneNumber' => '', 'Extension' => ''), 
                'Primary' => 'true'                                             
                );
array_push($Receivers,$Receiver);

$Receiver = array(
                'Amount' => '10.00',                                            
                'Email' => 'receiver2accountid',                                                
                'InvoiceID' => '',                                          
                'PaymentType' => 'GOODS',                                       
                'PaymentSubType' => '',                                     
                'Phone' => array('CountryCode' => '', 'PhoneNumber' => '', 'Extension' => ''), 
                'Primary' => 'false'                                                
                );
array_push($Receivers,$Receiver);

$SenderIdentifierFields = array(
                                'UseCredentials' => ''                      
                                );

$AccountIdentifierFields = array(
                                'Email' => '',                              
                                'Phone' => array('CountryCode' => '', 'PhoneNumber' => '', 'Extension' => '')                               
                                );

$PayPalRequestData = array(
                    'PayRequestFields' => $PayRequestFields, 
                    'ClientDetailsFields' => $ClientDetailsFields, 
                    'FundingTypes' => $FundingTypes, 
                    'Receivers' => $Receivers, 
                    'SenderIdentifierFields' => $SenderIdentifierFields, 
                    'AccountIdentifierFields' => $AccountIdentifierFields
                    );


$PayPalResult = $PayPal->Pay($PayPalRequestData);

if(!$PayPalResult)
    {
        $errors = array('Errors'=>$PayPalResult['Errors']);

echo '<pre />';
print_r($errors);
exit();
    }
    else
    {

        header('Location: '.$PayPalResult['RedirectURL']);


$ExecutePaymentFields = array(
                            'PayKey' => $PayPalResult['PayKey'],                                
                            'FundingPlanID' => ''                           
                            );

$PayPalRequestData = array('ExecutePaymentFields' => $ExecutePaymentFields);


$PayPalResult = $PayPal->ExecutePayment($PayPalRequestData);
if(!$PayPalResult)
    {
        $errors = array('Errors'=>$PayPalResult['Errors']);

echo '<pre />';
print_r($errors);
exit();
    }
    else
    {

echo '<pre />';
print_r($PayPalResult);
}
}

?>
4

1 回答 1

8

您的问题是使用 PAY_PRIMARY 而不仅仅是 PAY。根据 PayPal 的文档...

仅对于链式付款,指定此值以延迟向辅助接收方付款;只处理对主要收款人的付款。

你真的需要推迟它,或者你只是在分裂之后?看起来你正试图同时触发它们,所以真的不需要延迟。

在您的情况下,您可以像您一样简单地设置主要和次要接收者,然后使用 PAY 而不是 PAY_PRIMARY 的 ActionType 调用 Pay。这仍会将其拆分为链式付款(买家在结账时只能看到主要收款人),但次要收款人会像您预期的那样同时收到付款。

根据我的理解,我已经调整了您的代码以执行您想要的操作...

<?php
require_once('../includes/config.php');
require_once('../includes/paypal.class.php');

$PayPalConfig = array(
                      'Sandbox' => $sandbox,
                      'DeveloperAccountEmail' => $developer_account_email,
                      'ApplicationID' => $application_id,
                      'DeviceID' => $device_id,
                      'IPAddress' => $_SERVER['REMOTE_ADDR'],
                      'APIUsername' => $api_username,
                      'APIPassword' => $api_password,
                      'APISignature' => $api_signature,
                      'APISubject' => $api_subject
                    );

$PayPal = new PayPal_Adaptive($PayPalConfig);

$PayRequestFields = array(
                        'ActionType' => 'PAY',                              
                        'CancelURL' => $domain.'cancel.php',                        
                        'CurrencyCode' => 'USD',                                
                        'FeesPayer' => 'EACHRECEIVER',                                  
                        'IPNNotificationURL' => '',                         
                        'Memo' => '',                                       
                        'Pin' => '',                                        
                        'PreapprovalKey' => '',                              
                        'ReturnURL' => $domain.'return.php',                                    
                        'ReverseAllParallelPaymentsOnError' => '',          
                        'SenderEmail' => '',                                
                        'TrackingID' => ''                                  
                        );

$ClientDetailsFields = array(
                        'CustomerID' => '',                                 
                        'CustomerType' => '',                               
                        'GeoLocation' => '',                                
                        'Model' => '',                                      
                        'PartnerName' => ''                                 
                        );

$FundingTypes = array('ECHECK', 'BALANCE', 'CREDITCARD');                   

$Receivers = array();
$Receiver = array(
                'Amount' => '100.00',                                           
                'Email' => 'receiver1accountid',                                                
                'InvoiceID' => '',                                          
                'PaymentType' => 'GOODS',                                       
                'PaymentSubType' => '',                                     
                'Phone' => array('CountryCode' => '', 'PhoneNumber' => '', 'Extension' => ''), 
                'Primary' => 'true'                                             
                );
array_push($Receivers,$Receiver);

$Receiver = array(
                'Amount' => '10.00',                                            
                'Email' => 'receiver2accountid',                                                
                'InvoiceID' => '',                                          
                'PaymentType' => 'GOODS',                                       
                'PaymentSubType' => '',                                     
                'Phone' => array('CountryCode' => '', 'PhoneNumber' => '', 'Extension' => ''), 
                'Primary' => 'false'                                                
                );
array_push($Receivers,$Receiver);

$SenderIdentifierFields = array(
                                'UseCredentials' => ''                      
                                );

$AccountIdentifierFields = array(
                                'Email' => '',                              
                                'Phone' => array('CountryCode' => '', 'PhoneNumber' => '', 'Extension' => '')                               
                                );

$PayPalRequestData = array(
                    'PayRequestFields' => $PayRequestFields, 
                    'ClientDetailsFields' => $ClientDetailsFields, 
                    'FundingTypes' => $FundingTypes, 
                    'Receivers' => $Receivers, 
                    'SenderIdentifierFields' => $SenderIdentifierFields, 
                    'AccountIdentifierFields' => $AccountIdentifierFields
                    );


$PayPalResult = $PayPal->Pay($PayPalRequestData);

if($PayPal->APICallSuccessful($PayPalResult['Ack']))
{
    // Redirect to PayPal so user can complete payment.
    header('Location: '.$PayPalResult['RedirectURL']);
}
else
{
    // Error    
    echo '<pre />';
    print_r($PayPalResult['Errors']);
    exit();
}
?>

同样,您无需担心在这种情况下使用 ExecutePayment。它只会将用户重定向到他们完成付款的 PayPal,然后他们将像现在一样返回到您的 RedirectURL,但同时会触发二次付款。

如果您确实出于某种原因确实想延迟二次付款(大多数人最终会在触发二次付款之前等待一天/一周/等),那么请告诉我,我可以为您提供帮助。

另一个提示:如果您使用的是我的库的最新版本,其中包含一个新功能 PayWithOptions,它将允许您在组合中包含 SetPaymentOptions(),这样您就可以提供有关付款的更多详细信息而无需设置额外的调用靠自己。我建议使用这个。一切都将设置相同,但它带有一些您可以设置的附加参数,这些参数对不同的项目很有用。

于 2012-11-27T06:53:30.307 回答