gpt4 book ai didi

php - Paypal PHP SDK批量支付

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

我正在尝试测试 Paypals 批量支付:

我的代码:

// ...

public function sendBatchPayment(array $payoutItems, $senderBatchId, $type= 'Email', $currency = 'CAD', $note = '') {

$payouts = new \PayPal\Api\Payout();

$senderBatchHeader = new \PayPal\Api\PayoutSenderBatchHeader();

$senderBatchHeader->setSenderBatchId($senderBatchId)
->setEmailSubject("You have a Payout!");



foreach ($payoutItems as $payoutItem) {

$emailExists = (isset($payoutItem['email']) && !empty($payoutItem['email']));

$amountExists = (isset($payoutItem['amount']) && !empty($payoutItem['amount']));

$senderItemIdExists = (isset($payoutItem['sender_item_id']) && !empty($payoutItem['sender_item_id']));

if(!$emailExists || !$amountExists || !$senderItemIdExists) continue;

$receiver = $payoutItem['email'];

$item_id = $payoutItem['sender_item_id'];

$value = (float) $payoutItem['amount'];

$senderItem = new \PayPal\Api\PayoutItem();

$senderItem->setRecipientType('Email')
->setNote('Your Payment')
->setReceiver($receiver)
->setSenderItemId($item_id)
->setAmount(new \PayPal\Api\Currency('{
"value":$value,
"currency":"CAD"
}'));


$payouts->setSenderBatchHeader($senderBatchHeader)
->addItem($senderItem);


} // EO foreach

$request = clone $payouts;

try {

$output = $payouts->create(null, $this->apiContext);

} catch (Exception $e) {

return $e->getMessage;
}

return $output;


}

但我一直得到 400。

我怀疑这是因为它在循环中:

$payouts->setSenderBatchHeader($senderBatchHeader)
->addItem($senderItem);

当 Paypals 的例子是这样的:

$payouts->setSenderBatchHeader($senderBatchHeader)
->addItem($senderItem1)
->addItem($senderItem2);

;

如何在循环中添加项目?

编辑:错误:

PayPalConnectionException in PayPalHttpConnection.php line 180:
Got Http response code 400 when accessing https://api.sandbox.paypal.com/v1/payments/payouts?.

谢谢。

最佳答案

我设法通过将 $senderBatchId 值更改为以下内容来解决问题:

uniqid()

代替:

uniqid() . microtime(true)

出于某种原因,Paypal REST API 不喜欢这种方式。如果比我更好的程序员可以解释这一点,我会标记他/她的答案是正确的。

关于php - Paypal PHP SDK批量支付,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32171890/

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