-
Notifications
You must be signed in to change notification settings - Fork 995
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Configure AppInfo for IdentityAPIClient (#814)
Creates an `IdentityAPIClientImpl` implementation of the `IdentityAPIClient` protocol which wraps an `STPAPIClient` and configures the beta headers and appInfo. This also simplifies the Identity code by making all of the networking logic self-contained in `IdentityAPIClient`. Because none of the Identity API requests use a public key but instead use an ephemeral key secret, we're able to instantiate an APIClient using the ephemeral key secret in place of the public key.
- Loading branch information
1 parent
b38ab85
commit 03636f7
Showing
15 changed files
with
398 additions
and
355 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
112 changes: 112 additions & 0 deletions
112
StripeIdentity/StripeIdentity/Source/API Bindings/IdentityAPIClient.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,112 @@ | ||
// | ||
// IdentityAPIClient.swift | ||
// StripeIdentity | ||
// | ||
// Created by Mel Ludowise on 10/26/21. | ||
// | ||
|
||
import Foundation | ||
import UIKit | ||
@_spi(STP) import StripeCore | ||
|
||
protocol IdentityAPIClient { | ||
var verificationSessionId: String { get } | ||
|
||
func getIdentityVerificationPage() -> Promise<VerificationPage> | ||
|
||
func updateIdentityVerificationPageData( | ||
updating verificationData: VerificationPageDataUpdate | ||
) -> Promise<VerificationPageData> | ||
|
||
func submitIdentityVerificationPage() -> Promise<VerificationPageData> | ||
|
||
func uploadImage( | ||
_ image: UIImage, | ||
compressionQuality: CGFloat, | ||
purpose: String, | ||
fileName: String | ||
) -> Promise<StripeFile> | ||
} | ||
|
||
final class IdentityAPIClientImpl: IdentityAPIClient { | ||
static let apiVersion: Int = 1 | ||
|
||
static var betas: Set<String> { | ||
return ["identity_client_api=v\(apiVersion)"] | ||
} | ||
|
||
let apiClient: STPAPIClient | ||
let verificationSessionId: String | ||
|
||
private init( | ||
verificationSessionId: String, | ||
apiClient: STPAPIClient | ||
) { | ||
self.verificationSessionId = verificationSessionId | ||
self.apiClient = apiClient | ||
} | ||
|
||
convenience init( | ||
verificationSessionId: String, | ||
ephemeralKeySecret: String | ||
) { | ||
let apiClient = STPAPIClient(publishableKey: ephemeralKeySecret) | ||
apiClient.betas = IdentityAPIClientImpl.betas | ||
apiClient.appInfo = STPAPIClient.shared.appInfo | ||
|
||
self.init( | ||
verificationSessionId: verificationSessionId, | ||
apiClient: apiClient | ||
) | ||
} | ||
|
||
func getIdentityVerificationPage() -> Promise<VerificationPage> { | ||
return apiClient.get( | ||
resource: APIEndpointVerificationPage(id: verificationSessionId), | ||
parameters: [:] | ||
) | ||
} | ||
|
||
func updateIdentityVerificationPageData( | ||
updating verificationData: VerificationPageDataUpdate | ||
) -> Promise<VerificationPageData> { | ||
return apiClient.post( | ||
resource: APIEndpointVerificationPageData(id: verificationSessionId), | ||
object: verificationData | ||
) | ||
} | ||
|
||
func submitIdentityVerificationPage() -> Promise<VerificationPageData> { | ||
return apiClient.post( | ||
resource: APIEndpointVerificationPageSubmit(id: verificationSessionId), | ||
parameters: [:] | ||
) | ||
} | ||
|
||
func uploadImage( | ||
_ image: UIImage, | ||
compressionQuality: CGFloat, | ||
purpose: String, | ||
fileName: String | ||
) -> Promise<StripeFile> { | ||
return apiClient.uploadImage( | ||
image, | ||
compressionQuality: compressionQuality, | ||
purpose: purpose, | ||
fileName: fileName, | ||
ownedBy: verificationSessionId | ||
) | ||
} | ||
|
||
|
||
} | ||
|
||
private func APIEndpointVerificationPage(id: String) -> String { | ||
return "identity/verification_pages/\(id)" | ||
} | ||
private func APIEndpointVerificationPageData(id: String) -> String { | ||
return "identity/verification_pages/\(id)/data" | ||
} | ||
private func APIEndpointVerificationPageSubmit(id: String) -> String { | ||
return "identity/verification_pages/\(id)/submit" | ||
} |
92 changes: 0 additions & 92 deletions
92
StripeIdentity/StripeIdentity/Source/API Bindings/STPAPIClient+Identity.swift
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.