Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename Sample App + Update Instructions #17

Merged
merged 2 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ jobs:
- name: Checkout Code
uses: actions/checkout@v2

- name: Build SwiftUI project
- name: Build DonutCounter project
run: |
xcodebuild -project Example/SwiftUIExample/MobilePaymentsSwiftUIExample.xcodeproj -scheme MobilePaymentsSwiftUIExample -sdk iphoneos -configuration Release SKIP_SETUP_SCRIPT=YES CODE_SIGNING_ALLOWED=NO CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY=NO
xcodebuild -project Example/DonutCounter/DonutCounter.xcodeproj -scheme DonutCounter -sdk iphoneos -configuration Release SKIP_SETUP_SCRIPT=YES CODE_SIGNING_ALLOWED=NO CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY=NO
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
D0D89F202CE5AFF700FDD0B8 /* MockReaderUI in Frameworks */ = {isa = PBXBuildFile; productRef = D0D89F1F2CE5AFF700FDD0B8 /* MockReaderUI */; };
D0D89F222CE5AFF700FDD0B8 /* SquareMobilePaymentsSDK in Frameworks */ = {isa = PBXBuildFile; productRef = D0D89F212CE5AFF700FDD0B8 /* SquareMobilePaymentsSDK */; };
D0F1F9242CDEA4DC00E00BB6 /* PermissionRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0F1F9232CDEA4DC00E00BB6 /* PermissionRow.swift */; };
FB1E68D22C1CC55C004DC0A9 /* MobilePaymentsApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = FB1E68C32C1CC55C004DC0A9 /* MobilePaymentsApp.swift */; };
FB1E68D22C1CC55C004DC0A9 /* DonutCounterApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = FB1E68C32C1CC55C004DC0A9 /* DonutCounterApp.swift */; };
FB1E68D32C1CC55C004DC0A9 /* MobilePaymentsSDKViewHolder.swift in Sources */ = {isa = PBXBuildFile; fileRef = FB1E68C52C1CC55C004DC0A9 /* MobilePaymentsSDKViewHolder.swift */; };
FB1E68D42C1CC55C004DC0A9 /* AppButtons.swift in Sources */ = {isa = PBXBuildFile; fileRef = FB1E68C62C1CC55C004DC0A9 /* AppButtons.swift */; };
FB1E68D52C1CC55C004DC0A9 /* HomeViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = FB1E68C82C1CC55C004DC0A9 /* HomeViewModel.swift */; };
Expand All @@ -36,8 +36,8 @@
D09D32332CE50F8E002DB265 /* Config+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Config+Extensions.swift"; sourceTree = "<group>"; };
D0D5BB642CDD75F20054771D /* Color+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Color+Extensions.swift"; sourceTree = "<group>"; };
D0F1F9232CDEA4DC00E00BB6 /* PermissionRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PermissionRow.swift; sourceTree = "<group>"; };
FB1E68AD2C1CC50A004DC0A9 /* MobilePaymentsSwiftUIExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MobilePaymentsSwiftUIExample.app; sourceTree = BUILT_PRODUCTS_DIR; };
FB1E68C32C1CC55C004DC0A9 /* MobilePaymentsApp.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MobilePaymentsApp.swift; sourceTree = "<group>"; };
FB1E68AD2C1CC50A004DC0A9 /* DonutCounter.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DonutCounter.app; sourceTree = BUILT_PRODUCTS_DIR; };
FB1E68C32C1CC55C004DC0A9 /* DonutCounterApp.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DonutCounterApp.swift; sourceTree = "<group>"; };
FB1E68C52C1CC55C004DC0A9 /* MobilePaymentsSDKViewHolder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MobilePaymentsSDKViewHolder.swift; sourceTree = "<group>"; };
FB1E68C62C1CC55C004DC0A9 /* AppButtons.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppButtons.swift; sourceTree = "<group>"; };
FB1E68C82C1CC55C004DC0A9 /* HomeViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HomeViewModel.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -105,30 +105,30 @@
FB1E68A42C1CC50A004DC0A9 = {
isa = PBXGroup;
children = (
FB1E68AF2C1CC50A004DC0A9 /* MobilePaymentsSwiftUIExample */,
FB1E68AF2C1CC50A004DC0A9 /* DonutCounter */,
FB1E68AE2C1CC50A004DC0A9 /* Products */,
);
sourceTree = "<group>";
};
FB1E68AE2C1CC50A004DC0A9 /* Products */ = {
isa = PBXGroup;
children = (
FB1E68AD2C1CC50A004DC0A9 /* MobilePaymentsSwiftUIExample.app */,
FB1E68AD2C1CC50A004DC0A9 /* DonutCounter.app */,
);
name = Products;
sourceTree = "<group>";
};
FB1E68AF2C1CC50A004DC0A9 /* MobilePaymentsSwiftUIExample */ = {
FB1E68AF2C1CC50A004DC0A9 /* DonutCounter */ = {
isa = PBXGroup;
children = (
D09D32302CE4703B002DB265 /* Helpers */,
D0D5BB632CDD75DE0054771D /* Extensions */,
FB1E68C42C1CC55C004DC0A9 /* Components */,
FB1E68C32C1CC55C004DC0A9 /* MobilePaymentsApp.swift */,
FB1E68C32C1CC55C004DC0A9 /* DonutCounterApp.swift */,
FB1E68C72C1CC55C004DC0A9 /* Screens */,
FB1E68DF2C1CC5E8004DC0A9 /* Shared */,
);
path = MobilePaymentsSwiftUIExample;
path = DonutCounter;
sourceTree = "<group>";
};
FB1E68C42C1CC55C004DC0A9 /* Components */ = {
Expand Down Expand Up @@ -181,9 +181,9 @@
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
FB1E68AC2C1CC50A004DC0A9 /* MobilePaymentsSwiftUIExample */ = {
FB1E68AC2C1CC50A004DC0A9 /* DonutCounter */ = {
isa = PBXNativeTarget;
buildConfigurationList = FB1E68BB2C1CC50A004DC0A9 /* Build configuration list for PBXNativeTarget "MobilePaymentsSwiftUIExample" */;
buildConfigurationList = FB1E68BB2C1CC50A004DC0A9 /* Build configuration list for PBXNativeTarget "DonutCounter" */;
buildPhases = (
FB1E68A92C1CC50A004DC0A9 /* Sources */,
FB1E68AA2C1CC50A004DC0A9 /* Frameworks */,
Expand All @@ -194,13 +194,13 @@
);
dependencies = (
);
name = MobilePaymentsSwiftUIExample;
name = DonutCounter;
packageProductDependencies = (
D0D89F1F2CE5AFF700FDD0B8 /* MockReaderUI */,
D0D89F212CE5AFF700FDD0B8 /* SquareMobilePaymentsSDK */,
);
productName = MobilePaymentsSwiftUIExample;
productReference = FB1E68AD2C1CC50A004DC0A9 /* MobilePaymentsSwiftUIExample.app */;
productReference = FB1E68AD2C1CC50A004DC0A9 /* DonutCounter.app */;
productType = "com.apple.product-type.application";
};
/* End PBXNativeTarget section */
Expand All @@ -219,7 +219,7 @@
};
};
};
buildConfigurationList = FB1E68A82C1CC50A004DC0A9 /* Build configuration list for PBXProject "MobilePaymentsSwiftUIExample" */;
buildConfigurationList = FB1E68A82C1CC50A004DC0A9 /* Build configuration list for PBXProject "DonutCounter" */;
compatibilityVersion = "Xcode 14.0";
developmentRegion = en;
hasScannedForEncodings = 0;
Expand All @@ -235,7 +235,7 @@
projectDirPath = "";
projectRoot = "";
targets = (
FB1E68AC2C1CC50A004DC0A9 /* MobilePaymentsSwiftUIExample */,
FB1E68AC2C1CC50A004DC0A9 /* DonutCounter */,
);
};
/* End PBXProject section */
Expand Down Expand Up @@ -278,7 +278,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
FB1E68D22C1CC55C004DC0A9 /* MobilePaymentsApp.swift in Sources */,
FB1E68D22C1CC55C004DC0A9 /* DonutCounterApp.swift in Sources */,
D09D322F2CE445C4002DB265 /* String+Extensions.swift in Sources */,
FB1E68D32C1CC55C004DC0A9 /* MobilePaymentsSDKViewHolder.swift in Sources */,
FB1E68D62C1CC55C004DC0A9 /* HomeView.swift in Sources */,
Expand Down Expand Up @@ -448,7 +448,7 @@
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.squareup.MobilePaymentsSwiftUIExample;
PRODUCT_BUNDLE_IDENTIFIER = com.squareup.DonutCounter;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
Expand Down Expand Up @@ -487,7 +487,7 @@
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.squareup.MobilePaymentsSwiftUIExample;
PRODUCT_BUNDLE_IDENTIFIER = com.squareup.DonutCounter;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
Expand All @@ -498,7 +498,7 @@
/* End XCBuildConfiguration section */

/* Begin XCConfigurationList section */
FB1E68A82C1CC50A004DC0A9 /* Build configuration list for PBXProject "MobilePaymentsSwiftUIExample" */ = {
FB1E68A82C1CC50A004DC0A9 /* Build configuration list for PBXProject "DonutCounter" */ = {
isa = XCConfigurationList;
buildConfigurations = (
FB1E68B92C1CC50A004DC0A9 /* Debug */,
Expand All @@ -507,7 +507,7 @@
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
FB1E68BB2C1CC50A004DC0A9 /* Build configuration list for PBXNativeTarget "MobilePaymentsSwiftUIExample" */ = {
FB1E68BB2C1CC50A004DC0A9 /* Build configuration list for PBXNativeTarget "DonutCounter" */ = {
isa = XCConfigurationList;
buildConfigurations = (
FB1E68BC2C1CC50A004DC0A9 /* Debug */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1540"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES"
buildArchitectures = "Automatic">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "FB1E68AC2C1CC50A004DC0A9"
BuildableName = "DonutCounter.app"
BlueprintName = "DonutCounter"
ReferencedContainer = "container:DonutCounter.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "FB1E68AC2C1CC50A004DC0A9"
BuildableName = "DonutCounter.app"
BlueprintName = "DonutCounter"
ReferencedContainer = "container:DonutCounter.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "FB1E68AC2C1CC50A004DC0A9"
BuildableName = "DonutCounter.app"
BlueprintName = "DonutCounter"
ReferencedContainer = "container:DonutCounter.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class AppDelegate: NSObject, UIApplicationDelegate {
}

@main
struct MobilePaymentsExampleApp: App {
struct DonutCounterApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate

var body: some Scene {
Expand Down
86 changes: 79 additions & 7 deletions Example/README.md
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love the updates to this! So much more detailed!

Original file line number Diff line number Diff line change
@@ -1,17 +1,89 @@
# Square Mobile Payments SDK Example App
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may end up having multiple example apps so this README may need to be more generic but for now I think it's fine to have it specific to the donut counter app

# 🍩 Donut Counter - A Square Mobile Payments SDK Sample App

<p align="center">
<img src="../Images/donut-counter-home.png" width="300"/> <img src="../Images/donut-counter-take-payment.png" width="300"/>
</p>

### Assumptions and prerequisites
Donut Counter is a sample application for building with the [Square Mobile Payments SDK](https://developer.squareup.com/docs/mobile-payments-sdk) on iOS. The app demonstrates how to install and initialize the SDK in a SwiftUI project as well as utilizing the APIs and user interfaces provided by the SDK to authorize a merchant, pair and manage card readers, and take a payment. To get started, follow the steps below.

The example app make the following assumptions:
## 1. Review requirements

### Assumptions
The example app makes the following assumptions:

* You have read the [Mobile Payments SDK "Build on iOS"](https://developer.squareup.com/docs/mobile-payments-sdk/ios) documentation. The example app focuses on demonstrating how the Square Mobile Payments SDK works by using all of the provided user interfaces of the SDK.
* You have a Square account enabled for payment processing. If you have not
enabled payment processing on your account (or you are not sure), visit
[squareup.com/activate](https://squareup.com/activate).
### Install the required tools
* Confirm your environment meets the Square Mobile Payments SDK build requirements listed in the [root README] for this repo.

### Prerequisites

* Confirm your environment meets the Square Mobile Payments SDK build requirements listed in the [root README](../README.md) for this repo.
* Clone this repo (if you have not already):
`git clone https://github.com/square/mobile-payments-sdk-ios`

## 2. Get application credentials
In your [Developer Dashboard](https://developer.squareup.com/apps), create an application or open an existing one you would like to use. If this is your first time creating an application with Square, you can review this [Get Started](https://developer.squareup.com/docs/square-get-started) guide for more information.

On the application's Credentials page, toggle the environment you'd like to use at the top (Production/Sandbox). Sandbox credentials will allow you to take mock payments with a mock reader. Make note of:
* **Application ID**
* **Access Token**

Click "Locations" in the left navigation and make note of the Default Test Account's **Location ID** as well. These values will be used in the next step.

## 3. Configure the SDK
In the [Config.swift](./Shared/Config.swift) file, populate the values for Square application id, access token, and location id you obtained from the previous step.

## 4. Run the app
1. Open `DonutCounter.xcodeproj` in Xcode
2. Select the `DonutCounter` target found at the top of Xcode.
3. Select your desired device and click the Run button.

## 5. Request required permissions
On the first install of the application, you will be required to grant various device permissions in order for the SDK to be fully functional.

Tap the 'Permissions' button found on the top right of the home view. Tap the empty checkbox next to each permission to grant the specific device permission. The checkbox will update with a checkmark if the proper permission is granted. All permissions must be granted.

<img src="../Images/donut-counter-permissions.png" width="250"/>

## 6. Authorize the SDK
Within the Permissions screen, you will find a `Sign In` button. Tap this button to authorize the sdk with the credentials you provided in Step 3. If an issue occurs during authorization, check the Xcode console for a log with the specific authorization error. You will know the SDK is fully authorized when the button updates to `Sign Out` and the text below the button reads `The device is authorized`.

## 7. Pair a reader
Depending on what environment you are authorized in, the steps for pairing a reader will differ. Follow the steps below according to your current environment.

### Production
In a production environment, you are only able to pair actual Square card readers. Mock readers do not work in a production environment.

To pair a reader:
1. Tap the `Settings` button found in the top left corner of the application. This will display the Square provided settings screen allowing you to manage and pair readers.
2. Tap the "Pair a reader" button.
3. Follow the instructions on the dialog that present on how to pair your contactless reader to your device.
4. After a successful pair, you should see the reader available in the `Devices` tab of the settings screen.
5. The reader is ready to be used for payments once the state updates to `Ready`.

### Sandbox
In a sandbox environment, you are only able to add mock readers utilizing the `MockReaderUI` framework. The `MockReaderUI` framework is provided as a part of this repo and has already been added to the DonutCounter app. Please note that MockReaderUI is to only be used in debug builds of your application, not in a production application.

To pair a mock reader:
1. Once the SDK has been authorized in sandbox, navigate back to the main home view of the app.
2. On the bottom of the main donut counter app view, tap the button `Show Mock Reader`
3. A reader shaped button should appear on the screen. This button can be placed anywhere on the screen by holding down the button and dragging around the screen.
4. Tapping on the button should reveal a menu to add a mock magstripe or contactless & chip reader.
5. Tap on the reader type you'd like to connect. You can verify the mock reader has been added correctly in the Settings screen.

<img src="../Images/donut-counter-home-mock-reader.png" width="250"/>

## 8. Take a Payment

To process a payment, follow these steps:

1. On the main screen of the application, tap the "Buy for $1" button. This action will present the default payment prompt screen provided by the SDK.

2. Depending on your environment:
- **Production Environment**: Use your paired Square reader to tap, insert, or swipe a payment card.
- **Sandbox Environment**: Tap the mock reader button and choose an option to tap, insert, or swipe a mock payment card.

<p align="center">
<img src="../Images/donut-counter-take-payment.png" width="250"/><img src="../Images/donut-counter-take-payment-mock-reader.png" width="250"/>
</p>
Binary file added Images/donut-counter-home-mock-reader.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/donut-counter-home.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/donut-counter-permissions.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/donut-counter-take-payment.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,7 @@ Follow the [Build on iOS guide](https://developer.squareup.com/docs/mobile-payme

If you need more assistance, contact [Developer and App Marketplace Support](https://squareup.com/help/us/en/contact?panel=BF53A9C8EF68) or ask for help in the [Developer Forums](https://developer.squareup.com/forums/).

## Mobile Payments SDK Sample App
<img src="./Images/donut-counter-home.png" width="300"/> <img src="./Images/donut-counter-take-payment.png" width="300"/>

[Donut Counter](Example/) is a sample application included in the Examples folder of this repository. It is built using SwiftUI and designed to help developers utilize the Square Mobile Payments SDK. This application serves as a practical guide for integrating and leveraging the SDK's capabilities within your own projects. It demonstrates essential functions such as initializing and authorizing the SDK, pairing with Square card readers and mock readers, and processing a $1.00 payment.
Loading