Skip to content

Conversation

rldaulton
Copy link
Contributor

In the current Firebase Cloud Function example, users lack the ability to add a payment source that they can later initiate a charge on

In the current Firebase Cloud Function example, users lack the ability to add a payment source that they can later initiate a charge on
@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If you signed the CLA as a corporation, please let us know the company's name.
@rldaulton
Copy link
Contributor Author

Signed!

@googlebot
Copy link

CLAs look good, thanks!

Copy link
Member

@jamesdaniels jamesdaniels left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the right direction with some changes happy to merge

});

// Add a payment source (card) for a user by writing a stripe payment source token to Realtime database
exports.addPaymentSource = functions.database.ref('/stripe_customers/{userId}/cards/{token}').onWrite(event => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if we listened instead to /stripe_customers/{userId}/cards/{pushid}/token? or are you writing token:token to the RTDB. Guess I'm a bit confused on the schema.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we'd also need to change how the stripe customer id was stored

Copy link
Contributor Author

@rldaulton rldaulton Mar 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jamesdaniels yea you're right, I missed one there. Should be more like /stripe_customers/{userId}/cards/token. I'll make this change.

I was going off of what was returned in customer creation. Seemed to me you were setting the Stripe customer id at this location, but I see now it is the unique used id in Firebase.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your original suggestion of listening at /stripe_customers/{userId}/cards/{pushid}/token is better. Then writing back makes more sense.

user,
{source: token}
).then(response => {
return console.log('payment source added successfully for user', user);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if instead we wrote back the response return event.data.ref.parent.set(response), that's what I am doing in my scratch project then you have VISA ***1234, exp date, etc. to allow selection

// Add a payment source (card) for a user by writing a stripe payment source token to Realtime database
exports.addPaymentSource = functions.database.ref('/stripe_customers/{userId}/cards/{token}').onWrite(event => {
const token = event.data.val();
const user = event.params.userId;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that isn't going to be the stripe customer id but instead the user id in firebase, but as I mentioned above this schema change conflicts with how the customer_id is currently stored

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this the location in your schema where you are currently storing a Stripe customer id?

const user = event.params.userId;
return stripe.customers.createSource(
user,
{source: token}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, if we called token source instead we could use shorthand {source}

- `ref` changed to `/stripe_customers/{userId}/cards/{pushId}/token`. Users can now write back to RTDB and store redacted card information. See line 74: `return event.data.ref.parent.set(response);` - shorthand on `{source}`
@rldaulton
Copy link
Contributor Author

Copy link
Contributor Author

@rldaulton rldaulton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • ref changed to /stripe_customers/{userId}/cards/{pushId}/token. Users can now write back to RTDB and store redacted card information. See line 74: return event.data.ref.parent.set(response);
  • shorthand on {source}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants