Skip to content
34 changes: 17 additions & 17 deletions Braintree.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
084135452ED0CBAD00884FE9 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 0841353E2ED0CBAD00884FE9 /* Assets.xcassets */; };
084135472ED0DCCC00884FE9 /* PaymentButtonColorProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 084135462ED0DCCC00884FE9 /* PaymentButtonColorProtocol.swift */; };
0848260C2FAB8DAD008C754F /* ExpirationDateFieldValidatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0848260B2FAB8DAD008C754F /* ExpirationDateFieldValidatorTests.swift */; };
FDCDC009DA7E4809AA4BCE98 /* ExpirationDateFieldViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8A6A6CDCC4845908AF49560 /* ExpirationDateFieldViewModelTests.swift */; };
086D56D02F8566B500120B47 /* CardBrand.swift in Sources */ = {isa = PBXBuildFile; fileRef = 086D56CF2F8566B500120B47 /* CardBrand.swift */; };
086D56D62F8568BB00120B47 /* CardNumberFieldValidatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 086D56D52F8568BB00120B47 /* CardNumberFieldValidatorTests.swift */; };
087831332F7B09CE003BB460 /* BraintreeCard.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A7C889901B5F043B007A0E9C /* BraintreeCard.framework */; platformFilter = ios; };
Expand Down Expand Up @@ -148,8 +147,6 @@
624454DE2DDE399D00A3383B /* CreateCustomerSessionMutationGraphQLBody.swift in Sources */ = {isa = PBXBuildFile; fileRef = 624454DD2DDE398200A3383B /* CreateCustomerSessionMutationGraphQLBody.swift */; };
624B27F72B6AE0C2000AC08A /* BTShopperInsightsError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 624B27F62B6AE0C2000AC08A /* BTShopperInsightsError.swift */; };
625010722F9FF5E000EFB8E0 /* BTSEPADirectDebitClient_IntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 625010712F9FF5D700EFB8E0 /* BTSEPADirectDebitClient_IntegrationTests.swift */; };
701D2C1EC8604C8EBCB24E9A /* BraintreeShopperInsights_IntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 743B93AD5C7644ABAC2D5436 /* BraintreeShopperInsights_IntegrationTests.swift */; };
E943983246FD4C94BAA4C009 /* BraintreeShopperInsights.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 804698302B27C5340090878E /* BraintreeShopperInsights.framework */; };
625719C52F0DBAF6008D019E /* BTHTTPMethod.swift in Sources */ = {isa = PBXBuildFile; fileRef = 625719C42F0DBAE2008D019E /* BTHTTPMethod.swift */; };
62970D102B5AF2C000BAB584 /* BTShopperInsightsAnalytics_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62970D0E2B5AE1E400BAB584 /* BTShopperInsightsAnalytics_Tests.swift */; };
6298A1992B91010600E46EDF /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 6298A1982B91010600E46EDF /* PrivacyInfo.xcprivacy */; };
Expand All @@ -164,6 +161,7 @@
62D5754A2D5299A700DCDAC1 /* ThreeDSecureAuthenticateJWTPOSTBody.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62D575492D5299A700DCDAC1 /* ThreeDSecureAuthenticateJWTPOSTBody.swift */; };
62DE8FBF2B9656BF00F08F53 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 62DE8FBE2B9656BF00F08F53 /* PrivacyInfo.xcprivacy */; };
62EA90492B63071800DD79BC /* BTEligiblePaymentMethods.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62EA90482B63071800DD79BC /* BTEligiblePaymentMethods.swift */; };
701D2C1EC8604C8EBCB24E9A /* BraintreeShopperInsights_IntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 743B93AD5C7644ABAC2D5436 /* BraintreeShopperInsights_IntegrationTests.swift */; };
800E78C429E0DD5300D1B0FC /* FPTIBatchData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 800E78C329E0DD5300D1B0FC /* FPTIBatchData.swift */; };
800ED7832B4F5B66007D8A30 /* BTEligiblePaymentsRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 800ED7822B4F5B66007D8A30 /* BTEligiblePaymentsRequest.swift */; };
800FC544257FDC5100DEE132 /* BTApplePayCardNonce_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 800FC543257FDC5100DEE132 /* BTApplePayCardNonce_Tests.swift */; };
Expand Down Expand Up @@ -442,6 +440,8 @@
BEFE9A3B29C8EC6B00BF69AB /* BTCardClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEFE9A3A29C8EC6B00BF69AB /* BTCardClient.swift */; };
BEFE9A3D29C8ECAA00BF69AB /* BTCardError.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEFE9A3C29C8ECAA00BF69AB /* BTCardError.swift */; };
CE836AA02E4FDCE300AC7FCA /* UIApplication+ApplicationState.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE836A9F2E4FDCE000AC7FCA /* UIApplication+ApplicationState.swift */; };
E943983246FD4C94BAA4C009 /* BraintreeShopperInsights.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 804698302B27C5340090878E /* BraintreeShopperInsights.framework */; };
FDCDC009DA7E4809AA4BCE98 /* ExpirationDateFieldViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8A6A6CDCC4845908AF49560 /* ExpirationDateFieldViewModelTests.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -487,21 +487,21 @@
remoteGlobalIDString = A7C8898F1B5F043B007A0E9C;
remoteInfo = BraintreeCard;
};
622160F32FA103570072377B /* PBXContainerItemProxy */ = {
19BBD08D78BD4A2AB8A39FC4 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = A75DA344192138F000D997A2 /* Project object */;
proxyType = 1;
remoteGlobalIDString = BEF3F17227CE9EC600072467;
remoteInfo = BraintreeSEPADirectDebit;
remoteGlobalIDString = 8046982F2B27C5340090878E;
remoteInfo = BraintreeShopperInsights;
};
804698432B27C5530090878E /* PBXContainerItemProxy */ = {
622160F32FA103570072377B /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = A75DA344192138F000D997A2 /* Project object */;
proxyType = 1;
remoteGlobalIDString = 8046982F2B27C5340090878E;
remoteInfo = BraintreeShopperInsights;
remoteGlobalIDString = BEF3F17227CE9EC600072467;
remoteInfo = BraintreeSEPADirectDebit;
};
19BBD08D78BD4A2AB8A39FC4 /* PBXContainerItemProxy */ = {
804698432B27C5530090878E /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = A75DA344192138F000D997A2 /* Project object */;
proxyType = 1;
Expand Down Expand Up @@ -854,7 +854,6 @@
084135402ED0CBAD00884FE9 /* VenmoButtonColor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VenmoButtonColor.swift; sourceTree = "<group>"; };
084135462ED0DCCC00884FE9 /* PaymentButtonColorProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaymentButtonColorProtocol.swift; sourceTree = "<group>"; };
0848260B2FAB8DAD008C754F /* ExpirationDateFieldValidatorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExpirationDateFieldValidatorTests.swift; sourceTree = "<group>"; };
C8A6A6CDCC4845908AF49560 /* ExpirationDateFieldViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExpirationDateFieldViewModelTests.swift; sourceTree = "<group>"; };
086D56CF2F8566B500120B47 /* CardBrand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardBrand.swift; sourceTree = "<group>"; };
086D56D52F8568BB00120B47 /* CardNumberFieldValidatorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardNumberFieldValidatorTests.swift; sourceTree = "<group>"; };
087831382F7C1666003BB460 /* ValidationResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ValidationResult.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -984,7 +983,6 @@
624454DD2DDE398200A3383B /* CreateCustomerSessionMutationGraphQLBody.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreateCustomerSessionMutationGraphQLBody.swift; sourceTree = "<group>"; };
624B27F62B6AE0C2000AC08A /* BTShopperInsightsError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTShopperInsightsError.swift; sourceTree = "<group>"; };
625010712F9FF5D700EFB8E0 /* BTSEPADirectDebitClient_IntegrationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTSEPADirectDebitClient_IntegrationTests.swift; sourceTree = "<group>"; };
743B93AD5C7644ABAC2D5436 /* BraintreeShopperInsights_IntegrationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BraintreeShopperInsights_IntegrationTests.swift; sourceTree = "<group>"; };
625719C42F0DBAE2008D019E /* BTHTTPMethod.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTHTTPMethod.swift; sourceTree = "<group>"; };
62970D0E2B5AE1E400BAB584 /* BTShopperInsightsAnalytics_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTShopperInsightsAnalytics_Tests.swift; sourceTree = "<group>"; };
6298A1982B91010600E46EDF /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
Expand All @@ -999,6 +997,7 @@
62D575492D5299A700DCDAC1 /* ThreeDSecureAuthenticateJWTPOSTBody.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThreeDSecureAuthenticateJWTPOSTBody.swift; sourceTree = "<group>"; };
62DE8FBE2B9656BF00F08F53 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
62EA90482B63071800DD79BC /* BTEligiblePaymentMethods.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTEligiblePaymentMethods.swift; sourceTree = "<group>"; };
743B93AD5C7644ABAC2D5436 /* BraintreeShopperInsights_IntegrationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BraintreeShopperInsights_IntegrationTests.swift; sourceTree = "<group>"; };
800E23DC22206A8300C5D22E /* BTThreeDSecureAuthenticateJWT_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTThreeDSecureAuthenticateJWT_Tests.swift; sourceTree = "<group>"; };
800E78C329E0DD5300D1B0FC /* FPTIBatchData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FPTIBatchData.swift; sourceTree = "<group>"; };
800ED7822B4F5B66007D8A30 /* BTEligiblePaymentsRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTEligiblePaymentsRequest.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1269,6 +1268,7 @@
BEFE6DA927E28A0B002BE9C8 /* MockViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockViewController.swift; sourceTree = "<group>"; };
BEFE9A3A29C8EC6B00BF69AB /* BTCardClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTCardClient.swift; sourceTree = "<group>"; };
BEFE9A3C29C8ECAA00BF69AB /* BTCardError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTCardError.swift; sourceTree = "<group>"; };
C8A6A6CDCC4845908AF49560 /* ExpirationDateFieldViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExpirationDateFieldViewModelTests.swift; sourceTree = "<group>"; };
CE836A9F2E4FDCE000AC7FCA /* UIApplication+ApplicationState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIApplication+ApplicationState.swift"; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -4219,16 +4219,16 @@
target = BEF3F17227CE9EC600072467 /* BraintreeSEPADirectDebit */;
targetProxy = 622160F32FA103570072377B /* PBXContainerItemProxy */;
};
804698442B27C5530090878E /* PBXTargetDependency */ = {
66A126AF330B4AF798BC043F /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
platformFilter = ios;
target = 8046982F2B27C5340090878E /* BraintreeShopperInsights */;
targetProxy = 804698432B27C5530090878E /* PBXContainerItemProxy */;
targetProxy = 19BBD08D78BD4A2AB8A39FC4 /* PBXContainerItemProxy */;
};
66A126AF330B4AF798BC043F /* PBXTargetDependency */ = {
804698442B27C5530090878E /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
platformFilter = ios;
target = 8046982F2B27C5340090878E /* BraintreeShopperInsights */;
targetProxy = 19BBD08D78BD4A2AB8A39FC4 /* PBXContainerItemProxy */;
targetProxy = 804698432B27C5530090878E /* PBXContainerItemProxy */;
};
80AB42522B27CAC200249218 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
Expand Down
16 changes: 14 additions & 2 deletions Sources/BraintreeUIComponents/CardFields/CardFields.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import BraintreeCard
import BraintreeCore
import SwiftUI

/// A SwiftUI view that renders a complete card entry form, including fields for card number,
Expand All @@ -11,6 +12,7 @@ public struct CardFields: View {
@StateObject private var viewModel: CardFieldsViewModel
@State private var containerWidth: CGFloat = CardFieldsConstants.defaultContainerWidth
private var onValidityChange: ((Bool, @escaping () -> Void) -> Void)?
private var apiClient: BTAPIClient

private var useHorizontalLayout: Bool {
containerWidth >= CardFieldsConstants.horizontalLayoutThreshold
Expand Down Expand Up @@ -48,10 +50,19 @@ public struct CardFields: View {
completion: completion
)
)

self.apiClient = BTAPIClient(authorization: authorization)
}

// MARK: - View

private var submitAction: () -> Void {
{
apiClient.sendAnalyticsEvent(UIComponentsAnalytics.cardFieldsValidated)
viewModel.tokenize()
}
}

public var body: some View {
VStack(spacing: 12) {
CardNumberFieldView(
Expand Down Expand Up @@ -85,10 +96,11 @@ public struct CardFields: View {
}
)
.onAppear {
onValidityChange?(viewModel.isFormValid, viewModel.tokenize)
apiClient.sendAnalyticsEvent(UIComponentsAnalytics.cardFieldsPresented)
onValidityChange?(viewModel.isFormValid, submitAction)
}
.onChange(of: viewModel.isFormValid) { _, isValid in
onValidityChange?(isValid, viewModel.tokenize)
onValidityChange?(isValid, submitAction)
}
}

Expand Down
5 changes: 5 additions & 0 deletions Sources/BraintreeUIComponents/UIComponentsAnalytics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import Foundation

enum UIComponentsAnalytics {

// MARK: - Card Fields Events

static let cardFieldsPresented = "ui-components:card-fields:presented"
static let cardFieldsValidated = "ui-components:card-fields:validated"

// MARK: - PayPal Button Events

static let payPalButtonPresented = "ui-components:paypal-button:presented"
Expand Down
Loading