Skip to content

[in_app_purchase] How to Use Promotional Offers for iOS Subscriptions #145898

Closed as not planned
@xiaolongwuhpu

Description

@xiaolongwuhpu

Description:

I'm trying to implement promotional offers for iOS subscriptions using the [in_app_purchase] library. For example: offering the first week for free or providing a discount for the first year.
In my Android project, I've successfully implemented these offers using the following code:

 late PurchaseParam purchaseParam;
    if (Device.isAndroid) {
// Code snippet for implementing promotional offers in Android
// Different promotional offers have different ProductDetails, making it easy to implement them
      purchaseParam = GooglePlayPurchaseParam(productDetails: productDetails, changeSubscriptionParam: null);
    } else if(Device.isIOS) {
      purchaseParam = AppStorePurchaseParam(
        productDetails: productDetails,
        discount: SKPaymentDiscountWrapper(identifier: '', keyIdentifier: '', nonce: '', signature: "", timestamp: DateTime.now().millisecondsSinceEpoch),
      );
    }
    bool paySuccess = await _inAppPurchase.buyNonConsumable(purchaseParam: purchaseParam);

screenshot-20240328-220405

However, I'm unsure about how to achieve the same in iOS. Can someone please provide detailed guidance? I've gone through the documentation here but couldn't grasp it entirely. Do we need our server to generate signatures for this?

Thank you for any assistance you can provide!

if(Device.isIOS) {
      purchaseParam = AppStorePurchaseParam(
        productDetails: productDetails,
        discount: SKPaymentDiscountWrapper(identifier: '', keyIdentifier: '', nonce: '', signature: "", timestamp: DateTime.now().millisecondsSinceEpoch),
      );
    }

Where can I obtain the parameters for this class SKPaymentDiscountWrapper, and how should I construct this object? Are there any alternative approaches to achieve this?

doc: https://developer.apple.com/documentation/storekit/in-app_purchase/original_api_for_in-app_purchase/subscriptions_and_offers/generating_a_signature_for_promotional_offers?language=objc

Metadata

Metadata

Assignees

No one assigned

    Labels

    r: duplicateIssue is closed as a duplicate of an existing issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions