socialincome-san / public

Fighting global poverty with the help of everyday people and your coding skills. Public repository of the NGO and global initiative Social Income.
https://socialincome.org
Other
91 stars 26 forks source link

feature(functions): support twint #883

Closed andrashee closed 3 months ago

andrashee commented 3 months ago

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. https://github.com/socialincome-san/public/blob/77ac33184b22fc4562f6063953714dd34a1f5d16/shared/src/stripe/StripeEventHandler.ts#L183

{
  "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": "xyz@socialincome.org",
  "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?

vercel[bot] commented 3 months ago

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

1 Skipped Deployment | Name | Status | Preview | Comments | Updated (UTC) | | :--- | :----- | :------ | :------- | :------ | | **public** | ⬜️ Ignored ([Inspect](https://vercel.com/social-income/public/AAdciGEUgiRAtnFJuBoA4E9Eaq5q)) | [Visit Preview](https://public-git-ahee-optional-name-social-income.vercel.app) | | Aug 6, 2024 6:57am |
github-actions[bot] commented 3 months ago

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 commented 3 months ago

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.