<?php use Magento\Sales\Api\Data\TransactionInterface; use Magento\Sales\Api\TransactionRepositoryInterface; use Magento\Framework\Api\SearchCriteriaBuilder; use Magento\Framework\HTTP\Client\Curl; class ... { /** @var TransactionRepositoryInterface */ private $_transactionRepositoryInterface; /** @var SearchCriteriaBuilder */ private $_searchCriteriaBuilder; /** @var Curl */ private $_curl; /** * ... * @param Curl $_curl * @param TransactionRepositoryInterface $_transactionRepositoryInterface * @param SearchCriteriaBuilder $_searchCriteriaBuilder */ public function __construct( ... Curl $_curl, TransactionRepositoryInterface $_transactionRepositoryInterface, SearchCriteriaBuilder $_searchCriteriaBuilder ) { parent::__construct(...); $this->_curl = $_curl; $this->_transactionRepositoryInterface = $_transactionRepositoryInterface; $this->_searchCriteriaBuilder = $_searchCriteriaBuilder; } public function excute() { $orderId = 123; $trans = $this->_getTransactionFromOrder($orderId); $tran = false; if (is_array($trans) && count($trans) > 0) { $tran = reset($trans); } if ($tran) { /** @var TransactionInterface $trans */ $transId = $tran->getTxnId(); echo "<br>Trans ID: " . $transId . "<br>"; $addInfo = $tran->getAdditionalInformation(); if (isset($addInfo["raw_details_info"]["profile_id"])) { echo "<br>profile_id: " . $addInfo["raw_details_info"]["profile_id"]; } if (isset($addInfo["raw_details_info"]["payment_id"])) { echo "<br>payment_id: " . $addInfo["raw_details_info"]["payment_id"]; } } // Get Data by Trans ID from Authorize net API $transId = 4444; $data = $this->_getTransDetail($transId); } /** * @param $orderId * * @return TransactionInterface[] */ private function _getTransactionFromOrder($orderId) { $this->_searchCriteriaBuilder->addFilter('order_id', $orderId); $list = $this->_transactionRepositoryInterface->getList( $this->_searchCriteriaBuilder->create() ); return $list->getItems(); } /** * Get Transaction Detail from authorize net API * @param $transId * * @return false|string */ private function _getTransDetail($transId) { if (!$transId) { return false; } try { // Set the external URL $apiUrl = 'https://apitest.authorize.net/xml/v1/request.api'; $apiUrlProduction = 'https://api.authorize.net/xml/v1/request.api'; // Set the POST data as JSON $postData = [ 'getTransactionDetailsRequest' => [ 'merchantAuthentication' => [ 'name' => 'API_USER_ID', 'transactionKey' => 'TRANS_KEY', ], 'transId' => $transId, ], ]; $postDataJson = json_encode($postData); // Make the POST request $this->_curl->post($apiUrl, $postDataJson); $response = $this->_curl->getBody(); return $response; } catch (\Exception $e) { return false; } } }
Search
Dec 7, 2023
Get transaction (profile id, payment id) from order in magento 2
Sep 28, 2023
Magento 2: get discount, gift card amount, subtotal, grand total
<?php
use Magento\Checkout\Model\Session as CheckoutSession;
use Magento\GiftCardAccount\Api\GiftCardAccountManagementInterface;
use Magento\GiftCardAccount\Api\Data\GiftCardAccountInterface;
class Price {
/** @var CheckoutSession */
protected $checkoutSession;
/** @var GiftCardAccountManagementInterface */
private $giftCardAccountManagementInterface;
public function __construct(
CheckoutSession $checkoutSession,
GiftCardAccountManagementInterface $giftCardAccountManagementInterface
)
{
$this->checkoutSession = $checkoutSession;
$this->giftCardAccountManagementInterface = $giftCardAccountManagementInterface;
}
public function execute()
{
$quote = $this->getCurrentQuote();
if ($quote) {
$shippingAddress = $quote->getShippingAddress();
$subTotal = round((float) $quote->getSubtotal(), 2);
$grandTotal = round((float) $quote->getGrandTotal(), 2);
$taxAmount = round((float) $shippingAddress->getTaxAmount(), 2);
$giftCardAmountAvailableTotal = round((float) $quote->getGiftCardsAmount(), 2);
// Get giftcard used
$giftCardAccount = $this->getGiftCardAccount();
$giftCardUsedAmount = $giftCardAccount->getGiftCardsAmountUsed();
$giftCardAmount = round($giftCardUsedAmount, 2);
// Get discount
$items = $quote->getAllItems();
$discountAmount = 0;
foreach ($items as $item) {
$discountAmount += $item->getDiscountAmount();
}
$discountAmount = round((float) $discountAmount, 2);
}
}
/**
* @param $quoteId
* @return GiftCardAccountInterface
*/
protected function getGiftCardAccount($quoteId = null)
{
if (!$quoteId) {
$quoteId = $this->getCurrentQuote()->getId();
}
return $this->giftCardAccountManagementInterface->getListByQuoteId($quoteId);
}
/**
* @return CartInterface|Quote
*/
public function getCurrentQuote()
{
return $this->checkoutSession->getQuote();
}
}
Sep 25, 2023
Ubuntu: DNS server not responding, unable to resolve host - temporary failure in name resolution
1. Check 2 files /etc/hostname and /etc/hosts
sudo nano /etc/hostname
samuel
sudo nano /etc/hosts
127.0.0.1 localhost localhost.localdomain samuel 127.0.1.1 samuel-ubuntu 127.0.1.1 samuel
2. Make sure the name is the same in both files
3. Check content in /etc/resolv.conf file
nano /etc/resolv.conf
4. Add nameserver to the resolv.conf
nameserver 8.8.8.8
5. Restart service
sudo systemctl restart systemd-resolved.service
Sep 22, 2023
installed tab not showing in software center in ubuntu
Remove gnome-software
sudo apt-get remove --purge gnome-software
Re-install gnome-software
sudo apt-get install gnome-software
Sep 20, 2023
Magento 2: Format Price
In phtml file
/** @var $priceHelper Magento\Framework\Pricing\Helper\Data */
$priceHelper = $this->helper(Magento\Framework\Pricing\Helper\Data::class);
echo $priceHelper->currency(100.57, true, false);
In php file
3 4 5 6 7 8 9 10 | use Magento\Framework\Pricing\Helper\Data protected $priceHelper; public function __construct(Data $priceHelper) { $this->priceHelper = $priceHelper; } public function getFormattedPrice($price) { return $this->priceHelper->currency($price, true, false); } |
Subscribe to:
Posts (Atom)