-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Convert startProductRequest(), finishTransaction(), restoreTransactions(), presentCodeRedemptionSheet() to pigeon #6032
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
cabdcf4
55f3524
751b034
50fe53a
bab76ff
214cc93
b0d16e1
7524ba8
1374433
a3a7439
f7e0c4a
569abc2
0aadf34
26681aa
7b011be
0cb73cf
2247065
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -376,9 +376,8 @@ + (nullable SKStorefrontMessage *)convertStorefrontToPigeon:(nullable SKStorefro | |||||
| return msg; | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
| + (nullable SKProductSubscriptionPeriodMessage*)convertSKProductSubscriptionPeriodToPigeon:(nullable SKProductSubscriptionPeriod *)period | ||||||
| API_AVAILABLE(ios(12.2)) { | ||||||
| + (nullable SKProductSubscriptionPeriodMessage *)convertSKProductSubscriptionPeriodToPigeon: | ||||||
| (nullable SKProductSubscriptionPeriod *)period API_AVAILABLE(ios(12.2)) { | ||||||
| if (!period) { | ||||||
| return nil; | ||||||
| } | ||||||
|
|
@@ -399,13 +398,14 @@ + (nullable SKProductSubscriptionPeriodMessage*)convertSKProductSubscriptionPeri | |||||
| break; | ||||||
| } | ||||||
|
|
||||||
| SKProductSubscriptionPeriodMessage *msg = [SKProductSubscriptionPeriodMessage makeWithNumberOfUnits:period.numberOfUnits unit:unit]; | ||||||
| SKProductSubscriptionPeriodMessage *msg = | ||||||
| [SKProductSubscriptionPeriodMessage makeWithNumberOfUnits:period.numberOfUnits unit:unit]; | ||||||
|
|
||||||
| return msg; | ||||||
| } | ||||||
|
|
||||||
| + (nullable SKProductDiscountMessage*)convertProductDiscountToPigeon:(nullable SKProductDiscount *)productDiscount | ||||||
| API_AVAILABLE(ios(12.2)) { | ||||||
| + (nullable SKProductDiscountMessage *)convertProductDiscountToPigeon: | ||||||
| (nullable SKProductDiscount *)productDiscount API_AVAILABLE(ios(12.2)) { | ||||||
| if (!productDiscount) { | ||||||
| return nil; | ||||||
| } | ||||||
|
|
@@ -433,64 +433,68 @@ + (nullable SKProductDiscountMessage*)convertProductDiscountToPigeon:(nullable S | |||||
| break; | ||||||
| } | ||||||
|
|
||||||
| SKProductDiscountMessage *msg = [SKProductDiscountMessage makeWithPrice:productDiscount.price.description | ||||||
| priceLocale:[self convertNSLocaleToPigeon:productDiscount.priceLocale] | ||||||
| numberOfPeriods:productDiscount.numberOfPeriods | ||||||
| paymentMode:paymentMode | ||||||
| subscriptionPeriod:[self convertSKProductSubscriptionPeriodToPigeon:productDiscount.subscriptionPeriod] | ||||||
| identifier:productDiscount.identifier | ||||||
| type:type]; | ||||||
| SKProductDiscountMessage *msg = [SKProductDiscountMessage | ||||||
| makeWithPrice:productDiscount.price.description | ||||||
| priceLocale:[self convertNSLocaleToPigeon:productDiscount.priceLocale] | ||||||
| numberOfPeriods:productDiscount.numberOfPeriods | ||||||
| paymentMode:paymentMode | ||||||
| subscriptionPeriod:[self convertSKProductSubscriptionPeriodToPigeon:productDiscount | ||||||
| .subscriptionPeriod] | ||||||
| identifier:productDiscount.identifier | ||||||
| type:type]; | ||||||
|
|
||||||
| return msg; | ||||||
| } | ||||||
|
|
||||||
| + (nullable SKPriceLocaleMessage*)convertNSLocaleToPigeon:(nullable NSLocale *)locale | ||||||
| API_AVAILABLE(ios(12.2)) { | ||||||
| + (nullable SKPriceLocaleMessage *)convertNSLocaleToPigeon:(nullable NSLocale *)locale | ||||||
| API_AVAILABLE(ios(12.2)) { | ||||||
| if (!locale) { | ||||||
| return nil; | ||||||
| } | ||||||
| SKPriceLocaleMessage *msg = [SKPriceLocaleMessage makeWithCurrencySymbol:locale.currencySymbol | ||||||
| SKPriceLocaleMessage *msg = [SKPriceLocaleMessage makeWithCurrencySymbol:locale.currencySymbol | ||||||
| currencyCode:locale.currencyCode | ||||||
| countryCode:locale.countryCode]; | ||||||
|
|
||||||
| return msg; | ||||||
| } | ||||||
|
|
||||||
| + (nullable SKProductMessage*)convertProductToPigeon:(nullable SKProduct *)product | ||||||
| API_AVAILABLE(ios(12.2)) { | ||||||
| + (nullable SKProductMessage *)convertProductToPigeon:(nullable SKProduct *)product | ||||||
| API_AVAILABLE(ios(12.2)) { | ||||||
| NSArray<SKProductDiscount *> *skProductDiscounts = product.discounts; | ||||||
| NSMutableArray<SKProductDiscountMessage *> *pigeonProductDiscounts = [[NSMutableArray alloc] init]; | ||||||
| NSMutableArray<SKProductDiscountMessage *> *pigeonProductDiscounts = | ||||||
| [[NSMutableArray alloc] init]; | ||||||
|
|
||||||
| for (SKProductDiscount *productDiscount in skProductDiscounts) { | ||||||
| [pigeonProductDiscounts addObject:[self convertProductDiscountToPigeon:productDiscount]]; | ||||||
| }; | ||||||
|
|
||||||
| SKProductMessage *msg = | ||||||
| [SKProductMessage makeWithProductIdentifier:product.productIdentifier | ||||||
| localizedTitle:product.localizedTitle | ||||||
| localizedDescription:product.localizedDescription | ||||||
| priceLocale:[self convertNSLocaleToPigeon:product.priceLocale] | ||||||
| subscriptionGroupIdentifier:product.subscriptionGroupIdentifier | ||||||
| price:product.price.description | ||||||
| subscriptionPeriod:[self convertSKProductSubscriptionPeriodToPigeon:product.subscriptionPeriod] | ||||||
| introductoryPrice:[self convertProductDiscountToPigeon:product.introductoryPrice] | ||||||
| discounts:pigeonProductDiscounts]; | ||||||
| SKProductMessage *msg = [SKProductMessage | ||||||
| makeWithProductIdentifier:product.productIdentifier | ||||||
| localizedTitle:product.localizedTitle | ||||||
| localizedDescription:product.localizedDescription | ||||||
| priceLocale:[self convertNSLocaleToPigeon:product.priceLocale] | ||||||
| subscriptionGroupIdentifier:product.subscriptionGroupIdentifier | ||||||
| price:product.price.description | ||||||
| subscriptionPeriod: | ||||||
| [self convertSKProductSubscriptionPeriodToPigeon:product.subscriptionPeriod] | ||||||
| introductoryPrice:[self convertProductDiscountToPigeon:product.introductoryPrice] | ||||||
| discounts:pigeonProductDiscounts]; | ||||||
|
|
||||||
| return msg; | ||||||
| } | ||||||
|
|
||||||
| + (nullable SKProductsResponseMessage*)convertProductsResponseToPigeon:(nullable SKProductsResponse *)productsResponse | ||||||
| API_AVAILABLE(ios(12.2)) { | ||||||
|
|
||||||
| + (nullable SKProductsResponseMessage *)convertProductsResponseToPigeon: | ||||||
| (nullable SKProductsResponse *)productsResponse API_AVAILABLE(ios(12.2)) { | ||||||
| NSArray<SKProduct *> *skProducts = productsResponse.products; | ||||||
| NSMutableArray<SKProductMessage *> *pigeonProducts = [[NSMutableArray alloc] init]; | ||||||
|
||||||
| NSMutableArray<SKProductMessage *> *pigeonProducts = [[NSMutableArray alloc] init]; | |
| NSMutableArray<SKProductMessage *> *pigeonProducts = [NSMutableArray arrayWithCapacity: skProducts.count]; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -136,8 +136,9 @@ - (nullable SKStorefrontMessage *)storefrontWithError:(FlutterError *_Nullable * | |
| return [FIAObjectTranslator convertStorefrontToPigeon:storefront]; | ||
| } | ||
|
|
||
| - (void)startProductRequestProductIdentifiers:(NSArray<NSString *> *)productIdentifiers completion:(void (^)(SKProductsResponseMessage *_Nullable, FlutterError *_Nullable))completion { | ||
|
|
||
| - (void)startProductRequestProductIdentifiers:(NSArray<NSString *> *)productIdentifiers | ||
| completion:(void (^)(SKProductsResponseMessage *_Nullable, | ||
| FlutterError *_Nullable))completion { | ||
| SKProductsRequest *request = | ||
| [self getProductRequestWithIdentifiers:[NSSet setWithArray:productIdentifiers]]; | ||
| FIAPRequestHandler *handler = [[FIAPRequestHandler alloc] initWithRequest:request]; | ||
|
|
@@ -149,14 +150,14 @@ - (void)startProductRequestProductIdentifiers:(NSArray<NSString *> *)productIden | |
| FlutterError *error = nil; | ||
| if (startProductRequestError != nil) { | ||
| error = [FlutterError errorWithCode:@"storekit_getproductrequest_platform_error" | ||
| message:startProductRequestError.localizedDescription | ||
| details:startProductRequestError.description]; | ||
| message:startProductRequestError.localizedDescription | ||
| details:startProductRequestError.description]; | ||
| } | ||
| if (!response) { | ||
| error = [FlutterError errorWithCode:@"storekit_platform_no_response" | ||
| message:@"Failed to get SKProductResponse in startRequest " | ||
| @"call. Error occured on iOS platform" | ||
| details:productIdentifiers]; | ||
| message:@"Failed to get SKProductResponse in startRequest " | ||
| @"call. Error occured on iOS platform" | ||
| details:productIdentifiers]; | ||
| } | ||
| for (SKProduct *product in response.products) { | ||
| [self.productsCache setObject:product forKey:product.productIdentifier]; | ||
|
|
@@ -224,7 +225,8 @@ - (void)addPaymentPaymentMap:(nonnull NSDictionary *)paymentMap | |
| } | ||
| } | ||
|
|
||
| - (void)finishTransactionFinishMap:(nonnull NSDictionary<NSString *,NSString *> *)finishMap error:(FlutterError * _Nullable __autoreleasing * _Nonnull)error { | ||
| - (void)finishTransactionFinishMap:(nonnull NSDictionary<NSString *, NSString *> *)finishMap | ||
| error:(FlutterError *_Nullable __autoreleasing *_Nonnull)error { | ||
| NSString *transactionIdentifier = [finishMap objectForKey:@"transactionIdentifier"]; | ||
| NSString *productIdentifier = [finishMap objectForKey:@"productIdentifier"]; | ||
|
|
||
|
|
@@ -243,19 +245,22 @@ - (void)finishTransactionFinishMap:(nonnull NSDictionary<NSString *,NSString *> | |
| [self.paymentQueueHandler finishTransaction:transaction]; | ||
| } @catch (NSException *e) { | ||
| *error = [FlutterError errorWithCode:@"storekit_finish_transaction_exception" | ||
| message:e.name | ||
| details:e.description]; | ||
| message:e.name | ||
| details:e.description]; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. where is this error used?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. all generated pigeon functions have like an extra "error" param, I think it gets passed back to the dart side automatically |
||
| return; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| - (void)restoreTransactionsApplicationUserName:(nullable NSString *)applicationUserName error:(FlutterError * _Nullable __autoreleasing * _Nonnull)error { | ||
| - (void)restoreTransactionsApplicationUserName:(nullable NSString *)applicationUserName | ||
| error:(FlutterError *_Nullable __autoreleasing *_Nonnull) | ||
| error { | ||
| [self.paymentQueueHandler restoreTransactions:applicationUserName]; | ||
| } | ||
|
|
||
| - (void)presentCodeRedemptionSheetWithError:(FlutterError * _Nullable __autoreleasing * _Nonnull)error { | ||
| - (void)presentCodeRedemptionSheetWithError: | ||
| (FlutterError *_Nullable __autoreleasing *_Nonnull)error { | ||
| #if TARGET_OS_IOS | ||
| [self.paymentQueueHandler presentCodeRedemptionSheet]; | ||
| #endif | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: you know the size here. It's more efficient to create the array of the proper size.