Search code examples
node.jsreact-nativesquare

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.


Solution

  • 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.