Get the amount to refund

@return string refund amount, as a numeric string`
186406
private function _getRefundAmount()
    {
        print PHP_EOL . "----------------------------------------------------------------------------" . PHP_EOL;
        
        print "Enter the amount to refund the customer (to 2 decimal places): ";
        do {
            $refundAmount = trim(fgets(STDIN));
        } while (!is_numeric($refundAmount));
        
        return $refundAmount;
    }
545029
public function getData()
    {
        $this->setDefaults();

        $this->validate(
            'partner',
            '_input_charset',
            'refund_date',
            'batch_no',
            'refund_items'
        );

        $this->validateOne(
            'seller_user_id',
            'seller_email'
        );

        $this->setBatchNum(count($this->getRefundItems()));
        $this->setRefundDetail($this->getDetailData());

        $data = [
            'service'        => $this->service,
            'partner'        => $this->getPartner(),
            'notify_url'     => $this->getNotifyUrl(),
            'seller_user_id' => $this->getPartner(),
            'refund_date'    => $this->getRefundDate(),
            'batch_no'       => $this->getBatchNo(),
            'batch_num'      => $this->getBatchNum(),
            'detail_data'    => $this->getDetailData(),
            '_input_charset' => $this->getInputCharset(),
        ];

        $data['sign'] = $this->sign($data, $this->getSignType());
        $data['sign_type'] = $this->getSignType();

        return $data;
    }
1252276
public function refund()
    {
        if (!userHasPermission('admin:invoice:payment:refund')) {
            unauthorised();
        }

        // --------------------------------------------------------------------------

        $oUri          = Factory::service('Uri');
        $oInput        = Factory::service('Input');
        $oPaymentModel = Factory::model('Payment', 'nails/module-invoice');
        $iPaymentId    = $oUri->segment(5);
        $sAmount       = $oInput->post('amount') ?: null;
        $sReason       = $oInput->post('reason') ?: null;
        $sRedirect     = urldecode($oInput->post('return_to')) ?: 'invoice/payment/view/' . $iPaymentId;

        try {

            $oPayment = $oPaymentModel->getById($iPaymentId);
            if (empty($oPaymentModel)) {
                throw new NailsException('Invalid payment ID.');
            }

            // --------------------------------------------------------------------------

            //  Convert the amount to its smallest unit
            $iAmount = intval($sAmount * pow(10, $oPayment->currency->decimal_precision));

            // --------------------------------------------------------------------------

            if (!$oPaymentModel->refund($iPaymentId, $iAmount, $sReason)) {
                throw new NailsException('Failed to refund payment. ' . $oPaymentModel->lastError(), 1);
            }

            $sStatus  = 'success';
            $sMessage = 'Payment refunded successfully.';

        } catch (NailsException $e) {
            $sStatus  = 'error';
            $sMessage = $e->getMessage();
        }

        $oSession = Factory::service('Session', 'nails/module-auth');
        $oSession->setFlashData($sStatus, $sMessage);
        redirect($sRedirect);
    }
481665
public function product(){
		
		Number::setScale(static::NUMERIC_FUNCTIONS_SCALE);
		
		$total = \strval($this->front());
		
		for($i = 1, $l = $this->count(); $i < $l; ++$i){
			$total = Number::multiply($total, \strval($this->_Arr[$i]));
		}
		
		return $total;
		
	}
699399
def admin_refund
      return if !user_is_allowed('orders', 'edit')
    
      response = Caboose::StdClass.new({
        'refresh' => nil,
        'error' => nil,
        'success' => nil
      })
    
      order = Order.find(params[:id])
    
      if order.financial_status != 'captured'
        response.error = "This order hasn't been captured yet, you will need to void instead"
      else
        if PaymentProcessor.refund(order)
          order.update_attributes(
            :financial_status => 'refunded',
            :status => 'cancelled'
          )
          
          response.success = 'Order refunded successfully'
        else
          response.error = 'Error refunding order'
        end
        
        #if order.calculate_net < (order.amount_discounted || 0) || PaymentProcessor.refund(order)
        #  order.financial_status = 'refunded'
        #  order.status = 'refunded'
        #  order.save
        #  
        #  if order.discounts.any?
        #    discount = order.discounts.first
        #    amount_to_refund = order.calculate_net < order.amount_discounted ? order.calculate_net : order.amount_discounted
        #    discount.update_attribute(:amount_current, amount_to_refund + discount.amount_current)
        #  end
        #  
        #  response.success = "Order refunded successfully"
        #else
        #  response.error = "Error refunding order."
        #end
      end
    
      render json: response
      
      # return if !user_is_allowed('orders', 'edit')
      #     
      # response = Caboose::StdClass.new({
      #   'refresh' => nil,
      #   'error' => nil,
      #   'success' => nil
      # })
      #     
      # order = Order.find(params[:id])
      #     
      # if order.financial_status != 'captured'
      #   response.error = "This order hasn't been captured yet, you will need to void instead"
      # else
      #   if PaymentProcessor.refund(order)
      #     order.financial_status = 'refunded'
      #     order.status = 'refunded'
      #     order.save
      #     
      #     # Add the variant quantities ordered back
      #     order.cancel
      #     
      #     response.success = "Order refunded successfully"
      #   else
      #     response.error = "Error refunding order."
      #   end
      # end
      #     
      # render :json => response
    end
1350082
public function getLineItemTotal()
    {
        $amount = 0;

        foreach ($this->getLineItems() as $lineItem)
        {
            $amount += ($lineItem->getPrice()*$lineItem->getQuantity());
        }

        return $amount;
    }
695933
public function refund($data = [])
    {
        $resource = "payments/" . urlencode($this->id) . "/refunds";

        $body = null;
        if (count($data) > 0) {
            $body = json_encode($data);
        }

        $result = $this->client->performHttpCall(
            MollieApiClient::HTTP_POST,
            $resource,
            $body
        );

        return ResourceFactory::createFromApiResult(
            $result,
            new Refund($this->client)
        );
    }
346375
protected function getAvailableTotals()
    {
        $sign = $this->getSign();
        if ($this->getType() === Source::Order) {
            $amount = $this->source->getTotalProductsWithoutTaxes()
                      + $this->source->total_shipping_tax_excl
                      + $this->source->total_wrapping_tax_excl
                      - $this->source->total_discounts_tax_excl;
            $amountInc = $this->source->getTotalProductsWithTaxes()
                         + $this->source->total_shipping_tax_incl
                         + $this->source->total_wrapping_tax_incl
                         - $this->source->total_discounts_tax_incl;
        } else {
            // On credit notes, the amount ex VAT will not have been corrected
            // for discounts that are subtracted from the refund. This will be
            // corrected later in getDiscountLinesCreditNote().
            $amount = $this->source->total_products_tax_excl
                      + $this->source->total_shipping_tax_excl;
            $amountInc = $this->source->total_products_tax_incl
                         + $this->source->total_shipping_tax_incl;
        }

        return array(
            Meta::InvoiceAmountInc => $sign * $amountInc,
            Meta::InvoiceAmount => $sign * $amount,
        );
    }
1235954
public function getTaxTotal(): int
    {
        $taxTotal = 0;

        foreach ($this->getAdjustments(AdjustmentInterface::TAX_ADJUSTMENT) as $taxAdjustment) {
            $taxTotal += $taxAdjustment->getAmount();
        }

        foreach ($this->units as $unit) {
            $taxTotal += $unit->getTaxTotal();
        }

        return $taxTotal;
    }
61482
public function balance() {
        $data = $this->getSend()->parameters([
            'method' => 'GetNum'
        ])->json();
        if ($data['code'] == 2) {
            return $data['num'];
        }
        throw new \Exception($data['msg']);
    }
457814
public function refund($amount, $originalTransactionReference, $clientReference = NULL, $comment = NULL, $description = NULL, $cardHolderName = NULL, $taxAmount = NULL)
	{
		$request = Request::createFromClient($this);

		$request->setTransactionType(Request::TRANSACTION_TYPE_REFUND)
		        ->setTotalAmount($amount)
		        ->setOriginalTransactionReference($originalTransactionReference)
		        ->setClientReference($clientReference)
		        ->setComment($comment)
		        ->setMerchantDescription($description)
		        ->setMerchantCardHolderName($cardHolderName)
		        ->setTaxAmount($taxAmount);

		return $request;
	}
297570
public function getUnitPriceInclVat(): ?Money
    {
        $unitPrice = $this->getUnitPrice();
        if (!$unitPrice) {
            return null;
        }

        $multiplier = BigDecimal::of('100')->plus($this->vatPct)->exactlyDividedBy('100');

        return $unitPrice->multiply((string) $multiplier);
    }
53329
public function getRefundResult()
    {
        $responseVariables = get_object_vars($this->getResponse());
        if (!array_key_exists('refundResult', $responseVariables)) {
            return new RefundResult();
        }
        $refundResult = $responseVariables['refundResult'];
        if (!($refundResult instanceof RefundResult)) {
            return new RefundResult();
        }
        return $refundResult;
    }
1085458
public function toMicro()
    {
        $inner = $this->getAttribute("amount", false); //cast=false
        $decimals = $this->getDivisibility();

        if (is_integer($inner)) {
            $attrib = $inner;
        }
        elseif (is_float($inner)) {
            // we want only integer!
            $attrib = $inner * pow(10, $decimals);
        }
        elseif (is_string($inner)) {
            // parse number string representation. Parsing to float.
            $isFloat = false !== strpos($inner, ".");
            $number = $isFloat ? (float) $inner : (int) $inner;
            $multi  = $isFloat ? pow(10, $decimals) : 1;
            $attrib = $number * $multi;
        }
        elseif (is_array($inner)) {
            // try to read first value of array
            $attrib = array_shift($inner);
        }
        else {
            $attrib = (int) $inner;
        }

        $this->micro = (int) $attrib;
        if ($this->micro < 0)
            // not allowed: 0 in micro XEM is the minimum possible value!
            $this->micro = 0;

        return $this->micro;
    }
77887
public function amount()
    {
        // Indian Rupee use special format
        if ($this->currency->getCode() == 'INR') {
            $decimals = null;
            $amount = $this->amount;

            // Extract decimals from amount
            if (($pos = strpos($amount, ".")) !== false) {
                $decimals = substr(round(substr($amount, $pos), 2), 1);
                $amount = substr($amount, 0, $pos);
            }

            // Extract last 3 from amount
            $result = substr($amount, -3);
            $amount = substr($amount, 0, -3);

            // Apply digits 2 by 2
            while (strlen($amount) > 0) {
                $result = substr($amount, -2).",".$result;
                $amount = substr($amount, 0, -2);
            }

            return $result.$decimals;
        }

        // Return western format
        return number_format(
            $this->amount,
            $this->currency->getPrecision(),
            $this->currency->getDecimalSeparator(),
            $this->currency->getThousandSeparator()
        );
    }
269958
public function getData()
    {
        parent::getData();

        $this->validate('amount', 'currency', 'description', 'transactionId');

        return array(
            'amount' => $this->getAmountInteger(),
            'currency' => $this->getCurrency(),
            'description' => $this->getDescription(),
            'id' => $this->getTransactionId(),
            'type' => 'refund',
        );
    }
1234970
protected function getManualLines()
    {
        $result = array();

        if (isset($this->creditNote) && !Number::isZero($this->creditNote->getBaseAdjustment())) {
            $line = array(
                Tag::Product => $this->t('refund_adjustment'),
                Tag::UnitPrice => -$this->creditNote->getBaseAdjustment(),
                Tag::Quantity => 1,
                Tag::VatRate => 0,
            );
            $result[] = $line;
        }
        return $result;
    }