We're using a custom module to calculate an amount we need to include in the grand total of the order, i.e. the customer will be charged for the product PLUS this custom amount.

The result is our custom amount goes as Total Due and Stripe only charges the customer for the original value of the product and its shipping without our custom calculation.

Custom module code is as follows:

class CustomAmount extends \Magento\Quote\Model\Quote\Address\Total\AbstractTotal
    public function collect(
        \Magento\Quote\Model\Quote $quote,
        \Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment,
        \Magento\Quote\Model\Quote\Address\Total $total
    ) {
        parent::collect($quote, $shippingAssignment, $total);
        $amount = 187; // fixed amount as example, but this will change
        $total->setTotalAmount('installation', $amount);
        $total->setBaseTotalAmount('installation', $amount);
        $total->addTotalAmount($this->getCode(), $amount);
        $total->addBaseTotalAmount($this->getCode(), $amount);
        return $this;

and we're seeing this on admin panel enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.