Add level 2 meta data for Braintree payment gateway

This commit is contained in:
David Bomba 2025-04-08 14:19:53 +10:00
parent a3e27e8550
commit 12702b1ff3
4 changed files with 33 additions and 7 deletions

View File

@ -140,6 +140,10 @@ class ACH implements MethodInterface, LivewireMethodInterface
->where('id', $this->decodePrimaryKey($request->source)) ->where('id', $this->decodePrimaryKey($request->source))
->firstOrFail(); ->firstOrFail();
$total_taxes = \App\Models\Invoice::query()->whereIn('id', $this->transformKeys(array_column($this->braintree->payment_hash->invoices(), 'invoice_id')))->withTrashed()->sum('total_taxes');
$invoice = $this->braintree->payment_hash->fee_invoice;
$po_number = $invoice->po_number ?? $invoice->number ?? '';
$result = $this->braintree->gateway->transaction()->sale([ $result = $this->braintree->gateway->transaction()->sale([
'amount' => $this->braintree->payment_hash->data->amount_with_fee, 'amount' => $this->braintree->payment_hash->data->amount_with_fee,
'paymentMethodToken' => $token->token, 'paymentMethodToken' => $token->token,
@ -147,6 +151,8 @@ class ACH implements MethodInterface, LivewireMethodInterface
'options' => [ 'options' => [
'submitForSettlement' => true, 'submitForSettlement' => true,
], ],
'tax_amount' => $total_taxes,
'purchase_order_number' => $po_number,
]); ]);
if ($result->success) { if ($result->success) {

View File

@ -12,19 +12,21 @@
namespace App\PaymentDrivers\Braintree; namespace App\PaymentDrivers\Braintree;
use App\Exceptions\PaymentFailed; use App\Models\Payment;
use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest; use App\Models\SystemLog;
use App\Models\GatewayType;
use App\Models\PaymentType;
use App\Http\Requests\Request; use App\Http\Requests\Request;
use App\Jobs\Util\SystemLogger; use App\Jobs\Util\SystemLogger;
use App\Models\GatewayType; use App\Utils\Traits\MakesHash;
use App\Models\Payment; use App\Exceptions\PaymentFailed;
use App\Models\PaymentType;
use App\Models\SystemLog;
use App\PaymentDrivers\BraintreePaymentDriver; use App\PaymentDrivers\BraintreePaymentDriver;
use App\PaymentDrivers\Common\LivewireMethodInterface; use App\PaymentDrivers\Common\LivewireMethodInterface;
use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest;
class CreditCard implements LivewireMethodInterface class CreditCard implements LivewireMethodInterface
{ {
use MakesHash;
/** /**
* @var BraintreePaymentDriver * @var BraintreePaymentDriver
*/ */
@ -108,6 +110,10 @@ class CreditCard implements LivewireMethodInterface
$token = $this->getPaymentToken($request->all(), $customer->id); $token = $this->getPaymentToken($request->all(), $customer->id);
$total_taxes = \App\Models\Invoice::query()->whereIn('id', $this->transformKeys(array_column($this->braintree->payment_hash->invoices(), 'invoice_id')))->withTrashed()->sum('total_taxes');
$invoice = $this->braintree->payment_hash->fee_invoice;
$po_number = $invoice->po_number ?? $invoice->number ?? '';
$data = [ $data = [
'amount' => $this->braintree->payment_hash->data->amount_with_fee, //@phpstan-ignore-line 'amount' => $this->braintree->payment_hash->data->amount_with_fee, //@phpstan-ignore-line
'paymentMethodToken' => $token, 'paymentMethodToken' => $token,
@ -122,7 +128,9 @@ class CreditCard implements LivewireMethodInterface
'locality' => $this->braintree->client->city ?: '', 'locality' => $this->braintree->client->city ?: '',
'postalCode' => $this->braintree->client->postal_code ?: '', 'postalCode' => $this->braintree->client->postal_code ?: '',
'countryCodeAlpha2' => $this->braintree->client->country ? $this->braintree->client->country->iso_3166_2 : 'US', 'countryCodeAlpha2' => $this->braintree->client->country ? $this->braintree->client->country->iso_3166_2 : 'US',
] ],
'tax_amount' => $total_taxes,
'purchase_order_number' => $po_number,
]; ];
if ($this->braintree->company_gateway->getConfigField('merchantAccountId')) { if ($this->braintree->company_gateway->getConfigField('merchantAccountId')) {

View File

@ -11,9 +11,11 @@ use App\Models\PaymentType;
use App\Models\SystemLog; use App\Models\SystemLog;
use App\PaymentDrivers\BraintreePaymentDriver; use App\PaymentDrivers\BraintreePaymentDriver;
use App\PaymentDrivers\Common\LivewireMethodInterface; use App\PaymentDrivers\Common\LivewireMethodInterface;
use App\Utils\Traits\MakesHash;
class PayPal implements LivewireMethodInterface class PayPal implements LivewireMethodInterface
{ {
use MakesHash;
/** /**
* @var BraintreePaymentDriver * @var BraintreePaymentDriver
*/ */
@ -68,6 +70,10 @@ class PayPal implements LivewireMethodInterface
$token = $this->getPaymentToken($request->all(), $customer->id); $token = $this->getPaymentToken($request->all(), $customer->id);
$total_taxes = \App\Models\Invoice::query()->whereIn('id', $this->transformKeys(array_column($this->braintree->payment_hash->invoices(), 'invoice_id')))->withTrashed()->sum('total_taxes');
$invoice = $this->braintree->payment_hash->fee_invoice;
$po_number = $invoice->po_number ?? $invoice->number ?? '';
$result = $this->braintree->gateway->transaction()->sale([ $result = $this->braintree->gateway->transaction()->sale([
'amount' => $this->braintree->payment_hash->data->amount_with_fee, 'amount' => $this->braintree->payment_hash->data->amount_with_fee,
'paymentMethodToken' => $token, 'paymentMethodToken' => $token,
@ -79,6 +85,8 @@ class PayPal implements LivewireMethodInterface
'description' => 'Meaningful description.', 'description' => 'Meaningful description.',
], ],
], ],
'tax_amount' => $total_taxes,
'purchase_order_number' => $po_number,
]); ]);
if ($result->success) { if ($result->success) {

View File

@ -222,6 +222,7 @@ class BraintreePaymentDriver extends BaseDriver
$amount = array_sum(array_column($payment_hash->invoices(), 'amount')) + $payment_hash->fee_total; $amount = array_sum(array_column($payment_hash->invoices(), 'amount')) + $payment_hash->fee_total;
$invoice = Invoice::query()->whereIn('id', $this->transformKeys(array_column($payment_hash->invoices(), 'invoice_id')))->withTrashed()->first(); $invoice = Invoice::query()->whereIn('id', $this->transformKeys(array_column($payment_hash->invoices(), 'invoice_id')))->withTrashed()->first();
$total_taxes = Invoice::query()->whereIn('id', $this->transformKeys(array_column($payment_hash->invoices(), 'invoice_id')))->withTrashed()->sum('total_taxes');
if ($invoice) { if ($invoice) {
$description = "Invoice {$invoice->number} for {$amount} for client {$this->client->present()->name()}"; $description = "Invoice {$invoice->number} for {$amount} for client {$this->client->present()->name()}";
@ -235,9 +236,12 @@ class BraintreePaymentDriver extends BaseDriver
'amount' => $amount, 'amount' => $amount,
'paymentMethodToken' => $cgt->token, 'paymentMethodToken' => $cgt->token,
'deviceData' => '', 'deviceData' => '',
'channel' => 'invoiceninja_BT',
'options' => [ 'options' => [
'submitForSettlement' => true, 'submitForSettlement' => true,
], ],
'tax_amount' => $total_taxes,
'purchase_order_number' => $invoice->po_number ?? $invoice->number,
]); ]);
if ($result->success) { if ($result->success) {