forked from adjust/ios_sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathADJSubscription.m
143 lines (114 loc) · 4.2 KB
/
ADJSubscription.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
//
// ADJSubscription.m
// Adjust
//
// Created by Uglješa Erceg on 16.04.20.
// Copyright © 2020 adjust GmbH. All rights reserved.
//
#import "ADJUtil.h"
#import "ADJSubscription.h"
#import "ADJAdjustFactory.h"
@interface ADJSubscription()
@property (nonatomic, weak) id<ADJLogger> logger;
@property (nonatomic, strong) NSMutableDictionary *mutableCallbackParameters;
@property (nonatomic, strong) NSMutableDictionary *mutablePartnerParameters;
@end
@implementation ADJSubscription
- (nullable id)initWithPrice:(nonnull NSDecimalNumber *)price
currency:(nonnull NSString *)currency
transactionId:(nonnull NSString *)transactionId
andReceipt:(nonnull NSData *)receipt {
self = [super init];
if (self == nil) {
return nil;
}
_price = [price copy];
_currency = [currency copy];
_transactionId = [transactionId copy];
_receipt = [receipt copy];
_billingStore = @"iOS";
_logger = ADJAdjustFactory.logger;
return self;
}
- (void)setTransactionDate:(NSDate *)transactionDate {
@synchronized (self) {
_transactionDate = [transactionDate copy];
}
}
- (void)setSalesRegion:(NSString *)salesRegion {
@synchronized (self) {
_salesRegion = [salesRegion copy];
}
}
- (void)addCallbackParameter:(nonnull NSString *)key
value:(nonnull NSString *)value
{
@synchronized (self) {
NSString *immutableKey = [key copy];
NSString *immutableValue = [value copy];
if (![ADJUtil isValidParameter:immutableKey
attributeType:@"key"
parameterName:@"Callback"]) {
return;
}
if (![ADJUtil isValidParameter:immutableValue
attributeType:@"value"
parameterName:@"Callback"]) {
return;
}
if (self.mutableCallbackParameters == nil) {
self.mutableCallbackParameters = [[NSMutableDictionary alloc] init];
}
if ([self.mutableCallbackParameters objectForKey:immutableKey]) {
[self.logger warn:@"key %@ was overwritten", immutableKey];
}
[self.mutableCallbackParameters setObject:immutableValue forKey:immutableKey];
}
}
- (void)addPartnerParameter:(nonnull NSString *)key
value:(nonnull NSString *)value
{
@synchronized (self) {
NSString *immutableKey = [key copy];
NSString *immutableValue = [value copy];
if (![ADJUtil isValidParameter:immutableKey
attributeType:@"key"
parameterName:@"Partner"]) {
return;
}
if (![ADJUtil isValidParameter:immutableValue
attributeType:@"value"
parameterName:@"Partner"]) {
return;
}
if (self.mutablePartnerParameters == nil) {
self.mutablePartnerParameters = [[NSMutableDictionary alloc] init];
}
if ([self.mutablePartnerParameters objectForKey:immutableKey]) {
[self.logger warn:@"key %@ was overwritten", immutableKey];
}
[self.mutablePartnerParameters setObject:immutableValue forKey:immutableKey];
}
}
- (nonnull NSDictionary *)callbackParameters {
return [self.mutableCallbackParameters copy];
}
- (nonnull NSDictionary *)partnerParameters {
return [self.mutablePartnerParameters copy];
}
- (id)copyWithZone:(NSZone *)zone {
ADJSubscription *copy = [[[self class] allocWithZone:zone] init];
if (copy) {
copy->_price = [self.price copyWithZone:zone];
copy->_currency = [self.currency copyWithZone:zone];
copy->_transactionId = [self.transactionId copyWithZone:zone];
copy->_receipt = [self.receipt copyWithZone:zone];
copy->_billingStore = [self.billingStore copyWithZone:zone];
copy->_transactionDate = [self.transactionDate copyWithZone:zone];
copy->_salesRegion = [self.salesRegion copyWithZone:zone];
copy.mutableCallbackParameters = [self.mutableCallbackParameters copyWithZone:zone];
copy.mutablePartnerParameters = [self.mutablePartnerParameters copyWithZone:zone];
}
return copy;
}
@end