Skip to content

feat: Enhanced Stripe customer data with duplicate prevention#13

Open
jimtyrro wants to merge 1 commit intoInvoiceShelf:mainfrom
jimtyrro:feature/stripe-customer-enhancement
Open

feat: Enhanced Stripe customer data with duplicate prevention#13
jimtyrro wants to merge 1 commit intoInvoiceShelf:mainfrom
jimtyrro:feature/stripe-customer-enhancement

Conversation

@jimtyrro
Copy link

@jimtyrro jimtyrro commented Feb 15, 2026

Enhanced Stripe Customer Data & Duplicate Prevention

Summary

This PR enhances the Stripe payment integration to prevent duplicate customer creation and sync complete customer data to Stripe. Currently, each payment creates a new Stripe customer with minimal information. This change searches for existing customers by email and includes comprehensive customer data.

What This Adds

  • Duplicate Prevention: Search for existing Stripe customers by email before creating new ones
  • Complete Customer Data: Sync name, email, phone, and billing address to Stripe
  • Company Name Support: Retrieve company name from InvoiceShelf custom fields (CUSTOM_CUSTOMER_COMPANY_NAME)
  • Enhanced Payment Descriptions: Include invoice number and customer email in payment descriptions
  • Comprehensive Metadata: Store service provider, customer, and invoice details in Stripe metadata for reporting
  • Automatic Receipts: Configure Stripe to send payment receipt emails

Technical Changes

New Methods

  • findExistingStripeCustomer($email) - Search Stripe for existing customer by email
  • getOrCreateStripeCustomer($invoice, $customer) - Get existing or create new customer with full data
  • getCustomerCompanyName($customer) - Retrieve company name from custom field string_answer column
  • getCustomerBilling($customer) - Flexible billing address retrieval supporting multiple address relationship patterns
  • getCountryCode($country) - Country code detection supporting multiple field name patterns (iso2, code, short_code)

Modified Method

  • generatePayment(Company $company, $invoice) - Now creates/reuses customers and includes complete data

Backward Compatibility

Fully backward compatible. Gracefully handles:

  • Missing custom fields
  • Empty address data
  • Missing customer information
  • Special characters in customer names (URL-encoded)

Testing

Tested with:

  • InvoiceShelf v2.1.1
  • Payments Module v1.1.0
  • Real Stripe account (test mode)
  • Multiple payment scenarios (new customers, repeat customers, missing data)

Fixes #8

- Add duplicate customer prevention via email search
- Include complete customer data (name, email, phone, address)
- Retrieve company name from custom fields
- Add comprehensive metadata for reporting
- Improve payment descriptions with invoice number
- Support automatic Stripe receipt emails
- Add flexible address handling for multiple InvoiceShelf versions
- Implement robust country code detection

Fixes InvoiceShelf#8
@rihards-simanovics
Copy link
Member

Hey @jimtyrro thanks for the PR, I will review this PR in the following weeks if time allows. In the interim, I appreciate this is generated by AI, but please clean up the PR body to be concise and to the point, you have a lot of “froth” on top. Summary and what this adds is mostly all I need, all the sections after are just noise and padding.

Lastly, please indicate how much of the code is written by the AI and how much was written by you. Use of AI is not bad per se, but I need to know beforehand.

@jimtyrro
Copy link
Author

It’s all AI. I’ve asked you to help fix the missing data for the Stripe payment an year ago, you’re apparently very busy so asked AI to help and now I have a working add-on that does everything I need and decided to share. I will clean up PR description per your suggestion and you can use it or not use it, it’s totally up to you.

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.

Payments Module (Stripe) - Customer data (name, email and phone) are not being submitted

2 participants