1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-05 18:52:44 +01:00

Merge remote-tracking branch 'upstream/v2' into v2-2306-payments

This commit is contained in:
Benjamin Beganović 2020-06-24 17:35:13 +02:00
commit be61945c93
48 changed files with 97473 additions and 95687 deletions

View File

@ -0,0 +1,54 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Events\Document;
use App\Models\Document;
use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
/**
* Class DocumentWasArchived.
*/
class DocumentWasArchived
{
use Dispatchable, InteractsWithSockets, SerializesModels;
/**
* @var Document
*/
public $document;
/**
* Create a new event instance.
*
* @param Document $document
*/
public function __construct(Document $document)
{
$this->document = $document;
}
/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new PrivateChannel('channel-name');
}
}

View File

@ -0,0 +1,38 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Events\Document;
use App\Models\Document;
use Illuminate\Queue\SerializesModels;
/**
* Class DocumentWasCreated.
*/
class DocumentWasCreated
{
use SerializesModels;
/**
* @var Document
*/
public $document;
/**
* Create a new event instance.
*
* @param Document $document
*/
public function __construct(Document $document)
{
$this->document = $document;
}
}

View File

@ -0,0 +1,38 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Events\Document;
use App\Models\Document;
use Illuminate\Queue\SerializesModels;
/**
* Class DocumentWasDeleted.
*/
class DocumentWasDeleted
{
use SerializesModels;
/**
* @var Document
*/
public $document;
/**
* Create a new event instance.
*
* @param Document $document
*/
public function __construct(Document $document)
{
$this->document = $document;
}
}

View File

@ -0,0 +1,38 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Events\Document;
use App\Models\Document;
use Illuminate\Queue\SerializesModels;
/**
* Class DocumentWasRestored.
*/
class DocumentWasRestored
{
use SerializesModels;
/**
* @var Document
*/
public $document;
/**
* Create a new event instance.
*
* @param Document $document
*/
public function __construct(Document $document)
{
$this->document = $document;
}
}

View File

@ -0,0 +1,38 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Events\Document;
use App\Models\Document;
use Illuminate\Queue\SerializesModels;
/**
* Class DocumentWasUpdated.
*/
class DocumentWasUpdated
{
use SerializesModels;
/**
* @var Document
*/
public $document;
/**
* Create a new event instance.
*
* @param Document $document
*/
public function __construct(Document $document)
{
$this->document = $document;
}
}

View File

@ -137,7 +137,10 @@ class InvoiceController extends Controller
//if only 1 pdf, output to buffer for download
if ($invoices->count() == 1) {
return response()->download(TempFile::path($invoices->first()->pdf_file_path()), basename($invoices->first()->pdf_file_path()));
return response()->streamDownload(function () use($invoices) {
echo file_get_contents($invoices->first()->pdf_file_path());
}, basename($invoices->first()->pdf_file_path()));
//return response()->download(TempFile::path($invoices->first()->pdf_file_path()), basename($invoices->first()->pdf_file_path()));
}
# enable output of HTTP headers

View File

@ -74,7 +74,10 @@ class QuoteController extends Controller
}
if ($quotes->count() == 1) {
return response()->download(TempFile::path($invoices->first()->pdf_file_path()), basename($quotes->first()->pdf_file_path()));
return response()->streamDownload(function () use($invoices) {
echo file_get_contents($invoices->first()->pdf_file_path());
}, basename($invoices->first()->pdf_file_path()));
//return response()->download(TempFile::path($invoices->first()->pdf_file_path()), basename($quotes->first()->pdf_file_path()));
}
# enable output of HTTP headers

View File

@ -527,7 +527,10 @@ class CreditController extends BaseController
}
break;
case 'download':
return response()->download(TempFile::path($credit->pdf_file_path()), basename($credit->pdf_file_path()));
return response()->streamDownload(function () use($credit) {
echo file_get_contents($credit->pdf_file_path());
}, basename($credit->pdf_file_path()));
//return response()->download(TempFile::path($credit->pdf_file_path()), basename($credit->pdf_file_path()));
break;
case 'archive':
$this->credit_repository->archive($credit);

View File

@ -31,7 +31,6 @@ use Illuminate\Support\Facades\Cache;
/**
* Class DesignController
* @package App\Http\Controllers
* @covers App\Http\Controllers\DesignController
*/
class DesignController extends BaseController
{
@ -480,15 +479,11 @@ class DesignController extends BaseController
$action = request()->input('action');
$ids = request()->input('ids');
$designs = Design::withTrashed()->find($this->transformKeys($ids));
info($designs);
info(auth()->user()->id);
info(auth()->user()->getCompany()->id);
$designs->each(function ($design, $key) use ($action) {
if (auth()->user()->can('edit', $design)) {
info("authed");
$this->design_repo->{$action}($design);
}
});

View File

@ -0,0 +1,151 @@
<?php
namespace App\Http\Controllers;
use App\Http\Requests\Document\DestroyDocumentRequest;
use App\Http\Requests\Document\EditDocumentRequest;
use App\Http\Requests\Document\ShowDocumentRequest;
use App\Http\Requests\Document\StoreDocumentRequest;
use App\Http\Requests\Document\UpdateDocumentRequest;
use App\Models\Document;
use App\Repositories\DocumentRepository;
use App\Transformers\DocumentTransformer;
use App\Utils\Traits\MakesHash;
use Illuminate\Http\Request;
class DocumentController extends BaseController
{
use MakesHash;
protected $entity_type = Document::class;
protected $entity_transformer = DocumentTransformer::class;
/**
* @var DocumentRepository
*/
protected $document_repo;
/**
* DocumentController constructor.
* @param DocumentRepository $document_repo
*/
public function __construct(DocumentRepository $document_repo)
{
parent::__construct();
$this->document_repo = $document_repo;
}
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(StoreDocumentRequest $request)
{
//
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show(ShowDocumentRequest $request, Document $document)
{
return $this->itemResponse($document);
}
public function download(ShowDocumentRequest $request, Document $document)
{
return response()->streamDownload(function () use($document) {
echo file_get_contents($document->generateUrl());
}, basename($document->generateUrl()));
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit(EditDocumentRegquest $request, Document $document)
{
return $this->itemResponse($document);
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(UpdateDocumentRequest $request, Document $document)
{
return $this->itemResponse($document);
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy(DestroyDocumentRequest $request, Document $document)
{
$this->document_repo->delete($document);
return response()->json(['message'=>'success']);
}
public function bulk()
{
$action = request()->input('action');
$ids = request()->input('ids');
$documents = Document::withTrashed()->whereIn('id', $this->transformKeys($ids))->company()->get();
if (!$invoices) {
return response()->json(['message' => 'No Documents Found']);
}
/*
* Send the other actions to the switch
*/
$documents->each(function ($document, $key) use ($action) {
if (auth()->user()->can('edit', $document)) {
$this->{$action}($document);
}
});
/* Need to understand which permission are required for the given bulk action ie. view / edit */
return $this->listResponse(Document::withTrashed()->whereIn('id', $this->transformKeys($ids))->company());
}
}

View File

@ -415,4 +415,82 @@ class GroupSettingController extends BaseController
return response()->json([], 200);
}
/**
* Perform bulk actions on the list view
*
* @return Collection
*
* @OA\Post(
* path="/api/v1/group_settings/bulk",
* operationId="bulkGroupSettings",
* tags={"group_settings"},
* summary="Performs bulk actions on an array of group_settings",
* description="",
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
* @OA\Parameter(ref="#/components/parameters/index"),
* @OA\RequestBody(
* description="An array of group_settings ids",
* required=true,
* @OA\MediaType(
* mediaType="application/json",
* @OA\Schema(
* type="array",
* @OA\Items(
* type="integer",
* description="Array of hashed IDs to be bulk 'actioned",
* example="[0,1,2,3]",
* ),
* )
* )
* ),
* @OA\Response(
* response=200,
* description="The Bulk Action response",
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
* ),
* @OA\Response(
* response=422,
* description="Validation error",
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
* ),
* @OA\Response(
* response="default",
* description="Unexpected Error",
* @OA\JsonContent(ref="#/components/schemas/Error"),
* ),
* )
*
*/
public function bulk()
{
$action = request()->input('action');
$ids = request()->input('ids');
$group_settings = GroupSetting::withTrashed()->whereIn('id', $this->transformKeys($ids))->company()->get();
if (!$group_settings) {
return response()->json(['message' => 'No Group Settings Found']);
}
/*
* Send the other actions to the switch
*/
$group_settings->each(function ($group, $key) use ($action) {
if (auth()->user()->can('edit', $group)) {
$this->group_setting_repo->{$action}($group);
}
});
/* Need to understand which permission are required for the given bulk action ie. view / edit */
return $this->listResponse(GroupSetting::withTrashed()->whereIn('id', $this->transformKeys($ids))->company());
}
}

View File

@ -660,7 +660,10 @@ class InvoiceController extends BaseController
}
break;
case 'download':
return response()->download(TempFile::path($invoice->pdf_file_path()), basename($invoice->pdf_file_path()));
return response()->streamDownload(function () use($invoice) {
echo file_get_contents($invoice->pdf_file_path());
}, basename($invoice->pdf_file_path()));
//return response()->download(TempFile::path($invoice->pdf_file_path()), basename($invoice->pdf_file_path()));
break;
case 'restore':
$this->invoice_repo->restore($invoice);

View File

@ -661,7 +661,10 @@ class QuoteController extends BaseController
# code...
break;
case 'download':
return response()->download(TempFile::path($quote->pdf_file_path()), basename($quote->pdf_file_path()));
return response()->streamDownload(function () use($quote) {
echo file_get_contents($quote->pdf_file_path());
}, basename($quote->pdf_file_path()));
//return response()->download(TempFile::path($quote->pdf_file_path()), basename($quote->pdf_file_path()));
break;
case 'archive':
$this->invoice_repo->archive($quote);

View File

@ -0,0 +1,29 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Http\Requests\Document;
use App\Http\Requests\Request;
use App\Models\Document;
class CreateDocumentRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize() : bool
{
return auth()->user()->can('create', Document::class);
}
}

View File

@ -0,0 +1,28 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Http\Requests\Document;
use App\Http\Requests\Request;
class DestroyDocumentRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize() : bool
{
return auth()->user()->can('edit', $this->document);
}
}

View File

@ -0,0 +1,39 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Http\Requests\Document;
use App\Http\Requests\Request;
class EditDocumentRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize() : bool
{
return auth()->user()->can('edit', $this->document);
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
//
];
}
}

View File

@ -0,0 +1,39 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Http\Requests\Document;
use App\Http\Requests\Request;
class ShowDocumentRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize() : bool
{
return auth()->user()->can('view', $this->document);
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
//
];
}
}

View File

@ -0,0 +1,43 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Http\Requests\Document;
use App\Http\Requests\Request;
use App\Models\Document;
class StoreDocumentRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize() : bool
{
return auth()->user()->can('create', Document::class);
}
public function rules()
{
return [
];
}
protected function prepareForValidation()
{
$input = $this->all();
$this->replace($input);
}
}

View File

@ -0,0 +1,44 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Http\Requests\Document;
use App\Http\Requests\Request;
use App\Models\Document;
use App\Utils\Traits\ChecksEntityStatus;
use Illuminate\Support\Facades\Log;
class UpdateDocumentRequest extends Request
{
use ChecksEntityStatus;
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize() : bool
{
return auth()->user()->can('edit', $this->document);
}
public function rules()
{
return [];
}
protected function prepareForValidation()
{
$input = $this->all();
$this->replace($input);
}
}

View File

@ -25,11 +25,11 @@ class Activity extends StaticModel
const ARCHIVE_INVOICE=8;
const DELETE_INVOICE=9;
const CREATE_PAYMENT=10;
//const UPDATE_PAYMENT=11;
const UPDATE_PAYMENT=11;
const ARCHIVE_PAYMENT=12;
const DELETE_PAYMENT=13;
const CREATE_CREDIT=14;
//const UPDATE_CREDIT=15;
const UPDATE_CREDIT=15;
const ARCHIVE_CREDIT=16;
const DELETE_CREDIT=17;
const CREATE_QUOTE=18;

View File

@ -72,6 +72,7 @@ class Company extends BaseModel
];
protected $fillable = [
'enabled_item_tax_rates',
'fill_products',
'industry_id',
'subdomain',
@ -133,6 +134,11 @@ class Company extends BaseModel
self::ENTITY_RECURRING_QUOTE => 2048,
];
public function documents()
{
return $this->morphMany(Document::class, 'documentable');
}
public function getEntityType()
{
return Company::class;
@ -192,7 +198,7 @@ class Company extends BaseModel
public function activities()
{
return $this->hasMany(Activity::class);
return $this->hasMany(Activity::class)->orderBy('id', 'DESC')->take(300);
}
/**

View File

@ -112,4 +112,14 @@ class Document extends BaseModel
return null;
}
public function generateRoute($absolute = false)
{
return route('api.documents.show', ['document' => $this->hashed_id]) . '/download';
}
public function deleteFile()
{
Storage::disk($this->disk)->delete($this->url);
}
}

View File

@ -11,6 +11,8 @@
namespace App\PaymentDrivers;
use App\Models\Payment;
abstract class AbstractPaymentDriver
{
@ -18,7 +20,7 @@ abstract class AbstractPaymentDriver
abstract public function purchase($amount, $return_client_response = false);
abstract public function refund($amount, $transaction_reference, $return_client_response = false);
abstract public function refund(Payment $payment, $refund_amount, $return_client_response = false);
abstract public function setPaymentMethod($payment_method_id);

View File

@ -12,6 +12,7 @@
namespace App\PaymentDrivers\Authorize;
use App\PaymentDrivers\AuthorizePaymentDriver;
use net\authorize\api\contract\v1\GetTransactionDetailsRequest;
use net\authorize\api\controller\GetTransactionDetailsController;
@ -50,15 +51,15 @@ class AuthorizeTransactions
if (($response != null) && ($response->getMessages()->getResultCode() == "Ok"))
{
echo "SUCCESS: Transaction Status:" . $response->getTransaction()->getTransactionStatus() . "\n";
echo " Auth Amount:" . $response->getTransaction()->getAuthAmount() . "\n";
echo " Trans ID:" . $response->getTransaction()->getTransId() . "\n";
info( "SUCCESS: Transaction Status:" . $response->getTransaction()->getTransactionStatus() );
info( " Auth Amount:" . $response->getTransaction()->getAuthAmount() );
info( " Trans ID:" . $response->getTransaction()->getTransId() );
}
else
{
echo "ERROR : Invalid response\n";
info( "ERROR : Invalid response\n");
$errorMessages = $response->getMessages()->getMessage();
echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n";
info( "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() );
}
return $response;

View File

@ -12,7 +12,9 @@
namespace App\PaymentDrivers\Authorize;
use App\Models\Payment;
use App\PaymentDrivers\AuthorizePaymentDriver;
use App\PaymentDrivers\Authorize\AuthorizeTransactions;
use net\authorize\api\contract\v1\CreateTransactionRequest;
use net\authorize\api\contract\v1\CustomerProfilePaymentType;
use net\authorize\api\contract\v1\PaymentProfileType;
@ -26,14 +28,22 @@ use net\authorize\api\controller\CreateTransactionController;
*/
class RefundTransaction
{
public $authorize;
public $authorize_transaction;
public function __construct(AuthorizePaymentDriver $authorize)
{
$this->authorize = $authorize;
$this->authorize_transaction = new AuthorizeTransactions($this->authorize);
}
function refundTransaction($transaction_reference, $amount, $payment_profile_id, $profile_id)
function refundTransaction(Payment $payment, $amount)
{
error_reporting (E_ALL & ~E_DEPRECATED);
$transaction_details = $this->authorize_transaction->getTransactionDetails($payment->transaction_reference);
$this->authorize->init();
@ -41,11 +51,11 @@ class RefundTransaction
$refId = 'ref' . time();
$paymentProfile = new PaymentProfileType();
$paymentProfile->setPaymentProfileId( $payment_profile_id );
$paymentProfile->setPaymentProfileId( $transaction_details->getTransaction()->getProfile()->getCustomerPaymentProfileId() );
// set customer profile
$customerProfile = new CustomerProfilePaymentType();
$customerProfile->setCustomerProfileId( $profile_id );
$customerProfile->setCustomerProfileId( $transaction_details->getTransaction()->getProfile()->getCustomerProfileId() );
$customerProfile->setPaymentProfile( $paymentProfile );
//create a transaction
@ -53,7 +63,7 @@ class RefundTransaction
$transactionRequest->setTransactionType("refundTransaction");
$transactionRequest->setAmount($amount);
$transactionRequest->setProfile($customerProfile);
$transactionRequest->setRefTransId($transaction_reference);
$transactionRequest->setRefTransId($payment->transaction_reference);
$request = new CreateTransactionRequest();
$request->setMerchantAuthentication($this->authorize->merchant_authentication);
@ -68,20 +78,32 @@ class RefundTransaction
{
$tresponse = $response->getTransactionResponse();
if ($tresponse != null && $tresponse->getMessages() != null)
if ($tresponse != null && $tresponse->getMessages() != null)
{
echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n";
echo "Refund SUCCESS: " . $tresponse->getTransId() . "\n";
echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n";
echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n";
return [
'transaction_reference' => $tresponse->getTransId(),
'success' => true,
'description' => $tresponse->getMessages()[0]->getDescription(),
'code' => $tresponse->getMessages()[0]->getCode(),
'transaction_response' => $tresponse->getResponseCode()
];
}
else
{
echo "Transaction Failed \n";
if($tresponse->getErrors() != null)
{
echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n";
echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n";
return [
'transaction_reference' => '',
'transaction_response' => '',
'success' => false,
'description' => $tresponse->getErrors()[0]->getErrorText(),
'code' => $tresponse->getErrors()[0]->getErrorCode(),
];
}
}
}
@ -91,22 +113,50 @@ class RefundTransaction
$tresponse = $response->getTransactionResponse();
if($tresponse != null && $tresponse->getErrors() != null)
{
echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n";
echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n";
return [
'transaction_reference' => '',
'transaction_response' => '',
'success' => false,
'description' => $tresponse->getErrors()[0]->getErrorText(),
'code' => $tresponse->getErrors()[0]->getErrorCode(),
];
}
else
{
echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n";
echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n";
return [
'transaction_reference' => '',
'transaction_response' => '',
'success' => false,
'description' => $response->getMessages()->getMessage()[0]->getText(),
'code' => $response->getMessages()->getMessage()[0]->getCode(),
];
}
}
}
else
{
echo "No response returned \n";
return [
'transaction_reference' => '',
'transaction_response' => '',
'success' => false,
'description' => 'No response returned',
'code' => 'No response returned',
];
}
return $response;
return [
'transaction_reference' => '',
'transaction_response' => '',
'success' => false,
'description' => 'No response returned',
'code' => 'No response returned',
];
}

View File

@ -14,8 +14,10 @@ namespace App\PaymentDrivers;
use App\Models\ClientGatewayToken;
use App\Models\GatewayType;
use App\Models\Payment;
use App\PaymentDrivers\Authorize\AuthorizeCreditCard;
use App\PaymentDrivers\Authorize\AuthorizePaymentMethod;
use App\PaymentDrivers\Authorize\RefundTransaction;
use net\authorize\api\constants\ANetEnvironment;
use net\authorize\api\contract\v1\CreateTransactionRequest;
use net\authorize\api\contract\v1\GetMerchantDetailsRequest;
@ -110,16 +112,12 @@ class AuthorizePaymentDriver extends BaseDriver
public function processPaymentView($data)
{
return $this->payment_method->processPaymentView($data);
}
public function processPaymentResponse($request)
{
return $this->payment_method->processPaymentResponse($request);
}
public function purchase($amount, $return_client_response = false)
@ -127,9 +125,9 @@ class AuthorizePaymentDriver extends BaseDriver
return false;
}
public function refund($amount, $transaction_reference, $return_client_response = false)
public function refund(Payment $payment, $refund_amount, $return_client_response = false)
{
return (new RefundTransaction($this))->refundTransaction($payment, $refund_amount);
}
public function findClientGatewayRecord() :?ClientGatewayToken

View File

@ -82,12 +82,12 @@ class BaseDriver extends AbstractPaymentDriver
/**
* Executes a refund attempt for a given amount with a transaction_reference
*
* @param Payment $payment The Payment Object
* @param float $amount The amount to be refunded
* @param string $transaction_reference The transaction reference
* @param boolean $return_client_response Whether the method needs to return a response (otherwise we assume an unattended payment)
* @return mixed
*/
public function refund($amount, $transaction_reference, $return_client_response = false) {}
public function refund(Payment $payment, $amount, $return_client_response = false) {}
/**
* Set the inbound request payment method type for access.

View File

@ -0,0 +1,16 @@
<?php
namespace App\Policies;
use App\Models\User;
use Illuminate\Auth\Access\HandlesAuthorization;
class DocumentPolicy extends EntityPolicy
{
use HandlesAuthorization;
public function create(User $user) : bool
{
return $user->isAdmin() || $user->hasPermission('create_all');
}
}

View File

@ -18,6 +18,7 @@ use App\Models\CompanyGateway;
use App\Models\CompanyToken;
use App\Models\Credit;
use App\Models\Design;
use App\Models\Document;
use App\Models\Expense;
use App\Models\GroupSetting;
use App\Models\Invoice;
@ -38,6 +39,7 @@ use App\Policies\CompanyPolicy;
use App\Policies\CompanyTokenPolicy;
use App\Policies\CreditPolicy;
use App\Policies\DesignPolicy;
use App\Policies\DocumentPolicy;
use App\Policies\ExpensePolicy;
use App\Policies\GroupSettingPolicy;
use App\Policies\InvoicePolicy;
@ -70,6 +72,7 @@ class AuthServiceProvider extends ServiceProvider
CompanyGateway::class => CompanyGatewayPolicy::class,
Credit::class => CreditPolicy::class,
Design::class => DesignPolicy::class,
Document::class => DocumentPolicy::class,
Expense::class => ExpensePolicy::class,
GroupSetting::class => GroupSettingPolicy::class,
Invoice::class => InvoicePolicy::class,

View File

@ -111,6 +111,17 @@ class EventServiceProvider extends ServiceProvider
],
ClientWasRestored::class =>[
],
// Documents
DocumentWasCreated::class =>[
],
DocumentWasArchived::class =>[
],
DocumentWasUpdated::class =>[
],
DocumentWasDeleted::class =>[
],
DocumentWasRestored::class =>[
],
CreditWasMarkedSent::class => [
],
//Designs

View File

@ -0,0 +1,50 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Repositories;
use App\Models\Document;
/**
* Class for document repository.
*/
class DocumentRepository extends BaseRepository
{
/**
* Gets the class name.
*
* @return string The class name.
*/
public function getClassName()
{
return Document::class;
}
public function delete($document)
{
$document->deleteFile();
$document->forceDelete();
}
public function restore($document)
{
if (! $document->trashed()) {
return;
}
$document->restore();
if (class_exists($className)) {
event(new $className($document));
}
}
}

View File

@ -14,7 +14,7 @@ namespace App\Repositories;
use App\Models\GroupSetting;
use App\Utils\Traits\MakesHash;
class GroupSettingRepository
class GroupSettingRepository extends BaseRepository
{
use MakesHash;
/**

View File

@ -12,6 +12,7 @@
namespace App\Services\Ledger;
use App\Factory\CompanyLedgerFactory;
use App\Models\Activity;
use App\Models\CompanyLedger;
class LedgerService
@ -38,6 +39,7 @@ class LedgerService
$company_ledger->adjustment = $adjustment;
$company_ledger->notes = $notes;
$company_ledger->balance = $balance + $adjustment;
$company_ledger->activity_id = Activity::UPDATE_INVOICE;
$company_ledger->save();
$this->entity->company_ledger()->save($company_ledger);
@ -60,6 +62,7 @@ class LedgerService
$company_ledger->client_id = $this->entity->client_id;
$company_ledger->adjustment = $adjustment;
$company_ledger->balance = $balance + $adjustment;
$company_ledger->activity_id = Activity::UPDATE_PAYMENT;
$company_ledger->save();
$this->entity->company_ledger()->save($company_ledger);
@ -80,6 +83,7 @@ class LedgerService
$company_ledger->adjustment = $adjustment;
$company_ledger->notes = $notes;
$company_ledger->balance = $balance + $adjustment;
$company_ledger->activity_id = Activity::UPDATE_CREDIT;
$company_ledger->save();
$this->entity->company_ledger()->save($company_ledger);

View File

@ -58,9 +58,7 @@ class RefundPayment
private function processGatewayRefund()
{
// if ($this->refund_data['gateway_refund'] !== false && $this->total_refund > 0) {
if (true) {
if ($this->refund_data['gateway_refund'] !== false && $this->total_refund > 0) {
$gateway = CompanyGateway::first();
if ($gateway) {
@ -294,127 +292,3 @@ class RefundPayment
return $this->payment;
}
}
/*
private function refundPaymentWithNoInvoices(array $data)
{
$this->createActivity($data, $credit_note->id);
//determine if we need to refund via gateway
if ($data['gateway_refund'] !== false) {
//todo process gateway refund, on success, reduce the credit note balance to 0
}
$this->save();
//$this->client->paid_to_date -= $data['amount'];
$this->client->save();
return $this->fresh();
}
private function refundPaymentWithInvoices($data)
{
if ($data['gateway_refund'] !== false && $this->total_refund > 0) {
$gateway = CompanyGateway::find($this->company_gateway_id);
if ($gateway) {
$response = $gateway->driver($this->client)->refund($this, $this->total_refund);
if (!$response) {
throw new PaymentRefundFailed();
}
}
}
if ($this->total_refund > 0) {
$this->refunded += $this->total_refund;
}
$this->save();
$client_balance_adjustment = $this->adjustInvoices($data);
$credit_note->ledger()->updateCreditBalance($client_balance_adjustment, $ledger_string);
$this->client->paid_to_date -= $data['amount'];
$this->client->save();
return $this;
}
private function createActivity(array $data, int $credit_id)
{
$fields = new \stdClass;
$activity_repo = new ActivityRepository();
$fields->payment_id = $this->id;
$fields->user_id = $this->user_id;
$fields->company_id = $this->company_id;
$fields->activity_type_id = Activity::REFUNDED_PAYMENT;
$fields->credit_id = $credit_id;
if (isset($data['invoices'])) {
foreach ($data['invoices'] as $invoice) {
$fields->invoice_id = $invoice->id;
$activity_repo->save($fields, $this);
}
} else {
$activity_repo->save($fields, $this);
}
}
private function buildCreditNote(array $data) :?Credit
{
$credit_note = CreditFactory::create($this->company_id, $this->user_id);
$credit_note->assigned_user_id = isset($this->assigned_user_id) ?: null;
$credit_note->date = $data['date'];
$credit_note->status_id = Credit::STATUS_SENT;
$credit_note->client_id = $this->client->id;
$credit_note->amount = $data['amount'];
$credit_note->balance = $data['amount'];
return $credit_note;
}
private function adjustInvoices(array $data)
{
$adjustment_amount = 0;
foreach ($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);
}
$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
}
return $adjustment_amount;
}
}
*/

View File

@ -35,6 +35,7 @@ class CompanyLedgerTransformer extends EntityTransformer
'notes' => (string)$company_ledger->notes ?: '',
'balance' => (float) $company_ledger->balance,
'adjustment' => (float) $company_ledger->adjustment,
'activity_id' => (int)$company_ledger->activity_id,
'created_at' => (int)$company_ledger->created_at,
'updated_at' => (int)$company_ledger->updated_at,
'archived_at' => (int)$company_ledger->deleted_at,

View File

@ -37,7 +37,7 @@ class DocumentTransformer extends EntityTransformer
'assigned_user_id' => $this->encodePrimaryKey($document->assigned_user_id),
'project_id' => $this->encodePrimaryKey($document->project_id),
'vendor_id' => $this->encodePrimaryKey($document->vendor_id),
'url' => (string) $document->generateUrl() ?: '',
'url' => (string) $document->generateRoute() ?: '',
'preview' => (string) $document->preview ?: '',
'name' => (string) $document->name,
'type' => (string) $document->type,

View File

@ -12,9 +12,11 @@
namespace App\Transformers;
use App\Models\Client;
use App\Models\Document;
use App\Models\Invoice;
use App\Models\Payment;
use App\Models\Paymentable;
use App\Transformers\DocumentTransformer;
use App\Utils\Traits\MakesHash;
class PaymentTransformer extends EntityTransformer
@ -23,12 +25,15 @@ class PaymentTransformer extends EntityTransformer
protected $serializer;
protected $defaultIncludes = ['invoices'];
protected $defaultIncludes = [
// 'invoices'
];
protected $availableIncludes = [
'client',
'invoices',
'paymentables'
'paymentables',
'documents'
];
public function __construct($serializer = null)
@ -59,6 +64,11 @@ class PaymentTransformer extends EntityTransformer
return $this->includeCollection($payment->paymentables, $transformer, Paymentable::class);
}
public function includeDocuments(Payment $payment)
{
$transformer = new DocumentTransformer($this->serializer);
return $this->includeCollection($payment->documents, $transformer, Document::class);
}
public function transform(Payment $payment)
{

View File

@ -12,8 +12,10 @@
namespace App\Transformers;
use App\Models\Company;
use App\Models\Document;
use App\Models\Product;
use App\Models\User;
use App\Transformers\DocumentTransformer;
use App\Utils\Traits\MakesHash;
class ProductTransformer extends EntityTransformer
@ -28,7 +30,8 @@ class ProductTransformer extends EntityTransformer
*/
protected $availableIncludes = [
'company',
'user'
'user',
'documents',
];
@ -56,6 +59,12 @@ class ProductTransformer extends EntityTransformer
return $this->includeItem($product->company, $transformer, Company::class);
}
public function includeDocuments(Product $product)
{
$transformer = new DocumentTransformer($this->serializer);
return $this->includeCollection($product->documents, $transformer, Document::class);
}
public function transform(Product $product)
{
return [

View File

@ -1120,6 +1120,7 @@ class CreateUsersTable extends Migration
$table->unsignedInteger('company_id');
$table->unsignedInteger('client_id')->nullable();
$table->unsignedInteger('user_id')->nullable();
$table->unsignedInteger('activity_id')->nullable();
$table->decimal('adjustment', 16, 4)->nullable();
$table->decimal('balance', 16, 4)->nullable(); //this is the clients balance carried forward
@ -1167,6 +1168,7 @@ class CreateUsersTable extends Migration
$table->unsignedInteger('user_id')->nullable();
$table->string('name')->nullable();
$table->mediumText('settings')->nullable();
$table->boolean('is_default')->default(0);
$table->softDeletes('deleted_at', 6);
$table->timestamps(6);

View File

@ -265,43 +265,43 @@ 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();
// $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')) {
if (config('ninja.testvars.stripe')) {
$cg = new CompanyGateway;
$cg->company_id = $company->id;
$cg->user_id = $user->id;
$cg->gateway_key = '38f2c48af60c7dd69e04248cbb24c36e';
$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.paypal'));
$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;
// $cg->company_id = $company->id;
// $cg->user_id = $user->id;
// $cg->gateway_key = '38f2c48af60c7dd69e04248cbb24c36e';
// $cg->require_cvv = true;
// $cg->show_billing_address = true;
// $cg->show_shipping_address = true;
// $cg->update_details = true;
// $cg->config = encrypt(config('ninja.testvars.paypal'));
// $cg->save();
// }
// if(config('ninja.testvars.checkout')) {
// $cg = new CompanyGateway;
// $cg->company_id = $company->id;
@ -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

@ -3,7 +3,7 @@ const MANIFEST = 'flutter-app-manifest';
const TEMP = 'flutter-temp-cache';
const CACHE_NAME = 'flutter-app-cache';
const RESOURCES = {
"main.dart.js": "5780eeba1b1479aa66e3fbe19893b624",
"main.dart.js": "c815cadd52fe49aa8088f7392c1e34a1",
"favicon.ico": "51636d3a390451561744c42188ccd628",
"manifest.json": "77215c1737c7639764e64a192be2f7b8",
"assets/fonts/Roboto-Regular.ttf": "3e1af3ef546b9e6ecef9f3ba197bf7d2",
@ -17,7 +17,6 @@ const RESOURCES = {
"assets/assets/images/google-icon.png": "0f118259ce403274f407f5e982e681c3",
"assets/assets/images/logo.png": "090f69e23311a4b6d851b3880ae52541",
"assets/AssetManifest.json": "43bc57fb55ca8ea2fc1975108be086c9",
"index.html": "57fdc91b6cf6f7a7eddf1419c5763c19",
"/": "57fdc91b6cf6f7a7eddf1419c5763c19"
};
@ -26,7 +25,6 @@ const RESOURCES = {
const CORE = [
"/",
"main.dart.js",
"index.html",
"assets/NOTICES",
"assets/AssetManifest.json",
"assets/FontManifest.json"];
@ -105,7 +103,6 @@ self.addEventListener("activate", function(event) {
self.addEventListener("fetch", (event) => {
var origin = self.location.origin;
var key = event.request.url.substring(origin.length + 1);
// Redirect URLs to the index.html
if (event.request.url == origin || event.request.url.startsWith(origin + '/#')) {
key = '/';
}

191847
public/main.dart.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -5,7 +5,7 @@
<title>Invoice Ninja</title>
<meta name="report_errors" content="{{ $report_errors }}">
<meta name="google-signin-client_id" content="{{ config('services.google.client_id') }}">
<meta name="minimum_client_version" content="{{ config('ninja.minimum_client_version') }}">
<link rel="manifest" href="manifest.json">
</head>
<body style="background-color:#888888;">

View File

@ -69,6 +69,10 @@ Route::group(['middleware' => ['api_db', 'token_auth', 'locale'], 'prefix' => 'a
Route::post('vendors/bulk', 'VendorController@bulk')->name('vendors.bulk');
Route::resource('documents', 'DocumentController');// name = (documents. index / create / show / update / destroy / edit
Route::get('documents/{document}/download', 'DocumentController@download')->name('documents.download');
Route::post('documents/bulk', 'DocumentController@bulk')->name('documents.bulk');
Route::resource('client_statement', 'ClientStatementController@statement');// name = (client_statement. index / create / show / update / destroy / edit
Route::resource('payment_terms', 'PaymentTermController');// name = (payments. index / create / show / update / destroy / edit
@ -108,6 +112,7 @@ Route::group(['middleware' => ['api_db', 'token_auth', 'locale'], 'prefix' => 'a
Route::put('company_users/{user}', 'CompanyUserController@update');
Route::resource('group_settings', 'GroupSettingController');
Route::post('group_settings/bulk', 'GroupSettingController@bulk');
Route::resource('tax_rates', 'TaxRateController');// name = (tasks. index / create / show / update / destroy / edit

View File

@ -49,7 +49,9 @@ Route::group(['middleware' => ['auth:contact','locale'], 'prefix' => 'client', '
Route::resource('payment_methods', 'ClientPortal\PaymentMethodController');// name = (payment_methods. index / create / show / update / destroy / edit
Route::match(['GET', 'POST'], 'quotes/approve', 'ClientPortal\QuoteController@bulk')->name('quotes.bulk');
Route::resource('quotes', 'ClientPortal\QuoteController')->only('index', 'show');
Route::get('quotes', 'ClientPortal\QuoteController@index')->name('quotes.index')->middleware('portal_enabled');
Route::get('quotes/{quote}', 'ClientPortal\QuoteController@show')->name('quote.show');
Route::get('quotes/{quote_invitation}', 'ClientPortal\QuoteController@show')->name('quote.show_invitation');
Route::resource('credits', 'ClientPortal\CreditController')->only('index', 'show');

View File

@ -132,4 +132,80 @@ class DesignApiTest extends TestCase
$this->assertTrue((bool)$design->is_deleted);
$this->assertGreaterThan(0, $design->deleted_at);
}
public function testDesignArchive()
{
$design = [
'body' => 'body',
'includes' => 'includes',
'product' => 'product',
'task' => 'task',
'footer' => 'footer',
'header' => 'header'
];
$data = [
'name' => $this->faker->firstName,
'design' => $design
];
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token
])->post('/api/v1/designs', $data);
$response->assertStatus(200);
$arr = $response->json();
$this->id = $arr['data']['id'];
$data['ids'][] = $arr['data']['id'];
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token
])->post('/api/v1/designs/bulk?action=archive', $data);
$response->assertStatus(200);
$design = Design::where('id', $this->decodePrimaryKey($arr['data']['id']))->withTrashed()->first();
$this->assertNotNull($design->deleted_at);
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token
])->post('/api/v1/designs/bulk?action=restore', $data);
$response->assertStatus(200);
$design = Design::where('id', $this->decodePrimaryKey($arr['data']['id']))->withTrashed()->first();
$this->assertNull($design->deleted_at);
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token
])->post('/api/v1/designs/bulk?action=delete', $data);
$response->assertStatus(200);
$design = Design::where('id', $this->decodePrimaryKey($arr['data']['id']))->withTrashed()->first();
$this->assertTrue((bool)$design->is_deleted);
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token
])->post('/api/v1/designs/bulk?action=restore', $data);
$response->assertStatus(200);
$design = Design::where('id', $this->decodePrimaryKey($arr['data']['id']))->withTrashed()->first();
$this->assertFalse((bool)$design->is_deleted);
$this->assertNull($design->deleted_at);
}
}

View File

@ -2,6 +2,10 @@
namespace Tests\Integration\PaymentDrivers;
use App\Factory\PaymentFactory;
use App\Models\CompanyGateway;
use App\PaymentDrivers\AuthorizePaymentDriver;
use Tests\MockAccountData;
use Tests\TestCase;
use net\authorize\api\constants\ANetEnvironment;
use net\authorize\api\contract\v1 as AnetAPI;
@ -31,10 +35,11 @@ use net\authorize\api\controller\GetMerchantDetailsController;
*/
class AuthorizeTest extends TestCase
{
use MockAccountData;
public $customer_profile_id = 1512191314;
public $customer_profile_id = 1512373273;
public $customer_payment_profile = 1512219932;
public $customer_payment_profile = 1512424103;
public function setUp() :void
{
@ -43,7 +48,8 @@ class AuthorizeTest extends TestCase
if (! config('ninja.testvars.authorize')) {
$this->markTestSkipped('authorize.net not configured');
}
$this->makeTestData();
}
public function testUnpackingVars()
@ -148,15 +154,7 @@ class AuthorizeTest extends TestCase
// Create an array of any shipping addresses
$shippingProfiles[] = $customerShippingAddress;
$refId = 'ref' . time();
$email = "test@gmail.com";
// // Create a new CustomerPaymentProfile object
// $paymentProfile = new AnetAPI\CustomerPaymentProfileType();
// $paymentProfile->setCustomerType('individual');
// $paymentProfile->setBillTo($billTo);
// $paymentProfile->setPayment($paymentCreditCard);
// $paymentProfiles[] = $paymentProfile;
$email = "test12@gmail.com";
// Create a new CustomerProfileType and add the payment profile object
$customerProfile = new CustomerProfileType();
@ -188,6 +186,8 @@ class AuthorizeTest extends TestCase
$errorMessages = $response->getMessages()->getMessage();
info("Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n");
}
info("the new customer profile id = ". $response->getCustomerProfileId());
$this->assertNotNull($response);
@ -241,16 +241,16 @@ class AuthorizeTest extends TestCase
// Set credit card information for payment profile
$creditCard = new CreditCardType();
$creditCard->setCardNumber("4007000000027");
$creditCard->setExpirationDate("2038-12");
$creditCard->setCardCode("142");
$creditCard->setCardNumber("4111111111111111");
$creditCard->setExpirationDate("2024-01");
$creditCard->setCardCode("100");
$paymentCreditCard = new PaymentType();
$paymentCreditCard->setCreditCard($creditCard);
// Create the Bill To info for new payment type
$billto = new CustomerAddressType();
$billto->setFirstName("Ellen");
$billto->setLastName("Johnson");
$billto->setFirstName("Elas");
$billto->setLastName("Joson");
$billto->setCompany("Souveniropolis");
$billto->setAddress("14 Main Street");
$billto->setCity("Pecan Springs");
@ -315,7 +315,7 @@ class AuthorizeTest extends TestCase
$transactionRequestType = new TransactionRequestType();
$transactionRequestType->setTransactionType( "authCaptureTransaction");
$transactionRequestType->setAmount(400);
$transactionRequestType->setAmount(350);
$transactionRequestType->setProfile($profileToCharge);
$request = new CreateTransactionRequest();
@ -372,6 +372,31 @@ class AuthorizeTest extends TestCase
}
$this->assertNotNull($response);
$this->assertNotNull($tresponse);
/* Testing refunds - need to research more as payments are in a pending state so cannot be 'refunded'*/
// info("transaction reference = " . $tresponse->getTransId());
// $payment = PaymentFactory::create($this->company->id, $this->user->id);
// $payment->amount = 400;
// $payment->client_id = $this->client->id;
// $payment->date = now();
// $payment->transaction_reference = $tresponse->getTransId();
// $payment->company_gateway_id = 1;
// $payment->save();
// $company_gateway = CompanyGateway::where('gateway_key', '3b6621f970ab18887c4f6dca78d3f8bb')->first();
// $authorize_payment_driver = new AuthorizePaymentDriver($company_gateway, $this->client);
// $response = $authorize_payment_driver->refund($payment, 350);
// info(print_r($response,1));
// $this->assertTrue(is_array($response));
}
}