Я пытаюсь включить несколько lineItems в транзакцию Braintree для каждого продукта в корзине.
Приведенная ниже транзакция прошла успешно и работает, как и ожидалось, в качестве lineItem добавляется только один элемент.
$result = Braintree_Transaction::sale([
'orderId' => $hash,
'amount' => $this->basket->subTotal() + $this->basket->delivery(),
'paymentMethodNonce' => $request->getParam('payment_method_nonce'),
'shippingAmount' => $this->basket->delivery(),
'discountAmount' => '0',
'shipsFromPostalCode' => '7008',
'taxExempt' => true,
'purchaseOrderNumber' => $hash1,
'options' => [
'submitForSettlement' => true,
],
'customer' => [
'firstName' => $request->getParam('name'),
'email' => $request->getParam('email'),
],
'shipping' => [
'firstName' => $request->getParam('name'),
'streetAddress' => $request->getParam('address1'),
'locality' => $request->getParam('city'),
'postalCode' => $request->getParam('postal_code'),
'countryCodeAlpha3' => 'AUS',
],
'lineItems' => [
[
'quantity' => $product->quantity,
'name' => $product->title,
'kind' => 'debit',
'unitAmount' => $product->price,
'totalAmount' => $product->price * $product->quantity
],
]
]);
Однако, когда я пытаюсь включить все товары в корзину, как показано ниже
$basketProducts = $this->basket->all();
if($basketProducts){
$lineItems = '';
foreach ($basketProducts as $product){
$lineItems .= <<<EOD
[
'quantity' => $product->quantity,
'name' => $product->title,
'kind' => 'debit',
'unitAmount' => $product->price,
'totalAmount' => $product->price * $product->quantity
],
EOD;
}
}
$result = Braintree_Transaction::sale([
'orderId' => $hash,
'amount' => $this->basket->subTotal() + $this->basket->delivery(),
'paymentMethodNonce' => $request->getParam('payment_method_nonce'),
'shippingAmount' => $this->basket->delivery(),
'discountAmount' => '0',
'shipsFromPostalCode' => '7008',
'taxExempt' => true,
'purchaseOrderNumber' => $hash1,
'options' => [
'submitForSettlement' => true,
],
'customer' => [
'firstName' => $request->getParam('name'),
'email' => $request->getParam('email'),
],
'shipping' => [
'firstName' => $request->getParam('name'),
'streetAddress' => $request->getParam('address1'),
'locality' => $request->getParam('city'),
'postalCode' => $request->getParam('postal_code'),
'countryCodeAlpha3' => 'AUS',
],
'lineItems' => [
$lineItems
]
]);
Я получаю это сообщение об ошибке:
Тип: InvalidArgumentException
Сообщение: недопустимые ключи: lineItems [['amount' => 1, 'name' =>Абрикосовый цыпленок, 'kind' => 'debit', 'unitAmount' => 9.8, 'totalAmount' => 9.8 * 1],]
Файл: C: \ wamp64 \ www \ vendor \ braintree \ braintree_php \ lib \Braintree \ Util.php
Строка: 396
Итак, похоже, что он извлекает нужные данные из этой переменной, просто Braintree обнаруживает их как недействительные.
Я что-то упустил?Любая помощь будет очень благодарна!