-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[in_app_purchase_storekit] Add support to win back offers / promotional offers #8474
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 27 commits
b372744
bedc5f8
63d2270
1fa0441
1b298c6
7faddc0
b67d029
caf6cc9
ea32bd1
45f6fb2
3822279
acaa4fb
39f94da
c696b03
8c9bd1e
01cf3c0
36314b8
73257b2
5362391
a64d3bc
e327191
ef114df
26784e4
179a4df
a10dbb9
d8c090a
5d213ab
853cc99
26596f2
6377464
8d68c8c
f47b7d2
6abc429
cd59de0
baec1a4
87a424c
09b651a
0792274
7f9d9c2
8e96dbd
2b4099e
a6697e1
0f7530d
af4dfff
69025cb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,10 +52,23 @@ extension Product.ProductType { | |
| @available(iOS 15.0, macOS 12.0, *) | ||
| extension Product.SubscriptionInfo { | ||
| var convertToPigeon: SK2SubscriptionInfoMessage { | ||
| var allOffers: [SK2SubscriptionOfferMessage] = [] | ||
|
|
||
| if #available(iOS 18.0, macOS 15.0, *) { | ||
| allOffers.append(contentsOf: winBackOffers.map { $0.convertToPigeon }) | ||
| } | ||
|
|
||
| allOffers.append(contentsOf: promotionalOffers.map { $0.convertToPigeon }) | ||
|
|
||
| if let introductory = introductoryOffer { | ||
| allOffers.append(introductory.convertToPigeon) | ||
| } | ||
|
|
||
| return SK2SubscriptionInfoMessage( | ||
| promotionalOffers: promotionalOffers.map({ $0.convertToPigeon }), | ||
| promotionalOffers: allOffers, | ||
| subscriptionGroupID: subscriptionGroupID, | ||
| subscriptionPeriod: subscriptionPeriod.convertToPigeon) | ||
| subscriptionPeriod: subscriptionPeriod.convertToPigeon | ||
| ) | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -90,6 +103,33 @@ extension SK2SubscriptionOfferMessage: Equatable { | |
| } | ||
| } | ||
|
|
||
| extension SK2SubscriptionOfferSignatureMessage { | ||
| @available(iOS 17.4, macOS 14.4, *) | ||
| var convertToSignature: Product.SubscriptionOffer.Signature { | ||
| return Product.SubscriptionOffer.Signature( | ||
| keyID: keyID, | ||
| nonce: nonceAsUUID, | ||
| timestamp: Int(timestamp), | ||
| signature: signatureAsData | ||
| ) | ||
| } | ||
|
|
||
| var nonceAsUUID: UUID { | ||
| guard let uuid = UUID(uuidString: nonce) else { | ||
| fatalError("Invalid UUID format for nonce: \(nonce)") | ||
|
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. So if the developer passes in a nonce that is not a valid UUID it would crash the app? That seems to be a bit heavy-handed. Is there an error reporting mechanism for programmer errors like this?
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. Agreed, it felt a bit heavy-handed, but I followed the existing pattern in this file. Happy to change it if there’s a preferred way — any suggestion on the standard we should follow here?
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. Ah I didn't know it was an existing pattern. In that case if there's a better way to handle these errors more gracefully we can refactor those later.
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. If you show me the way, I can do a PR later. |
||
| } | ||
| return uuid | ||
| } | ||
|
|
||
| var signatureAsData: Data { | ||
| guard let data = Data(base64Encoded: signature) else { | ||
| fatalError("Invalid Base64 format for signature: \(signature)") | ||
| } | ||
| return data | ||
| } | ||
|
|
||
| } | ||
|
|
||
| @available(iOS 15.0, macOS 12.0, *) | ||
| extension Product.SubscriptionOffer.OfferType { | ||
| var convertToPigeon: SK2SubscriptionOfferTypeMessage { | ||
|
|
@@ -99,7 +139,12 @@ extension Product.SubscriptionOffer.OfferType { | |
| case .promotional: | ||
| return SK2SubscriptionOfferTypeMessage.promotional | ||
| default: | ||
| fatalError("An unknown OfferType was passed in") | ||
| if #available(iOS 18.0, macOS 15.0, *) { | ||
LongCatIsLooong marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if self == .winBack { | ||
| return SK2SubscriptionOfferTypeMessage.winBack | ||
| } | ||
| } | ||
| fatalError("An unknown or unsupported OfferType was passed in") | ||
kaiquegazola marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| } | ||
|
|
||
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: maybe:
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.
I updated it to include a .verified check to avoid using unverified data: