stripe-ios/StripeCardScan
John Woo b5e349fa75
Remove generated project files for v23.9.1 (#2648)
2023-06-13 02:05:40 +01:00
..
BuildConfigurations Use tuist to generate xcode projects (#2102) 2022-12-20 12:55:37 -08:00
StripeCardScan Fix build on Xcode 14.3 (#2340) 2023-03-02 15:37:02 -08:00
StripeCardScanTests Lint StripeCameraCore and StripeCardScan (#2212) 2023-01-11 12:31:02 -08:00
Project.swift Lint StripeCameraCore and StripeCardScan (#2212) 2023-01-11 12:31:02 -08:00
README.md Remove Xcode 13 support (#2441) 2023-04-05 13:18:12 -07:00

README.md

Stripe CardScan iOS SDK

This library provides support for the standalone Stripe CardScan product.

Overview

This library provides a user interface through which users can scan payment cards and extract information from them. It uses the Stripe Publishable Key to authenticate with Stripe services.

Note that this is a standalone SDK and, while compatible with, does not directly integrate with the PaymentIntent API nor with next_action.

This library can be used entirely outside of a Stripe integration and with other payment processing providers.

Requirements

  • iOS 13.0 or higher
  • XCode 14.1 or higher

Example

See the CardImageVerification Example directory for an example application that you can try for yourself!

Installation

  • Cocoapod
    • pod install StripeCardScan
  • SPM
    • In Xcode, select File > Add Packages… and enter https://github.com/stripe/stripe-ios-spm as the repository URL.
    • Select the latest version number from our releases page.
    • Add the StripeCardScan product to the target of your app.

Integration

Credit Card OCR

Add CardScanSheet in your view controller where you want to invoke the credit card scanning flow.

  1. Set up camera permissions
    • The SDK uses the camera, so you'll need to add an description of camera usage to your Info.plist file: info.plist camera permissions camera permissions prompt

    • Alternatively, you can add this permission directly to your Info.plist file:

    <key>NSCameraUsageDescriptionkey>
    <string>We need access to your camera to scan your cardstring>
    
  2. Add CardScanSheet in your app where you want to invoke the scan flow
    • Initialize CardScanSheet
    • When its time to invoke the scan flow, display the sheet with CardScanSheet.present()
    • When the verification flow is finished, the sheet will be dismissed and the completion block will be called with a Result

Example Implementation


import UIKit
import StripeCardScan

class ViewController: UIViewController {

    @IBAction func cardScanSheetButtonPressed() {
        let cardScanSheet = CardScanSheet()

        cardScanSheet.present(from: self) { [weak self] result in
            switch result {
                case .completed(let scannedCard):
                /*
                 * The user scanned a card. The result of the scan are detailed 
                 * in the `scannedCard` field of the result.
                 */
                print("scan success")
            case .canceled:
                /*
                * The scan was canceled by the user.
                */
                print("scan canceled")
            case .failed(let error):
                 /*
                 * The scan failed. The displayable error is
                 * included in the `localizedDescription`. 
                 */
                 print("scan failed: \(error.localizedDescription)")
            }
        }
    }
}

Credit Card Verification

🚧