Skip to content

getCurrentUserPayments throws an error #379

@aabounegm

Description

@aabounegm

Bug report

Describe the bug

Calling the getCurrentUserPayments function from @stripe/firestore-stripe-payments throws the following error:

payment.ts:282 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'map')
    at Object.fromFirestore (payment.ts:282:68)
    at bh.data (index.esm2017.js:17862:40)
    at bh.data (index.esm2017.js:17918:22)
    at payment.ts:340:26
    at index.esm2017.js:17952:15
    at index.esm2017.js:13422:53
    at Un.inorderTraversal (index.esm2017.js:3873:49)
    at Bn.inorderTraversal (index.esm2017.js:3777:26)
    at Cu.forEach (index.esm2017.js:13422:24)
    at Vh.forEach (index.esm2017.js:17951:29)

Looking at the line (payment.ts:282) from where it throws, it seems that it tries to read data.prices, but there is no property prices on the object (as can be seen in the screenshot below from Firestore)

To Reproduce

Here is a minimal snippet from the part of my code where it throws this error:

import { getApp } from "@firebase/app";
import { getCurrentUserPayments } from "@stripe/firestore-stripe-payments";

const app: FirebaseApp = getApp();
const payments = getStripePayments(app, {
  productsCollection: "subscription-plans",
  customersCollection: "users",
});

async function getSubscriptionDetails(sub: Subscription) {
  const product = await getProduct(payments, sub.product);
  const price = await getPrice(payments, sub.product, sub.price);
  const payment = await getCurrentUserPayments(payments, { status: 'succeeded' }); // fails here
  return {
    ...sub,
    product,
    price,
    payment,
  };
}

Expected behavior

I expected it to return the user's payment information to extract the payment method from it (since this info is available on Firestore).

Screenshots

image

System information

  • OS: Windows 10
  • Browser: Chrome (v100)

Additional context

I use getCurrentUserSubscriptions to get a list of the user's subscriptions. Then, I need to also display the payment method the user used for this subscription (last 4 digits of card + expiration).
I also tried using getCurrentUserPayment(payments, paymentId), but I couldn't figure out a way to get the paymentId. The JSDoc hint suggests that the second parameter is called subscriptionId, but using sub.id didn't work. Even if I hardcode the ID from Firestore, it still throws the same error as above.

My target is to display the payment method associated with a subscription to give the user the option to update it if needed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions