Skip to content

Commit

Permalink
Merge pull request #48 from surprisehighway/release/v3.0.0
Browse files Browse the repository at this point in the history
Release/v3.0.0
  • Loading branch information
imagehat authored Jul 18, 2022
2 parents ae314a4 + e6d22d4 commit 1ccb1fb
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 96 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

## 3.0.0
### Added
- Craft 4 compatibility.

## 2.2.0
### Added
- Updated Avatax SDK to version 22.3.0.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Avatax plugin for Craft CMS 3.x
# Avatax plugin for Craft CMS 4.x

Calculate and add sales tax to an order's base tax using Avalara's AvaTax service.

Expand All @@ -8,7 +8,7 @@ Calculate and add sales tax to an order's base tax using Avalara's AvaTax servic

## Requirements

This plugin requires Craft 3.3 and Craft Commerce 2.2 or later, or Craft 3.4 and Craft Commerce 3.0 and later.
This plugin requires Craft 4 and Craft Commerce 4.0 or later and Craft Commerce 4.0 or later.

> Related: The Craft 2.x Commerce 1.x [version](https://github.com/surprisehighway/craft-avataxtaxadjuster) of this plugin is no longer actively maintained but is still available.
Expand Down
17 changes: 13 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "surprisehighway/craft-avatax",
"description": "Calculate and add sales tax to an order's base tax using Avalara's Avatax service.",
"type": "craft-plugin",
"version": "2.2.0",
"version": "3.0.0",
"keywords": [
"craft",
"cms",
Expand All @@ -22,8 +22,8 @@
}
],
"require": {
"craftcms/commerce": "^2.2.0|^3.0",
"craftcms/cms": "^3.3",
"craftcms/commerce": "^4.0",
"craftcms/cms": "^4.0",
"avalara/avataxclient": "^22.3.0"
},
"repositories": [
Expand All @@ -48,5 +48,14 @@
"salesTaxService": "surprisehighway\\avatax\\services\\SalesTaxService",
"logService": "surprisehighway\\avatax\\services\\LogService"
}
}
},
"config": {
"allow-plugins": {
"yiisoft/yii2-composer": true,
"craftcms/plugin-installer": true
},
"platform": {
"php": "8.0.2"
}
}
}
23 changes: 12 additions & 11 deletions src/Avatax.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use craft\events\PluginEvent;
use craft\events\RegisterComponentTypesEvent;
use craft\events\RegisterUrlRulesEvent;
use craft\events\ModelEvent;
use craft\fields\Dropdown;
use craft\fields\PlainText;
use craft\helpers\UrlHelper;
Expand All @@ -33,7 +34,7 @@
use craft\commerce\events\RefundTransactionEvent;
use craft\commerce\models\TaxCategory;
use craft\commerce\models\Transaction;
use craft\commerce\services\Addresses;
use craft\elements\Address;
use craft\commerce\services\OrderAdjustments;
use craft\commerce\services\Payments;
use craft\commerce\services\TaxCategories;
Expand Down Expand Up @@ -65,7 +66,7 @@ class Avatax extends Plugin
/**
* @var string
*/
public $schemaVersion = '2.0.0';
public string $schemaVersion = '2.0.0';


// Public Methods
Expand Down Expand Up @@ -125,9 +126,9 @@ function(Event $event) {

// Register address save event listener
Event::on(
Addresses::class,
Addresses::EVENT_BEFORE_SAVE_ADDRESS,
function(AddressEvent $event) {
Address::class,
Address::EVENT_BEFORE_SAVE,
function(ModelEvent $event) {
$this->onBeforeSaveAddress($event);
}
);
Expand Down Expand Up @@ -168,10 +169,10 @@ public function onBeforeOrderComplete(Event $event)
* Raised before address has been saved.
* Validate an address in avatax.
*/
public function onBeforeSaveAddress(AddressEvent $event)
public function onBeforeSaveAddress(ModelEvent $event)
{
// @var AddressEvent $address
$address = $event->address;
// @var Address $address
$address = $event->sender;

if(Craft::$app->getRequest()->getIsSiteRequest()) {
$this->SalesTaxService->validateAddress($address);
Expand Down Expand Up @@ -344,15 +345,15 @@ static function error($message, $data = [])
/**
* @inheritdoc
*/
protected function createSettingsModel()
protected function createSettingsModel(): ?\craft\base\Model
{
return new Settings();
}

/**
* @inheritdoc
*/
protected function settingsHtml(): string
protected function settingsHtml(): ?string
{
return Craft::$app->view->renderTemplate(
'avatax/settings',
Expand All @@ -365,7 +366,7 @@ protected function settingsHtml(): string
/**
* @inheritdoc
*/
public function getSettingsResponse()
public function getSettingsResponse(): mixed
{
return Craft::$app->controller->redirect(UrlHelper::cpUrl('avatax/settings'));
}
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class BaseController extends Controller
* The actions must be in 'kebab-case'
* @access protected
*/
protected $allowAnonymous = false;
protected array|int|bool $allowAnonymous = false;

// Public Methods
// =========================================================================
Expand Down
27 changes: 11 additions & 16 deletions src/controllers/JsonController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Craft;
use craft\web\Controller;
use craft\commerce\Plugin as Commerce;
use craft\commerce\models\Address;
use craft\elements\Address;

/**
* @author Surprise Highway
Expand All @@ -35,7 +35,7 @@ class JsonController extends Controller
* The actions must be in 'kebab-case'
* @access protected
*/
protected $allowAnonymous = true;
protected array|int|bool $allowAnonymous = true;

// Public Methods
// =========================================================================
Expand All @@ -54,21 +54,16 @@ public function actionValidateAddress()

// Shared attributes
$attributes = [
'attention',
'title',
'firstName',
'lastName',
'address1',
'address2',
'city',
'zipCode',
'phone',
'fullName',
'addressLine1',
'addressLine2',
'locality',
'postalCode',
'alternativePhone',
'businessName',
'businessTaxId',
'businessId',
'countryId',
'stateValue'
'organization',
'organizationTaxId',
'countryCode',
'administrativeArea'
];

foreach ($attributes as $attr)
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/UtilityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class UtilityController extends Controller
* The actions must be in 'kebab-case'
* @access protected
*/
protected $allowAnonymous = false;
protected array|int|bool $allowAnonymous = false;

// Public Methods
// =========================================================================
Expand Down
4 changes: 2 additions & 2 deletions src/models/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class Settings extends Model
// Public Methods
// =========================================================================

public function behaviors()
public function behaviors(): array
{
return [
'parser' => [
Expand Down Expand Up @@ -230,7 +230,7 @@ public function getSandboxCompanyCode()
/**
* @inheritdoc
*/
public function rules()
public function rules(): array
{
return [
['environment', 'string'],
Expand Down
2 changes: 1 addition & 1 deletion src/services/CertCaptureService.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class CertCaptureService extends Component
/**
* @inheritdoc
*/
public function init()
public function init(): void
{
parent::init();

Expand Down
2 changes: 1 addition & 1 deletion src/services/LogService.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class LogService extends Component
// Public Methods
// =========================================================================

public function init()
public function init(): void
{
$this->logFile = Craft::$app->path->getLogPath() . '/avatax.log';

Expand Down
Loading

0 comments on commit 1ccb1fb

Please sign in to comment.