Skip to content

Commit

Permalink
Cleanup revenue deprecated api
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey70 committed Nov 28, 2023
1 parent 389d3c6 commit 4a604aa
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 115 deletions.
4 changes: 2 additions & 2 deletions AppMetricaCore/Protos/Revenue.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ message Revenue
}

optional uint32 quantity = 1 [default = 1];
optional double price = 2;
reserved 2;
required bytes currency = 3; // ISO 4217
optional bytes product_id = 4; // arbitrary string
optional bytes payload = 5; // arbitrary JSON, same rules as for EVENT_CLIENT

optional Receipt receipt = 6; // data for revenue validation

optional int64 price_micros = 7; // Price value in micros(price * 10^6). If this field is filled, price field is ignored. Used in Android(3.7.0+) and iOS (3.7.0+).
optional int64 price_micros = 7; // Price value in micros(price * 10^6).

optional bool auto_collected = 8 [default = false];

Expand Down
81 changes: 14 additions & 67 deletions AppMetricaCore/Sources/AMARevenueInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

@interface AMARevenueInfo ()

@property (nonatomic, assign, readwrite) double price;
@property (nonatomic, strong, readwrite) NSDecimalNumber *priceDecimal;
@property (nonatomic, copy, readwrite) NSString *currency;

Expand All @@ -20,17 +19,6 @@ @interface AMARevenueInfo ()

@implementation AMARevenueInfo

- (instancetype)initWithPrice:(double)price currency:(NSString *)currency
{
return [self initWithPrice:price
currency:currency
quantity:kAMARevenueInfoDefaultQuantity
productID:nil
transactionID:nil
receiptData:nil
payload:nil];
}

- (instancetype)initWithPriceDecimal:(NSDecimalNumber *)priceDecimal
currency:(NSString *)currency
{
Expand All @@ -43,54 +31,16 @@ - (instancetype)initWithPriceDecimal:(NSDecimalNumber *)priceDecimal
payload:nil];
}

- (instancetype)initWithPrice:(double)price
currency:(NSString *)currency
quantity:(NSUInteger)quantity
productID:(NSString *)productID
transactionID:(NSString *)transactionID
receiptData:(NSData *)receiptData
payload:(NSDictionary *)payload
{
return [self initWithPrice:price
priceDecimal:nil
currency:currency
quantity:quantity
productID:productID
transactionID:transactionID
receiptData:receiptData
payload:payload];
}

- (instancetype)initWithPriceDecimal:(NSDecimalNumber *)priceDecimal
currency:(NSString *)currency
quantity:(NSUInteger)quantity
productID:(NSString *)productID
transactionID:(NSString *)transactionID
receiptData:(NSData *)receiptData
payload:(NSDictionary *)payload
{
return [self initWithPrice:0.0
priceDecimal:priceDecimal
currency:currency
quantity:quantity
productID:productID
transactionID:transactionID
receiptData:receiptData
payload:payload];
}

- (instancetype)initWithPrice:(double)price
priceDecimal:(NSDecimalNumber *)priceDecimal
currency:(NSString *)currency
quantity:(NSUInteger)quantity
productID:(NSString *)productID
transactionID:(NSString *)transactionID
receiptData:(NSData *)receiptData
payload:(NSDictionary *)payload
{
self = [super init];
if (self != nil) {
_price = price;
_priceDecimal = priceDecimal;
_currency = [currency copy];

Expand All @@ -110,21 +60,19 @@ - (id)copyWithZone:(nullable NSZone *)zone

- (id)mutableCopyWithZone:(nullable NSZone *)zone
{
return [[AMAMutableRevenueInfo alloc] initWithPrice:self.price
priceDecimal:self.priceDecimal
currency:self.currency
quantity:self.quantity
productID:self.productID
transactionID:self.transactionID
receiptData:self.receiptData
payload:self.payload];
return [[AMAMutableRevenueInfo alloc] initWithPriceDecimal:self.priceDecimal
currency:self.currency
quantity:self.quantity
productID:self.productID
transactionID:self.transactionID
receiptData:self.receiptData
payload:self.payload];
}

@end

@implementation AMAMutableRevenueInfo

@dynamic price;
@dynamic priceDecimal;
@dynamic currency;
@dynamic quantity;
Expand All @@ -135,14 +83,13 @@ @implementation AMAMutableRevenueInfo

- (id)copyWithZone:(nullable NSZone *)zone
{
return [[AMARevenueInfo alloc] initWithPrice:self.price
priceDecimal:self.priceDecimal
currency:self.currency
quantity:self.quantity
productID:self.productID
transactionID:self.transactionID
receiptData:self.receiptData
payload:self.payload];
return [[AMARevenueInfo alloc] initWithPriceDecimal:self.priceDecimal
currency:self.currency
quantity:self.quantity
productID:self.productID
transactionID:self.transactionID
receiptData:self.receiptData
payload:self.payload];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ - (AMALightRevenueEvent *)eventFromSerializedValue:(id)value
priceMicros = [[NSDecimalNumber alloc] initWithLongLong:revenueData->price_micros];
}
else {
priceMicros = [[NSDecimalNumber alloc] initWithDouble:(revenueData->price * 1000000)];
priceMicros = [NSDecimalNumber zero];
}
NSString *currency = [AMAProtobufUtilities stringForBinaryData:&revenueData->currency];
return [[AMALightRevenueEvent alloc] initWithPriceMicros:priceMicros
Expand Down
44 changes: 16 additions & 28 deletions AppMetricaCore/Sources/Generated/Revenue.pb-c.c
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ const ProtobufCEnumDescriptor ama__revenue__in_app_type__descriptor =
static const uint32_t ama__revenue__quantity__default_value = 1u;
static const protobuf_c_boolean ama__revenue__auto_collected__default_value = 0;
static const Ama__Revenue__InAppType ama__revenue__in_app_type__default_value = AMA__REVENUE__IN_APP_TYPE__PURCHASE;
static const ProtobufCFieldDescriptor ama__revenue__field_descriptors[11] =
static const ProtobufCFieldDescriptor ama__revenue__field_descriptors[10] =
{
{
"quantity",
Expand All @@ -556,18 +556,6 @@ static const ProtobufCFieldDescriptor ama__revenue__field_descriptors[11] =
0, /* flags */
0,NULL,NULL /* reserved1,reserved2, etc */
},
{
"price",
2,
PROTOBUF_C_LABEL_OPTIONAL,
PROTOBUF_C_TYPE_DOUBLE,
offsetof(Ama__Revenue, has_price),
offsetof(Ama__Revenue, price),
NULL,
NULL,
0, /* flags */
0,NULL,NULL /* reserved1,reserved2, etc */
},
{
"currency",
3,
Expand Down Expand Up @@ -678,23 +666,23 @@ static const ProtobufCFieldDescriptor ama__revenue__field_descriptors[11] =
},
};
static const unsigned ama__revenue__field_indices_by_name[] = {
7, /* field[7] = auto_collected */
2, /* field[2] = currency */
8, /* field[8] = in_app_type */
4, /* field[4] = payload */
1, /* field[1] = price */
6, /* field[6] = price_micros */
3, /* field[3] = product_id */
6, /* field[6] = auto_collected */
1, /* field[1] = currency */
7, /* field[7] = in_app_type */
3, /* field[3] = payload */
5, /* field[5] = price_micros */
2, /* field[2] = product_id */
0, /* field[0] = quantity */
5, /* field[5] = receipt */
10, /* field[10] = subscription_info */
9, /* field[9] = transaction_info */
4, /* field[4] = receipt */
9, /* field[9] = subscription_info */
8, /* field[8] = transaction_info */
};
static const ProtobufCIntRange ama__revenue__number_ranges[2 + 1] =
static const ProtobufCIntRange ama__revenue__number_ranges[3 + 1] =
{
{ 1, 0 },
{ 10, 8 },
{ 0, 11 }
{ 3, 1 },
{ 10, 7 },
{ 0, 10 }
};
const ProtobufCMessageDescriptor ama__revenue__descriptor =
{
Expand All @@ -704,10 +692,10 @@ const ProtobufCMessageDescriptor ama__revenue__descriptor =
"Ama__Revenue",
"ama",
sizeof(Ama__Revenue),
11,
10,
ama__revenue__field_descriptors,
ama__revenue__field_indices_by_name,
2, ama__revenue__number_ranges,
3, ama__revenue__number_ranges,
(ProtobufCMessageInit) ama__revenue__init,
NULL,NULL,NULL /* reserved[123] */
};
6 changes: 2 additions & 4 deletions AppMetricaCore/Sources/Generated/Revenue.pb-c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ - (NSData *)dataWithRevenueInfoModel:(AMARevenueInfoModel *)model
revenue.receipt = [self receiptForRevenueInfoModel:model tracker:tracker];
BOOL hasDecimalPrice = model.priceDecimal != nil;

revenue.has_price = hasDecimalPrice == NO;
revenue.has_price_micros = hasDecimalPrice;
if (hasDecimalPrice) {
revenue.has_price_micros = [AMADecimalUtils fillMicrosValue:&revenue.price_micros
Expand Down
12 changes: 0 additions & 12 deletions AppMetricaCore/Tests/AMARevenueInfoModelSerializerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,6 @@
transactionInfo:nil];
revenue = serializeAndDeserializeModel(model);
});
it(@"Should fill price", ^{
[[theValue(revenue->price) should] equal:0 withDelta:DBL_EPSILON];
});
it(@"Should fill has_price", ^{
[[theValue(revenue->has_price) should] beYes];
});
it(@"Should not fill has_price_micros", ^{
[[theValue(revenue->has_price_micros) should] beNo];
});
Expand Down Expand Up @@ -148,12 +142,6 @@
transactionInfo:transaction];
revenue = serializeAndDeserializeModel(model);
});
it(@"Should not fill price", ^{
[[theValue(revenue->price) should] equal:0.0 withDelta:DBL_EPSILON];
});
it(@"Should fill has_price", ^{
[[theValue(revenue->has_price) should] beNo];
});
it(@"Should fill price_micros", ^{
[[theValue(revenue->price_micros) should] equal:theValue(23550000)];
});
Expand Down

0 comments on commit 4a604aa

Please sign in to comment.