我想向两个接收者付款,即买家购买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);
}
}
?>
答案 0 :(得分:8)
您的问题是使用PAY_PRIMARY而不仅仅是PAY。 Per 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(),这样您就可以在不设置的情况下提供有关付款的更多详细信息额外的电话自己。我建议使用这个。一切都会设置相同,但随后它会附带一些您可以设置的附加参数,这些参数可用于不同的项目。