AyeCode / invoicing

GetPaid (Formerly the Invoicing plugin) is a lightweight Payments and Invoicing system for WordPress. It can be used to sell anything online via payment forms or buy now buttons that can be added to any landing page. It can also be used by freelancers to manage their Invoices or by 3rd party Themes and Plugins as their payment system. GeoDirectory currently uses GetPaid as its payment system
https://wpgetpaid.com/
Other
39 stars 22 forks source link

Strange behaviour when using wpinv_get_item_price filter hook. Possible bug? #809

Open aayla-secura opened 3 weeks ago

aayla-secura commented 3 weeks ago

Not 100% if it's a bug or I'm doing it wrong.

Am I correct that if a developer wants to programmatically and dynamically change how much a user is charged for an item, they should add a filter hook for wpinv_get_item_price? As in:

add_filter(
    'wpinv_get_item_price',
    function ($price, $item) {
        return 50; // or whatever, dynamic based on other conditions
    },
    10,
    2
);

I'm doing this and seeing some strange behaviour.

  1. Firstly, when I change the price using this filter hook to 0, to make the item free for some users, checkout fails with a vague error: "An error occured while processing your payment. Please try again." and nothing more is logger either.

  2. Secondly, when I change the price to something above 0, even though the user is charged the custom amount I return from the filter hook, at least according to Stripe, the total amount of the invoice reflects the original price, which is confusing:

Screenshot 2024-10-12 203825

  1. The third peculiarity, is that when I return a custom price from that filter hook, the user-set/dynamic pricing during checkout no longer works. The price that the user inputs always gets overridden with what I return from the hook. If I just return the original price from the hook, it works again...

What is the correct way to set dynamic pricing server-side (i.e. not using "let customer name their price")? And how is the wpinv_get_item_price supposed to be used?

aayla-secura commented 3 weeks ago

Well, I found a way to set an item price during checkout: using the filter hook getpaid_payment_form_submission_processed_item and editing the form item's price there works as expected.

But I'll leave this open as I wonder whether the wpinv_get_item_price should also have the same effect, or if not, what is its intended use case?