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

Deprecate BTCardRequest #1129

Merged
merged 5 commits into from
Nov 3, 2023
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
## unreleased
* BraintreeThreeDSecure
* Add `cardAddChallengeRequested` to `BTThreeDSecureRequest`
* BraintreeCard
* Deprecate unused `BTCardRequest` class

## 5.24.0 (2023-10-30)
* BraintreePayPalDataCollector
Expand Down
15 changes: 7 additions & 8 deletions Sources/BraintreeCard/BTCardClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import BraintreeCore
@objc(tokenizeCard:completion:)
public func tokenize(_ card: BTCard, completion: @escaping (BTCardNonce?, Error?) -> Void) {
apiClient.sendAnalyticsEvent(BTCardAnalytics.cardTokenizeStarted)
let request = BTCardRequest(card: card)

apiClient.fetchOrReturnRemoteConfiguration() { configuration, error in
if let error {
Expand All @@ -47,12 +46,12 @@ import BraintreeCore
}

if self.isGraphQLEnabled(for: configuration) {
if request.card.authenticationInsightRequested && request.card.merchantAccountID == nil {
if card.authenticationInsightRequested && card.merchantAccountID == nil {
self.notifyFailure(with: BTCardError.integration, completion: completion)
return
}

let parameters = request.card.graphQLParameters()
let parameters = card.graphQLParameters()

self.apiClient.post("", parameters: parameters, httpType: .graphQLAPI) { body, _, error in
if let error = error as NSError? {
Expand Down Expand Up @@ -80,7 +79,7 @@ import BraintreeCore
return
}
} else {
let parameters = self.clientAPIParameters(for: request)
let parameters = self.clientAPIParameters(for: card)

self.apiClient.post("v1/payment_methods/credit_cards", parameters: parameters) {body, _, error in
if let error = error as NSError? {
Expand Down Expand Up @@ -137,9 +136,9 @@ import BraintreeCore
return false
}

private func clientAPIParameters(for request: BTCardRequest) -> [String: Any] {
private func clientAPIParameters(for card: BTCard) -> [String: Any] {
var parameters: [String: Any] = [:]
parameters["credit_card"] = request.card.parameters()
parameters["credit_card"] = card.parameters()

let metadata: [String: String] = [
"source": apiClient.metadata.source.stringValue,
Expand All @@ -149,9 +148,9 @@ import BraintreeCore

parameters["_meta"] = metadata

if request.card.authenticationInsightRequested {
if card.authenticationInsightRequested {
parameters["authenticationInsight"] = true
parameters["merchantAccountId"] = request.card.merchantAccountID
parameters["merchantAccountId"] = card.merchantAccountID
}

return parameters
Expand Down
2 changes: 2 additions & 0 deletions Sources/BraintreeCard/BTCardRequest.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Foundation

/// Contains information about a card to tokenize
// TODO: - NEXT_MAJOR_VERSION remove this class
@available(*, deprecated, message: "Use BTCard directly instead")
@objcMembers public class BTCardRequest: NSObject {

/// The `BTCard` associated with this instance.
Expand Down