RevenueCat / purchases-ios

In-app purchases and subscriptions made easy. Support for iOS, watchOS, tvOS, macOS, and visionOS.
https://www.revenuecat.com/
MIT License
2.37k stars 319 forks source link

Dismiss promotional offer sheet after successful purchase #4475

Closed fire-at-will closed 2 weeks ago

fire-at-will commented 2 weeks ago

Description

This PR addresses https://github.com/RevenueCat/purchases-ios/issues/4456 by automatically dismissing the promotional offer sheet after successfully purchasing a promotional offer.

It does so by introducing back-flow logic into the PromotionalOfferView where presenting views can take actions based off of the result of the user visiting the PromotionalOfferView.

It introduces a new PromotionalOfferViewAction that tells presenters of the PromotionalOfferView what caused the PromotionalOfferView to be dismissed:

enum PromotionalOfferViewAction {
    /// The user clicked the "No Thanks" button and declined the offer
    case declinePromotionalOffer

    /// The user successfully redeemed the promotional offer
    case successfullyRedeemedPromotionalOffer(PurchaseResultData)

    // Promotional code redemption failed. Either the user attempted to redeem the promotional offer, and it failed,
    // or the promotional offer was not loaded successfully.
    case promotionalCodeRedemptionFailed(Error)
}

Changes

Refund Flow

Cancel/Survey Flow

Misc

Testing

Manually tested changes

Videos

Redeeming Promo Offer Through Refund Flow

https://github.com/user-attachments/assets/840898af-8136-407d-99eb-d5168bbff303

Redeeming Promo Offer Through Cancel/Survey Flow

https://github.com/user-attachments/assets/401c0fe3-37dd-425d-9334-4772f369c9e3