How would you recommend getting a customer's payme...
# prisma-whats-new
m
How would you recommend getting a customer's payment sources (credit cards, etc) from Stripe? I'm storing the Stripe customer id on the user model and was thinking of creating an aws lambda function to make the API call, but wondering how to call aws through Graphcool - maybe I shouldn't. Thanks!
n
@mll Stripe handles this typically with one time tokens
you should not store actual payment information, but rather these tokens
m
Yes. True. I would never store card info on Graphcool, but wonder how to access a customer's saved card info so they don't need to enter it every time. I don't think we can access saved credit cards data with stripe publishable key so would need to go through a server of some kind to get it. What is the best way to do this? Maybe I should call aws lambda directly from my app instead of going through Graphcool.
n
Oh why do you need to ask them multiple times?
If you have recurring payments, you would typically create a "subscription" with the Stripe API
m
I don't have recurring payments. Think of Amazon remembering your cards for future use and offering you to choose which one you would like to use for your purchase.
n
yes you can use the Functions feature to access the stripe API with your secret key - but I'm not sure what workflow exactly you want to target here
m
I would basically want to see the current user’s registered credit cards on Stripe. An example graphql request would be:
Copy code
query {
  user {
    id
    stripeCustomerId
    stripeCustomer
  }
}
Where
stripeCustomerId
would be saved on graphcool and stripeCustomer would be equal to the object returned by the Stripe API for this customer (https://stripe.com/docs/api/node#retrieve_customer):
Copy code
{
  "id": "cus_AiG2iGbb9IQdzu",
  "object": "customer",
  "account_balance": 0,
  "created": 1495593991,
  "currency": "usd",
  "default_source": "card_1AMpW82eZvKYlo2Csqq8T4tc",
  "delinquent": false,
  "description": null,
  "discount": null,
  "email": "<mailto:tests+1495593987@showclix.com|tests+1495593987@showclix.com>",
  "livemode": false,
  "metadata": {},
  "shipping": null,
  "sources": {
    "object": "list",
    "data": [
      {
        "id": "card_1AMpW82eZvKYlo2Csqq8T4tc",
        "object": "card",
        "address_city": "Pittsburgh",
        "address_country": "US",
        "address_line1": "414 Grant St",
        "address_line1_check": "pass",
        "address_line2": "",
        "address_state": "PA",
        "address_zip": "15219",
        "address_zip_check": "pass",
        "brand": "Visa",
        "country": "US",
        "customer": "cus_AiG2iGbb9IQdzu",
        "cvc_check": "pass",
        "dynamic_last4": null,
        "exp_month": 12,
        "exp_year": 2022,
        "fingerprint": "tiDP36QdYA6X7km8",
        "funding": "unknown",
        "last4": "1111",
        "metadata": {},
        "name": "Harold Hamburger",
        "tokenization_method": null
      }
    ],
    "has_more": false,
    "total_count": 1,
    "url": "/v1/customers/cus_AiG2iGbb9IQdzu/sources"
  },
  "subscriptions": {
    "object": "list",
    "data": [],
    "has_more": false,
    "total_count": 0,
    "url": "/v1/customers/cus_AiG2iGbb9IQdzu/subscriptions"
  }
}
Is it possible or should I just call a aws lambda directly from my app?
n
Hey @mll sorry for not getting back - our Functions feature currently only allows you to hook into mutations
You could write a function that fetches the stripe customer information from the Stripe API and returns it as part of the mutation payload
So, you could run a "dummy" update mutation on the
User
type, make the call to the Stripe API from the
PRE_WRITE
hook point of the request pipeline and return the customer for the
stripeCustomer
field
m
No worries @nilan , thanks for the tip!
n
Cheers! 🙂 Let me know how it goes
m
Sure. :) Side question: how do you recommend securing calls between Graphcool and aws lambdas? I'm using serverless and was thinking of simply using a secret that would be sent with all requests as a query param.
n
That's a perfectly valid approach - another one would be using a header
m
Right. Thanks!