-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- UI Enhancements - Added support for iOS 14
- Loading branch information
Showing
64 changed files
with
1,421 additions
and
223 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
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,29 @@ | ||
// | ||
// Copyright 2018 - Present Hyperwallet | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software | ||
// and associated documentation files (the "Software"), to deal in the Software without restriction, | ||
// including without limitation the rights to use, copy, modify, merge, publish, distribute, | ||
// sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all copies or | ||
// substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING | ||
// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
//! Project version number for BalanceRepository. | ||
FOUNDATION_EXPORT double BalanceRepositoryVersionNumber; | ||
|
||
//! Project version string for BalanceRepository. | ||
FOUNDATION_EXPORT const unsigned char BalanceRepositoryVersionString[]; | ||
|
||
// In this header, you should import all the public headers of your framework using statements like #import <BalanceRepository/PublicHeader.h> | ||
|
||
|
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,41 @@ | ||
import HyperwalletSDK | ||
|
||
/// Balance repository factory | ||
public final class BalanceRepositoryFactory { | ||
private static var instance: BalanceRepositoryFactory? | ||
private var remoteUserBalanceRepository: UserBalanceRepository | ||
private var remotePrepaidCardBalanceRepository: PrepaidCardBalanceRepository | ||
|
||
/// Returns the previously initialized instance of the BalanceRepositoryFactory object | ||
public static var shared: BalanceRepositoryFactory { | ||
guard let instance = instance else { | ||
self.instance = BalanceRepositoryFactory() | ||
return self.instance! | ||
} | ||
return instance | ||
} | ||
|
||
private init() { | ||
remoteUserBalanceRepository = RemoteUserBalanceRepository() | ||
remotePrepaidCardBalanceRepository = RemotePrepaidCardBalanceRepository() | ||
} | ||
|
||
/// Clears the BalanceRepositoryFactory singleton instance. | ||
public static func clearInstance() { | ||
instance = nil | ||
} | ||
|
||
/// Gets the `UserBalanceRepository` implementation. | ||
/// | ||
/// - Returns: The implementation of the UserBalanceRepository protocol | ||
public func userBalanceRepository() -> UserBalanceRepository { | ||
return remoteUserBalanceRepository | ||
} | ||
|
||
/// Gets the `PrepaidCardBalanceRepository` implementation. | ||
/// | ||
/// - Returns: The implementation of the PrepaidCardBalanceRepository protocol | ||
public func prepaidCardBalanceRepository() -> PrepaidCardBalanceRepository { | ||
return remotePrepaidCardBalanceRepository | ||
} | ||
} |
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,22 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>CFBundleDevelopmentRegion</key> | ||
<string>$(DEVELOPMENT_LANGUAGE)</string> | ||
<key>CFBundleExecutable</key> | ||
<string>$(EXECUTABLE_NAME)</string> | ||
<key>CFBundleIdentifier</key> | ||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> | ||
<key>CFBundleInfoDictionaryVersion</key> | ||
<string>6.0</string> | ||
<key>CFBundleName</key> | ||
<string>$(PRODUCT_NAME)</string> | ||
<key>CFBundlePackageType</key> | ||
<string>FMWK</string> | ||
<key>CFBundleShortVersionString</key> | ||
<string>$(MARKETING_VERSION)</string> | ||
<key>CFBundleVersion</key> | ||
<string>$(CURRENT_PROJECT_VERSION)</string> | ||
</dict> | ||
</plist> |
58 changes: 58 additions & 0 deletions
58
BalanceRepository/Sources/PrepaidCardBalanceRepository.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,58 @@ | ||
import HyperwalletSDK | ||
|
||
/// Prepaid Card balance repository protocol | ||
public protocol PrepaidCardBalanceRepository { | ||
/// Returns the list of balances for the Prepaid Card associated with the authentication user. | ||
/// | ||
/// - Parameters: | ||
/// - offset: The number of records to skip. If no filters are applied, records will be skipped from the | ||
/// beginning (based on default sort criteria). Range is from 0 to {n-1} where | ||
/// n = number of matching records for the query. | ||
/// - limit: The maximum number of records that will be returned per page. | ||
/// - completion: The callback handler of responses from the Hyperwallet platform. | ||
func listPrepaidCardBalances(prepaidCardToken: String, | ||
offset: Int, | ||
limit: Int, | ||
completion: @escaping (Result<HyperwalletPageList<HyperwalletBalance>?, | ||
HyperwalletErrorType>) -> Void) | ||
} | ||
|
||
/// Prepaid Card balance repository | ||
public final class RemotePrepaidCardBalanceRepository: PrepaidCardBalanceRepository { | ||
public func listPrepaidCardBalances(prepaidCardToken: String, | ||
offset: Int, | ||
limit: Int, | ||
completion: @escaping (Result<HyperwalletPageList<HyperwalletBalance>?, | ||
HyperwalletErrorType>) -> Void) { | ||
Hyperwallet.shared.listPrepaidCardBalances(prepaidCardToken: prepaidCardToken, | ||
queryParam: setUpPrepaidCardBalanceQueryParam(offset, limit), | ||
completion: listPrepaidCardBalancesHandler(completion)) | ||
} | ||
|
||
/// Preparid card balance response handler | ||
private func listPrepaidCardBalancesHandler( | ||
_ completion: @escaping (Result<HyperwalletPageList<HyperwalletBalance>?, | ||
HyperwalletErrorType>) -> Void) | ||
-> (HyperwalletPageList<HyperwalletBalance>?, HyperwalletErrorType?) -> Void { | ||
return { (result, error) in | ||
if let error = error { | ||
DispatchQueue.main.async { | ||
completion(.failure(error)) | ||
} | ||
} else { | ||
DispatchQueue.main.async { | ||
completion(.success(result)) | ||
} | ||
} | ||
} | ||
} | ||
|
||
/// Set up prepaid card balance query param | ||
private func setUpPrepaidCardBalanceQueryParam(_ offset: Int, _ limit: Int) | ||
-> HyperwalletPrepaidCardBalanceQueryParam { | ||
let queryParam = HyperwalletPrepaidCardBalanceQueryParam() | ||
queryParam.offset = offset | ||
queryParam.limit = limit | ||
return queryParam | ||
} | ||
} |
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,44 @@ | ||
import HyperwalletSDK | ||
|
||
/// User balance repository protocol | ||
public protocol UserBalanceRepository { | ||
/// Returns the list of balances for the User associated with the authentication token. | ||
/// | ||
/// - Parameters: | ||
/// - offset: The number of records to skip. If no filters are applied, records will be skipped from the | ||
/// beginning (based on default sort criteria). Range is from 0 to {n-1} where | ||
/// n = number of matching records for the query. | ||
/// - limit: The maximum number of records that will be returned per page. | ||
/// - completion: The callback handler of responses from the Hyperwallet platform. | ||
func listUserBalances( offset: Int, | ||
limit: Int, | ||
completion: @escaping (Result<HyperwalletPageList<HyperwalletBalance>?, | ||
HyperwalletErrorType>) -> Void) | ||
} | ||
|
||
/// User balance repository | ||
public final class RemoteUserBalanceRepository: UserBalanceRepository { | ||
public func listUserBalances( offset: Int, | ||
limit: Int, | ||
completion: @escaping (Result<HyperwalletPageList<HyperwalletBalance>?, | ||
HyperwalletErrorType>) -> Void) { | ||
Hyperwallet.shared.listUserBalances(queryParam: setUpBalanceQueryParam(offset, limit), | ||
completion: listUserBalancesHandler(completion)) | ||
} | ||
|
||
private func listUserBalancesHandler( | ||
_ completion: @escaping (Result<HyperwalletPageList<HyperwalletBalance>?, | ||
HyperwalletErrorType>) -> Void) | ||
-> (HyperwalletPageList<HyperwalletBalance>?, HyperwalletErrorType?) -> Void { | ||
return { (result, error) in if let error = error { | ||
DispatchQueue.main.async { completion(.failure(error)) } } else { | ||
DispatchQueue.main.async { completion(.success(result)) } } } | ||
} | ||
|
||
private func setUpBalanceQueryParam(_ offset: Int, _ limit: Int) -> HyperwalletBalanceQueryParam { | ||
let queryParam = HyperwalletBalanceQueryParam() | ||
queryParam.offset = offset | ||
queryParam.limit = limit | ||
return queryParam | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
BalanceRepository/Tests/BalanceRepositoryFactoryTests.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,22 @@ | ||
import BalanceRepository | ||
import XCTest | ||
|
||
class BalanceRepositoryFactoryTests: XCTestCase { | ||
func testBalanceRepository() { | ||
let factory = BalanceRepositoryFactory.shared | ||
|
||
XCTAssertNotNil(factory, "BalanceRepositoryFactory instance should not be nil") | ||
XCTAssertNoThrow(factory.userBalanceRepository(), "BalanceRepository should exist") | ||
XCTAssertNoThrow(factory.prepaidCardBalanceRepository(), "PrepaidCardBalanceRepository should exist") | ||
} | ||
|
||
func testClearInstance() { | ||
let factory = BalanceRepositoryFactory.shared | ||
BalanceRepositoryFactory.clearInstance() | ||
let recreatedFactory = BalanceRepositoryFactory.shared | ||
|
||
XCTAssertNotNil(factory, "Previously created BalanceRepositoryFactory instance should not be nil") | ||
XCTAssertNotNil(recreatedFactory, "Recreated BalanceRepositoryFactory instance should not be nil") | ||
XCTAssertFalse(factory === recreatedFactory, "Factory instances should not be the same") | ||
} | ||
} |
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,43 @@ | ||
// | ||
// Copyright 2018 - Present Hyperwallet | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software | ||
// and associated documentation files (the "Software"), to deal in the Software without restriction, | ||
// including without limitation the rights to use, copy, modify, merge, publish, distribute, | ||
// sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all copies or | ||
// substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING | ||
// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
import Hippolyte | ||
import HyperwalletSDK | ||
import XCTest | ||
|
||
class PrepaidCardBalanceRequestHelper { | ||
static func setUpRequest(_ payload: Data, | ||
_ error: NSError? = nil, | ||
_ prepaidCardToken: String? = nil, | ||
_ httpCode: Int = 200) -> StubRequest { | ||
let response = HyperwalletTestHelper.setUpMockedResponse(payload: payload, error: error) | ||
let balanceURL = "/prepaid-cards/\(prepaidCardToken!)/balances?" | ||
let url = String(format: "%@%@", HyperwalletTestHelper.userRestURL, balanceURL) | ||
return HyperwalletTestHelper.buildGetRequestRegexMatcher(pattern: url, response) | ||
} | ||
} | ||
|
||
class UserBalanceRequestHelper { | ||
static func setUpRequest(_ payload: Data, | ||
_ error: NSError? = nil, | ||
_ httpCode: Int = 200) -> StubRequest { | ||
let response = HyperwalletTestHelper.setUpMockedResponse(payload: payload, error: error) | ||
let url = String(format: "%@/balances?", HyperwalletTestHelper.userRestURL) | ||
return HyperwalletTestHelper.buildGetRequestRegexMatcher(pattern: url, response) | ||
} | ||
} |
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,22 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>CFBundleDevelopmentRegion</key> | ||
<string>$(DEVELOPMENT_LANGUAGE)</string> | ||
<key>CFBundleExecutable</key> | ||
<string>$(EXECUTABLE_NAME)</string> | ||
<key>CFBundleIdentifier</key> | ||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> | ||
<key>CFBundleInfoDictionaryVersion</key> | ||
<string>6.0</string> | ||
<key>CFBundleName</key> | ||
<string>$(PRODUCT_NAME)</string> | ||
<key>CFBundlePackageType</key> | ||
<string>BNDL</string> | ||
<key>CFBundleShortVersionString</key> | ||
<string>$(MARKETING_VERSION)</string> | ||
<key>CFBundleVersion</key> | ||
<string>$(CURRENT_PROJECT_VERSION)</string> | ||
</dict> | ||
</plist> |
Oops, something went wrong.