Skip to content

Ssm/26614 customer not found fix#14

Open
StanislavSmetaninSSM wants to merge 3 commits intomainfrom
ssm/26614-customer_not_found_fix
Open

Ssm/26614 customer not found fix#14
StanislavSmetaninSSM wants to merge 3 commits intomainfrom
ssm/26614-customer_not_found_fix

Conversation

@StanislavSmetaninSSM
Copy link
Contributor

@StanislavSmetaninSSM StanislavSmetaninSSM commented Dec 9, 2025

The original task: https://dev.azure.com/dynamicwebsoftware/Dynamicweb/_workitems/edit/26614

The description: "I discovered this bug while investigating a Stripe issue.
Stripe needs a customer ID to associate a transaction with their data. We retrieve the customer ID from one of the customer's saved cards (it's stored in the saved card details) and then attempt to use that ID to complete the transaction.

But if the customer has been deleted or blocked, we get an exception (preventing the payment from being processed!). This is completely stupid and must be fixed immediately, before any customer will face this.

Also, we really need to add logging of requests/responses to the Stripe provider."

Explanations of problem:
"Stripe uses a customer ID to manage payments. This is necessary so that Stripe can register a customer and link all their payments to a single account, allowing the Stripe account administrator to easily understand how many orders a customer has placed and what payment methods they use (cards, etc.). For an existing customer, their payment information will be pre-filled with Stripe data (in the Stripe payment system form), so the user receives their card details and just clicks the "pay" button.
We don't have any option to not create the customer (we MUST create a Stripe customer to make a payment). We can only create a new customer for payment or use an existing one. For saved cards, we must explicitly (there's no other way) use the existing customer data, just like for recurring orders. Regarding a new card, there's a small issue.

In the existing code, I get the saved customer ID through the saved dynamicweb card. When we create a new card, the code scans the customer's saved cards and looks for the customer ID there. However, I discovered a bug where if the customer's ID is invalid (for example, if the customer has been deleted), we get an error preventing payment.
We need the customer's ID to link the customer's new card to the general customer record in the Stripe admin panel system."

So, what I did here:

  1. Added logging of all requests/responses, to see what's going on. It's really needed to work with customers, since without these data we maybe do not understand the source of possible issues.
  2. When we get the customerId from saved card token data, we do a request for a customer to Stripe. If customer is invalid, or if there is some error related with request, we return null instead. Then, in the Create Session request, we create a new customer instead of old one.
  3. To protect us from the MAYBE possible situations where the current customer is somehow "invalid," and for whatever reason, we are unable to perform a preliminary check, I hace added new setting "Create new customer for new cards". When enabled, the provider always creates a new Stripe customer for payments with new cards instead of trying to reuse existing customer data. This prevents issues with invalid or deleted customer records.
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant