Repository navigation
Commit 334faff
authored
[in_app_purchase] Support StoreKit 2 introductory offer eligibility JWS (#12584)
Adds an optional StoreKit 2-specific field to `Sk2PurchaseParam` that forwards a server-signed compact JWS to [`Product.PurchaseOption.introductoryOfferEligibility(compactJWS:)`](https://developer.apple.com/documentation/storekit/product/purchaseoption/introductoryoffereligibility(compactjws:)).
Fixes flutter/flutter#191668
## Problem
StoreKit 2 lets an app's own server decide, per purchase, whether an introductory offer applies. The app receives a compact JWS signed with an App Store Connect In-App Purchase key ([Generating JWS to sign App Store requests](https://developer.apple.com/documentation/storekit/generating-jws-to-sign-app-store-requests)) whose `allowIntroductoryOffer` claim Apple documents as "a Boolean value, `true` or `false`, that determines whether the customer is eligible for an introductory offer".
The plugin did not expose this purchase option, so apps whose eligibility rules live on their own server could not use the plugin's purchase path.
This is distinct from the existing `isIntroductoryOfferEligible(productId)`, which wraps `Product.SubscriptionInfo.isEligibleForIntroOffer` and **reads** the App Store's *default* eligibility. That read cannot express a server-signed per-purchase decision.
## Implementation
```dart
Sk2PurchaseParam(
productDetails: productDetails,
introductoryOfferEligibilityCompactJWS: compactJWSFromMyServer,
);
```
The value flows through `SK2ProductPurchaseOptions` and the Pigeon message to the Swift purchase-option builder:
```swift
if let compactJWS = options?.introductoryOfferEligibilityCompactJWS {
purchaseOptions.insert(.introductoryOfferEligibility(compactJWS: compactJWS))
}
```
The JWS is opaque to the plugin: it is never generated, signed, parsed, validated or inspected.
Generated Pigeon files were regenerated with the repository's canonical `dart run pigeon --input pigeons/sk2_pigeon.dart`.
## Availability
No `#available` gate is required. `introductoryOfferEligibility(compactJWS:)` is declared `@backDeployed(before: iOS 18.4, macOS 15.4, tvOS 18.4, watchOS 11.4, visionOS 2.4)` with availability iOS 15.0+ / macOS 12.0+, which is the same floor as the existing `@available(iOS 15.0, macOS 12.0, *)` StoreKit 2 extension it is added to.
## Backwards compatibility
Not breaking:
- the field is optional and null by default
- when null, no purchase option is added and the App Store applies its own default eligibility, so existing apps behave identically
- the new Pigeon field is appended, so existing encoded payloads decode unchanged
- StoreKit 1 is untouched
- `isIntroductoryOfferEligible`, promotional offers, win-back offers, `appAccountToken` and `quantity` are unchanged and continue to work alongside the new option
## Tests
Dart (`in_app_purchase_storekit_2_platform_test.dart`), all passing:
- null JWS -> no option is sent
- non-null JWS -> forwarded unchanged
- JWS coexists with `appAccountToken`, `quantity`, `promotionalOffer` and `winBackOfferId`
- a generic `PurchaseParam` sends no JWS
Native (`InAppPurchaseStoreKit2PluginTests.swift`):
- `testPurchaseWithIntroductoryOfferEligibilityJWS` drives a purchase with the option set and passes.
## Known limitation in local native verification
I could not run the full `RunnerTests` suite locally. It crashes in `StoreKit2TranslatorTests.setUp()` (`StoreKit2TranslatorTests.swift:69`) with `EXC_BREAKPOINT`/`SIGTRAP`, and the existing purchase-success tests fail with `PigeonError` plus an asynchronous timeout.
This is independent of this change: I reproduced the identical crash signature and the identical purchase-test failure on the unmodified upstream base (9f595f3) under the same Xcode 26.6 / iOS 26.5 simulator. It matches flutter/flutter#184678, including the same file and line and the same `SKTestSession` `SKInternalErrorDomain Code=3` symptom.
To be precise about what was verified locally: the patch-specific native test passes, and `dart format`, `flutter analyze`, the 106 Dart unit tests and `swift-format lint --strict` are all clean. I am **not** claiming the full native suite passes. Because product lookup fails in that environment, the native test exercises the call path but cannot by itself assert the option reached StoreKit; the deterministic assertions for that are the Dart tests above, and the Swift call site was additionally verified with `swiftc -typecheck` against the iOS 15 target.
No unrelated upstream test was modified or worked around.
## Pre-Review Checklist
[^1]: See "Known limitation in local native verification" above regarding the pre-existing native suite failure tracked in flutter/flutter#184678.1 parent e941cd1 commit 334faff
11 files changed
Lines changed: 194 additions & 6 deletions
File tree
- packages/in_app_purchase/in_app_purchase_storekit
- darwin/in_app_purchase_storekit/Sources/in_app_purchase_storekit/StoreKit2
- lib/src
- store_kit_2_wrappers
- types
- pigeons
- test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
1 | 8 | | |
2 | 9 | | |
3 | 10 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
88 | 95 | | |
89 | 96 | | |
90 | 97 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
640 | 640 | | |
641 | 641 | | |
642 | 642 | | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
643 | 649 | | |
644 | 650 | | |
645 | 651 | | |
646 | 652 | | |
647 | 653 | | |
648 | 654 | | |
649 | 655 | | |
| 656 | + | |
650 | 657 | | |
651 | 658 | | |
652 | 659 | | |
653 | 660 | | |
654 | 661 | | |
655 | | - | |
| 662 | + | |
| 663 | + | |
656 | 664 | | |
657 | 665 | | |
658 | 666 | | |
| |||
661 | 669 | | |
662 | 670 | | |
663 | 671 | | |
| 672 | + | |
664 | 673 | | |
665 | 674 | | |
666 | 675 | | |
| |||
673 | 682 | | |
674 | 683 | | |
675 | 684 | | |
| 685 | + | |
| 686 | + | |
676 | 687 | | |
677 | 688 | | |
678 | 689 | | |
| |||
681 | 692 | | |
682 | 693 | | |
683 | 694 | | |
| 695 | + | |
| 696 | + | |
684 | 697 | | |
685 | 698 | | |
686 | 699 | | |
687 | 700 | | |
688 | | - | |
| 701 | + | |
689 | 702 | | |
690 | 703 | | |
691 | 704 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
389 | 389 | | |
390 | 390 | | |
391 | 391 | | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
392 | 412 | | |
393 | 413 | | |
394 | 414 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
| 111 | + | |
| 112 | + | |
111 | 113 | | |
112 | 114 | | |
113 | 115 | | |
| |||
163 | 165 | | |
164 | 166 | | |
165 | 167 | | |
| 168 | + | |
| 169 | + | |
166 | 170 | | |
167 | 171 | | |
168 | 172 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
579 | 579 | | |
580 | 580 | | |
581 | 581 | | |
| 582 | + | |
582 | 583 | | |
583 | 584 | | |
584 | 585 | | |
| |||
589 | 590 | | |
590 | 591 | | |
591 | 592 | | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
592 | 600 | | |
593 | | - | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
594 | 608 | | |
595 | 609 | | |
596 | 610 | | |
| |||
604 | 618 | | |
605 | 619 | | |
606 | 620 | | |
| 621 | + | |
607 | 622 | | |
608 | 623 | | |
609 | 624 | | |
| |||
619 | 634 | | |
620 | 635 | | |
621 | 636 | | |
622 | | - | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
623 | 642 | | |
624 | 643 | | |
625 | 644 | | |
| |||
628 | 647 | | |
629 | 648 | | |
630 | 649 | | |
631 | | - | |
| 650 | + | |
632 | 651 | | |
633 | 652 | | |
634 | 653 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
289 | 289 | | |
290 | 290 | | |
291 | 291 | | |
| 292 | + | |
292 | 293 | | |
293 | 294 | | |
294 | 295 | | |
| |||
303 | 304 | | |
304 | 305 | | |
305 | 306 | | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
306 | 313 | | |
307 | 314 | | |
308 | 315 | | |
309 | 316 | | |
310 | 317 | | |
311 | 318 | | |
312 | 319 | | |
| 320 | + | |
313 | 321 | | |
314 | 322 | | |
315 | 323 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
54 | 55 | | |
55 | 56 | | |
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 | + | |
57 | 86 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
154 | 154 | | |
155 | 155 | | |
156 | 156 | | |
| 157 | + | |
157 | 158 | | |
158 | 159 | | |
159 | 160 | | |
160 | 161 | | |
161 | 162 | | |
162 | 163 | | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
163 | 171 | | |
164 | 172 | | |
165 | 173 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
0 commit comments