Stripe - Create a Source for a Credit Card using only Stripe API - stripe-payments

I'm trying to register a user payment info by directly using fetch to Stripe's API (since it's a React Native app, I can't use Stripe Elements). It follows the usual concept: a user registers his credit card, which is then associated to his account so he can make payments in the app.
I tried to approach this problem by creating a credit card token with the info that the user provides on signup, but I've realized that that token is only worth for one payment, or for associating to a customer.
Meanwhile I saw that Sources are maybe what I need in my app, since we can get back to it and charge it multiple times. However, from what I see in the API docs there's no reference to the credit card info when creating the source.
What do I need to create to be able to do this (registering a card to be used several times) only through the API?

By creating a token previously, you can then use it as an argument to the creation of the source. Then, the token properties will override source parameters. Thanks to #Evgenii Malikov for the tip.

You need to create a token of your card previously. For that, you can use tipsi-stripe package.
Perfect package if you want to implement credit card, apple / google pay.

Related

Saving User's card in Square Payments

I'm new to Square and want to implement it in a React Native app with a Node backend.
I see that there is a method to save the customer's card details.
https://github.com/square/square-nodejs-sdk/blob/master/src/api/customersApi.ts#L230
But there is also the payment form?
https://developer.squareup.com/docs/payment-form/how-it-works
Firstly, I cannot see if the payment form is even available in React Native - information seems very scarce.
Secondly, even if I do implement that form, I can't see a way to connect it to the customers API endpoint.
I don't want to use in-app payments (i.e. google or apple pay). I want to be able to save card details like Amazon does, and use them whenever a user places an order in app (probably triggered by a node process). I'm not sure if I'm going about this the correct way, guidance would be appreciated.
In-App Payments SDK will be the way to go (and there is a React Native plugin already). The In-App Payments SDK is basically a mobile Square Payment Form, that you linked to. It will generate a secure nonce, and you can use the nonce to save the card on file. The next time the customer comes, instead of bringing up In-App Payments, you can simply call CreatePayment in your backend, with the customer_id and the customer_card_id as the source.
As for "connecting it to the Customers API" - you don't connect it directly per se. You would collect information from the customer, on your own, and pass it directly to the Customers API to create a customer. You can then call CreateCustomerCard using the nonce (generated by In-App Payments), and the customer_id that you just created, to save the card to this customer profile.

Stripe - Using the right react frontend component for credit card storage?

I am working on a stripe backend in node and a react frontend, the idea being to create a platform for buyers and sellers. I have created the seller's side where users create connect accounts and add a bank to that account.
Now I want to set up the buyer's side. I want to be able to have a customer store their credit/debit card information to use to pay in the future. Below are my questions, they're a bit broad but I just want some basic guidance, not looking for code answers:
Should I aim to have users enter information and then have stripe create a customer object with all their information as a way of storing credit card info?
Can I use the react-stripe-elementslibrary to facilitate this process as it seems to be made to be secure? I've been looking at the examples but they seem to revolve around paying directly by inputting information to pay right away. Unless I am misunderstanding?
Should I aim to have users enter information and then have stripe
create a customer object with all their information as a way of
storing credit card info?
Yes, the main approach is to collect the card details which will produce a PaymentMethod object that you can then save to a Customer. The easiest way to do this is by using the SetupIntents API as described here:
https://stripe.com/docs/payments/save-and-reuse
If you follow that guide a PaymentMethod will be created automatically when you confirm the SetupIntent, and since you provide a Customer when creating the SetupIntent, Stripe will automatically save the PaymentMethod to the Customer.
Can I use the react-stripe-elementslibrary to facilitate this process
as it seems to be made to be secure? I've been looking at the examples
but they seem to revolve around paying directly by inputting
information to pay right away. Unless I am misunderstanding?
You should use the new React library from Stripe instead (assuming you're on React v16.8 and above):
https://github.com/stripe/react-stripe-js
The library is a simple wrapper around Stripe Elements which exposes an input field for your users to enter in their credit card details. When you use that pre-built input field from Stripe, they will automatically create PCI compliant forms for you: https://stripe.com/docs/security/guide. Otherwise, you would need to prove your business's PCI compliance annually which is a lot of work.
The client-side steps in the Save and Reuse guide all have a "React" tab that you can click on to show the React version (that uses the new react-stripe-js library):
https://stripe.com/docs/payments/save-and-reuse#web-collect-card-details

Stripe payment APIs -- without using Stripe UI

Can Stripe APIs be used without their client side UI ? For example, we already have credit card info and we want to pass it to Stripe to process charges ?
Yes, it's possible to use the Stripe API without Stripe Elements. I wouldn't personally recommend it since the handling your customers raw credit card information like you're describing has a host of regulatory implications which Stripe covers in-depth here:
https://stripe.com/docs/security/guide
That being said, if your business is prepared to assume that level of liability for your customer's credit card information, you can pass raw credit card information directly to the PaymentMethods API server-side as shown in the example on this page:
https://stripe.com/docs/api/payment_methods/create
Once you've created the payment method, you can use the payment method like any other throughout the rest of the API.

save card to customer with Stripe.js

How do I save a card to a customer with Stripe.js?
I don't want to change them at this point. I just want to save the credit card info to their stripe account so I can use it later.
It seems like I'd need to use createToken from Stipe.js. But my understanding is that this is a one time use token. I want to save the credit card info for later use.
This seems to be a similar question: Stripe Payment: Save token and customer and make payment later from token
but the solution isn't clear. I'm not sure if it means for the customer I need to save card=token and everything will work fine.
Though the question is an old one and solution of this problem is now pretty straightforward in the current Stripe API, I'm just answering for those who accidentally reached or will reach here without reading the Official Stripe Doc properly(like me) searching for this question.
To make a stripe payment You first need to make a call to the Stripe API(Using Stripe's Checkout widget, Elements or Mobile SDKs) with the User's card information. As a response, you will get a token. Then you can charge your customer immediately using Stripe's Charge API. This is for just one-time payment. You will find an example here.
If you want to save customer's information for later payment, you need to create a 'Customer' first using Stripe's API and then using that customer's ID (returned as a response from the previous API call) you can charge this customer. Example here.
I just described the process briefly to show the idea at a glance. But you should really need to read this quickstart guide in Stripe's documentation. This explains the process very well.
I just want to save the credit card info to their stripe account so I
can use it later.
Then that's exactly what you can do!
If you're already passing the token back into your server-side code, you just need to update that server-side code to retrieve the customer and create the card on that customer record using the token.
Not knowing what language you're using I can't provide relevant sample code, but the Stripe API reference has functional examples for Ruby, Python, PHP, Java, and Node.js.
Note that if the customer has any outstanding invoices, this card will be used the next time they attempt to settleā€”so while simply adding the card won't create a charge by itself, it's possible the card may still be billed.
A key point that the prior answers seems to dance around but do not explicitly state is that you can't simply save the credit card (token) in Stripe. Stripe's API's don't save credit cards per se, however, they can save a customer and attached to the customer you can save one more credit cards (or payment sources). So a credit card (or payment source) is not a stand alone entity in the Stripe storage system, it's a child entity of a Customer.

What is the format for Stripe Connect access tokens?

I'm trying to use stripe connect and I want to make sure that I'm receiving stripe access tokens that I can use to make charges on the behalf of Stripe users. The access token I'm getting in my test environment looks like this:
sk_test_VyqtfZ6IIPMR1dyY0Po9O29i
Is this how they are formatted? Is there a way I can do a test charge on this token?
That looks to me more like a Test Secret Key, an internal API key, rather than a card token. To generate a card token you should be using the createToken function from Stripe's JavaScript API. Once you've done that you can pass that token instead of credit card details when creating a charge. Here is the relevant documentation from the API, and the part of interest:
card: optional, either card or customer is required, but not both. A card to be charged. The card can either be a token, like the ones returned by Stripe.js, or a dictionary containing a user's credit card details
Depending on your specific needs you might consider taking a look at Temboo's Stripe SDK, it reduces the complexity of doing things like creating customers, charges, subscriptions, etc. The free Temboo SDK is available in many popular languages and is a drop-in solution.
Full disclosure: I'm a Temboo employee

Resources