Merge pull request #6472 from turbo124/v5-develop

Updates for authorize.net
This commit is contained in:
David Bomba 2021-08-17 18:45:21 +10:00 committed by GitHub
commit 17ba910ba2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 78 additions and 17 deletions

View File

@ -81,6 +81,8 @@ class InvoiceItemSum
private function push()
{
nlog($this->sub_total . " + ". $this->getLineTotal());
$this->sub_total += $this->getLineTotal();
$this->line_items[] = $this->item;
@ -103,7 +105,15 @@ class InvoiceItemSum
if ($this->invoice->is_amount_discount) {
$this->setLineTotal($this->getLineTotal() - $this->formatValue($this->item->discount, $this->currency->precision));
} else {
$this->setLineTotal($this->getLineTotal() - $this->formatValue(round($this->item->line_total * ($this->item->discount / 100), 2), $this->currency->precision));
/*Test 16-08-2021*/
$discount = ($this->item->line_total * ($this->item->discount / 100));
$this->setLineTotal($this->formatValue(($this->getLineTotal() - $discount), $this->currency->precision));
/*Test 16-08-2021*/
//replaces the following
// $this->setLineTotal($this->getLineTotal() - $this->formatValue(round($this->item->line_total * ($this->item->discount / 100), 2), $this->currency->precision));
}
$this->item->is_amount_discount = $this->invoice->is_amount_discount;

View File

@ -433,9 +433,14 @@ class CompanyGatewayController extends BaseController
*/
public function destroy(DestroyCompanyGatewayRequest $request, CompanyGateway $company_gateway)
{
$company_gateway->driver(new Client)
->disconnect();
$company_gateway->delete();
return $this->itemResponse($company_gateway->fresh());
}
/**

View File

@ -81,6 +81,8 @@ class StripeConnectController extends BaseController
}
MultiDB::findAndSetDbByCompanyKey($request->getTokenContent()['company_key']);
$company = Company::where('company_key', $request->getTokenContent()['company_key'])->first();
$company_gateway = CompanyGateway::query()

View File

@ -175,7 +175,8 @@ class ReminderJob implements ShouldQueue
$invoice->line_items = $invoice_items;
/**Refresh Invoice values*/
$invoice = $invoice->calc()->getInvoice()->save();
$invoice->calc()->getInvoice()->save();
$invoice->fresh();
$invoice->service()->deletePdf();
nlog("adjusting client balance and invoice balance by ". ($invoice->balance - $temp_invoice_balance));

View File

@ -115,7 +115,7 @@ class AuthorizeCreditCard
];
$logger_message = [
'server_response' => $response->getTransactionResponse()->getTransId(),
'server_response' => $response->getTransId(),
'data' => $this->formatGatewayResponse($data, $vars),
];
@ -130,11 +130,11 @@ class AuthorizeCreditCard
];
$logger_message = [
'server_response' => $response->getTransactionResponse()->getTransId(),
'server_response' => $response->getTransId(),
'data' => $this->formatGatewayResponse($data, $vars),
];
PaymentFailureMailer::dispatch($this->authorize->client, $response->getTransactionResponse()->getTransId(), $this->authorize->client->company, $amount);
PaymentFailureMailer::dispatch($this->authorize->client, $response->getTransId(), $this->authorize->client->company, $amount);
SystemLogger::dispatch($logger_message, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_AUTHORIZE, $this->authorize->client, $this->authorize->client->company);
@ -147,8 +147,8 @@ class AuthorizeCreditCard
{
$response = $data['response'];
if ($response != null && $response->getMessages()->getResultCode() == 'Ok') {
// if ($response != null && $response->getMessages()->getResultCode() == 'Ok') {
if ($response != null && $response->getMessages() != null) {
return $this->processSuccessfulResponse($data, $request);
}
@ -165,7 +165,7 @@ class AuthorizeCreditCard
$payment_record['amount'] = $amount;
$payment_record['payment_type'] = PaymentType::CREDIT_CARD_OTHER;
$payment_record['gateway_type_id'] = GatewayType::CREDIT_CARD;
$payment_record['transaction_reference'] = $response->getTransactionResponse()->getTransId();
$payment_record['transaction_reference'] = $response->getTransId();
$payment = $this->authorize->createPayment($payment_record);
@ -183,7 +183,7 @@ class AuthorizeCreditCard
];
$logger_message = [
'server_response' => $data['response']->getTransactionResponse()->getTransId(),
'server_response' => $data['response']->getTransId(),
'data' => $this->formatGatewayResponse($data, $vars),
];
@ -204,7 +204,7 @@ class AuthorizeCreditCard
$response = $data['response'];
$amount = array_key_exists('amount_with_fee', $data) ? $data['amount_with_fee'] : 0;
PaymentFailureMailer::dispatch($this->authorize->client, $response->getTransactionResponse()->getTransId(), $this->authorize->client->company, $data['amount_with_fee']);
PaymentFailureMailer::dispatch($this->authorize->client, $response->getTransId(), $this->authorize->client->company, $data['amount_with_fee']);
throw new \Exception(ctrans('texts.error_title'));
}
@ -216,15 +216,20 @@ class AuthorizeCreditCard
$code = '';
$description = '';
if($response->getTransactionResponse()->getMessages() !== null){
$code = $response->getTransactionResponse()->getMessages()[0]->getCode();
$description = $response->getTransactionResponse()->getMessages()[0]->getDescription();
if($response->getMessages() !== null){
$code = $response->getMessages()[0]->getCode();
$description = $response->getMessages()[0]->getDescription();
}
if ($response->getErrors() != null) {
$code = $response->getErrors()[0]->getErrorCode();
$description = $response->getErrors()[0]->getErrorText();
}
return [
'transaction_reference' => $response->getTransactionResponse()->getTransId(),
'transaction_reference' => $response->getTransId(),
'amount' => $vars['amount'],
'auth_code' => $response->getTransactionResponse()->getAuthCode(),
'auth_code' => $response->getAuthCode(),
'code' => $code,
'description' => $description,
'invoices' => $vars['invoices'],

View File

@ -93,7 +93,7 @@ class ChargePaymentProfile
}
return [
'response' => $response,
'response' => $tresponse,
'amount' => $amount,
'profile_id' => $profile_id,
'payment_profile_id' => $payment_profile_id,

View File

@ -631,4 +631,9 @@ class BaseDriver extends AbstractPaymentDriver
return $types;
}
public function disconnect()
{
return true;
}
}

View File

@ -547,4 +547,29 @@ class StripePaymentDriver extends BaseDriver
{
return (new Verify($this))->run();
}
public function disconnect()
{
if(!$this->stripe_connect)
return true;
if(!strlen($this->company_gateway->getConfigField('account_id')) > 1 )
throw new StripeConnectFailure('Stripe Connect has not been configured');
Stripe::setApiKey(config('ninja.ninja_stripe_key'));
try {
\Stripe\OAuth::deauthorize([
'client_id' => config('ninja.ninja_stripe_client_id'),
'stripe_user_id' => $this->company_gateway->getConfigField('account_id'),
]);
}
catch(\Exception $e){
throw new StripeConnectFailure('Unable to disconnect Stripe Connect');
}
return response()->json(['message' => 'success'], 200);
}
}

View File

@ -55,6 +55,13 @@ trait CleanLineItems
//always cast the value!
$item[$key] = BaseSettings::castAttribute(InvoiceItem::$casts[$key], $item[$key]);
}
if(array_key_exists('type_id', $item) && $item['type_id'] == '0')
$item['type_id'] = '1';
if(!array_key_exists('type_id', $item))
$item['type_id'] = '1';
}
if (array_key_exists('id', $item)) {

View File

@ -158,6 +158,7 @@ class CompanyLedgerTest extends TestCase
$item = [];
$item['quantity'] = 1;
$item['cost'] = 10;
$item['type_id'] = "1";
$line_items[] = $item;