

Store a Card on File using Reader SDK
source link: https://developer.squareup.com/blog/store-a-card-on-file-using-reader-sdk/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.


Store a Card on File using Reader SDK
New Feature in Square Reader SDK
Last year, we announced the release of Square Reader SDK for iOS and Android, along with plugins for React Native and Flutter. While Reader SDK makes it easy to take in-person payments within your own app using Square hardware, you may also want to store customer card information securely to use in the future (for example, to create a recurring billing plan).
To help you create a seamless experience for returning customers and enable recurring payments, Reader SDK now supports storing a card on file using Square hardware. This new functionality works in tandem with the Customers API and Transactions API, allowing you to create a customer profile; swipe, tap, or dip a card to store it securely; and then charge the card for future purchases at any time.
Here’s how it works:
Create a Customer
Use the Customers API to create a customer profile, including contact information such as name, address, email, and phone number.
curl https://connect.squareup.com/v2/customers \
-H "Authorization: Bearer SQUARE_ACCESS_TOKEN" \
-H "Content-Type: 'application/json'" \
-d '{
"given_name": "Amelia",
"family_name": "Earhart",
"email_address": "[email protected]",
"address": {
"address_line_1": "500 Electric Ave",
"address_line_2": "Suite 600",
"locality": "New York",
"administrative_district_level_1": "NY",
"postal_code": "10003",
"country": "US"
},
"phone_number": "1-212-555-4240",
"reference_id": "YOUR_REFERENCE_ID",
"note": "a customer"
}'
Store a Card on File
Use Reader SDK to swipe, tap, or dip a customer’s card and store it as a card on file. Reader SDK handles all payment information securely and creates a Customer Card object for you, so you don’t have to worry about handling raw card details or dealing with PCI compliance.
Android
Create a CustomerCardManager:
import com.squareup.sdk.reader.ReaderSdk;
Import com.squareup.sdk.reader.crm.CustomerCardManager;
CustomerCardManager customerCardManager =
ReaderSdk.customerCardManager();
Write a callback to handle the result:
import com.squareup.sdk.reader.core.CallbackReference;
CallbackReference storeCardCallbackRef = customerCardManager.addStoreCardActivityCallback(result -> {
hideLoadingIndicatorOnYourActivity();
if (result.isSuccess()) {
showStoreCardSuccessDialog(result.getSuccessValue());
} else {
showErrorDialog(result.getError());
}
Add code to start the Store Customer Card flow:
showLoadingIndicatorOnYourActivity();
customerCardManager.startStoreCardActivity(activity, customerId));
Implement StoreCustomerCardControllerDelegate Methods:
import SquareReaderSDK
extension <#YourViewController#>: SQRDStoreCustomerCardControllerDelegate {
func storeCustomerCardController(_ storeCustomerCardController: SQRDStoreCustomerCardController, didFailWith error: Error) {
hideLoadingView()
// Show error message to user
}
func storeCustomerCardController(_ storeCustomerCardController: SQRDStoreCustomerCardController, didFinishWith card: SQRDCard) {
hideLoadingView()
// Indicate to user that card was linked
}
func storeCustomerCardControllerDidCancel(_ storeCustomerCardController: SQRDStoreCustomerCardController) {
hideLoadingView()
// Return to previous UI state
}
Add code to start the Store Customer Card flow:
import SquareReaderSDK
extension <#YourViewController#> {
func storeCardOnFile() {
showLoadingView()
let cardOnFileController = SQRDStoreCustomerCardController(customerID: customerID, delegate: self)
cardOnFileController.present(from: self)
}
}
Charge the Card on File
Once you’ve stored a Card on File for a given Customer, you can use the Transactions API to charge the card for future payments.
curl https://connect.squareup.com/v2/locations/LOCATION_ID/transactions \
-H 'Authorization: Bearer SQUARE_ACCESS_TOKEN' \
-H 'Content-Type: application/json' \
-d '{
"idempotency_key": "UNIQUE_IDEMPOTENCY_KEY",
"customer_id":"CBASEBJj_XENvP8BFVzZvlOa_y0gAQ",
"customer_card_id": "8299e337-b459-5008-6dda-3724dda71f6b",
"amount_money": {
"amount": 100,
"currency": "USD"
}
}'
Meet your buyers wherever they are
With Square’s omnichannel developer platform and the addition of Card on File to Reader SDK, you can now add cards to a customer profile regardless of where the customer relationship starts: online, in-store, or in-app. We are excited to see what you’ll build!
You can read more about Reader SDK in our documentation. Be sure to read and follow the requirements for obtaining customer consent and disclosing terms and conditions outlined in the documentation.
If you want to keep up to date with the rest of our content, be sure to follow this blog, follow our Twitter account, and sign up for our developer newsletter! We also have a Slack community for connecting with and talking to other developers implementing Square APIs.
Recommend
-
3
SD Card Reader Won't Show in File Explorer? Here's How to Fix It By Tashreef Shareef Published 5 hours ago It's annoying when...
-
15
Upload and Store Image File in Database using PHP and MySQL Server-side file upload can be easily implemented using PHP. There are various ways available to up...
-
5
-
6
-
4
Bloomberg: Next MacBook Pro to Feature SD Card ReaderFriday January 22, 2021 6:50 am PST by Joe RossignolLast week, reputable analyst Ming-...
-
10
Introduction I recently built a MIDI "score sampler" project that reads MIDI files off of an SD card. The SD readers I have do not have a pin to detect when a card has been removed or inserted, although some do. Fortunately, you can more...
-
12
When Your Smart ID Card Reader Comes With Malware – Krebs on Security Millions of U.S. government employees and contractors have been issued a secure smart ID card that enables physical acce...
-
10
MacBook Pro Retina Late 2013 SD Card Reader very slow M
-
6
Create a Barcode Reader You can find barcodes and QR codes in a lot of places. Their primary purpose is storing data and making it available. While barcodes are more commonly used for basic identification and tracking, QR codes are...
-
4
Link Reader Disappears From ChatGPT Plugin Store Link Reader, a popular feature that accesses the web, was missing from the plugin store, limiting web acces...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK