Skip to content

Commit

Permalink
Deprecate BTCardRequest (#1129)
Browse files Browse the repository at this point in the history
  • Loading branch information
scannillo authored Nov 3, 2023
1 parent 9c9f462 commit e40b421
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
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

0 comments on commit e40b421

Please sign in to comment.