Merge pull request #3849 from turbo124/v2

Fix for adding credit card as payment method with authorize.net
This commit is contained in:
David Bomba 2020-06-27 12:22:14 +10:00 committed by GitHub
commit 168750183b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 511 additions and 203 deletions

View File

@ -90,6 +90,11 @@ class Payment extends BaseModel
return $this->belongsTo(Client::class)->withTrashed();
}
public function company_gateway()
{
return $this->belongsTo(CompanyGateway::class)->withTrashed();
}
public function company()
{
return $this->belongsTo(Company::class);

View File

@ -120,6 +120,7 @@ class AuthorizeCreditCard
$payment->client_id = $this->authorize->client->id;
$payment->company_gateway_id = $this->authorize->company_gateway->id;
$payment->status_id = Payment::STATUS_COMPLETED;
$payment->gateway_type_id = $this->authorize->payment_method;
$payment->type_id = PaymentType::CREDIT_CARD_OTHER;
$payment->currency_id = $this->authorize->client->getSetting('currency_id');
$payment->date = Carbon::now();
@ -129,7 +130,6 @@ class AuthorizeCreditCard
$payment->client->getNextPaymentNumber($this->authorize->client);
$payment->save();
$this->authorize->attachInvoices($payment, $request->hashed_ids);
$payment->service()->updateInvoicePayment();

View File

@ -64,11 +64,11 @@ class AuthorizePaymentMethod
}
public function authorizeResponseView($payment_method, $data)
public function authorizeResponseView($data)
{
$this->payment_method = $payment_method;
$this->payment_method = $data['payment_method_id'];
switch ($payment_method) {
switch ($this->payment_method) {
case GatewayType::CREDIT_CARD:
return $this->authorizeCreditCardResponse($data);
break;

View File

@ -102,7 +102,7 @@ class AuthorizePaymentDriver extends BaseDriver
public function authorizeResponseView(array $data)
{
return (new AuthorizePaymentMethod($this))->authorizeResponseView($data['gateway_type_id'], $data);
return (new AuthorizePaymentMethod($this))->authorizeResponseView($data);
}
public function authorize($payment_method)

View File

@ -44,8 +44,9 @@ class RefundPayment
return $this->calculateTotalRefund() //sets amount for the refund (needed if we are refunding multiple invoices in one payment)
->setStatus() //sets status of payment
->buildCreditNote() //generate the credit note
->buildCreditLineItems() //generate the credit note items
//->reversePayment()
//->buildCreditNote() //generate the credit note
//->buildCreditLineItems() //generate the credit note items
->updateCreditables() //return the credits first
->updatePaymentables() //update the paymentable items
->adjustInvoices()
@ -53,19 +54,23 @@ class RefundPayment
->save();
}
/**
* Process the refund through the gateway
*
* @return $this
*/
private function processGatewayRefund()
{
if ($this->refund_data['gateway_refund'] !== false && $this->total_refund > 0) {
$gateway = CompanyGateway::first();
if ($gateway) {
if ($this->payment->company_gateway) {
$response = $gateway->driver($this->payment->client)->refund($this->payment, $this->total_refund);
if ($response['success']) {
throw new PaymentRefundFailed();
}
$this->payment->refunded = $this->total_refund;
$this->payment->refunded += $this->total_refund;
$this
->createActivity($gateway)
@ -78,20 +83,12 @@ class RefundPayment
return $this;
}
public function updateCreditNoteBalance()
{
$this->credit_note->balance -= $this->total_refund;
$this->credit_note->status_id = Credit::STATUS_APPLIED;
$this->credit_note->balance === 0
? $this->credit_note->status_id = Credit::STATUS_APPLIED
: $this->credit_note->status_id = Credit::STATUS_PARTIAL;
$this->credit_note->save();
return $this;
}
/**
* Create the payment activity
*
* @param json $notes gateway_transaction
* @return $this
*/
private function createActivity($notes)
{
$fields = new \stdClass;
@ -116,90 +113,43 @@ class RefundPayment
return $this;
}
/**
* Determine the amount of refund
*
* @return $this
*/
private function calculateTotalRefund()
{
if (array_key_exists('invoices', $this->refund_data) && count($this->refund_data['invoices']) > 0){
info("array of invoice to refund");
if (array_key_exists('invoices', $this->refund_data) && count($this->refund_data['invoices']) > 0)
$this->total_refund = collect($this->refund_data['invoices'])->sum('amount');
}
else{
info("no invoices found - refunding total.");
else
$this->total_refund = $this->refund_data['amount'];
}
return $this;
}
/**
* Set the payment status
*/
private function setStatus()
{
if ($this->refund_data['amount'] == $this->payment->amount) {
if ($this->refund_data['amount'] == $this->payment->amount)
$this->payment->status_id = Payment::STATUS_REFUNDED;
} else {
else
$this->payment->status_id = Payment::STATUS_PARTIALLY_REFUNDED;
}
return $this;
}
private function buildCreditNote()
{
$this->credit_note = CreditFactory::create($this->payment->company_id, $this->payment->user_id);
$this->credit_note->assigned_user_id = isset($this->payment->assigned_user_id) ?: null;
$this->credit_note->date = $this->refund_data['date'];
$this->credit_note->status_id = Credit::STATUS_SENT;
$this->credit_note->client_id = $this->payment->client->id;
$this->credit_note->amount = $this->total_refund;
$this->credit_note->balance = $this->total_refund;
$this->credit_note->save();
$this->credit_note->number = $this->payment->client->getNextCreditNumber($this->payment->client);
$this->credit_note->save();
return $this;
}
private function buildCreditLineItems()
{
$ledger_string = '';
if (isset($this->refund_data['invoices']) && count($this->refund_data['invoices']) > 0) {
foreach ($this->refund_data['invoices'] as $invoice) {
$inv = Invoice::find($invoice['invoice_id']);
$credit_line_item = InvoiceItemFactory::create();
$credit_line_item->quantity = 1;
$credit_line_item->cost = $invoice['amount'];
$credit_line_item->product_key = ctrans('texts.invoice');
$credit_line_item->notes = ctrans('texts.refund_body', ['amount' => $invoice['amount'], 'invoice_number' => $inv->number]);
$credit_line_item->line_total = $invoice['amount'];
$credit_line_item->date = $this->refund_data['date'];
$ledger_string .= $credit_line_item->notes . ' ';
$line_items[] = $credit_line_item;
}
} else {
$credit_line_item = InvoiceItemFactory::create();
$credit_line_item->quantity = 1;
$credit_line_item->cost = $this->refund_data['amount'];
$credit_line_item->product_key = ctrans('texts.credit');
$credit_line_item->notes = ctrans('texts.credit_created_by', ['transaction_reference' => $this->payment->number]);
$credit_line_item->line_total = $this->refund_data['amount'];
$credit_line_item->date = $this->refund_data['date'];
$line_items = [];
$line_items[] = $credit_line_item;
}
$this->credit_note->line_items = $line_items;
$this->credit_note->save();
return $this;
}
/**
* Update the paymentable records
*
* @return $this
*/
private function updatePaymentables()
{
if (isset($this->refund_data['invoices']) && count($this->refund_data['invoices']) > 0) {
@ -218,6 +168,12 @@ class RefundPayment
return $this;
}
/**
* If credits have been bundled in this payment, we
* need to reverse these
*
* @return $this
*/
private function updateCreditables()
{
@ -229,9 +185,9 @@ class RefundPayment
if ($available_credit > $this->total_refund) {
$paymentable_credit->pivot->refunded += $this->total_refund;
$paymentable_credit->pivot->save();
$paymentable_credit->balance += $this->total_refund;
$paymentable_credit->save();
$paymentable_credit->service()->setStatus(Credit::STATUS_SENT)->save();
//$paymentable_credit->save();
$this->total_refund = 0;
} else {
@ -239,7 +195,8 @@ class RefundPayment
$paymentable_credit->pivot->save();
$paymentable_credit->balance += $available_credit;
$paymentable_credit->save();
$paymentable_credit->service()->setStatus(Credit::STATUS_SENT)->save();
// $paymentable_credit->save();
$this->total_refund -= $available_credit;
}
@ -253,22 +210,29 @@ class RefundPayment
return $this;
}
/**
* Reverse the payments made on invoices
*
* @return $this
*/
private function adjustInvoices()
{
$adjustment_amount = 0;
if (isset($this->refund_data['invoices']) && count($this->refund_data['invoices']) > 0) {
foreach ($this->refund_data['invoices'] as $refunded_invoice) {
foreach ($this->refund_data['invoices'] as $refunded_invoice)
{
$invoice = Invoice::find($refunded_invoice['invoice_id']);
$invoice->service()->updateBalance($refunded_invoice['amount'])->save();
$invoice->ledger()->updateInvoiceBalance($refunded_invoice['amount'], "Refund of payment # {$this->payment->number}")->save();
if ($invoice->amount == $invoice->balance) {
if ($invoice->amount == $invoice->balance)
$invoice->service()->setStatus(Invoice::STATUS_SENT);
} else {
else
$invoice->service()->setStatus(Invoice::STATUS_PARTIAL);
}
$invoice->save();
@ -276,27 +240,107 @@ class RefundPayment
$adjustment_amount += $refunded_invoice['amount'];
$client->balance += $refunded_invoice['amount'];
$client->save();
//todo adjust ledger balance here? or after and reference the credit and its total
}
$ledger_string = ''; //todo
// $ledger_string = "Refund for Invoice {$invoice->number} for amount " . $refunded_invoice['amount']; //todo
$this->credit_note->ledger()->updateCreditBalance($adjustment_amount, $ledger_string);
// $this->credit_note->ledger()->updateCreditBalance($adjustment_amount, $ledger_string);
$this->payment->client->paid_to_date -= $this->refund_data['amount'];
$this->payment->client->save();
$client = $this->payment->client->fresh();
$client->paid_to_date -= $this->total_refund;
$client->save();
}
return $this;
}
/**
* Saves the payment
*
* @return Payment $payment
*/
private function save()
{
$this->payment->save();
return $this->payment;
}
// public function updateCreditNoteBalance()
// {
// $this->credit_note->balance -= $this->total_refund;
// $this->credit_note->status_id = Credit::STATUS_APPLIED;
// $this->credit_note->balance === 0
// ? $this->credit_note->status_id = Credit::STATUS_APPLIED
// : $this->credit_note->status_id = Credit::STATUS_PARTIAL;
// $this->credit_note->save();
// return $this;
// }
// private function buildCreditNote()
// {
// $this->credit_note = CreditFactory::create($this->payment->company_id, $this->payment->user_id);
// $this->credit_note->assigned_user_id = isset($this->payment->assigned_user_id) ?: null;
// $this->credit_note->date = $this->refund_data['date'];
// $this->credit_note->status_id = Credit::STATUS_SENT;
// $this->credit_note->client_id = $this->payment->client->id;
// $this->credit_note->amount = $this->total_refund;
// $this->credit_note->balance = $this->total_refund;
// $this->credit_note->save();
// $this->credit_note->number = $this->payment->client->getNextCreditNumber($this->payment->client);
// $this->credit_note->save();
// return $this;
// }
// private function buildCreditLineItems()
// {
// $ledger_string = '';
// if (isset($this->refund_data['invoices']) && count($this->refund_data['invoices']) > 0) {
// foreach ($this->refund_data['invoices'] as $invoice) {
// $inv = Invoice::find($invoice['invoice_id']);
// $credit_line_item = InvoiceItemFactory::create();
// $credit_line_item->quantity = 1;
// $credit_line_item->cost = $invoice['amount'];
// $credit_line_item->product_key = ctrans('texts.invoice');
// $credit_line_item->notes = ctrans('texts.refund_body', ['amount' => $invoice['amount'], 'invoice_number' => $inv->number]);
// $credit_line_item->line_total = $invoice['amount'];
// $credit_line_item->date = $this->refund_data['date'];
// $ledger_string .= $credit_line_item->notes . ' ';
// $line_items[] = $credit_line_item;
// }
// } else {
// $credit_line_item = InvoiceItemFactory::create();
// $credit_line_item->quantity = 1;
// $credit_line_item->cost = $this->refund_data['amount'];
// $credit_line_item->product_key = ctrans('texts.credit');
// $credit_line_item->notes = ctrans('texts.credit_created_by', ['transaction_reference' => $this->payment->number]);
// $credit_line_item->line_total = $this->refund_data['amount'];
// $credit_line_item->date = $this->refund_data['date'];
// $line_items = [];
// $line_items[] = $credit_line_item;
// }
// $this->credit_note->line_items = $line_items;
// $this->credit_note->save();
// return $this;
// }
}

View File

@ -0,0 +1,302 @@
<?php
namespace App\Services\Payment;
use App\Exceptions\PaymentRefundFailed;
use App\Factory\CreditFactory;
use App\Factory\InvoiceItemFactory;
use App\Models\Activity;
use App\Models\CompanyGateway;
use App\Models\Credit;
use App\Models\Invoice;
use App\Models\Payment;
use App\Repositories\ActivityRepository;
class RefundPayment
{
public $payment;
public $refund_data;
private $credit_note;
private $total_refund;
private $gateway_refund_status;
private $activity_repository;
public function __construct($payment, $refund_data)
{
$this->payment = $payment;
$this->refund_data = $refund_data;
$this->total_refund = 0;
$this->gateway_refund_status = false;
$this->activity_repository = new ActivityRepository();
}
public function run()
{
return $this->calculateTotalRefund() //sets amount for the refund (needed if we are refunding multiple invoices in one payment)
->setStatus() //sets status of payment
->buildCreditNote() //generate the credit note
->buildCreditLineItems() //generate the credit note items
->updateCreditables() //return the credits first
->updatePaymentables() //update the paymentable items
->adjustInvoices()
->processGatewayRefund() //process the gateway refund if needed
->save();
}
private function processGatewayRefund()
{
if ($this->refund_data['gateway_refund'] !== false && $this->total_refund > 0) {
$gateway = CompanyGateway::first();
if ($gateway) {
$response = $gateway->driver($this->payment->client)->refund($this->payment, $this->total_refund);
if ($response['success']) {
throw new PaymentRefundFailed();
}
$this->payment->refunded = $this->total_refund;
$this
->createActivity($gateway)
->updateCreditNoteBalance();
}
} else {
$this->payment->refunded += $this->total_refund;
}
return $this;
}
public function updateCreditNoteBalance()
{
$this->credit_note->balance -= $this->total_refund;
$this->credit_note->status_id = Credit::STATUS_APPLIED;
$this->credit_note->balance === 0
? $this->credit_note->status_id = Credit::STATUS_APPLIED
: $this->credit_note->status_id = Credit::STATUS_PARTIAL;
$this->credit_note->save();
return $this;
}
private function createActivity($notes)
{
$fields = new \stdClass;
$activity_repo = new ActivityRepository();
$fields->payment_id = $this->payment->id;
$fields->user_id = $this->payment->user_id;
$fields->company_id = $this->payment->company_id;
$fields->activity_type_id = Activity::REFUNDED_PAYMENT;
$fields->credit_id = $this->credit_note->id;
$fields->notes = json_encode($notes);
if (isset($this->refund_data['invoices'])) {
foreach ($this->refund_data['invoices'] as $invoice) {
$fields->invoice_id = $invoice['invoice_id'];
$activity_repo->save($fields, $this->payment);
}
} else {
$activity_repo->save($fields, $this->payment);
}
return $this;
}
private function calculateTotalRefund()
{
if (array_key_exists('invoices', $this->refund_data) && count($this->refund_data['invoices']) > 0){
info("array of invoice to refund");
$this->total_refund = collect($this->refund_data['invoices'])->sum('amount');
}
else{
info("no invoices found - refunding total.");
$this->total_refund = $this->refund_data['amount'];
}
return $this;
}
private function setStatus()
{
if ($this->refund_data['amount'] == $this->payment->amount) {
$this->payment->status_id = Payment::STATUS_REFUNDED;
} else {
$this->payment->status_id = Payment::STATUS_PARTIALLY_REFUNDED;
}
return $this;
}
private function buildCreditNote()
{
$this->credit_note = CreditFactory::create($this->payment->company_id, $this->payment->user_id);
$this->credit_note->assigned_user_id = isset($this->payment->assigned_user_id) ?: null;
$this->credit_note->date = $this->refund_data['date'];
$this->credit_note->status_id = Credit::STATUS_SENT;
$this->credit_note->client_id = $this->payment->client->id;
$this->credit_note->amount = $this->total_refund;
$this->credit_note->balance = $this->total_refund;
$this->credit_note->save();
$this->credit_note->number = $this->payment->client->getNextCreditNumber($this->payment->client);
$this->credit_note->save();
return $this;
}
private function buildCreditLineItems()
{
$ledger_string = '';
if (isset($this->refund_data['invoices']) && count($this->refund_data['invoices']) > 0) {
foreach ($this->refund_data['invoices'] as $invoice) {
$inv = Invoice::find($invoice['invoice_id']);
$credit_line_item = InvoiceItemFactory::create();
$credit_line_item->quantity = 1;
$credit_line_item->cost = $invoice['amount'];
$credit_line_item->product_key = ctrans('texts.invoice');
$credit_line_item->notes = ctrans('texts.refund_body', ['amount' => $invoice['amount'], 'invoice_number' => $inv->number]);
$credit_line_item->line_total = $invoice['amount'];
$credit_line_item->date = $this->refund_data['date'];
$ledger_string .= $credit_line_item->notes . ' ';
$line_items[] = $credit_line_item;
}
} else {
$credit_line_item = InvoiceItemFactory::create();
$credit_line_item->quantity = 1;
$credit_line_item->cost = $this->refund_data['amount'];
$credit_line_item->product_key = ctrans('texts.credit');
$credit_line_item->notes = ctrans('texts.credit_created_by', ['transaction_reference' => $this->payment->number]);
$credit_line_item->line_total = $this->refund_data['amount'];
$credit_line_item->date = $this->refund_data['date'];
$line_items = [];
$line_items[] = $credit_line_item;
}
$this->credit_note->line_items = $line_items;
$this->credit_note->save();
return $this;
}
private function updatePaymentables()
{
if (isset($this->refund_data['invoices']) && count($this->refund_data['invoices']) > 0) {
$this->payment->invoices->each(function ($paymentable_invoice) {
collect($this->refund_data['invoices'])->each(function ($refunded_invoice) use ($paymentable_invoice) {
if ($refunded_invoice['invoice_id'] == $paymentable_invoice->id) {
$paymentable_invoice->pivot->refunded += $refunded_invoice['amount'];
$paymentable_invoice->pivot->save();
}
});
});
}
return $this;
}
private function updateCreditables()
{
if ($this->payment->credits()->exists()) {
//Adjust credits first!!!
foreach ($this->payment->credits as $paymentable_credit) {
$available_credit = $paymentable_credit->pivot->amount - $paymentable_credit->pivot->refunded;
if ($available_credit > $this->total_refund) {
$paymentable_credit->pivot->refunded += $this->total_refund;
$paymentable_credit->pivot->save();
$paymentable_credit->balance += $this->total_refund;
$paymentable_credit->save();
$this->total_refund = 0;
} else {
$paymentable_credit->pivot->refunded += $available_credit;
$paymentable_credit->pivot->save();
$paymentable_credit->balance += $available_credit;
$paymentable_credit->save();
$this->total_refund -= $available_credit;
}
if ($this->total_refund == 0) {
break;
}
}
}
return $this;
}
private function adjustInvoices()
{
$adjustment_amount = 0;
if (isset($this->refund_data['invoices']) && count($this->refund_data['invoices']) > 0) {
foreach ($this->refund_data['invoices'] as $refunded_invoice) {
$invoice = Invoice::find($refunded_invoice['invoice_id']);
$invoice->service()->updateBalance($refunded_invoice['amount'])->save();
if ($invoice->amount == $invoice->balance) {
$invoice->service()->setStatus(Invoice::STATUS_SENT);
} else {
$invoice->service()->setStatus(Invoice::STATUS_PARTIAL);
}
$invoice->save();
$client = $invoice->client;
$adjustment_amount += $refunded_invoice['amount'];
$client->balance += $refunded_invoice['amount'];
$client->save();
//todo adjust ledger balance here? or after and reference the credit and its total
}
$ledger_string = ''; //todo
$this->credit_note->ledger()->updateCreditBalance($adjustment_amount, $ledger_string);
$this->payment->client->paid_to_date -= $this->refund_data['amount'];
$this->payment->client->save();
}
return $this;
}
private function save()
{
$this->payment->save();
return $this->payment;
}
}

View File

@ -954,6 +954,7 @@ class CreateUsersTable extends Migration
$t->unsignedInteger('client_contact_id')->nullable();
$t->unsignedInteger('invitation_id')->nullable();
$t->unsignedInteger('company_gateway_id')->nullable();
$t->unsignedInteger('gateway_type_id')->nullable();
$t->unsignedInteger('type_id')->nullable();
$t->unsignedInteger('status_id')->index();
$t->decimal('amount', 16, 4)->default(0);

View File

@ -265,29 +265,29 @@ class RandomDataSeeder extends Seeder
]);
if (config('ninja.testvars.stripe')) {
$cg = new CompanyGateway;
$cg->company_id = $company->id;
$cg->user_id = $user->id;
$cg->gateway_key = 'd14dd26a37cecc30fdd65700bfb55b23';
$cg->require_cvv = true;
$cg->show_billing_address = true;
$cg->show_shipping_address = true;
$cg->update_details = true;
$cg->config = encrypt(config('ninja.testvars.stripe'));
$cg->save();
// if (config('ninja.testvars.stripe')) {
// $cg = new CompanyGateway;
// $cg->company_id = $company->id;
// $cg->user_id = $user->id;
// $cg->gateway_key = 'd14dd26a37cecc30fdd65700bfb55b23';
// $cg->require_cvv = true;
// $cg->show_billing_address = true;
// $cg->show_shipping_address = true;
// $cg->update_details = true;
// $cg->config = encrypt(config('ninja.testvars.stripe'));
// $cg->save();
$cg = new CompanyGateway;
$cg->company_id = $company->id;
$cg->user_id = $user->id;
$cg->gateway_key = 'd14dd26a37cecc30fdd65700bfb55b23';
$cg->require_cvv = true;
$cg->show_billing_address = true;
$cg->show_shipping_address = true;
$cg->update_details = true;
$cg->config = encrypt(config('ninja.testvars.stripe'));
$cg->save();
}
// $cg = new CompanyGateway;
// $cg->company_id = $company->id;
// $cg->user_id = $user->id;
// $cg->gateway_key = 'd14dd26a37cecc30fdd65700bfb55b23';
// $cg->require_cvv = true;
// $cg->show_billing_address = true;
// $cg->show_shipping_address = true;
// $cg->update_details = true;
// $cg->config = encrypt(config('ninja.testvars.stripe'));
// $cg->save();
// }
// if (config('ninja.testvars.paypal')) {
// $cg = new CompanyGateway;
@ -315,18 +315,18 @@ class RandomDataSeeder extends Seeder
// $cg->save();
// }
// if(config('ninja.testvars.authorize')) {
// $cg = new CompanyGateway;
// $cg->company_id = $company->id;
// $cg->user_id = $user->id;
// $cg->gateway_key = '3b6621f970ab18887c4f6dca78d3f8bb';
// $cg->require_cvv = true;
// $cg->show_billing_address = true;
// $cg->show_shipping_address = true;
// $cg->update_details = true;
// $cg->config = encrypt(config('ninja.testvars.authorize'));
// $cg->save();
// }
if(config('ninja.testvars.authorize')) {
$cg = new CompanyGateway;
$cg->company_id = $company->id;
$cg->user_id = $user->id;
$cg->gateway_key = '3b6621f970ab18887c4f6dca78d3f8bb';
$cg->require_cvv = true;
$cg->show_billing_address = true;
$cg->show_shipping_address = true;
$cg->update_details = true;
$cg->config = encrypt(config('ninja.testvars.authorize'));
$cg->save();
}
}
}

View File

@ -1 +1,2 @@
!function(e){var t={};function n(a){if(t[a])return t[a].exports;var r=t[a]={i:a,l:!1,exports:{}};return e[a].call(r.exports,r,r.exports,n),r.l=!0,r.exports}n.m=e,n.c=t,n.d=function(e,t,a){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:a})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var a=Object.create(null);if(n.r(a),Object.defineProperty(a,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(a,r,function(t){return e[t]}.bind(null,r));return a},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="/",n(n.s=2)}({2:function(e,t,n){e.exports=n("6vDv")},"6vDv":function(e,t){function n(e,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}new(function(){function e(t,n){var a,r,o,i=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),o=function(){document.getElementById("card_number").addEventListener("keyup",(function(e){var t=document.getElementById("card_number_errors");valid.number(e.target.value).isValid?(t.hidden=!0,i.form.valid=!0):(t.textContent=i.translations.invalidCard,t.hidden=!1,i.form.valid=!1)})),document.getElementById("expiration_month").addEventListener("keyup",(function(e){var t=document.getElementById("expiration_month_errors");valid.expirationMonth(e.target.value).isValid?(t.hidden=!0,i.form.valid=!0):(t.textContent=i.translations.invalidMonth,t.hidden=!1,i.form.valid=!1)})),document.getElementById("expiration_year").addEventListener("keyup",(function(e){var t=document.getElementById("expiration_year_errors");valid.expirationYear(e.target.value).isValid?(t.hidden=!0,i.form.valid=!0):(t.textContent=i.translations.invalidYear,t.hidden=!1,i.form.valid=!1)}))},(r="handleFormValidation")in(a=this)?Object.defineProperty(a,r,{value:o,enumerable:!0,configurable:!0,writable:!0}):a[r]=o,this.publicKey=t,this.loginId=n,this.cardHolderName=document.getElementById("cardholder_name"),this.cardButton=document.getElementById("card_button"),this.form={valid:!1},this.translations={invalidCard:document.querySelector('meta[name="credit-card-invalid"]').content,invalidMonth:document.querySelector('meta[name="month-invalid"]').content,invalidYear:document.querySelector('meta[name="year-invalid"]').content}}var t,a,r;return t=e,(a=[{key:"handleAuthorization",value:function(){var e={};e.clientKey=this.publicKey,e.apiLoginID=this.loginId;var t={};t.cardNumber=document.getElementById("card_number").value,t.month=document.getElementById("expiration_month").value,t.year=document.getElementById("expiration_year").value,t.cardCode=document.getElementById("cvv").value;var n={};return n.authData=e,n.cardData=t,Accept.dispatchData(n,this.responseHandler),!1}},{key:"responseHandler",value:function(e){if("Error"===e.messages.resultCode)for(var t=0;t<e.messages.message.length;)console.log(e.messages.message[t].code+": "+e.messages.message[t].text),t+=1;else"Ok"===e.messages.resultCode&&(document.getElementById("dataDescriptor").value=e.opaqueData.dataDescriptor,document.getElementById("dataValue").value=e.opaqueData.dataValue,document.getElementById("server_response").submit());return!1}},{key:"handle",value:function(){var e=this;return this.handleFormValidation(),this.cardButton.addEventListener("click",(function(){e.cardButton.disabled=!e.cardButton.disabled})),this}}])&&n(t.prototype,a),r&&n(t,r),e}())(document.querySelector('meta[name="authorize-public-key"]').content,document.querySelector('meta[name="authorize-login-id"]').content).handle()}});
/*! For license information please see authorize-authorize-card.js.LICENSE.txt */
!function(e){var t={};function n(r){if(t[r])return t[r].exports;var a=t[r]={i:r,l:!1,exports:{}};return e[r].call(a.exports,a,a.exports,n),a.l=!0,a.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var a in e)n.d(r,a,function(t){return e[t]}.bind(null,a));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="/",n(n.s=2)}({2:function(e,t,n){e.exports=n("6vDv")},"6vDv":function(e,t){function n(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}new(function(){function e(t,n){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.publicKey=t,this.loginId=n,this.cardHolderName=document.getElementById("cardholder_name"),this.cardButton=document.getElementById("card_button")}var t,r,a;return t=e,(r=[{key:"handleAuthorization",value:function(){var e=$("#my-card"),t={};t.clientKey=this.publicKey,t.apiLoginID=this.loginId;var n={};n.cardNumber=e.CardJs("cardNumber"),n.month=e.CardJs("expiryMonth"),n.year=e.CardJs("expiryYear"),n.cardCode=document.getElementById("cvv").value;var r={};return r.authData=t,r.cardData=n,Accept.dispatchData(r,this.responseHandler),!1}},{key:"responseHandler",value:function(e){if("Error"===e.messages.resultCode)for(var t=0;t<e.messages.message.length;)console.log(e.messages.message[t].code+": "+e.messages.message[t].text),t+=1;else"Ok"===e.messages.resultCode&&(document.getElementById("dataDescriptor").value=e.opaqueData.dataDescriptor,document.getElementById("dataValue").value=e.opaqueData.dataValue,document.getElementById("server_response").submit());return!1}},{key:"handle",value:function(){var e=this;return this.cardButton.addEventListener("click",(function(){e.cardButton.disabled=!e.cardButton.disabled,e.handleAuthorization()})),this}}])&&n(t.prototype,r),a&&n(t,a),e}())(document.querySelector('meta[name="authorize-public-key"]').content,document.querySelector('meta[name="authorize-login-id"]').content).handle()}});

View File

@ -4,7 +4,7 @@
"/js/clients/invoices/action-selectors.js": "/js/clients/invoices/action-selectors.js?id=d244486b16dc6f94a726",
"/js/clients/invoices/payment.js": "/js/clients/invoices/payment.js?id=d7e708d66a9c769b4c6e",
"/js/clients/payment_methods/authorize-ach.js": "/js/clients/payment_methods/authorize-ach.js?id=9e6495d9ae236b3cb5ad",
"/js/clients/payment_methods/authorize-authorize-card.js": "/js/clients/payment_methods/authorize-authorize-card.js?id=3f6129bf10ff3bf20332",
"/js/clients/payment_methods/authorize-authorize-card.js": "/js/clients/payment_methods/authorize-authorize-card.js?id=83c223814db63f9db590",
"/js/clients/payment_methods/authorize-stripe-card.js": "/js/clients/payment_methods/authorize-stripe-card.js?id=f4c45f0da9868d840799",
"/js/clients/payments/alipay.js": "/js/clients/payments/alipay.js?id=428ac5b81ed722636e8f",
"/js/clients/payments/authorize-credit-card-payment.js": "/js/clients/payments/authorize-credit-card-payment.js?id=3a74587f41c617a7cc81",

View File

@ -15,34 +15,26 @@ class AuthorizeAuthorizeCard {
this.loginId = loginId;
this.cardHolderName = document.getElementById("cardholder_name");
this.cardButton = document.getElementById("card_button");
this.form = { valid: false };
this.translations = {
invalidCard: document.querySelector('meta[name="credit-card-invalid"]').content,
invalidMonth: document.querySelector('meta[name="month-invalid"]').content,
invalidYear: document.querySelector('meta[name="year-invalid"]').content,
}
}
handleAuthorization() {
var myCard = $('#my-card');
var authData = {};
authData.clientKey = this.publicKey;
authData.apiLoginID = this.loginId;
var cardData = {};
cardData.cardNumber = document.getElementById("card_number").value;
cardData.month = document.getElementById("expiration_month").value;
cardData.year = document.getElementById("expiration_year").value;
cardData.cardNumber = myCard.CardJs('cardNumber');
cardData.month = myCard.CardJs('expiryMonth');
cardData.year = myCard.CardJs('expiryYear');;
cardData.cardCode = document.getElementById("cvv").value;
var secureData = {};
secureData.authData = authData;
secureData.cardData = cardData;
// If using banking information instead of card information,
// send the bankData object instead of the cardData object.
//
// secureData.bankData = bankData;
Accept.dispatchData(secureData, this.responseHandler);
return false;
@ -71,53 +63,15 @@ class AuthorizeAuthorizeCard {
return false;
}
handleFormValidation = () => {
document.getElementById("card_number").addEventListener('keyup', (e) => {
let errors = document.getElementById('card_number_errors');
if (valid.number(e.target.value).isValid) {
errors.hidden = true;
this.form.valid = true;
} else {
errors.textContent = this.translations.invalidCard;
errors.hidden = false;
this.form.valid = false;
}
});
document.getElementById("expiration_month").addEventListener('keyup', (e) => {
let errors = document.getElementById('expiration_month_errors');
if (valid.expirationMonth(e.target.value).isValid) {
errors.hidden = true;
this.form.valid = true;
} else {
errors.textContent = this.translations.invalidMonth;
errors.hidden = false;
this.form.valid = false;
}
});
document.getElementById("expiration_year").addEventListener('keyup', (e) => {
let errors = document.getElementById('expiration_year_errors');
if (valid.expirationYear(e.target.value).isValid) {
errors.hidden = true;
this.form.valid = true;
} else {
errors.textContent = this.translations.invalidYear;
errors.hidden = false;
this.form.valid = false;
}
});
}
handle() {
this.handleFormValidation();
//this.handleFormValidation();
// At this point as an small API you can request this.form.valid to check if input elements are valid.
// Note: this.form.valid will not handle empty fields.
this.cardButton.addEventListener("click", () => {
this.cardButton.disabled = !this.cardButton.disabled;
// this.handleAuthorization();
this.handleAuthorization();
});

View File

@ -3223,6 +3223,7 @@ return [
'month_invalid' => 'Provided month is not valid.',
'year_invalid' => 'Provided year is not valid.',
'https_required' => 'HTTPS is required, form will fail',
'if_you_need_help' => 'If you need help you can either post to our',
'reversed' => 'Reversed',
'update_password_on_confirm' => 'After updating password, your account will be confirmed.',

View File

@ -30,6 +30,9 @@
<div class="grid grid-cols-6 gap-4">
<div class="col-span-6 md:col-start-2 md:col-span-3">
<div class="alert alert-failure mb-4" hidden id="errors"></div>
@if(!Request::isSecure())
<p class="alert alert-failure">{{ ctrans('texts.https_required') }}</p>
@endif
<div class="bg-white shadow overflow-hidden sm:rounded-lg">
<div class="px-4 py-5 border-b border-gray-200 sm:px-6">
<h3 class="text-lg leading-6 font-medium text-gray-900">

View File

@ -47,9 +47,6 @@ class UserTest extends TestCase
$this->makeTestData();
$this->withoutMiddleware(
ThrottleRequests::class
);
}
public function testUserList()
@ -68,7 +65,7 @@ class UserTest extends TestCase
$data = [
'first_name' => 'hey',
'last_name' => 'you',
'email' => 'bob@good.ole.boys.com',
'email' => 'bob1@good.ole.boys.com',
'company_user' => [
'is_admin' => false,
'is_owner' => false,