Paypal 自适应支付

问题描述 投票:0回答:1

我想向两个接收者付款,即买家以 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);
}
}

?>
php paypal paypal-adaptive-payments
1个回答
8
投票

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

仅对于链式支付,指定此值以延迟向 辅助接收器;仅向主要接收者付款 已处理。

你真的需要推迟它吗?或者你只是在分手之后? 看起来您正在尝试同时触发它们,因此实际上没有必要延迟。

在您的情况下,您可以简单地设置主要和辅助接收者,然后使用 ActionType PAY 而不是 PAY_PRIMARY 调用 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() ,以便您可以提供有关付款的更多详细信息,而无需设置自行拨打额外电话。 我建议使用这个。 一切设置都相同,但它附带了一些您可以设置的附加参数,这些参数对于不同的项目很有用。

© www.soinside.com 2019 - 2024. All rights reserved.