From 078bd4606e95ee0b9d6106fa6df750d945e8894d Mon Sep 17 00:00:00 2001 From: rekrutik Date: Mon, 7 Nov 2022 20:25:28 +0300 Subject: [PATCH] Add receipt support for revenue logging --- .../AmplitudeFlutterPlugin.kt | 8 +++++ example/pubspec.lock | 31 +++++++------------ ios/Classes/SwiftAmplitudeFlutterPlugin.swift | 6 ++++ lib/amplitude.dart | 12 ++++++- 4 files changed, 37 insertions(+), 20 deletions(-) diff --git a/android/src/main/kotlin/com/amplitude/amplitude_flutter/AmplitudeFlutterPlugin.kt b/android/src/main/kotlin/com/amplitude/amplitude_flutter/AmplitudeFlutterPlugin.kt index e37c3bf..1fb73fe 100644 --- a/android/src/main/kotlin/com/amplitude/amplitude_flutter/AmplitudeFlutterPlugin.kt +++ b/android/src/main/kotlin/com/amplitude/amplitude_flutter/AmplitudeFlutterPlugin.kt @@ -161,6 +161,14 @@ class AmplitudeFlutterPlugin : FlutterPlugin, MethodCallHandler { val revenue = Revenue().setProductId(json.getString("productIdentifier")) .setPrice(json.getDouble("price")) .setQuantity(json.getInt("quantity")) + json.optString("revenueType", null)?.let { it -> + revenue.setRevenueType(it) + } + val receipt = json.optString("receipt", null) + val receiptSignature = json.optString("receiptSignature", null) + if (receipt != null && receiptSignature != null) { + revenue.setReceipt(receipt, receiptSignature) + } client.logRevenueV2(revenue) result.success("logRevenue called..") diff --git a/example/pubspec.lock b/example/pubspec.lock index 6432320..809a22d 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -14,7 +14,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.8.2" + version: "2.9.0" boolean_selector: dependency: transitive description: @@ -28,21 +28,14 @@ packages: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" - charcode: - dependency: transitive - description: - name: charcode - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.1" + version: "1.2.1" clock: dependency: transitive description: name: clock url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.1.1" collection: dependency: transitive description: @@ -63,7 +56,7 @@ packages: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.3.1" flutter: dependency: "direct main" description: flutter @@ -92,28 +85,28 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.11" + version: "0.12.12" material_color_utilities: dependency: transitive description: name: material_color_utilities url: "https://pub.dartlang.org" source: hosted - version: "0.1.4" + version: "0.1.5" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.7.0" + version: "1.8.0" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.1" + version: "1.8.2" sky_engine: dependency: transitive description: flutter @@ -125,7 +118,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.2" + version: "1.9.0" stack_trace: dependency: transitive description: @@ -146,21 +139,21 @@ packages: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.1.1" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.2.1" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.4.9" + version: "0.4.12" vector_math: dependency: transitive description: diff --git a/ios/Classes/SwiftAmplitudeFlutterPlugin.swift b/ios/Classes/SwiftAmplitudeFlutterPlugin.swift index 657a687..3ac11e5 100644 --- a/ios/Classes/SwiftAmplitudeFlutterPlugin.swift +++ b/ios/Classes/SwiftAmplitudeFlutterPlugin.swift @@ -124,6 +124,12 @@ import Amplitude revenue.setProductIdentifier((args["productIdentifier"] as! String)) revenue.setQuantity(args["quantity"] as! Int) revenue.setPrice(NSNumber(value: args["price"] as! Double)) + if let revenueType = args["revenueType"] as? String { + revenue.setRevenueType(revenueType) + } + if let receipt = args["receipt"] as? String { + revenue.setReceipt(Data(base64Encoded: receipt, options: .ignoreUnknownCharacters)) + } Amplitude.instance(withName: instanceName).logRevenueV2(revenue) diff --git a/lib/amplitude.dart b/lib/amplitude.dart index 185512f..9423102 100644 --- a/lib/amplitude.dart +++ b/lib/amplitude.dart @@ -152,11 +152,21 @@ class Amplitude extends _Amplitude { /// active user (ARPDAU), 7, 30, and 90 day revenue, lifetime value (LTV) /// estimates, and revenue by advertising campaign cohort and daily/weekly/monthly cohorts. Future logRevenue( - String productIdentifier, int quantity, double price) async { + String productIdentifier, int quantity, double price, + {String? revenueType, String? receipt, String? receiptSignature,}) async { Map properties = _baseProperties(); properties['productIdentifier'] = productIdentifier; properties['quantity'] = quantity; properties['price'] = price; + if (revenueType != null) { + properties['revenueType'] = revenueType; + } + if (receipt != null) { + properties['receipt'] = receipt; + } + if (receiptSignature != null) { + properties['receiptSignature'] = receiptSignature; + } return await _channel.invokeMethod('logRevenue', jsonEncode(properties)); }