This Android application demonstrates how to integrate Square's Mobile Payments SDK to accept in-person payments using Square Readers or Tap to Pay on Android.
β¨ Features Jetpack Compose permission screen with Material Design 3!
- Square Mobile Payments SDK integration
- Modern Jetpack Compose UI for permission handling
- Clean, modern Material Design UI
- Payment processing with Square Readers
- Tap to Pay on Android support (on compatible devices)
- Real-time payment status updates
Before you begin, ensure you have:
-
A Square Account enabled for payment processing
- Visit squareup.com/activation if needed
-
Square Developer Account
- Sign up at developer.squareup.com
-
Android Development Environment
- Android Studio (latest version recommended)
- Minimum SDK: API 28 (Android 9)
- Target SDK: API 35 (Android 15) or later
-
A Compatible Device
- Android device running Android 9 or later
- For Tap to Pay: A compatible Android phone
- Go to the Square Developer Console
- Create a new application or select an existing one
- Navigate to the Credentials page
- Copy the following:
- Application ID (for both Sandbox and Production)
- Access Token (use Sandbox for testing)
- Navigate to the Locations page
- Copy your Location ID
Open app/src/main/java/com/example/custompromptsample/MainActivity.kt and replace the placeholder
values:
private val squareApplicationId = "YOUR_SQUARE_APPLICATION_ID"
private val squareAccessToken = "YOUR_SQUARE_ACCESS_TOKEN"
private val squareLocationId = "YOUR_SQUARE_LOCATION_ID"Important Security Note:
- The access token should NEVER be hardcoded in a production app
- Instead, implement OAuth or use a backend server to securely provide authorization
- This sample uses hardcoded values for simplicity only
- Open the project in Android Studio
- Sync Gradle files using
File > Sync Project with Gradle Files - Connect your Android device or start an emulator
- Click Run or press
Shift + F10
When using Sandbox credentials, you can test payments without real money:
-
With Mock Readers:
- The SDK automatically provides mock readers in Sandbox mode
- No physical reader is required for testing
-
Test Card Numbers:
- Use Square's test card numbers
- Example:
4111 1111 1111 1111(Visa)
- Enter a payment amount in the text field
- Tap the Pay with Card button
- Follow the on-screen prompts to:
- Select a connected reader, OR
- Use Tap to Pay on Android (if available), OR
- Enter card details manually (if enabled)
- Complete the payment
- View the payment confirmation
The app includes a comprehensive settings screen accessible via the settings button (βοΈ) in the top-right corner of the main screen.
- SDK Version - Current version of the Mobile Payments SDK
- Environment - PRODUCTION or SANDBOX mode
- Security Compliance Version - Current security compliance version
- Authorization Status - Whether the SDK is authorized
- Business Name - Your Square business name
- Location Name - The authorized location name
- Currency - Currency code (e.g., USD)
- Card Processing Status - Whether card processing is activated
- Merchant ID - Your Square merchant identifier
- Location ID - Your Square location identifier
- Offline Processing - Whether offline payments are enabled
- Max Offline Transaction - Maximum single offline transaction amount
- Max Total Stored Offline - Maximum total offline payment amount
- Tracking Consent - Current analytics/performance tracking consent state
- Update Consent - Modify tracking consent preferences
- Deauthorize SDK - Disconnect the app from your Square account (requires confirmation)
- Update Tracking Consent - Grant or deny analytics data collection
- Open Square Settings - Access the Square-provided settings screen
- Refresh Settings - Reload all settings from the SDK
- π’ Green - Active, enabled, or authorized
- π΄ Red - Inactive, disabled, or not authorized
- π Orange - Pending or warning state
- βͺ Gray - Neutral or informational
app/
βββ src/main/
β βββ java/com/example/custompromptsample/
β β βββ MainActivity.kt # Main app logic
β βββ res/
β β βββ layout/
β β β βββ activity_main.xml # UI layout
β β βββ values/
β β βββ strings.xml # String resources
β β βββ colors.xml # Color definitions
β β βββ themes.xml # App themes
β βββ AndroidManifest.xml # App configuration
βββ build.gradle.kts # App dependencies
MobilePaymentsSdk.initialize(squareApplicationId, this)authorizationManager.authorize(accessToken, locationId) { result ->
when (result) {
is Result.Success -> // Handle success
is Result.Failure -> // Handle error
}
}val paymentParams = PaymentParameters.Builder(
amount = Money(amountInCents, CurrencyCode.USD),
paymentAttemptId = UUID.randomUUID().toString()
)
.referenceId(UUID.randomUUID().toString())
.note("Payment description")
.autocomplete(true)
.build()
val promptParams = PromptParameters(mode = PromptMode.DEFAULT)
paymentManager.startPaymentActivity(paymentParams, promptParams) { result ->
// Handle result
}The app requires the following permissions for Square Mobile Payments SDK:
ACCESS_FINE_LOCATION- To confirm that payments are occurring in a supported Square locationRECORD_AUDIO- To receive data from magstripe readersBLUETOOTH_CONNECT(Android 12+) - To receive data from contactless and chip readersBLUETOOTH_SCAN(Android 12+) - To discover and pair with Square ReadersREAD_PHONE_STATE- To identify the device sending information to Square servers
INTERNET- To communicate with Square serversBLUETOOTH(Android 11 and below) - To connect to Square Readers
The app includes a dedicated PermissionActivity that:
- Shows before the main payment screen on first launch
- Displays educational cards explaining why each permission is needed
- Allows granting individually or all at once
- Provides rationale dialogs when permissions are denied
- Handles Android version differences (API 28-36)
- Remembers permission state to avoid repeated prompts
- Directs to Settings if permissions are permanently denied
The permission screen follows Android best practices and Material Design guidelines for a modern, user-friendly experience.
- Ensure your reader is charged and turned on
- Follow the pairing guide
- Use the
ReaderManagerto pair and manage readers
- Automatically available on compatible devices
- No physical reader required
- Works when no other readers are paired
-
"SDK Not Authorized" Error
- Verify your Application ID, Access Token, and Location ID are correct
- Ensure the Access Token has the required permissions:
MERCHANT_PROFILE_READPAYMENTS_WRITEPAYMENTS_WRITE_IN_PERSON
-
"No Network" Error
- Check your internet connection
- Verify the device has proper network access
-
Build Errors
- Ensure you've added the Square Maven repository in
settings.gradle.kts - Sync Gradle files using
File > Sync Project with Gradle Files - Clean and rebuild the project
- Ensure you've added the Square Maven repository in
-
Reader Connection Issues
- Ensure Bluetooth is enabled
- Check location permissions are granted
- Make sure the reader is charged and within range
Before deploying to production:
-
Implement Secure Authorization
- Use OAuth for authorization
- Never hardcode access tokens
- Implement token refresh logic
-
Error Handling
- Add comprehensive error handling
- Log errors for debugging
- Provide user-friendly error messages
-
Testing
- Test with real Square Readers
- Test various payment scenarios
- Verify error handling
-
Compliance
- Follow PCI compliance guidelines
- Adhere to Square's branding requirements
- Review Square's terms of service
-
Application Signature
- When using Mobile Payments SDK version 2.1 or later
- Provide your application signature to Square before production
- Square Mobile Payments SDK: 2.3.2
- Min SDK Version: 28 (Android 9)
- Target SDK Version: 36 (Android 15)
- Kotlin Version: 2.0.21
This sample app is provided for demonstration purposes. Please review Square's SDK license terms for production use.
For help and support:
- Visit the Square Developer Documentation
- Ask questions in the Developer Forums
- Contact Square Developer Support