invertase / stripe-firebase-extensions

Repository of Firebase Extensions built by Stripe.
https://firebase.google.com/products/extensions
Apache License 2.0
438 stars 172 forks source link

Issue with creating customer portal Missing required param: customer #532

Open Nimo11 opened 1 year ago

Nimo11 commented 1 year ago

Bug report

Describe the bug

Creation portal work fine only after subscription.

Same problem as https://github.com/stripe/stripe-firebase-extensions/issues/226

Sorry to ask on a closed topic but I don't understand the solution given by tanosugi. I tried adding to the user document the fields uid and email, but the behavior remains the same.

To Reproduce

after subscription with this code

final docRef = await FirebaseFirestore.instance .collection('users') .doc(FirebaseAuth.instance.currentUser?.uid) .collection("checkout_sessions") .add({ "client": "web", "mode": "subscription", "price": _productId, "success_url": 'https://www.success.com', "cancel_url": 'https://www.cancelled.com' });

this function display portal

` var functionRef = FirebaseFunctions.instanceFor(region: 'europe-west2').httpsCallable('ext-firestore-stripe-payments-createPortalLink');

var data = await functionRef({
  "returnUrl": "https://www.silent.com",
  "locale": "auto", // Optional, defaults to "auto"
});
if (mounted) {
  Navigator.of(context).pushReplacement(MaterialPageRoute(
      builder: (context) => NavigatorWidget(
            url: data.data["url"],
          )));
}`

but it doesn't work next time

Expected behavior

Display portal at any time

Firebase logs:

textPayload: "❗️[Error]: Customer portal link creation failed for user [mycustomerid]: Missing required param: customer."

Nimo11 commented 1 year ago

After hour of search i have found solution. If you check in extension setting sync user, when a user is created in authentication list a user is also created in your users database path like explain in documentation. In the created user you can find to field stripeID and stripeLink needed to access user portal. So you must enable sync option to get values and make attention to keep this field when you save your data. Using merge option for exemple could be a good way.