def METHOD_NAME(payment_information: PaymentData, config: ApiConfig) -> GatewayResponse:
    """Refund an existing transaction.
    A new psp reference may be issued,
    which will be saved in payment object.
    """
    payment_id = payment_information.payment_id
    payment = Payment.objects.filter(pk=payment_id).first()
    if not payment:
        raise PaymentError(f"Payment with id {payment_id} does not exist.")
    goods, billed_amount = get_goods_with_refunds(config, payment, payment_information)
    # in case of refunding less than already captured
    # and not all lines are being refunded,
    # the transaction needs to be re-registered in NP Atobarai
    if payment_information.amount < payment.captured_amount:
        order = payment.order
        if not order:
            raise PaymentError(
                f"Order does not exist for payment with id {payment_id}."
            )
        result = api.change_transaction(
            config,
            payment,
            payment_information,
            goods,
            billed_amount,
        )
        if result.status == PaymentStatus.FOR_REREGISTRATION:
            fulfillment = get_fulfillment_for_order(order)
            shipping_company_code = get_shipping_company_code(config, fulfillment)
            tracking_number = fulfillment.tracking_number
            result = api.reregister_transaction_for_partial_return(
                config,
                payment,
                payment_information,
                shipping_company_code,
                tracking_number,
                goods,
                billed_amount,
            )
    else:
        result = api.cancel_transaction(config, payment_information)
    new_psp_reference = result.psp_reference
    if new_psp_reference and payment.psp_reference != new_psp_reference:
        payment.psp_reference = new_psp_reference
        payment.save(update_fields=["psp_reference"])
    return GatewayResponse(
        is_success=result.status == PaymentStatus.SUCCESS,
        action_required=False,
        kind=TransactionKind.REFUND,
        amount=payment_information.amount,
        currency=payment_information.currency,
        transaction_id=result.psp_reference or "",
        error=parse_errors(result.errors),
        raw_response=result.raw_response,
        psp_reference=result.psp_reference,
    )