0

Is there a way to get the stripe payment status on custom sales order grid column? enter image description here

enter image description here

3 Answers 3

0

You can show Payment Status as Succeeded for an order if total_paid and last_trans_id is not null in sales_order_payment table.

0
  1. UI component sales_order_grid.xml under [COMPANY]/[MODULE]/view/adminhtml/ui_component/sales_order_grid.xml add below code

     <?xml version="1.0" encoding="UTF-8"?><listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd"><columns name="sales_order_columns">
         <column name="stripe_payment_status" class="[COMPANY]\[MODULE]\Ui\Component\Listing\Column\Status">
             <argument name="data" xsi:type="array">
                 <item name="config" xsi:type="array">
                     <item name="visible" xsi:type="boolean">true</item>
                     <item name="label" xsi:type="string" translate="true">Stripe Payment Status</item>
                 </item>
             </argument>
         </column>
     </columns></listing>
    
  2. Then created the UI class under [COMPANY]/[MODULE]/Ui/Component/Listing/Column/Status.php add

Below Code

<?php namespace [COMPANY]\[MODULE]\Ui\Component\Listing\Column;
use \Magento\Sales\Api\OrderRepositoryInterface;
use \Magento\Framework\View\Element\UiComponent\ContextInterface;
use \Magento\Framework\View\Element\UiComponentFactory;
use \Magento\Ui\Component\Listing\Columns\Column;
use \Magento\Framework\Api\SearchCriteriaBuilder;

class Status extends Column
{
    protected $_orderRepository;
    protected $_searchCriteria;

    public function __construct(
        ContextInterface $context,
        UiComponentFactory $uiComponentFactory,
        OrderRepositoryInterface $orderRepository,
        SearchCriteriaBuilder $criteria,
        array $components = [],
        array $data = []
    ) {
        $this->_orderRepository = $orderRepository;
        $this->_searchCriteria  = $criteria;
        parent::__construct($context, $uiComponentFactory, $components, $data);
    }

    public function prepareDataSource(array $dataSource)
    {
        if (isset($dataSource['data']['items'])) {
            foreach ($dataSource['data']['items'] as & $item) {

                $order  = $this->_orderRepository->get($item["entity_id"]);
                $status = $order->getData("stripe_payment_status"); // customize code add here status which is came in the order view page

                   
                // $this->getData('name') returns the name of the column so in this case it would return export_status
                $item[$this->getData('name')] = $status;
            }
        }

        return $dataSource;
    }
}
  1. The value which coming here in below screenshot : enter image description here

That value you have to bind with $status = $order->getData("stripe_payment_status"); $status variable.

6
  • It is not working
    – mechanic
    Commented Dec 16, 2022 at 13:55
  • @mechanic Mark this answer useful if it works for you Commented Dec 16, 2022 at 15:00
  • It is not working. The status value is empty.
    – mechanic
    Commented Dec 16, 2022 at 15:42
  • what you have in this line $status = $order->getData("stripe_payment_status"); Commented Dec 16, 2022 at 16:00
  • That is what I want to know, how do I bind the stripe payment status with $status = $order->getData("stripe_payment_status");?
    – mechanic
    Commented Dec 16, 2022 at 16:09
0

The value is coming from the Stripe API. Please see \StripeIntegration\Payments\Block\PaymentInfo\Element::getPaymentStatus

The status of payment is pulled using the last transaction id as a param in the API, which is coming from the order additional info. I suggest you follow the method to see more in depth whats happening.

You could create your own method which gets the order id as an input, get the last transaction id of that order, and basically do a API request to Stripe using that transaction id as a param to determine the status of payment.

For how to render the status in the order dropdown, please follow @Saurabh Dwivedi answer. You basically have to set $status to the response you get from the API.

Note: this is based on stripe/module-payments, version 3.3.8.

Hope it helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.