mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Merge pull request #7486 from yois615/v5-develop
Auth.net Level 2 tax data
This commit is contained in:
commit
7a4c1f1779
@ -12,11 +12,14 @@
|
|||||||
|
|
||||||
namespace App\PaymentDrivers\Authorize;
|
namespace App\PaymentDrivers\Authorize;
|
||||||
|
|
||||||
|
use App\Models\Invoice;
|
||||||
use App\PaymentDrivers\AuthorizePaymentDriver;
|
use App\PaymentDrivers\AuthorizePaymentDriver;
|
||||||
|
use App\Utils\Traits\MakesHash;
|
||||||
use net\authorize\api\contract\v1\CreateTransactionRequest;
|
use net\authorize\api\contract\v1\CreateTransactionRequest;
|
||||||
use net\authorize\api\contract\v1\CustomerProfilePaymentType;
|
use net\authorize\api\contract\v1\CustomerProfilePaymentType;
|
||||||
use net\authorize\api\contract\v1\OrderType;
|
use net\authorize\api\contract\v1\OrderType;
|
||||||
use net\authorize\api\contract\v1\PaymentProfileType;
|
use net\authorize\api\contract\v1\PaymentProfileType;
|
||||||
|
use net\authorize\api\contract\v1\ExtendedAmountType;
|
||||||
use net\authorize\api\contract\v1\TransactionRequestType;
|
use net\authorize\api\contract\v1\TransactionRequestType;
|
||||||
use net\authorize\api\controller\CreateTransactionController;
|
use net\authorize\api\controller\CreateTransactionController;
|
||||||
|
|
||||||
@ -25,6 +28,8 @@ use net\authorize\api\controller\CreateTransactionController;
|
|||||||
*/
|
*/
|
||||||
class ChargePaymentProfile
|
class ChargePaymentProfile
|
||||||
{
|
{
|
||||||
|
use MakesHash;
|
||||||
|
|
||||||
public function __construct(AuthorizePaymentDriver $authorize)
|
public function __construct(AuthorizePaymentDriver $authorize)
|
||||||
{
|
{
|
||||||
$this->authorize = $authorize;
|
$this->authorize = $authorize;
|
||||||
@ -44,19 +49,40 @@ class ChargePaymentProfile
|
|||||||
$profileToCharge->setPaymentProfile($paymentProfile);
|
$profileToCharge->setPaymentProfile($paymentProfile);
|
||||||
|
|
||||||
$invoice_numbers = '';
|
$invoice_numbers = '';
|
||||||
|
$taxAmount = 0;
|
||||||
|
$invoiceTotal = 0;
|
||||||
|
$invoiceTaxes = 0;
|
||||||
|
|
||||||
if($this->authorize->payment_hash->data)
|
if($this->authorize->payment_hash->data) {
|
||||||
$invoice_numbers = collect($this->authorize->payment_hash->data->invoices)->pluck('invoice_number')->implode(',');
|
$invoice_numbers = collect($this->authorize->payment_hash->data->invoices)->pluck('invoice_number')->implode(",");
|
||||||
|
$invObj = Invoice::whereIn('id', $this->transformKeys(array_column($this->authorize->payment_hash->invoices(), 'invoice_id')))->withTrashed()->get();
|
||||||
|
|
||||||
|
$invoiceTotal = round($invObj->pluck('amount')->sum(), 2);
|
||||||
|
$invoiceTaxes = round($invObj->pluck('total_taxes')->sum(), 2);
|
||||||
|
|
||||||
|
if ($invoiceTotal != $amount) {
|
||||||
|
$taxRatio = $amount/$invoiceTotal;
|
||||||
|
$taxAmount = round($invoiceTaxes*$taxRatio, 2);
|
||||||
|
} else {
|
||||||
|
$taxAmount = $invoiceTaxes;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$description = "Invoices: {$invoice_numbers} for {$amount} for client {$this->authorize->client->present()->name()}";
|
$description = "Invoices: {$invoice_numbers} for {$amount} for client {$this->authorize->client->present()->name()}";
|
||||||
|
|
||||||
$order = new OrderType();
|
$order = new OrderType();
|
||||||
$order->setInvoiceNumber(substr($invoice_numbers,0,19));
|
$order->setInvoiceNumber(substr($invoice_numbers,0,19));
|
||||||
$order->setDescription(substr($description,0,255));
|
$order->setDescription(substr($description,0,255));
|
||||||
|
|
||||||
|
$tax = new ExtendedAmountType();
|
||||||
|
$tax->setName('tax');
|
||||||
|
$tax->setAmount($taxAmount);
|
||||||
|
|
||||||
$transactionRequestType = new TransactionRequestType();
|
$transactionRequestType = new TransactionRequestType();
|
||||||
$transactionRequestType->setTransactionType('authCaptureTransaction');
|
$transactionRequestType->setTransactionType('authCaptureTransaction');
|
||||||
$transactionRequestType->setAmount($amount);
|
$transactionRequestType->setAmount($amount);
|
||||||
|
$transactionRequestType->setTax($tax);
|
||||||
|
$transactionRequestType->setTaxExempt(empty($taxAmount));
|
||||||
$transactionRequestType->setOrder($order);
|
$transactionRequestType->setOrder($order);
|
||||||
$transactionRequestType->setProfile($profileToCharge);
|
$transactionRequestType->setProfile($profileToCharge);
|
||||||
$transactionRequestType->setCurrencyCode($this->authorize->client->currency()->code);
|
$transactionRequestType->setCurrencyCode($this->authorize->client->currency()->code);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user