@@ -76,6 +76,12 @@ import BraintreeDataCollector
7676 /// Used for analytics purposes, to determine if browser-presentation event is associated with a locally cached, or remotely fetched `BTConfiguration`
7777 private var isConfigFromCache : Bool ?
7878
79+ /// Used for analytics purpose to determine if user opted to save PayPal for future purchases and a vaulted billing agreement was created with the charge.
80+ private var shouldRequestBillingAgreement : Bool ?
81+
82+ /// Used for analytics purpose to determine if there is a recurring billing plan type, or charge pattern.
83+ private var recurringBillingPlanType : String ?
84+
7985 /// Used for analytics purpose to determine if the context type is `BA-TOKEN` or `EC-TOKEN`
8086 private var contextType : String ?
8187
@@ -139,6 +145,8 @@ import BraintreeDataCollector
139145 isVaultRequest = true
140146 contextType = " BA-TOKEN "
141147 fundingSource = getFundingSource ( from: request)
148+ shouldRequestBillingAgreement = false
149+ recurringBillingPlanType = request. recurringBillingPlanType? . rawValue
142150 tokenize ( request: request, completion: completion)
143151 }
144152
@@ -184,6 +192,8 @@ import BraintreeDataCollector
184192 isVaultRequest = false
185193 contextType = " EC-TOKEN "
186194 fundingSource = getFundingSource ( from: request)
195+ shouldRequestBillingAgreement = request. requestBillingAgreement
196+ recurringBillingPlanType = request. recurringBillingPlanType? . rawValue
187197 tokenize ( request: request, completion: completion)
188198 }
189199
@@ -231,7 +241,9 @@ import BraintreeDataCollector
231241 didPayPalServerAttemptAppSwitch: didPayPalServerAttemptAppSwitch,
232242 fundingSource: fundingSource? . rawValue,
233243 isVaultRequest: isVaultRequest,
234- shopperSessionID: payPalRequest? . shopperSessionID
244+ recurringBillingPlanType: recurringBillingPlanType,
245+ shopperSessionID: payPalRequest? . shopperSessionID,
246+ shouldRequestBillingAgreement: shouldRequestBillingAgreement
235247 )
236248
237249 guard
@@ -314,7 +326,9 @@ import BraintreeDataCollector
314326 didEnablePayPalAppSwitch: payPalRequest? . enablePayPalAppSwitch,
315327 didPayPalServerAttemptAppSwitch: didPayPalServerAttemptAppSwitch,
316328 fundingSource: fundingSource? . rawValue,
317- isVaultRequest: isVaultRequest
329+ isVaultRequest: isVaultRequest,
330+ recurringBillingPlanType: recurringBillingPlanType,
331+ shouldRequestBillingAgreement: shouldRequestBillingAgreement
318332 )
319333 BTPayPalClient . payPalClient = self
320334 appSwitchCompletion = completion
@@ -328,7 +342,9 @@ import BraintreeDataCollector
328342 didEnablePayPalAppSwitch: payPalRequest? . enablePayPalAppSwitch,
329343 didPayPalServerAttemptAppSwitch: didPayPalServerAttemptAppSwitch,
330344 fundingSource: fundingSource? . rawValue,
331- isVaultRequest: isVaultRequest
345+ isVaultRequest: isVaultRequest,
346+ recurringBillingPlanType: recurringBillingPlanType,
347+ shouldRequestBillingAgreement: shouldRequestBillingAgreement
332348 )
333349
334350 openURLInDefaultBrowser ( url, completion: completion)
@@ -346,7 +362,9 @@ import BraintreeDataCollector
346362 didPayPalServerAttemptAppSwitch: didPayPalServerAttemptAppSwitch,
347363 fundingSource: fundingSource? . rawValue,
348364 isVaultRequest: isVaultRequest,
349- shopperSessionID: payPalRequest? . shopperSessionID
365+ recurringBillingPlanType: recurringBillingPlanType,
366+ shopperSessionID: payPalRequest? . shopperSessionID,
367+ shouldRequestBillingAgreement: shouldRequestBillingAgreement
350368 )
351369
352370 application. open ( url, options: [ : ] ) { success in
@@ -370,7 +388,9 @@ import BraintreeDataCollector
370388 didEnablePayPalAppSwitch: payPalRequest? . enablePayPalAppSwitch,
371389 didPayPalServerAttemptAppSwitch: didPayPalServerAttemptAppSwitch,
372390 fundingSource: fundingSource? . rawValue,
373- isVaultRequest: isVaultRequest
391+ isVaultRequest: isVaultRequest,
392+ recurringBillingPlanType: recurringBillingPlanType,
393+ shouldRequestBillingAgreement: shouldRequestBillingAgreement
374394 )
375395
376396 if isSuccess {
@@ -422,7 +442,9 @@ import BraintreeDataCollector
422442 didEnablePayPalAppSwitch: payPalRequest? . enablePayPalAppSwitch,
423443 fundingSource: fundingSource? . rawValue,
424444 isVaultRequest: isVaultRequest,
425- shopperSessionID: payPalRequest? . shopperSessionID
445+ recurringBillingPlanType: recurringBillingPlanType,
446+ shopperSessionID: payPalRequest? . shopperSessionID,
447+ shouldRequestBillingAgreement: shouldRequestBillingAgreement
426448 )
427449 apiClient. fetchOrReturnRemoteConfiguration { configuration, error in
428450 if let error {
@@ -474,7 +496,6 @@ import BraintreeDataCollector
474496 }
475497
476498 self . contextID = approvalURL. baToken ?? approvalURL. ecToken
477-
478499 self . experiment = approvalURL. experiment
479500
480501 let dataCollector = BTDataCollector ( authorization: self . apiClient. authorization. originalValue)
@@ -530,7 +551,9 @@ import BraintreeDataCollector
530551 didPayPalServerAttemptAppSwitch: didPayPalServerAttemptAppSwitch,
531552 fundingSource: fundingSource? . rawValue,
532553 isVaultRequest: isVaultRequest,
533- shopperSessionID: payPalRequest? . shopperSessionID
554+ recurringBillingPlanType: recurringBillingPlanType,
555+ shopperSessionID: payPalRequest? . shopperSessionID,
556+ shouldRequestBillingAgreement: shouldRequestBillingAgreement
534557 )
535558
536559 return
@@ -549,7 +572,9 @@ import BraintreeDataCollector
549572 didPayPalServerAttemptAppSwitch: didPayPalServerAttemptAppSwitch,
550573 fundingSource: fundingSource? . rawValue,
551574 isVaultRequest: isVaultRequest,
552- shopperSessionID: payPalRequest? . shopperSessionID
575+ recurringBillingPlanType: recurringBillingPlanType,
576+ shopperSessionID: payPalRequest? . shopperSessionID,
577+ shouldRequestBillingAgreement: shouldRequestBillingAgreement
553578 )
554579
555580 var urlComponents = URLComponents ( url: payPalAppRedirectURL, resolvingAgainstBaseURL: true )
@@ -589,7 +614,9 @@ import BraintreeDataCollector
589614 didPayPalServerAttemptAppSwitch: didPayPalServerAttemptAppSwitch,
590615 fundingSource: fundingSource? . rawValue,
591616 isVaultRequest: isVaultRequest,
592- shopperSessionID: payPalRequest? . shopperSessionID
617+ recurringBillingPlanType: recurringBillingPlanType,
618+ shopperSessionID: payPalRequest? . shopperSessionID,
619+ shouldRequestBillingAgreement: shouldRequestBillingAgreement
593620 )
594621
595622 approvalURL = appSwitchURL
@@ -641,7 +668,9 @@ import BraintreeDataCollector
641668 fundingSource: fundingSource? . rawValue,
642669 isConfigFromCache: isConfigFromCache,
643670 isVaultRequest: isVaultRequest,
644- shopperSessionID: payPalRequest? . shopperSessionID
671+ recurringBillingPlanType: recurringBillingPlanType,
672+ shopperSessionID: payPalRequest? . shopperSessionID,
673+ shouldRequestBillingAgreement: shouldRequestBillingAgreement
645674 )
646675 } else {
647676 apiClient. sendAnalyticsEvent (
@@ -654,7 +683,9 @@ import BraintreeDataCollector
654683 didPayPalServerAttemptAppSwitch: didPayPalServerAttemptAppSwitch,
655684 fundingSource: fundingSource? . rawValue,
656685 isVaultRequest: isVaultRequest,
657- shopperSessionID: payPalRequest? . shopperSessionID
686+ recurringBillingPlanType: recurringBillingPlanType,
687+ shopperSessionID: payPalRequest? . shopperSessionID,
688+ shouldRequestBillingAgreement: shouldRequestBillingAgreement
658689 )
659690 }
660691 } sessionDidCancel: { [ self ] in
@@ -671,7 +702,9 @@ import BraintreeDataCollector
671702 didEnablePayPalAppSwitch: payPalRequest? . enablePayPalAppSwitch,
672703 didPayPalServerAttemptAppSwitch: didPayPalServerAttemptAppSwitch,
673704 fundingSource: fundingSource? . rawValue,
674- isVaultRequest: isVaultRequest
705+ isVaultRequest: isVaultRequest,
706+ recurringBillingPlanType: recurringBillingPlanType,
707+ shouldRequestBillingAgreement: shouldRequestBillingAgreement
675708 )
676709 }
677710
@@ -692,7 +725,9 @@ import BraintreeDataCollector
692725 didPayPalServerAttemptAppSwitch: didPayPalServerAttemptAppSwitch,
693726 fundingSource: fundingSource? . rawValue,
694727 isVaultRequest: isVaultRequest,
695- shopperSessionID: payPalRequest? . shopperSessionID
728+ recurringBillingPlanType: recurringBillingPlanType,
729+ shopperSessionID: payPalRequest? . shopperSessionID,
730+ shouldRequestBillingAgreement: shouldRequestBillingAgreement
696731 )
697732 }
698733 }
@@ -729,7 +764,9 @@ import BraintreeDataCollector
729764 didPayPalServerAttemptAppSwitch: didPayPalServerAttemptAppSwitch,
730765 fundingSource: fundingSource? . rawValue,
731766 isVaultRequest: isVaultRequest,
732- shopperSessionID: payPalRequest? . shopperSessionID
767+ recurringBillingPlanType: recurringBillingPlanType,
768+ shopperSessionID: payPalRequest? . shopperSessionID,
769+ shouldRequestBillingAgreement: shouldRequestBillingAgreement
733770 )
734771 completion ( result, nil )
735772 }
@@ -746,7 +783,9 @@ import BraintreeDataCollector
746783 errorDescription: error. localizedDescription,
747784 fundingSource: fundingSource? . rawValue,
748785 isVaultRequest: isVaultRequest,
749- shopperSessionID: payPalRequest? . shopperSessionID
786+ recurringBillingPlanType: recurringBillingPlanType,
787+ shopperSessionID: payPalRequest? . shopperSessionID,
788+ shouldRequestBillingAgreement: shouldRequestBillingAgreement
750789 )
751790 completion ( nil , error)
752791 }
@@ -761,7 +800,9 @@ import BraintreeDataCollector
761800 didPayPalServerAttemptAppSwitch: didPayPalServerAttemptAppSwitch,
762801 fundingSource: fundingSource? . rawValue,
763802 isVaultRequest: isVaultRequest,
764- shopperSessionID: payPalRequest? . shopperSessionID
803+ recurringBillingPlanType: recurringBillingPlanType,
804+ shopperSessionID: payPalRequest? . shopperSessionID,
805+ shouldRequestBillingAgreement: shouldRequestBillingAgreement
765806 )
766807 completion ( nil , BTPayPalError . canceled)
767808 }
0 commit comments