2012-11-26 201 views
0

我想付款給兩個接收者,即買家購買100件商品,接收者1得到90,接收者2得到10。我正在使用鏈接付款方式。我在收款人1的賬戶中收到了100美元,但是我無法收到收款人2的付款。收件人的帳戶ID已設置,但未在此處給出。我做錯了什麼?謝謝Paypal自適應付款

<?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); 
} 
} 

?> 

回答

8

你的問題是使用PAY_PRIMARY而不是隻是付費。每個PayPal的文檔...

僅限於鏈接付款,請指定此值以延遲付款給 輔助接收方;僅向主要接收方付款 已處理。

你是否真的需要延遲它,或者你是否僅僅在分裂之後?看起來你試圖同時觸發它們,所以真的不需要延遲。

在您的情況下,您可以像設置主要和次要接收器一樣簡單地設置,然後使用PAY的ActionType而不是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,但二次付款將同時觸發。

如果您真的想延遲二次付款出於某種原因(大多數人最終等待一天/周/等觸發二次付款之前),請讓我知道,我可以幫助你。

另一個提示:如果您使用的是most recent version of my library,則會有一個新功能,包括PayWithOptions,它允許您在組合中包含SetPaymentOptions(),以便您可以提供有關付款的更多詳細信息,而無需設置其他呼叫你自己。我建議使用這個。一切都會設置相同,但是它會附帶一些可以設置的附加參數,這些參數可以用於不同的項目。

+1

謝謝安德魯!我只是完成了它。不過,我只想讓這兩筆款項同時完成。感謝您寶貴的意見,以及您建立的圖書館。它真的很有趣。再次感謝........ –

+0

抱歉不能投票,因爲我的repu不允許截至目前....... :-) –

+0

@Andrew Angell您好,我想延遲二次付款,因爲二級接收器只有在完成任務後纔會被記入。所以,你能告訴我你的想法如何解決這個問題嗎?建議一些鏈接... – SDK

相關問題