Here's how you could accomplish this.
1) Create a product variant called 'custom amount' with a zero price.
2) Get the ID of that variant
3) When submitting/adding/updating the item to the cart make sure to post an 'amount' line item option. For docs on that see: https://docs.craftcms.com/commerce/v2/adding-to-and-updating-the-cart.html#line-item-options-and-notes
3) Create a plugin/module that attaches this listener:
Event::on(LineItems::class, LineItems::EVENT_POPULATE_LINE_ITEM, function(LineItemEvent $event) {
$lineItem = $event->lineItem;
$purchasable = $lineItem->getPurchasable();
if($purchasable && $purchasable->id = ID_OF_VARIANT_HERE)
{
$amount = $lineItem->options['amount'] ?? 0;
if($amount)
{
$lineItem->price = $amount;
$lineItem->salePrice = $amount;
}
}
});
This will set the price to the price of the line item option 'amount' that is submitted.