Repository navigation
Add DisplayAudience config to tailor payment UI for merchant-facing devices #136
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import Foundation | ||
|
|
||
| /// Describes who the Paystack payment UI is being shown to. | ||
| /// | ||
| /// Set it once on ``PaystackBuilder`` with ``PaystackBuilder/setDisplayAudience(_:)``. | ||
| /// The payment flows use it to decide which UI elements to show. When it isn't set, | ||
| /// ``customerFacing`` is used. | ||
| /// | ||
| /// Example Usage: | ||
| /// ```swift | ||
| /// let paystack = try PaystackBuilder.newInstance | ||
| /// .setKey("PUBLIC KEY GOES HERE") | ||
| /// .setDisplayAudience(.merchantFacing) | ||
| /// .build() | ||
| /// ``` | ||
| public struct DisplayAudience: Hashable { | ||
|
|
||
| let id: String | ||
|
|
||
| init(id: String) { | ||
| self.id = id | ||
| } | ||
|
|
||
| /// The customer is holding the device and paying on it. This is the default. | ||
| public static let customerFacing = DisplayAudience(id: "customer_facing") | ||
|
|
||
| /// The merchant is holding the device and showing the screen to the customer, | ||
| /// for example on a point-of-sale or terminal app. | ||
| public static let merchantFacing = DisplayAudience(id: "merchant_facing") | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import SwiftUI | ||
| import PaystackCore | ||
|
|
||
| enum AudienceGatedElement: CaseIterable { | ||
| case zapQRCode | ||
| case zapOpenAppButton | ||
| } | ||
|
|
||
| enum AudienceCopy: CaseIterable { | ||
| case zapInstruction | ||
| } | ||
|
|
||
| extension DisplayAudience { | ||
|
|
||
| func shows(_ element: AudienceGatedElement) -> Bool { | ||
| switch element { | ||
| case .zapQRCode: | ||
| return resolve(customerFacing: false, merchantFacing: true) | ||
| case .zapOpenAppButton: | ||
| return resolve(customerFacing: true, merchantFacing: false) | ||
| } | ||
| } | ||
|
|
||
| func text(_ copy: AudienceCopy) -> String { | ||
| switch copy { | ||
| case .zapInstruction: | ||
| return resolve(customerFacing: "Open Zap to complete this payment", | ||
| merchantFacing: "Scan this QR code with Zap to complete this payment") | ||
| } | ||
| } | ||
|
|
||
| private func resolve<Value>(customerFacing: Value, merchantFacing: Value) -> Value { | ||
| self == .merchantFacing ? merchantFacing : customerFacing | ||
| } | ||
| } | ||
|
|
||
| private struct AudienceVisibilityModifier: ViewModifier { | ||
|
|
||
| @Environment(\.displayAudience) | ||
| private var displayAudience | ||
|
|
||
| let element: AudienceGatedElement | ||
|
|
||
| @ViewBuilder | ||
| func body(content: Content) -> some View { | ||
| if displayAudience.shows(element) { | ||
| content | ||
| } | ||
| } | ||
| } | ||
|
|
||
| extension View { | ||
|
|
||
| func visible(for element: AudienceGatedElement) -> some View { | ||
| modifier(AudienceVisibilityModifier(element: element)) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import SwiftUI | ||
| import PaystackCore | ||
|
|
||
| private struct DisplayAudienceKey: EnvironmentKey { | ||
| static let defaultValue: DisplayAudience = .customerFacing | ||
| } | ||
|
|
||
| extension EnvironmentValues { | ||
| var displayAudience: DisplayAudience { | ||
| get { self[DisplayAudienceKey.self] } | ||
| set { self[DisplayAudienceKey.self] = newValue } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.