@@ -296,11 +296,12 @@ - (void)productsRequest:(SKProductsRequest *)request
296
296
NSString *key = RCTKeyForInstance (request);
297
297
NSDictionary *promiseBlock = _promiseBlocks[key];
298
298
if (promiseBlock) {
299
- RCTPromiseResolveBlock resolve = promiseBlock[@" resolve" ];
300
- if (resolve) {
299
+ RCTPromiseResolveBlock resolve = promiseBlock[@" resolve" ];
300
+ if (resolve) {
301
301
products = [NSMutableArray arrayWithArray: response.products];
302
302
NSMutableArray *productsArrayForJS = [NSMutableArray array ];
303
303
for (SKProduct *item in response.products ) {
304
+ NSDictionary *introductoryPrice = [InAppUtils parseIntroductoryPrice: item];
304
305
NSDictionary *product = @{
305
306
@" identifier" : item.productIdentifier ,
306
307
@" price" : item.price ,
@@ -311,6 +312,7 @@ - (void)productsRequest:(SKProductsRequest *)request
311
312
@" downloadable" : item.isDownloadable ? @" true" : @" false" ,
312
313
@" description" : item.localizedDescription ? item.localizedDescription : @" " ,
313
314
@" title" : item.localizedTitle ? item.localizedTitle : @" " ,
315
+ @" introductoryPrice" : (introductoryPrice == nil ) ? [NSNull null ] : introductoryPrice,
314
316
};
315
317
[productsArrayForJS addObject: product];
316
318
}
@@ -383,6 +385,66 @@ - (void)dealloc
383
385
[[SKPaymentQueue defaultQueue ] removeTransactionObserver: self ];
384
386
}
385
387
388
+ #pragma mark Static
389
+
390
+ + (NSDictionary *)parseIntroductoryPrice : (SKProduct *)product {
391
+ if (@available (iOS 11.2 , *)) {
392
+ if (product != nil && product.introductoryPrice != nil ) {
393
+ // paymentMode: Returning as string for ease of use and code resilience
394
+ NSString *paymentMode;
395
+ switch (product.introductoryPrice .paymentMode ) {
396
+ case SKProductDiscountPaymentModeFreeTrial:
397
+ paymentMode = @" freeTrial" ;
398
+ break ;
399
+ case SKProductDiscountPaymentModePayAsYouGo:
400
+ paymentMode = @" payAsYouGo" ;
401
+ break ;
402
+ case SKProductDiscountPaymentModePayUpFront:
403
+ paymentMode = @" payUpFront" ;
404
+ break ;
405
+ default :
406
+ paymentMode = @" unavailable" ;
407
+ break ;
408
+ }
409
+
410
+ // subscriptionPeriod: Returning as Dictionary { unit: NSString, numberOfUnits: NSNumber }
411
+ NSString *subscriptionPeriodUnit;
412
+ switch (product.introductoryPrice .subscriptionPeriod .unit ) {
413
+ case SKProductPeriodUnitDay:
414
+ subscriptionPeriodUnit = @" day" ;
415
+ break ;
416
+ case SKProductPeriodUnitWeek:
417
+ subscriptionPeriodUnit = @" week" ;
418
+ break ;
419
+ case SKProductPeriodUnitMonth:
420
+ subscriptionPeriodUnit = @" month" ;
421
+ break ;
422
+ case SKProductPeriodUnitYear:
423
+ subscriptionPeriodUnit = @" year" ;
424
+ break ;
425
+ default :
426
+ subscriptionPeriodUnit = @" unavailable" ;
427
+ break ;
428
+ }
429
+
430
+ NSDictionary *subscriptionPeriod = @{
431
+ @" unit" : subscriptionPeriodUnit,
432
+ @" numberOfUnits" : [[NSNumber alloc ] initWithLong: product.introductoryPrice.subscriptionPeriod.numberOfUnits],
433
+ };
434
+
435
+ NSDictionary *introductoryPrice = @{
436
+ @" price" : product.introductoryPrice .price ,
437
+ @" numberOfPeriods" : [[NSNumber alloc ] initWithLong: product.introductoryPrice.numberOfPeriods],
438
+ @" paymentMode" : paymentMode,
439
+ @" subscriptionPeriod" : subscriptionPeriod,
440
+ };
441
+ return introductoryPrice;
442
+ }
443
+ }
444
+
445
+ return nil ;
446
+ }
447
+
386
448
#pragma mark Private
387
449
388
450
static NSString *RCTKeyForInstance (id instance)
0 commit comments