Add this to your class where you need to retrieve the tax percent
private $taxCollectionFactory;
public function __construct(
.....
\Magento\Sales\Model\ResourceModel\Order\Tax\CollectionFactory $taxCollectionFactory,
...
) {
....
$this->taxCollectionFactory = $taxCollectionFactory;
...
}
then you can get all the taxes and tax percents applied to the order like this:
Assuming you have the $order
object
$taxes = $this->taxCollectionFactory->create()->loadByOrder($order);
Now you can loop through the taxes and get all the percentages:
foreach ($taxes as $tax) {
//do something with $tax->getPercent();
//or $tax->getAmount();
}
You will always gets a collection because you can have multiple taxes applied to the order. If you are sure you only have one tax configured you can use $taxes->getFirstItem()
in the code above and get the first element of the collection.