Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(functions): support twint #883

Merged
merged 2 commits into from
Aug 6, 2024
Merged

feature(functions): support twint #883

merged 2 commits into from
Aug 6, 2024

Conversation

andrashee
Copy link
Contributor

@andrashee andrashee commented Aug 6, 2024

The webhook importing twint charges throws an error:

Error Could not create user for Stripe customer: cus_QLt13VT23sUUFy, unknown id, email or name Error: Could not create user for Stripe customer: cus_QLt13VT23sUUFy, unknown id, email or name at StripeEventHandler.constructUser (/workspace/dist/shared/src/stripe/StripeEventHandler.js:157:23) at StripeEventHandler.getOrCreateFirestoreUser (/workspace/dist/shared/src/stripe/StripeEventHandler.js:54:43) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async StripeEventHandler.storeCharge (/workspace/dist/shared/src/stripe/StripeEventHandler.js:176:29) at async StripeEventHandler.handleChargeEvent (/workspace/dist/shared/src/stripe/StripeEventHandler.js:28:24) at async /workspace/dist/functions/src/webhooks/stripe/index.js:41:41

The problem is, that we actively check if the user has a name field, which is not set for a twint payment.

if (!customer.id || !customer.email || !customer.name) {

{
  "id": "cus_Qbth7ZrV08LMcs",
  "object": "customer",
  "address": {
    "city": null,
    "country": null,
    "line1": null,
    "line2": null,
    "postal_code": null,
    "state": null
  },
  "balance": 0,
  "created": 1722921967,
  "currency": null,
  "default_source": null,
  "delinquent": false,
  "description": null,
  "discount": null,
  "email": "[email protected]",
  "invoice_prefix": "12AD4FD6",
  "invoice_settings": {
    "custom_fields": null,
    "default_payment_method": null,
    "footer": null,
    "rendering_options": null
  },
  "livemode": false,
  "metadata": {},
  "name": null,
  "next_invoice_sequence": 1,
  "phone": null,
  "preferred_locales": [
    "en-GB"
  ],
  "shipping": null,
  "tax_exempt": "none",
  "test_clock": null
}

Since first and lastname are modelled as optional in our types, I assume we don't need them?

Copy link

vercel bot commented Aug 6, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
public ⬜️ Ignored (Inspect) Visit Preview Aug 6, 2024 6:57am

@@ -180,8 +180,8 @@ export class StripeEventHandler {
* This is mainly for failed payments where we didn't create a user through the website directly
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkue, is this comment actually true?
In the webhooks logs from Stripe, it seems that the user doesn't exist for a successful twint payment. Where do you create the user? Is it a race condition, whatever is faster?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this comment is wrong. The usual way for a user to get created is through the Stripe webhook.

And yes, it's technically a race condition. If a new user fills out the CreateUserForm before the Stripe webhook has been called (which should only happen if Stripe has a problem), then the user is created when the form is submitted. This is a very unlikely case, though.

I don't see how this can be avoided as we need to store the user info on form submit.

export const splitName = (name: string | undefined) => {
if (!name) {
return {
firstname: undefined,
Copy link
Contributor Author

@andrashee andrashee Aug 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be safe, we could also use '' here instead.

Copy link

github-actions bot commented Aug 6, 2024

Visit the preview URL for this PR (updated for commit cce8e6b):

https://si-admin-staging--pr883-ahee-optional-name-nv29fz30.web.app

(expires Tue, 13 Aug 2024 07:02:04 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: b7b0969384059dce6ea8fad1ee1d1737e54e6676

@ssandino
Copy link
Member

ssandino commented Aug 6, 2024

Since first and lastname are modelled as optional in our types, I assume we don't need them?

Yes, this is correct. Theoretically, there could be a contributor without a name. This ensures that if a user makes a payment (on stripe form) but never fills out "our" form (asking for name) afterwards, they are still handled as a normal constributor. I guess 99% will fill out the form after payment anyway.

There are rare cases where even the credit card company only provides the first name or only the last name. Making the fname and lname optional helps prevent errors in such situations.

@andrashee andrashee merged commit 024124a into main Aug 6, 2024
18 checks passed
@andrashee andrashee deleted the ahee/optional-name branch August 6, 2024 19:53
@ssandino ssandino linked an issue Aug 6, 2024 that may be closed by this pull request
2 tasks
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.

[Website Bug]: activate Twint payments via Stripe
3 participants