- Notifications
You must be signed in to change notification settings - Fork 3.9k
add payment source #59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
In the current Firebase Cloud Function example, users lack the ability to add a payment source that they can later initiate a charge on
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.
|
Signed! |
CLAs look good, thanks! |
There was a problem hiding this 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
stripe/functions/index.js Outdated
}); | ||
| ||
// 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 => { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
stripe/functions/index.js Outdated
user, | ||
{source: token} | ||
).then(response => { | ||
return console.log('payment source added successfully for user', user); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
stripe/functions/index.js Outdated
const user = event.params.userId; | ||
return stripe.customers.createSource( | ||
user, | ||
{source: token} |
There was a problem hiding this comment.
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}`
There was a problem hiding this 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}
In the current Firebase Cloud Function example, users lack the ability to add a payment source that they can later initiate a charge on