Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

190
Views
Angular and Stripe - Expanding Customer Retrieve to get Sources

I'm trying to integrate Angular 8 with Stripe. Reading the documentation, I did see that I need to expand the Customer retrieve to get the Sources data, but I didn't get yet:

customers.ts

// Read the stripe customer ID from firestore, or create a new one if missing
export const getOrCreateCustomer = async (uid: string) => {
  const user = await getUser(uid);
  const customerId = user && user.stripeCustomerId;
  const listOptions = {limit: 100};

  // If missing customerID, create it
  if (!customerId) {
    return createCustomer(uid);
  } else {
    const params = stripe.customers.listSources(customerId, listOptions); // -> this is my start approach, but I don't know how to include it into Customer Retrieve
    const customer = stripe.customers.retrieve(customerId);
    console.log(customer);
    return customer;
  }
};

sources.ts

// Attaches a payment source to a stripe customer account.
export const attachSource = async (uid: string, source: string) => {

    const customer = await getOrCreateCustomer(uid);

    const existingSource = customer.sources.data.filter((s) => s.id === source).pop();// -> here there is an error

    if (existingSource) {
        return existingSource;
    } else {
        await stripe.customers.createSource(customer.id, { source });
        return await stripe.customers.update(customer.id, { default_source: source });
    }
};

Since I couldn't expand the Customer retrieve, the sources.ts file displays the error:

Property 'sources' does not exist on type 'Response | (DeletedCustomer & { lastResponse: { headers: { [key: string]: string; }; requestId: string; statusCode: number; apiVersion?: string; idempotencyKey?: string; stripeAccount?: string; }; })'. Property 'sources' does not exist on type 'DeletedCustomer & { lastResponse: { headers: { [key: string]: string; }; requestId: string; statusCode: number; apiVersion?: string; idempotencyKey?: string; stripeAccount?: string; }; }'.ts(2339)

I found in a post something similar, but in PHP, that mentions about cards. But I didn't understand if it would be the same thing I'm looking for (furthermore, it doesn't explain how to get the data I need).

How can I do this?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!