solidusio / solidus_stripe

💳 Integrate Solidus with Stripe
https://stripe.com
BSD 3-Clause "New" or "Revised" License
36 stars 62 forks source link

Store credits leaving insufficient balance for Stripe payments #311

Open rainerdema opened 1 year ago

rainerdema commented 1 year ago

_Originally posted by @loicginoux in https://github.com/solidusio/solidus_stripe/issues/307#issuecomment-1621404691_

To Reproduce

  1. Create an order with a total of $50
  2. Apply store credits of $49.70 to the order
  3. Attempt to complete the order using Stripe as the payment method

Current behavior Currently, when store credits are applied and they cover almost all of the order, it can leave a balance that's insufficient for Stripe to process. For instance, if we have an order total of $50, and store credits of $49.70 are applied, the remaining amount to pay is $0.30. However, Stripe requires a minimum of $0.50 to process a payment, resulting in a Stripe::InvalidRequestError - Amount must be at least €0.50 $.

Expected behavior The system should handle scenarios where store credits leave a balance that falls below the minimum payment threshold of the payment gateway (Stripe, in this case). The customer should not be left with a balance that they cannot pay.

Screenshots In this specific example, the order total is < 0.50$ Screenshot 2023-07-05 at 17 51 06

Additional context The current logic covers scenarios where an order is fully covered by store credits,, but fails to handle cases where store credits almost fully cover the order, leaving a balance that's below the minimum payment threshold for certain payment methods. We need to figure out how to manage this situation, particularly as different currencies, other than USD, have varying minimum amounts.

loicginoux commented 1 year ago

here are the Ideas we had to solve this (in the configuration where you only have Stripe as a payment method), but none of them seems perfect: 1 - you don't let payment when total is < 0.50$ but might be hard to accept for customers, it's not really a good commercial gesture.

2 - you offer these few cents in different ways:

2.a Via a store credit added to user during checkout. The problem is if he does not complete the order, you need to remove these store credits

2.b Via a new sort of promotion "if order total is < 0.50$ then add a promo adjustment equal to this amount to make the order total == 0". The issue we see is that with this kind of promotion, we would need to be sure to check elligibility after all other potential promotions ( I still need to investigate but I don't think this is possible to ensure priorities)

2.c Via an adjustment of the amount remaining added when completing the order. seems hacky...

We are still investigating...

tmtrademarked commented 1 year ago

FWIW, we encountered this issue in our application, and chose to solve it by issuing new store credit with a special type. In practice, we observed that this amount is generally extremely small, and not worth worrying over. By having a custom type of store credit, we can run reports and determine if we need any special handling.

Applying this credit seems like it might be beyond the scope of the Stripe gem, however. We implemented it by replacing the add_store_credit method of Spree::Order with a custom implementation.