Skip to content

Commit 08b84ba

Browse files
committed
Purchase tracking fix variable type to be string
* SKProduct.price is an NSDecimalNumber and we had been sending this as is, but the backend expects a String * This can be reproduced manually by a creating purchase array and calling `OneSignalUserManagerImpl sendPurchases` * It returns a 400 with: "Field deltas.purchases.amount was expecting value of type 'string', received value of type 'number' instead"
1 parent 5d39587 commit 08b84ba

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

iOS_SDK/OneSignalSDK/Source/OneSignalTrackIAP.m

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,14 @@ - (void)productsRequest:(id)request didReceiveResponse:(id)response {
124124
NSString* productSku = [skProduct performSelector:@selector(productIdentifier)];
125125
NSMutableDictionary* purchase = skusToTrack[productSku];
126126
if (purchase) { // In rare cases this can be nil when there wasn't a connection to Apple when opening the app but there was when buying an IAP item.
127+
128+
// SKProduct.price is an NSDecimalNumber, but the backend expects a String
129+
NSNumberFormatter *formatter = [NSNumberFormatter new];
130+
[formatter setMinimumFractionDigits:2];
131+
NSString *formattedPrice = [formatter stringFromNumber:[skProduct performSelector:@selector(price)]];
132+
127133
purchase[@"sku"] = productSku;
128-
purchase[@"amount"] = [skProduct performSelector:@selector(price)];
134+
purchase[@"amount"] = formattedPrice;
129135
purchase[@"iso"] = [[skProduct performSelector:@selector(priceLocale)] objectForKey:NSLocaleCurrencyCode];
130136
if ([purchase[@"count"] intValue] == 1)
131137
[purchase removeObjectForKey:@"count"];

0 commit comments

Comments
 (0)