diff --git a/app/Ninja/PaymentDrivers/BasePaymentDriver.php b/app/Ninja/PaymentDrivers/BasePaymentDriver.php index 6822278b67cc..26a938f14dde 100644 --- a/app/Ninja/PaymentDrivers/BasePaymentDriver.php +++ b/app/Ninja/PaymentDrivers/BasePaymentDriver.php @@ -10,6 +10,7 @@ use App\Models\GatewayType; use App\Models\License; use App\Models\Payment; use App\Models\PaymentMethod; +use Omnipay\Common\Item; use CreditCard; use DateTime; use Exception; @@ -304,7 +305,10 @@ class BasePaymentDriver // prepare and process payment $data = $this->paymentDetails($paymentMethod); - $response = $gateway->purchase($data)->send(); + $items = $this->paymentItems(); + $response = $gateway->purchase($data) + ->setItems($items) + ->send(); $this->purchaseResponse = (array) $response->getData(); // parse the transaction reference @@ -337,6 +341,38 @@ class BasePaymentDriver } } + private function paymentItems() + { + $invoice = $this->invoice(); + $items = []; + $total = 0; + + foreach ($invoice->invoice_items as $invoiceItem) { + $item = new Item([ + 'name' => $invoiceItem->product_key, + 'description' => $invoiceItem->notes, + 'price' => $invoiceItem->cost, + 'quantity' => $invoiceItem->qty, + ]); + + $items[] = $item; + $total += $invoiceItem->cost * $invoiceItem->qty; + } + + if ($total != $invoice->getRequestedAmount()) { + $item = new Item([ + 'name' => trans('texts.other'), + 'description' => '', + 'price' => $invoice->getRequestedAmount() - $total, + 'quantity' => 1, + ]); + + $items[] = $item; + } + + return $items; + } + private function updateClient() { if (! $this->isGatewayType(GATEWAY_TYPE_CREDIT_CARD)) { diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 1deb2336f85d..8ad7014965da 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -2288,6 +2288,7 @@ $LANG = array( 'deleted_recurring_expense' => 'Successfully deleted project', 'deleted_recurring_expense' => 'Successfully deleted :count projects', 'view_recurring_expense' => 'View Recurring Expense', + 'other' => 'Other', );