-
Notifications
You must be signed in to change notification settings - Fork 294
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
BTShopperInsights
public API shell (#1142)
- Add public API shell for the Payment Insights feature - `BTShopperInsightsClient` - `BTShopperInsightsResult` - `BTShopperInsightsRequest` - Add template unit test file for ` BTShopperInsightsClient_Tests`
- Loading branch information
Showing
5 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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,27 @@ | ||
import Foundation | ||
|
||
/// Use `BTShopperInsightsClient` to optimize your checkout experience by prioritizing the customer’s preferred payment methods in your UI. | ||
/// By customizing each customer’s checkout experience, you can improve conversion, increase sales/repeat buys and boost user retention/loyalty. | ||
/// - Note: This feature is in beta. It's public API may change or be removed in future releases. | ||
public class BTShopperInsightsClient { | ||
|
||
private let apiClient: BTAPIClient | ||
|
||
/// Creates a `BTShopperInsightsClient` | ||
/// - Parameter apiClient: A `BTAPIClient` instance. | ||
/// - Note: This features only works with a client token. | ||
public init(apiClient: BTAPIClient) { | ||
self.apiClient = apiClient | ||
} | ||
|
||
/// This method confirms if the customer is a user of PayPal services using their email and phone number. | ||
/// - Parameters: | ||
/// - request: A `BTShopperInsightsRequest` containing the buyer's user information | ||
/// - Returns: A `BTShopperInsightsResult` instance | ||
/// - Note: This feature is in beta. It's public API may change or be removed in future releases. | ||
public func getRecommendedPaymentMethods(request: BTShopperInsightsRequest) async throws -> BTShopperInsightsResult { | ||
// TODO: - Add isAppInstalled checks for PP & Venmo. DTBTSDK-3176 | ||
// TODO: - Make API call to PaymentReadyAPI. DTBTSDK-3176 | ||
return BTShopperInsightsResult() | ||
} | ||
} |
This file contains 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,28 @@ | ||
import Foundation | ||
|
||
/// Buyer data required to use the Shopper Insights feature. | ||
/// - Note: This feature is in beta. It's public API may change or be removed in future releases. | ||
public struct BTShopperInsightsRequest { | ||
|
||
/// The buyer's email address. | ||
private let email: String | ||
|
||
/// The buyer's country code prefix to the national telephone number. An identifier for a specific country. | ||
/// Must not contain special characters. | ||
private let phoneCountryCode: String | ||
|
||
/// The buyer's national phone number. Must not contain special characters. | ||
private let phoneNationalNumber: String | ||
|
||
/// Initialize a `BTShopperInsightsRequest` | ||
/// - Parameters: | ||
/// - email: The buyer's email address. | ||
/// - phoneCountryCode: The buyer's country code prefix to the national telephone number. An identifier for a specific country. Must not contain special characters. | ||
/// - phoneNationalNumber: The buyer's national phone number. Must not contain special characters. | ||
/// - Note: This feature is in beta. It's public API may change or be removed in future releases. | ||
public init(email: String, phoneCountryCode: String, phoneNationalNumber: String) { | ||
self.email = email | ||
self.phoneCountryCode = phoneCountryCode | ||
self.phoneNationalNumber = phoneNationalNumber | ||
} | ||
} |
This file contains 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,12 @@ | ||
import Foundation | ||
|
||
/// A summary of the buyer's recommended payment methods. | ||
/// - Note: This feature is in beta. It's public API may change or be removed in future releases. | ||
public struct BTShopperInsightsResult { | ||
|
||
/// If true, display the PayPal button with high priority. | ||
public var isPayPalRecommended = false | ||
|
||
/// If true, dislpay the Venmo button with high priority. | ||
public var isVenmoRecommended = false | ||
} |
27 changes: 27 additions & 0 deletions
27
UnitTests/BraintreeCoreTests/BTShopperInsightsClient_Tests.swift
This file contains 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,27 @@ | ||
import Foundation | ||
import XCTest | ||
@testable import BraintreeCore | ||
@testable import BraintreeTestShared | ||
|
||
class BTShopperInsightsClient_Tests: XCTestCase { | ||
|
||
var mockAPIClient = MockAPIClient(authorization: "development_client_key")! | ||
var sut: BTShopperInsightsClient! | ||
|
||
override func setUp() { | ||
super.setUp() | ||
sut = BTShopperInsightsClient(apiClient: mockAPIClient) | ||
} | ||
|
||
func testGetRecommendedPaymentMethods_returnsDefaultRecommendations() async { | ||
let request = BTShopperInsightsRequest( | ||
email: "fake-email", | ||
phoneCountryCode: "fake-country-code", | ||
phoneNationalNumber: "fake-national-phone" | ||
) | ||
let result = try? await sut.getRecommendedPaymentMethods(request: request) | ||
|
||
XCTAssertNotNil(result!.isPayPalRecommended) | ||
XCTAssertNotNil(result!.isVenmoRecommended) | ||
} | ||
} |