Applies to: Point of Sale API - iOS
Learn how to open the Square Point of Sale application from your mobile iOS application to process in-person payments using Square hardware.
Applies to: Point of Sale API - iOS
Learn how to open the Square Point of Sale application from your mobile iOS application to process in-person payments using Square hardware.
You should install the latest version of the Square Point of Sale application from the Apple App Store to use with the latest version of the Point of Sale SDK for iOS.
To check your installed version of the Point of Sale application:
If you must use an older version of the Point of Sale SDK, you need to install a compatible version of the Point of Sale application:
Point of Sale version | iOS SDK version | iOS version |
---|---|---|
4.59 and later | v1.3 | 14 |
4.53 and later | v1.2 | 14 |
4.50 and later | v1.1 | 14 |
4.34 and later | v1.0 | 14 |
The Square Point of Sale application for iOS only accepts requests if it can authenticate the source of the request. Square uses the following to authenticate application requests:
myapp-url-scheme
. The URL scheme you provide must match the CFBundleURLSchemes
attribute of the Info.plist file for your application.To register your application:
To install the Point of Sale SDK manually, download the SquarePointOfSaleSDK-iOS repo in GitHub.
If you use Cocoapods to manage your dependencies, install the Point of Sale SDK by adding the following to your podfile:
platform :ios, '9.0'
pod 'SquarePointOfSaleSDK'
When installed, you can use the following commands to ensure that you have the most recent version of Point of Sale SDK installed.
pod update pod install --repo-update
If you use Carthage to manage your dependencies, install the Point of Sale SDK with the following shell command:
github "Square/SquarePointOfSaleSDK-iOS"
Set your URL scheme as square-commerce-v1
and set your custom response URL scheme.
Add the request URL scheme as a LSApplicationQueriesSchemes
key into your Info.plist file to indicate that your application uses the square-commerce-v1
URL scheme to open Square Point of Sale.
<key>LSApplicationQueriesSchemes</key>
<array>
<string>square-commerce-v1</string>
</array>
Add your custom response URL scheme as CFBundleURLTypes
keys in your Info.plist file.
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>YOUR_BUNDLE_URL_NAME</string>
<key>CFBundleURLSchemes</key>
<array>
<string>myapp-url-scheme</string>
</array>
</dict>
</array>
For more information about defining custom URL schemes and handling requests that use them, see Apple's App Programming Guide for iOS.
Create an SCCAPIRequest object with the details of your payment.
Information in the notes
field is saved in the Square Dashboard and printed on receipts.
// Replace with your app's callback URL.
// Note: You can retrieve this value from Info.plist
NSURL *const callbackURL = [NSURL URLWithString:redirectUrl];
// Specify the amount of money to charge.
SCCMoney *const amount = [SCCMoney moneyWithAmountCents:100 currencyCode:@"USD" error:NULL];
// Note: You only need to set your application ID once, before creating your first request.
[SCCAPIRequest setApplicationID:YOUR_APPLICATION_ID];
SCCAPIRequest *request = [SCCAPIRequest requestWithCallbackURL:callbackURL
amount:amount
userInfoString:nil
merchantID:nil
notes:@"Coffee"
customerID:nil
supportedTenderTypes:SCCAPIRequestTenderTypeAll
clearsDefaultFees:NO
returnAutomaticallyAfterPayment:NO
error:&error];
Use the SCCAPIConnection class to send your SCCAPIRequest
to the Square Point of Sale application.
BOOL success = [SCCAPIConnection performRequest:request error:&error];
You need to add code to receive results from the Square Point of Sale application and do something with it.
The following sample code implements the application:openURL:options: method in your UIApplicationDelegate to receive the results. If the transaction succeeds, the sample code prints the newly created checkout object; otherwise, it prints the error description.
Your application should keep track of whether a Point of Sale API request has been issued and whether a callback has been received. Because of the constraints of application-switching APIs, sellers can leave Square Point of Sale during an API request and return to your application. It's your responsibility to direct them to return to Square and finish the transaction.
- (BOOL)application:(UIApplication *)app
openURL:(NSURL *)url
options:(NSDictionary<NSString *, id> *)options;
{
NSString *const sourceApplication = options[UIApplicationOpenURLOptionsSourceApplicationKey];
// Make sure the URL comes from Square Point of Sale; fail if it doesn't.
if (![SCCAPIResponse isSquareResponse:url]) {
return NO;
}
// The response data is encoded in the URL and can be decoded as an SCCAPIResponse.
NSError *decodeError = nil;
SCCAPIResponse[] *const response = [SCCAPIResponse responseWithResponseURL:url
error:&decodeError];
if (response.isSuccessResponse) {
// Print checkout object
NSLog(@"Transaction successful: %@", response);
} else if (decodeError) {
// Print decode error
NSLog(@"Decode Error: %@", decodeError);
} else {
// Print the error code
NSLog(@"Request failed: %@", response.error);
}
return YES;
}
The Sandbox doesn't support credit card testing for mobile. To test with credit cards in production, connect your Square Reader, process small card payments (as low as $1 USD), and then issue refunds from Square Point of Sale. To test your application in development, see Testing for supported countries.
Now that you have a basic build in place, expand on it by integrating with the Square Payments API and Refunds API.
If you need more assistance, contact Developer and App Marketplace Support or ask for help in the Developer Forums.