question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Stripe - Upgrading to Firebase 4.1, Stripe v3

See original GitHub issue

I’m having a hard time figuring out how to upgrade this example to the latest and greatest Firebase and Stripe JS SDKs.

https://github.com/firebase/functions-samples/tree/master/stripe

How to reproduce these conditions In https://github.com/firebase/functions-samples/blob/master/stripe/public/index.html Add: <script src="https://js.stripe.com/v3/"></script> after the v2 script. So:

  <script src="https://js.stripe.com/v2/"></script>
  <script src="https://js.stripe.com/v3/"></script>

Replace:

    <script src="/__/firebase/3.9.0/firebase-app.js"></script>
    <script src="/__/firebase/3.9.0/firebase-auth.js"></script>
    <script src="/__/firebase/3.9.0/firebase-database.js"></script>
    <script src="/__/firebase/init.js"></script>

with:

   <script src="/__/firebase/4.1.1/firebase-app.js"></script>
    <script src="/__/firebase/4.1.1/firebase-auth.js"></script>
    <script src="/__/firebase/4.1.1/firebase-database.js"></script>
    <script src="/__/firebase/init.js"></script>

You may also need to switch the Stripe API Key from:

      var stripe = Stripe('pk_test_XXXXXXXXXXXXXXXXXXXX');

to:

      Stripe.setPublishableKey('pk_test_XXXXXXXXXXXXXXXXXXXX');

Sample name or URL where you found the bug https://github.com/firebase/functions-samples/tree/master/stripe

firebase/functions-samples/stripe

Failing Function code used (including require/import commands at the top) It’s not really the function code that seems to be failing, but listening to whether or not the customer has a stripe id in the firebase database. I’m able to create the customer/account in Firebase and see them in Stripe, but I am unable to tell if the stripe customer is initialized or to set stripeCustomerInitialized to be true.

            firebase.database().ref(`/stripe_customers/${this.currentUser.uid}/customer_id`).on('value', snapshot => {
              this.stripeCustomerInitialized = (snapshot.val() !== null);
            }, () => {
              this.stripeCustomerInitialized = false;
            });

When, it listens for this function, even though a customer is created and has values within Firebase, this.stripeCustomerInitialized always sets to be false.

Steps to set up and reproduce

Sample data pasted or attached as JSON (not an image)

{
  "stripe_customers" : {
    "XXXXXXXXXXXXXXXXXXX" : {
      "customer_id" : "cus_XXXXXXXXXXXXX"
    }
}

Not sure if I needed to obfusicate the UID and cus_ID or not. (The XXXXXXX’s in the database are a random unique string)

Security rules used

{
  "rules": {
    "stripe_customers": {
      "$uid": {
        ".read": "$uid === auth.uid",
        "sources": {
          "$chargeId" : {
            ".write": "$uid === auth.uid",
            "token": { ".validate": "newData.isString()" },
            "$other": { ".validate": false }
          }
        },
        "charges": {
          "$sourceId" : {
            ".write": "$uid === auth.uid",
            "source": { ".validate": "newData.isString()" },
            "amount": { ".validate": "newData.isNumber()" },
            "$other": { ".validate": false }
          }
        }
      }
    }
  }
}

Debug output

Errors in the console logs

c:0:0:0 Websocket connecting to wss://s-usc1c-nss-XXX.firebaseio.com/.ws?v=5&ns=XXXXXXXXXXXXXXXXXXX
SortedMap.js:287 c:0:0:0 Websocket connected.  
SortedMap.js:287 c:0:0: Realtime connection established.  
SortedMap.js:287 p:0: connection ready  
SortedMap.js:287 p:0: reportStats {"c":{"sdk.js.4-1-1":1}}  
SortedMap.js:287 p:0: {"r":1,"a":"s","b":{"c":{"sdk.js.4-1-1":1}}}  
SortedMap.js:287 p:0: Listen on /stripe_customers/XXXXXXXXXXXXXXXXXXX/customer_id for default  
SortedMap.js:287 p:0: {"r":2,"a":"q","b":{"p":"/stripe_customers/XXXXXXXXXXXXXXXXXXX/customer_id","h":""}}  
SortedMap.js:287 p:0: Listen on /stripe_customers/XXXXXXXXXXXXXXXXXXX/sources for default  
SortedMap.js:287 p:0: {"r":3,"a":"q","b":{"p":"/stripe_customers/XXXXXXXXXXXXXXXXXXX/sources","h":""}}  
SortedMap.js:287 p:0: Listen on /stripe_customers/XXXXXXXXXXXXXXXXXXX/charges for default  
SortedMap.js:287 p:0: {"r":4,"a":"q","b":{"p":"/stripe_customers/XXXXXXXXXXXXXXXXXXX/charges","h":""}}  
SortedMap.js:287 p:0: from server: {"r":1,"b":{"s":"ok","d":""}}  
SortedMap.js:287 c:0:0: Primary connection is healthy.  
SortedMap.js:287 p:0: from server: {"r":2,"b":{"s":"permission_denied","d":"Permission denied"}}  
SortedMap.js:287 p:0: listen response {"s":"permission_denied","d":"Permission denied"}  
SortedMap.js:287 event: /stripe_customers/XXXXXXXXXXXXXXXXXXX/customer_id:cancel 
SortedMap.js:287 p:0: from server: {"r":3,"b":{"s":"permission_denied","d":"Permission denied"}}  
SortedMap.js:287 p:0: listen response {"s":"permission_denied","d":"Permission denied"}  
SortedMap.js:287 event: /stripe_customers/XXXXXXXXXXXXXXXXXXX/sources:cancel 
SortedMap.js:287 p:0: from server: {"r":4,"b":{"s":"permission_denied","d":"Permission denied"}}  
SortedMap.js:287 p:0: listen response {"s":"permission_denied","d":"Permission denied"}  
SortedMap.js:287 event: /stripe_customers/XXXXXXXXXXXXXXXXXXX/charges:cancel 

Not sure if I needed to obfusicate the UID or not. (The XXXXXXX’s in the database are a random unique string)

Screenshots

Expected behavior stripe-expected Note: email@address.com is actually whatever email address of the user who is logged in.

Actual behavior stripe-screenshot Note: email@address.com is actually whatever email address of the user who is logged in.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
chasemaccommented, Jul 6, 2017

I’m having the same issue

1reaction
nicolasgarniercommented, Feb 28, 2018

@jamesdaniels: would be nice to polish the Stripe sample a bit, it’s pretty popular! 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add subscription payments to your web app with Firebase ...
Allow customers to manage their subscriptions and payment methods with the Stripe customer portal. Automatically delete user & customer data ...
Read more >
Upgrade and downgrade subscriptions | Stripe Documentation
Learn how to upgrade and downgrade subscriptions by changing the price. ... One way existing subscriptions can be modified is by upgrading or...
Read more >
How to integrate Stripe in Android using Firebase
When I run my app and press the confirmButton a token is created firestore "stripe_customers/uid/tokens" an error field is generated and the ...
Read more >
iOS Stripe Payments with Firebase in Swift – Tutorial
3. Setting Up the Firebase Server · Firebase Auth Cloud Function will be triggered right after a new account is created successfully. ·...
Read more >
STRIPE PAYMENT IN WEB APPLICATIONS - Theseus
Keywords: Firebase, Stripe, Subscriptions, Visual Studio, ... 2.1.3 Props and States ... 4.1 Checkout Session and Subscribe to the plan.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found