openfoodfoundation / openfoodnetwork

Connect suppliers, distributors and consumers to trade local produce.
https://www.openfoodnetwork.org
GNU Affero General Public License v3.0
1.1k stars 714 forks source link

Stripe Account Owner field will not save correctly in Payment Method #8490

Open RonellaG opened 2 years ago

RonellaG commented 2 years ago

Description

A hub (Food Next Door, Enterprise ID 3359) had subscribers with a Stripe payment method (Payment Method ID 736) (despite me telling them to use Stripe SCA - they must have forgotten). So I tried to change the payment method to Stripe SCA as a regular admin login but the platform would not let me (see screenshot).

Screen Shot 2021-11-15 at 6 48 50 pm

I checked their Stripe account and everything looks ok. Then I had a look when logged in as Superadmin and it showed that the account was connected to a different enterprise's Stripe account (It is connected to Puckawidgee!) see screenchot.

Screen Shot 2021-11-15 at 6 47 24 pm

Expected Behavior

I expect that when I change the Stripe Account Owner and hit save, the correct Stripe Account Owner should be displayed when the page refreshes.

Actual Behaviour

When I tried to change it to the correct Stripe Account Owner (Food Next Door Co-op, Stripe Account ID: acct_1IyVpsEAarFmBkB2) and hit save it just resets it back to Pukawidgee (Stripe Account ID: acct_1FZojPKsjNLCPMfd) which is a totally different and unrelated enterprise on the Platform.

Severity

bug-s1: a critical feature is broken: checkout, payments, signup, login

This is a big problem because this payment method is attached to existing subscriptions in an open order cycle for a hub. The hub has over 77 subscriptions connected to this payment method and was intending to include all of them in upcoming order cycles.

Rachel did not have a workaround for it in the Slack post in Instance Managers. And neither do I.

Your Environment

RonellaG commented 2 years ago

I just received an email from Food Next Door saying "Jill Couch (one of our employees and a subscriber), is the only person in the order cycle which has just closed, she advised us today that the payment has come up on her bank statement as “Warrenbayne Farm, Violet Town”, instead of Food Next Door."

FYI Warrenbayne Farm is Pukawidgee.

And what they mean by only person in the order cycle is that they tried to run the oc with 3 subscribers who are employees as a soft launch. 2 subscriptions were not placed for a separate reason (they changed the open and close times of a previous test order cycle which had already placed orders for those 2 subscriptions rather than creating a new one or duplicating an old one.

kirstenalarsen commented 2 years ago

Also S1 because we do not know how or why is happening and whether it is happening anywhere else which could cause MAJOR issues with money going to the wrong places

mkllnk commented 2 years ago

It looks like it's all saved correctly. I'm wondering if the old values are just cached somewhere...

mkllnk commented 2 years ago

Okay, I set the account owner manually and it displays correctly now. But that's just changing the owner in OFN. If that payment method got connected to Warrenbayne Farm originally, then it may still be referring to that within Stripe. I don't know. Can we test a payment?

mkllnk commented 2 years ago

The displayed account id id is connected to Food Next Door. So that should be correct now. :+1:

kirstenalarsen commented 2 years ago

So @mkllnk - this is now overridden in db (fixing immediate urgent problem), but we still don't know why or how this happened. Also, perhaps more importantly the issue of being unable to change the Stripe account seems to be persistent (still happening)

I think we could downgrade though, because usually the workaround would be to create another payment method. The problem here was all the existing subscriptions that were attached to the payment method.

So - pending thoughts from others - I think I'd make this S3 now?

mkllnk commented 2 years ago

I was wondering that, too. Does it happen somewhere else? It's totally valid that the Stripe account owner is different to the enterprise using the payment method but I queried some mismatches we can sanity check as humans.

enterprises_to_check = Enterprise.joins(:payment_methods).joins("JOIN spree_preferences ON key = CONCAT('/spree/gateway/stripe_sca/enterprise_id/', spree_payment_methods.id)").where("spree_preferences.value not like CONCAT('--- ', enterprises.id, '\n%')")

enterprises_to_check.distinct.map { |enterprise| [enterprise.id, enterprise.name, enterprise.payment_methods.where("spree_payment_methods.type ilike '%stripe%'").map { |pm| Enterprise.find(pm.preferred_enterprise_id).name }.join(" | ")] }
[[27, "Ballantyne (Thornbury)", "VT Organic Bulk Buy "],
 [262, "Meat Producer", "Demo Hub | Demo Hub"],
 [693, "Beechworth Food Co-op", "Black Barn Farm"],
 [2586, "Soul Food & Co", "Willunga Farmers Market"],
 [2813, "Pasta Adele", "Wangaratta Farmers' Market Hub"],
 [2895, "The Community Grocer - Fawkner", "The Community Grocer - Heidelberg West "],
 [2985, "Corang Estate", "Southern Harvest Association Community Stall"],
 [2992, "Carr's Organic Fruit Tree Nursery", "Harcourt Organic Farming Co-op (HOFCoop)"],
 [3005, "The Community Grocer - Fitzroy", "The Community Grocer - Heidelberg West "],
 [3025, "Kyogle Food Hub", "Arcoora Farm"],
 [3062, "Warby Range Citrus", "Wangaratta Farmers' Market Hub"],
 [3181, "The Community Grocer - Carlton", "The Community Grocer - Heidelberg West "],
 [3185, "The Community Grocer - Pakenham", "The Community Grocer - Heidelberg West "],
 [3199, "The Community Grocer - Events", "The Community Grocer - Heidelberg West  | The Community Grocer - Heidelberg West "],
 [3281, "Grown for You", "Murmungee Basin Produce"],
 [3359, "Food Next Door Co-op", "Pukawidgee (Warrenbayne Farm Collective) | Food Next Door Co-op"],
 [3389, "The Orchard Keepers", "Harcourt Organic Farming Co-op (HOFCoop)"]]

@RonellaG Is it worth checking these enterprises if their setup is correct? First column is the enterprise id, the second is the enterprise name and then follows a list of Stripe account owners of their payment methods. The second last one is the mismatch we resolved today. The last one is legit as far as I know, a coop sharing the Stripe account. I can't judge the others.

RonellaG commented 2 years ago

Will do Maikel 👍🏼

lin-d-hop commented 2 years ago

In AU have you updated Transifex so the name of the old Stripe payment method is 'Deprecated. Do not use.' or something?

Probably worth noting that I have seen something like this once before, over a year ago. We had to contact the person who received the money and ask them to send it to the right place. I assumed some user error was involved.

With that in mind it seems there might be a bug here, and since users almost never change their Stripe accounts it almost never surfaces...