From b47c1ac4ead7e314d06198023e893c7104c73be1 Mon Sep 17 00:00:00 2001 From: andreykropotov Date: Thu, 3 Sep 2026 22:03:31 +0400 Subject: [PATCH 1/4] chore(deps): move to the native SDKs that carry the gift package flag Android v2.37.0 -> v2.38.0, iOS 3.31.0 -> 3.33.0. --- android/build.gradle.kts | 2 +- ios/rees46_sdk.podspec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/android/build.gradle.kts b/android/build.gradle.kts index 3b1b9e4..3c7b000 100644 --- a/android/build.gradle.kts +++ b/android/build.gradle.kts @@ -87,7 +87,7 @@ android { dependencies { // REES46 Android SDK. - val rees46AndroidSdkVersion = "v2.37.0" + val rees46AndroidSdkVersion = "v2.38.0" add("rees46Implementation", "com.github.rees46:android-sdk:$rees46AndroidSdkVersion") // Used directly by the push presenter (NotificationCompat / ContextCompat). The native SDK diff --git a/ios/rees46_sdk.podspec b/ios/rees46_sdk.podspec index 8c3c268..4949ea5 100644 --- a/ios/rees46_sdk.podspec +++ b/ios/rees46_sdk.podspec @@ -14,7 +14,7 @@ Flutter plugin wrapper around REES46 native SDK. s.source = { :path => '.' } s.source_files = 'Classes/**/*' s.dependency 'Flutter' - s.dependency 'REES46', '3.31.0' + s.dependency 'REES46', '3.33.0' s.platform = :ios, '13.0' # Flutter.framework does not contain a i386 slice. From f2faec8240da7d7a09fe4f2c3c04d4837aa4b2bd Mon Sep 17 00:00:00 2001 From: andreykropotov Date: Thu, 3 Sep 2026 22:03:31 +0400 Subject: [PATCH 2/4] feat(tracking): bridge gift_package through to the natives DEV-T-691. `isGiftPackage` on `tracking.purchase` (and the deprecated `trackPurchase`) reaches the wire as `gift_package` only when true, the way `tax_free` does. Android builds the payload in the bridge, iOS hands the flag to the native request. --- README.md | 1 + .../FlutterTrackingBridge.kt | 9 +++++ .../Rees46FlutterSdkPlugin.kt | 2 ++ .../pigeon/PersonalizationApi.g.kt | 27 ++++++++------- ios/Classes/Rees46FlutterSdkPlugin.swift | 4 ++- ios/Classes/pigeon/PersonalizationApi.g.swift | 27 ++++++++------- lib/src/personalization_sdk.dart | 2 ++ lib/src/pigeon/personalization_api.g.dart | 4 +-- lib/src/tracking/tracking_api.dart | 2 ++ pigeons/personalization_api.dart | 1 + test/personalization_sdk_test.dart | 34 ++++++++++--------- test/tracking_namespace_test.dart | 19 +++++++++++ 12 files changed, 87 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index e94fede..724fdbf 100644 --- a/README.md +++ b/README.md @@ -252,6 +252,7 @@ await sdk.tracking.purchase( deliveryAddress: 'Tverskaya 1, Moscow', paymentType: 'card', isTaxFree: false, + isGiftPackage: true, promocode: 'WINTER20', orderCash: 100.0, orderBonuses: 49.8, diff --git a/android/src/main/kotlin/com/rees46/rees46_flutter_sdk/FlutterTrackingBridge.kt b/android/src/main/kotlin/com/rees46/rees46_flutter_sdk/FlutterTrackingBridge.kt index 24a7614..36b23dd 100644 --- a/android/src/main/kotlin/com/rees46/rees46_flutter_sdk/FlutterTrackingBridge.kt +++ b/android/src/main/kotlin/com/rees46/rees46_flutter_sdk/FlutterTrackingBridge.kt @@ -66,6 +66,7 @@ internal object FlutterTrackingBridge { const val DELIVERY_ADDRESS = "delivery_address" const val PAYMENT_TYPE = "payment_type" const val TAX_FREE = "tax_free" + const val GIFT_PACKAGE = "gift_package" const val PROMOCODE = "promocode" const val ORDER_CASH = "order_cash" const val ORDER_BONUSES = "order_bonuses" @@ -179,6 +180,7 @@ internal object FlutterTrackingBridge { deliveryAddress: String?, paymentType: String?, isTaxFree: Boolean, + isGiftPackage: Boolean, promocode: String?, orderCash: Double?, orderBonuses: Double?, @@ -199,6 +201,7 @@ internal object FlutterTrackingBridge { deliveryAddress = deliveryAddress, paymentType = paymentType, isTaxFree = isTaxFree, + isGiftPackage = isGiftPackage, promocode = promocode, orderCash = orderCash, orderBonuses = orderBonuses, @@ -249,6 +252,7 @@ internal object FlutterTrackingBridge { deliveryAddress: String?, paymentType: String?, isTaxFree: Boolean, + isGiftPackage: Boolean, promocode: String?, orderCash: Double?, orderBonuses: Double?, @@ -303,6 +307,7 @@ internal object FlutterTrackingBridge { deliveryAddress = deliveryAddress, paymentType = paymentType, isTaxFree = isTaxFree, + isGiftPackage = isGiftPackage, promocode = promocode, orderCash = orderCash, orderBonuses = orderBonuses, @@ -328,6 +333,7 @@ internal object FlutterTrackingBridge { deliveryAddress: String?, paymentType: String?, isTaxFree: Boolean, + isGiftPackage: Boolean, promocode: String?, orderCash: Double?, orderBonuses: Double?, @@ -370,6 +376,9 @@ internal object FlutterTrackingBridge { if (isTaxFree) { root.put(PurchaseWireKeys.TAX_FREE, true) } + if (isGiftPackage) { + root.put(PurchaseWireKeys.GIFT_PACKAGE, true) + } promocode?.takeIf { it.isNotBlank() }?.let { root.put(PurchaseWireKeys.PROMOCODE, it) } diff --git a/android/src/main/kotlin/com/rees46/rees46_flutter_sdk/Rees46FlutterSdkPlugin.kt b/android/src/main/kotlin/com/rees46/rees46_flutter_sdk/Rees46FlutterSdkPlugin.kt index 99a169c..a0e49e4 100644 --- a/android/src/main/kotlin/com/rees46/rees46_flutter_sdk/Rees46FlutterSdkPlugin.kt +++ b/android/src/main/kotlin/com/rees46/rees46_flutter_sdk/Rees46FlutterSdkPlugin.kt @@ -694,6 +694,7 @@ class Rees46FlutterSdkPlugin : deliveryAddress: String?, paymentType: String?, isTaxFree: Boolean, + isGiftPackage: Boolean, promocode: String?, orderCash: Double?, orderBonuses: Double?, @@ -731,6 +732,7 @@ class Rees46FlutterSdkPlugin : deliveryAddress = deliveryAddress, paymentType = paymentType, isTaxFree = isTaxFree, + isGiftPackage = isGiftPackage, promocode = promocode, orderCash = orderCash, orderBonuses = orderBonuses, diff --git a/android/src/main/kotlin/com/rees46/rees46_flutter_sdk/pigeon/PersonalizationApi.g.kt b/android/src/main/kotlin/com/rees46/rees46_flutter_sdk/pigeon/PersonalizationApi.g.kt index ada9154..c923cd5 100644 --- a/android/src/main/kotlin/com/rees46/rees46_flutter_sdk/pigeon/PersonalizationApi.g.kt +++ b/android/src/main/kotlin/com/rees46/rees46_flutter_sdk/pigeon/PersonalizationApi.g.kt @@ -514,7 +514,7 @@ interface PersonalizationHostApi { /** Stores the attribution source natively for the next event. */ fun trackSetSource(source: TrackingSourceWire, shopId: String?) /** [customJson] and [recommendedSourceJson] are JSON object strings or null. */ - fun trackPurchase(orderId: String, orderPrice: Double, items: List, deliveryType: String?, deliveryAddress: String?, paymentType: String?, isTaxFree: Boolean, promocode: String?, orderCash: Double?, orderBonuses: Double?, orderDelivery: Double?, orderDiscount: Double?, channel: String?, customJson: String?, recommendedSourceJson: String?, stream: String?, segment: String?, shopId: String?, callback: (Result) -> Unit) + fun trackPurchase(orderId: String, orderPrice: Double, items: List, deliveryType: String?, deliveryAddress: String?, paymentType: String?, isTaxFree: Boolean, isGiftPackage: Boolean, promocode: String?, orderCash: Double?, orderBonuses: Double?, orderDelivery: Double?, orderDiscount: Double?, channel: String?, customJson: String?, recommendedSourceJson: String?, stream: String?, segment: String?, shopId: String?, callback: (Result) -> Unit) companion object { /** The codec used by PersonalizationHostApi. */ @@ -1192,18 +1192,19 @@ interface PersonalizationHostApi { val deliveryAddressArg = args[4] as String? val paymentTypeArg = args[5] as String? val isTaxFreeArg = args[6] as Boolean - val promocodeArg = args[7] as String? - val orderCashArg = args[8] as Double? - val orderBonusesArg = args[9] as Double? - val orderDeliveryArg = args[10] as Double? - val orderDiscountArg = args[11] as Double? - val channelArg = args[12] as String? - val customJsonArg = args[13] as String? - val recommendedSourceJsonArg = args[14] as String? - val streamArg = args[15] as String? - val segmentArg = args[16] as String? - val shopIdArg = args[17] as String? - api.trackPurchase(orderIdArg, orderPriceArg, itemsArg, deliveryTypeArg, deliveryAddressArg, paymentTypeArg, isTaxFreeArg, promocodeArg, orderCashArg, orderBonusesArg, orderDeliveryArg, orderDiscountArg, channelArg, customJsonArg, recommendedSourceJsonArg, streamArg, segmentArg, shopIdArg) { result: Result -> + val isGiftPackageArg = args[7] as Boolean + val promocodeArg = args[8] as String? + val orderCashArg = args[9] as Double? + val orderBonusesArg = args[10] as Double? + val orderDeliveryArg = args[11] as Double? + val orderDiscountArg = args[12] as Double? + val channelArg = args[13] as String? + val customJsonArg = args[14] as String? + val recommendedSourceJsonArg = args[15] as String? + val streamArg = args[16] as String? + val segmentArg = args[17] as String? + val shopIdArg = args[18] as String? + api.trackPurchase(orderIdArg, orderPriceArg, itemsArg, deliveryTypeArg, deliveryAddressArg, paymentTypeArg, isTaxFreeArg, isGiftPackageArg, promocodeArg, orderCashArg, orderBonusesArg, orderDeliveryArg, orderDiscountArg, channelArg, customJsonArg, recommendedSourceJsonArg, streamArg, segmentArg, shopIdArg) { result: Result -> val error = result.exceptionOrNull() if (error != null) { reply.reply(PersonalizationApiPigeonUtils.wrapError(error)) diff --git a/ios/Classes/Rees46FlutterSdkPlugin.swift b/ios/Classes/Rees46FlutterSdkPlugin.swift index 70dc3a0..53523e7 100644 --- a/ios/Classes/Rees46FlutterSdkPlugin.swift +++ b/ios/Classes/Rees46FlutterSdkPlugin.swift @@ -1068,6 +1068,7 @@ final class PersonalizationHostApiImpl: PersonalizationHostApi { deliveryAddress: String?, paymentType: String?, isTaxFree: Bool, + isGiftPackage: Bool, promocode: String?, orderCash: Double?, orderBonuses: Double?, @@ -1127,7 +1128,8 @@ final class PersonalizationHostApiImpl: PersonalizationHostApi { custom: parseJsonObject(customJson), recommendedSource: parseJsonObject(recommendedSourceJson), stream: stream, - segment: segment + segment: segment, + isGiftPackage: isGiftPackage ) sdk.trackPurchase(request, recommendedBy: nil) { result in switch result { diff --git a/ios/Classes/pigeon/PersonalizationApi.g.swift b/ios/Classes/pigeon/PersonalizationApi.g.swift index ed45519..cc8146b 100644 --- a/ios/Classes/pigeon/PersonalizationApi.g.swift +++ b/ios/Classes/pigeon/PersonalizationApi.g.swift @@ -549,7 +549,7 @@ protocol PersonalizationHostApi { /// Stores the attribution source natively for the next event. func trackSetSource(source: TrackingSourceWire, shopId: String?) throws /// [customJson] and [recommendedSourceJson] are JSON object strings or null. - func trackPurchase(orderId: String, orderPrice: Double, items: [PurchaseLineItemWire], deliveryType: String?, deliveryAddress: String?, paymentType: String?, isTaxFree: Bool, promocode: String?, orderCash: Double?, orderBonuses: Double?, orderDelivery: Double?, orderDiscount: Double?, channel: String?, customJson: String?, recommendedSourceJson: String?, stream: String?, segment: String?, shopId: String?, completion: @escaping (Result) -> Void) + func trackPurchase(orderId: String, orderPrice: Double, items: [PurchaseLineItemWire], deliveryType: String?, deliveryAddress: String?, paymentType: String?, isTaxFree: Bool, isGiftPackage: Bool, promocode: String?, orderCash: Double?, orderBonuses: Double?, orderDelivery: Double?, orderDiscount: Double?, channel: String?, customJson: String?, recommendedSourceJson: String?, stream: String?, segment: String?, shopId: String?, completion: @escaping (Result) -> Void) } /// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. @@ -1191,18 +1191,19 @@ class PersonalizationHostApiSetup { let deliveryAddressArg: String? = nilOrValue(args[4]) let paymentTypeArg: String? = nilOrValue(args[5]) let isTaxFreeArg = args[6] as! Bool - let promocodeArg: String? = nilOrValue(args[7]) - let orderCashArg: Double? = nilOrValue(args[8]) - let orderBonusesArg: Double? = nilOrValue(args[9]) - let orderDeliveryArg: Double? = nilOrValue(args[10]) - let orderDiscountArg: Double? = nilOrValue(args[11]) - let channelArg: String? = nilOrValue(args[12]) - let customJsonArg: String? = nilOrValue(args[13]) - let recommendedSourceJsonArg: String? = nilOrValue(args[14]) - let streamArg: String? = nilOrValue(args[15]) - let segmentArg: String? = nilOrValue(args[16]) - let shopIdArg: String? = nilOrValue(args[17]) - api.trackPurchase(orderId: orderIdArg, orderPrice: orderPriceArg, items: itemsArg, deliveryType: deliveryTypeArg, deliveryAddress: deliveryAddressArg, paymentType: paymentTypeArg, isTaxFree: isTaxFreeArg, promocode: promocodeArg, orderCash: orderCashArg, orderBonuses: orderBonusesArg, orderDelivery: orderDeliveryArg, orderDiscount: orderDiscountArg, channel: channelArg, customJson: customJsonArg, recommendedSourceJson: recommendedSourceJsonArg, stream: streamArg, segment: segmentArg, shopId: shopIdArg) { result in + let isGiftPackageArg = args[7] as! Bool + let promocodeArg: String? = nilOrValue(args[8]) + let orderCashArg: Double? = nilOrValue(args[9]) + let orderBonusesArg: Double? = nilOrValue(args[10]) + let orderDeliveryArg: Double? = nilOrValue(args[11]) + let orderDiscountArg: Double? = nilOrValue(args[12]) + let channelArg: String? = nilOrValue(args[13]) + let customJsonArg: String? = nilOrValue(args[14]) + let recommendedSourceJsonArg: String? = nilOrValue(args[15]) + let streamArg: String? = nilOrValue(args[16]) + let segmentArg: String? = nilOrValue(args[17]) + let shopIdArg: String? = nilOrValue(args[18]) + api.trackPurchase(orderId: orderIdArg, orderPrice: orderPriceArg, items: itemsArg, deliveryType: deliveryTypeArg, deliveryAddress: deliveryAddressArg, paymentType: paymentTypeArg, isTaxFree: isTaxFreeArg, isGiftPackage: isGiftPackageArg, promocode: promocodeArg, orderCash: orderCashArg, orderBonuses: orderBonusesArg, orderDelivery: orderDeliveryArg, orderDiscount: orderDiscountArg, channel: channelArg, customJson: customJsonArg, recommendedSourceJson: recommendedSourceJsonArg, stream: streamArg, segment: segmentArg, shopId: shopIdArg) { result in switch result { case .success: reply(wrapResult(nil)) diff --git a/lib/src/personalization_sdk.dart b/lib/src/personalization_sdk.dart index da759e4..a39ae76 100644 --- a/lib/src/personalization_sdk.dart +++ b/lib/src/personalization_sdk.dart @@ -292,6 +292,7 @@ class PersonalizationSdk { String? deliveryAddress, String? paymentType, bool isTaxFree = false, + bool isGiftPackage = false, String? promocode, double? orderCash, double? orderBonuses, @@ -328,6 +329,7 @@ class PersonalizationSdk { deliveryAddress, paymentType, isTaxFree, + isGiftPackage, promocode, orderCash, orderBonuses, diff --git a/lib/src/pigeon/personalization_api.g.dart b/lib/src/pigeon/personalization_api.g.dart index 1a3bdb0..f09d8f5 100644 --- a/lib/src/pigeon/personalization_api.g.dart +++ b/lib/src/pigeon/personalization_api.g.dart @@ -1341,14 +1341,14 @@ class PersonalizationHostApi { } /// [customJson] and [recommendedSourceJson] are JSON object strings or null. - Future trackPurchase(String orderId, double orderPrice, List items, String? deliveryType, String? deliveryAddress, String? paymentType, bool isTaxFree, String? promocode, double? orderCash, double? orderBonuses, double? orderDelivery, double? orderDiscount, String? channel, String? customJson, String? recommendedSourceJson, String? stream, String? segment, String? shopId) async { + Future trackPurchase(String orderId, double orderPrice, List items, String? deliveryType, String? deliveryAddress, String? paymentType, bool isTaxFree, bool isGiftPackage, String? promocode, double? orderCash, double? orderBonuses, double? orderDelivery, double? orderDiscount, String? channel, String? customJson, String? recommendedSourceJson, String? stream, String? segment, String? shopId) async { final String pigeonVar_channelName = 'dev.flutter.pigeon.personalization_flutter_sdk.PersonalizationHostApi.trackPurchase$pigeonVar_messageChannelSuffix'; final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( pigeonVar_channelName, pigeonChannelCodec, binaryMessenger: pigeonVar_binaryMessenger, ); - final Future pigeonVar_sendFuture = pigeonVar_channel.send([orderId, orderPrice, items, deliveryType, deliveryAddress, paymentType, isTaxFree, promocode, orderCash, orderBonuses, orderDelivery, orderDiscount, channel, customJson, recommendedSourceJson, stream, segment, shopId]); + final Future pigeonVar_sendFuture = pigeonVar_channel.send([orderId, orderPrice, items, deliveryType, deliveryAddress, paymentType, isTaxFree, isGiftPackage, promocode, orderCash, orderBonuses, orderDelivery, orderDiscount, channel, customJson, recommendedSourceJson, stream, segment, shopId]); final List? pigeonVar_replyList = await pigeonVar_sendFuture as List?; if (pigeonVar_replyList == null) { diff --git a/lib/src/tracking/tracking_api.dart b/lib/src/tracking/tracking_api.dart index 1221c2d..6ce74a8 100644 --- a/lib/src/tracking/tracking_api.dart +++ b/lib/src/tracking/tracking_api.dart @@ -119,6 +119,7 @@ class TrackingApi { String? deliveryAddress, String? paymentType, bool isTaxFree = false, + bool isGiftPackage = false, String? promocode, double? orderCash, double? orderBonuses, @@ -152,6 +153,7 @@ class TrackingApi { deliveryAddress, paymentType, isTaxFree, + isGiftPackage, promocode, orderCash, orderBonuses, diff --git a/pigeons/personalization_api.dart b/pigeons/personalization_api.dart index 0c6c074..eb80664 100644 --- a/pigeons/personalization_api.dart +++ b/pigeons/personalization_api.dart @@ -329,6 +329,7 @@ abstract class PersonalizationHostApi { String? deliveryAddress, String? paymentType, bool isTaxFree, + bool isGiftPackage, String? promocode, double? orderCash, double? orderBonuses, diff --git a/test/personalization_sdk_test.dart b/test/personalization_sdk_test.dart index b4a2f80..a34182f 100644 --- a/test/personalization_sdk_test.dart +++ b/test/personalization_sdk_test.dart @@ -198,17 +198,17 @@ void main() { expect(wire.fashionSize, isNull); }); - test('custom null → customJson (arg[13]) is null', () async { + test('custom null → customJson (arg[14]) is null', () async { final getArgs = captureArgs(_trackPurchaseChannel); await PersonalizationSdk().trackPurchase( orderId: 'ord', orderPrice: 1.0, items: [const PurchaseLineItem(id: 'x', amount: 1, price: 1.0)], ); - expect(getArgs()[13], isNull); + expect(getArgs()[14], isNull); }); - test('custom provided → valid JSON at arg[13]', () async { + test('custom provided → valid JSON at arg[14]', () async { final getArgs = captureArgs(_trackPurchaseChannel); await PersonalizationSdk().trackPurchase( orderId: 'ord', @@ -216,11 +216,11 @@ void main() { items: [const PurchaseLineItem(id: 'x', amount: 1, price: 1.0)], custom: {'channel': 'app'}, ); - final json = jsonDecode(getArgs()[13] as String) as Map; + final json = jsonDecode(getArgs()[14] as String) as Map; expect(json['channel'], 'app'); }); - test('recommendedSource provided → valid JSON at arg[14]', () async { + test('recommendedSource provided → valid JSON at arg[15]', () async { final getArgs = captureArgs(_trackPurchaseChannel); await PersonalizationSdk().trackPurchase( orderId: 'ord', @@ -228,7 +228,7 @@ void main() { items: [const PurchaseLineItem(id: 'x', amount: 1, price: 1.0)], recommendedSource: {'type': 'popular', 'code': 'rec-1'}, ); - final json = jsonDecode(getArgs()[14] as String) as Map; + final json = jsonDecode(getArgs()[15] as String) as Map; expect(json['type'], 'popular'); expect(json['code'], 'rec-1'); }); @@ -243,6 +243,7 @@ void main() { deliveryAddress: 'Main St', paymentType: 'card', isTaxFree: true, + isGiftPackage: true, promocode: 'SAVE10', orderCash: 0.0, orderBonuses: 5.0, @@ -260,16 +261,17 @@ void main() { expect(args[4], 'Main St'); // deliveryAddress expect(args[5], 'card'); // paymentType expect(args[6], true); // isTaxFree - expect(args[7], 'SAVE10'); // promocode - expect(args[8], 0.0); // orderCash - expect(args[9], 5.0); // orderBonuses - expect(args[10], 0.0); // orderDelivery - expect(args[11], 10.0); // orderDiscount - expect(args[12], 'mobile'); // channel - // args[13] = customJson - // args[14] = recommendedSourceJson - expect(args[15], 'android'); // stream - expect(args[16], 'vip'); // segment + expect(args[7], true); // isGiftPackage + expect(args[8], 'SAVE10'); // promocode + expect(args[9], 0.0); // orderCash + expect(args[10], 5.0); // orderBonuses + expect(args[11], 0.0); // orderDelivery + expect(args[12], 10.0); // orderDiscount + expect(args[13], 'mobile'); // channel + // args[14] = customJson + // args[15] = recommendedSourceJson + expect(args[16], 'android'); // stream + expect(args[17], 'vip'); // segment }); }); } diff --git a/test/tracking_namespace_test.dart b/test/tracking_namespace_test.dart index be6076a..f432d34 100644 --- a/test/tracking_namespace_test.dart +++ b/test/tracking_namespace_test.dart @@ -245,6 +245,25 @@ void main() { expect(args()[1], 100.0); }); + test('purchase sends the gift package flag only when set', () async { + final plain = capture('trackPurchase'); + await PersonalizationSdk().tracking.purchase( + orderId: 'order-1', + orderPrice: 100, + items: const [PurchaseLineItem(id: 'sku-1', amount: 1, price: 100)], + ); + expect(plain()[7], false); + + final gifted = capture('trackPurchase'); + await PersonalizationSdk().tracking.purchase( + orderId: 'order-2', + orderPrice: 100, + items: const [PurchaseLineItem(id: 'sku-1', amount: 1, price: 100)], + isGiftPackage: true, + ); + expect(gifted()[7], true); + }); + test('custom reaches the existing trackEvent channel', () async { final args = capture('trackEvent'); await PersonalizationSdk().tracking.custom( From 231931ed1b140dd7d099c0ddaf8f3c8d9b741465 Mon Sep 17 00:00:00 2001 From: andreykropotov Date: Thu, 3 Sep 2026 22:08:43 +0400 Subject: [PATCH 3/4] chore(example): lock the example app to REES46 3.33.0 --- example/ios/Podfile.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 0fd4771..9db4988 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -7,10 +7,10 @@ PODS: - CocoaAsyncSocket (~> 7.6) - Flutter - FlutterMacOS - - REES46 (3.31.0) + - REES46 (3.33.0) - rees46_sdk (0.0.1): - Flutter - - REES46 (= 3.31.0) + - REES46 (= 3.33.0) DEPENDENCIES: - Flutter (from `Flutter`) @@ -38,8 +38,8 @@ SPEC CHECKSUMS: Flutter: cabc95a1d2626b1b06e7179b784ebcf0c0cde467 integration_test: 4a889634ef21a45d28d50d622cf412dc6d9f586e patrol: cea8074f183a2a4232d0ebd10569ae05149ada42 - REES46: 7ce1596d694a17cad9f5d646e37d31122520d680 - rees46_sdk: cafb55d934fd342eca9c0c4b2d3f5b2f04d2d282 + REES46: 92331668908a711e67515f368a9b00ed775fcffc + rees46_sdk: 8ad2e581dcb34d936af65c5c7af8c9c4c84f5255 PODFILE CHECKSUM: b6e248ac4c1eff5807c8b044b39b8bc326af3f5f From 878b9a53929351d718622a610d899e07c228d405 Mon Sep 17 00:00:00 2001 From: andreykropotov Date: Thu, 3 Sep 2026 22:43:40 +0400 Subject: [PATCH 4/4] refactor(tracking): let the native SDK own the purchase payload MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Android bridge hand-rolled the purchase JSON — wire keys, validation and the reserved-`custom` list — and posted it through the deprecated `SDK.sendAsync`, because published artifacts once had no public `trackPurchase`. They do now, so the plugin builds a `PurchaseTrackingRequest` and calls `sdk.tracking.purchase` the way every other event already goes through the namespace, and 290 lines of duplicated serialization are gone. Two gaps close with it: the stored attribution from `setSource` now reaches purchases, and a popup carried by the purchase response is handled. --- .../FlutterTrackingBridge.kt | 301 +----------------- .../Rees46FlutterSdkPlugin.kt | 58 +++- 2 files changed, 51 insertions(+), 308 deletions(-) diff --git a/android/src/main/kotlin/com/rees46/rees46_flutter_sdk/FlutterTrackingBridge.kt b/android/src/main/kotlin/com/rees46/rees46_flutter_sdk/FlutterTrackingBridge.kt index 36b23dd..72e282f 100644 --- a/android/src/main/kotlin/com/rees46/rees46_flutter_sdk/FlutterTrackingBridge.kt +++ b/android/src/main/kotlin/com/rees46/rees46_flutter_sdk/FlutterTrackingBridge.kt @@ -4,22 +4,21 @@ import com.personalization.SDK import com.personalization.api.OnApiCallbackListener import com.personalization.sdk.data.models.params.UserBasicParams import com.rees46.rees46_flutter_sdk.pigeon.FlutterError -import com.rees46.rees46_flutter_sdk.pigeon.PurchaseLineItemWire import org.json.JSONArray import org.json.JSONException import org.json.JSONObject /** - * Builds tracking JSON and posts via [SDK.sendAsync] for published `rees46-sdk` artifacts that do not - * expose `SDK.trackEvent` / `SDK.trackPurchase` (wire format aligned with personalization-sdk - * `TrackEventManagerImpl` and `PurchaseTrackingJsonBuilder`). + * Builds custom-event JSON and posts via [SDK.sendAsync] for published `rees46-sdk` artifacts that do + * not expose `SDK.trackEvent` (wire format aligned with personalization-sdk `TrackEventManagerImpl`). + * + * Purchases do not go through here: the plugin hands them to `sdk.tracking.purchase`, so the wire + * format, the validation and the reserved-key rules live in the native SDK alone. */ internal object FlutterTrackingBridge { private const val CUSTOM_PUSH_PATH = "push/custom" - private const val PURCHASE_PUSH_PATH = "push" private const val TRACK_EVENT_CLIENT_ERROR_CODE = -1 - private const val TRACK_PURCHASE_CLIENT_ERROR_CODE = -2 private const val KEY_EVENT = "event" private const val KEY_TIME = "time" @@ -51,57 +50,6 @@ internal object FlutterTrackingBridge { add(KEY_CODE) } - private object PurchaseWireKeys { - const val EVENT = "event" - const val PURCHASE_EVENT_VALUE = "purchase" - const val ITEMS = "items" - const val ID = "id" - const val AMOUNT = "amount" - const val PRICE = "price" - const val LINE_ID = "line_id" - const val FASHION_SIZE = "fashion_size" - const val ORDER_ID = "order_id" - const val ORDER_PRICE = "order_price" - const val DELIVERY_TYPE = "delivery_type" - const val DELIVERY_ADDRESS = "delivery_address" - const val PAYMENT_TYPE = "payment_type" - const val TAX_FREE = "tax_free" - const val GIFT_PACKAGE = "gift_package" - const val PROMOCODE = "promocode" - const val ORDER_CASH = "order_cash" - const val ORDER_BONUSES = "order_bonuses" - const val ORDER_DELIVERY = "order_delivery" - const val ORDER_DISCOUNT = "order_discount" - const val CHANNEL = "channel" - const val CUSTOM = "custom" - const val RECOMMENDED_SOURCE = "recommended_source" - const val RECOMMENDED_BY = "recommended_by" - const val RECOMMENDED_CODE = "recommended_code" - } - - private val RESERVED_PURCHASE_CUSTOM_KEYS: Set = - RESERVED_CUSTOM_EVENT_KEYS + - setOf( - PurchaseWireKeys.EVENT, - PurchaseWireKeys.ITEMS, - PurchaseWireKeys.ORDER_ID, - PurchaseWireKeys.ORDER_PRICE, - PurchaseWireKeys.DELIVERY_TYPE, - PurchaseWireKeys.DELIVERY_ADDRESS, - PurchaseWireKeys.PAYMENT_TYPE, - PurchaseWireKeys.TAX_FREE, - PurchaseWireKeys.PROMOCODE, - PurchaseWireKeys.ORDER_CASH, - PurchaseWireKeys.ORDER_BONUSES, - PurchaseWireKeys.ORDER_DELIVERY, - PurchaseWireKeys.ORDER_DISCOUNT, - PurchaseWireKeys.CHANNEL, - PurchaseWireKeys.CUSTOM, - PurchaseWireKeys.RECOMMENDED_SOURCE, - PurchaseWireKeys.RECOMMENDED_BY, - PurchaseWireKeys.RECOMMENDED_CODE, - ) - fun postTrackEvent( sdk: SDK, event: String, @@ -171,245 +119,6 @@ internal object FlutterTrackingBridge { ) } - fun postTrackPurchase( - sdk: SDK, - orderId: String, - orderPrice: Double, - items: List, - deliveryType: String?, - deliveryAddress: String?, - paymentType: String?, - isTaxFree: Boolean, - isGiftPackage: Boolean, - promocode: String?, - orderCash: Double?, - orderBonuses: Double?, - orderDelivery: Double?, - orderDiscount: Double?, - channel: String?, - custom: Map?, - recommendedSource: JSONObject?, - stream: String?, - segment: String?, - callback: (Result) -> Unit, - ) { - val buildResult = buildPurchaseJsonOrError( - orderId = orderId, - orderPrice = orderPrice, - items = items, - deliveryType = deliveryType, - deliveryAddress = deliveryAddress, - paymentType = paymentType, - isTaxFree = isTaxFree, - isGiftPackage = isGiftPackage, - promocode = promocode, - orderCash = orderCash, - orderBonuses = orderBonuses, - orderDelivery = orderDelivery, - orderDiscount = orderDiscount, - channel = channel, - custom = custom, - recommendedSource = recommendedSource, - stream = stream, - segment = segment, - ) - if (buildResult.isFailure) { - callback( - Result.failure( - FlutterError( - "track_purchase_failed", - buildResult.exceptionOrNull()?.message ?: "validation failed", - mapOf("code" to TRACK_PURCHASE_CLIENT_ERROR_CODE), - ), - ), - ) - return - } - val body = buildResult.getOrNull()!! - - @Suppress("DEPRECATION") - sdk.sendAsync( - PURCHASE_PUSH_PATH, - body, - object : OnApiCallbackListener() { - override fun onSuccess(response: JSONObject?) { - callback(Result.success(Unit)) - } - - override fun onError(code: Int, msg: String?) { - val message = listOfNotNull(code.toString(), msg).joinToString(": ") - callback(Result.failure(FlutterError("track_purchase_failed", message, null))) - } - }, - ) - } - - private fun buildPurchaseJsonOrError( - orderId: String, - orderPrice: Double, - items: List, - deliveryType: String?, - deliveryAddress: String?, - paymentType: String?, - isTaxFree: Boolean, - isGiftPackage: Boolean, - promocode: String?, - orderCash: Double?, - orderBonuses: Double?, - orderDelivery: Double?, - orderDiscount: Double?, - channel: String?, - custom: Map?, - recommendedSource: JSONObject?, - stream: String?, - segment: String?, - ): Result { - if (orderId.isBlank()) { - return Result.failure(IllegalArgumentException("trackPurchase: orderId must be non-empty")) - } - if (items.isEmpty()) { - return Result.failure(IllegalArgumentException("trackPurchase: items must not be empty")) - } - for (item in items) { - if (item.id.isBlank()) { - return Result.failure(IllegalArgumentException("trackPurchase: each item.id must be non-empty")) - } - if (item.amount <= 0) { - return Result.failure(IllegalArgumentException("trackPurchase: each item.amount must be > 0")) - } - if (!item.price.isFinite()) { - return Result.failure(IllegalArgumentException("trackPurchase: each item.price must be a finite number")) - } - } - if (!orderPrice.isFinite()) { - return Result.failure(IllegalArgumentException("trackPurchase: orderPrice must be a finite number")) - } - - val effectiveCustom = effectiveCustomFields(custom) - if (effectiveCustom.isNotEmpty()) { - val collisions = effectiveCustom.keys.intersect(RESERVED_PURCHASE_CUSTOM_KEYS) - if (collisions.isNotEmpty()) { - return Result.failure( - IllegalArgumentException( - "trackPurchase: custom contains reserved keys: ${collisions.toSortedSet().joinToString(", ")}", - ), - ) - } - } - - return try { - Result.success( - buildPurchaseJson( - orderId = orderId, - orderPrice = orderPrice, - items = items, - deliveryType = deliveryType, - deliveryAddress = deliveryAddress, - paymentType = paymentType, - isTaxFree = isTaxFree, - isGiftPackage = isGiftPackage, - promocode = promocode, - orderCash = orderCash, - orderBonuses = orderBonuses, - orderDelivery = orderDelivery, - orderDiscount = orderDiscount, - channel = channel, - effectiveCustom = effectiveCustom, - recommendedSource = recommendedSource, - stream = stream, - segment = segment, - ), - ) - } catch (e: JSONException) { - Result.failure(IllegalArgumentException("trackPurchase: failed to build JSON: ${e.message}", e)) - } - } - - private fun buildPurchaseJson( - orderId: String, - orderPrice: Double, - items: List, - deliveryType: String?, - deliveryAddress: String?, - paymentType: String?, - isTaxFree: Boolean, - isGiftPackage: Boolean, - promocode: String?, - orderCash: Double?, - orderBonuses: Double?, - orderDelivery: Double?, - orderDiscount: Double?, - channel: String?, - effectiveCustom: Map, - recommendedSource: JSONObject?, - stream: String?, - segment: String?, - ): JSONObject { - val root = JSONObject() - root.put(PurchaseWireKeys.EVENT, PurchaseWireKeys.PURCHASE_EVENT_VALUE) - root.put(PurchaseWireKeys.ORDER_ID, orderId) - root.put(PurchaseWireKeys.ORDER_PRICE, orderPrice) - - val itemsArray = JSONArray() - for (item in items) { - val row = JSONObject() - row.put(PurchaseWireKeys.ID, item.id) - row.put(PurchaseWireKeys.AMOUNT, item.amount) - row.put(PurchaseWireKeys.PRICE, item.price) - item.lineId?.takeIf { it.isNotBlank() }?.let { row.put(PurchaseWireKeys.LINE_ID, it) } - item.fashionSize?.takeIf { it.isNotBlank() }?.let { - row.put(PurchaseWireKeys.FASHION_SIZE, it) - } - itemsArray.put(row) - } - root.put(PurchaseWireKeys.ITEMS, itemsArray) - - deliveryType?.takeIf { it.isNotBlank() }?.let { - root.put(PurchaseWireKeys.DELIVERY_TYPE, it) - } - deliveryAddress?.takeIf { it.isNotBlank() }?.let { - root.put(PurchaseWireKeys.DELIVERY_ADDRESS, it) - } - paymentType?.takeIf { it.isNotBlank() }?.let { - root.put(PurchaseWireKeys.PAYMENT_TYPE, it) - } - if (isTaxFree) { - root.put(PurchaseWireKeys.TAX_FREE, true) - } - if (isGiftPackage) { - root.put(PurchaseWireKeys.GIFT_PACKAGE, true) - } - promocode?.takeIf { it.isNotBlank() }?.let { - root.put(PurchaseWireKeys.PROMOCODE, it) - } - orderCash?.let { root.put(PurchaseWireKeys.ORDER_CASH, it) } - orderBonuses?.let { root.put(PurchaseWireKeys.ORDER_BONUSES, it) } - orderDelivery?.let { root.put(PurchaseWireKeys.ORDER_DELIVERY, it) } - orderDiscount?.let { root.put(PurchaseWireKeys.ORDER_DISCOUNT, it) } - channel?.takeIf { it.isNotBlank() }?.let { - root.put(PurchaseWireKeys.CHANNEL, it) - } - - if (effectiveCustom.isNotEmpty()) { - val customJson = JSONObject() - for ((key, value) in effectiveCustom) { - putJsonValue(customJson, key, value) - } - root.put(PurchaseWireKeys.CUSTOM, customJson) - } - - recommendedSource?.let { root.put(PurchaseWireKeys.RECOMMENDED_SOURCE, it) } - - stream?.takeIf { it.isNotBlank() }?.let { - root.put(UserBasicParams.STREAM, it) - } - segment?.takeIf { it.isNotBlank() }?.let { - root.put(UserBasicParams.SEGMENT, it) - } - - return root - } - private fun effectiveCustomFields(map: Map?): Map { if (map.isNullOrEmpty()) return emptyMap() val out = LinkedHashMap() diff --git a/android/src/main/kotlin/com/rees46/rees46_flutter_sdk/Rees46FlutterSdkPlugin.kt b/android/src/main/kotlin/com/rees46/rees46_flutter_sdk/Rees46FlutterSdkPlugin.kt index a0e49e4..cdc81fb 100644 --- a/android/src/main/kotlin/com/rees46/rees46_flutter_sdk/Rees46FlutterSdkPlugin.kt +++ b/android/src/main/kotlin/com/rees46/rees46_flutter_sdk/Rees46FlutterSdkPlugin.kt @@ -21,6 +21,8 @@ import com.personalization.Rees46Config import com.personalization.SDK import com.personalization.api.OnApiCallbackListener import com.personalization.api.managers.TrackingApi +import com.personalization.api.models.purchase.PurchaseItemRequest +import com.personalization.api.models.purchase.PurchaseTrackingRequest import com.personalization.api.models.tracking.TrackingItem import com.personalization.api.models.tracking.TrackingSource import com.personalization.api.models.tracking.TrackingSourceType @@ -639,6 +641,42 @@ class Rees46FlutterSdkPlugin : } } + /// The native builder reports client-side validation with this code; the previous + /// hand-rolled path surfaced it in `details`, so keep that shape. + private val PURCHASE_CLIENT_VALIDATION_ERROR_CODE = -2 + + private fun purchaseListener(callback: (Result) -> Unit) = + object : OnApiCallbackListener() { + override fun onSuccess(response: JSONObject?) { + callback(Result.success(Unit)) + } + + override fun onError(code: Int, msg: String?) { + if (code == PURCHASE_CLIENT_VALIDATION_ERROR_CODE) { + callback( + Result.failure( + FlutterError( + "track_purchase_failed", + msg ?: "validation failed", + mapOf("code" to code), + ), + ), + ) + } else { + val message = listOfNotNull(code.toString(), msg).joinToString(": ") + callback(Result.failure(FlutterError("track_purchase_failed", message, null))) + } + } + } + + private fun PurchaseLineItemWire.toNative(): PurchaseItemRequest = PurchaseItemRequest( + id = id, + amount = amount.toInt(), + price = price, + lineId = lineId, + fashionSize = fashionSize, + ) + private fun TrackingItemWire.toNative(): TrackingItem = TrackingItem( id = id, quantity = quantity.toInt(), @@ -717,22 +755,14 @@ class Rees46FlutterSdkPlugin : return } try { - val recommendedSource = - if (recommendedSourceJson.isNullOrBlank()) { - null - } else { - JSONObject(recommendedSourceJson) - } - FlutterTrackingBridge.postTrackPurchase( - sdk = sdk(shopId), + val request = PurchaseTrackingRequest( orderId = orderId, orderPrice = orderPrice, - items = items, + items = items.map { it.toNative() }, deliveryType = deliveryType, deliveryAddress = deliveryAddress, paymentType = paymentType, isTaxFree = isTaxFree, - isGiftPackage = isGiftPackage, promocode = promocode, orderCash = orderCash, orderBonuses = orderBonuses, @@ -740,11 +770,15 @@ class Rees46FlutterSdkPlugin : orderDiscount = orderDiscount, channel = channel, custom = jsonObjectStringToMap(customJson), - recommendedSource = recommendedSource, + recommendedSource = + if (recommendedSourceJson.isNullOrBlank()) null else JSONObject(recommendedSourceJson), stream = stream, segment = segment, - callback = callback, + isGiftPackage = isGiftPackage, ) + // No per-call source: the Dart API only stores one via `setSource`, and the native + // manager attaches that stored attribution itself. + sdk(shopId).tracking.purchase(request, null, purchaseListener(callback)) } catch (t: Throwable) { callback(Result.failure(FlutterError("track_purchase_failed", t.message, null))) }