gpt4 book ai didi

Paypal 自适应支付

转载 作者:太空宇宙 更新时间:2023-11-03 16:12:56 25 4
gpt4 key购买 nike

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

?>

最佳答案

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

For chained payments only, specify this value to delay payments to the secondary receivers; only the payment to the primary receiver is processed.

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

在您的情况下,您可以简单地设置主要和次要接收者,然后使用 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,但二次付款将同时触发。

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

另一个提示:如果您使用 most recent version of my library包含一个新函数 PayWithOptions,它允许您在组合中包含 SetPaymentOptions(),这样您就可以提供有关付款的更多详细信息,而无需自行设置其他调用。我建议使用这个。一切都将设置相同,但它带有一些您可以设置的额外参数,这些参数对不同的项目很有用。

关于 Paypal 自适应支付,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13573882/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com