Skip to content
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

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

Closed
xiaolongwuhpu opened this issue Mar 28, 2024 · 2 comments
Closed
Labels
r: duplicate Issue is closed as a duplicate of an existing issue

Comments

@xiaolongwuhpu
Copy link

xiaolongwuhpu commented Mar 28, 2024

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

@huycozy huycozy added the in triage Presently being triaged by the triage team label Mar 29, 2024
@huycozy
Copy link
Member

huycozy commented Mar 29, 2024

Hi @xiaolongwuhpu
The promotional offers request on iOS has been implemented by flutter/plugins#4458 (issue #92231).

It depends on your subscription type to be able to get offers, please check this answer for the detail: #92872 (comment). There is also outlined: you can find discount from SKProductWrapper.discounts or SKPaymentWrapper.paymentDiscount. I check this quickly with package example and see you may get it through SKPaymentTransactionWrapper transaction, for e.g: transaction.payment.paymentDiscount.

https://github.com/flutter/packages/blob/1f208aa26454fb4debdfd1ebed9ee0d918b93c9a/packages/in_app_purchase/in_app_purchase/example/lib/main.dart#L502

Also, this is more of a how-to question than a bug or feature request. I see there is a known issue asking the example for this: #51757. So I would suggest you ask the same there (if my suggest above doesn't work) that may help to raise the issue. I will go ahead and close this in favor of that one. Thanks!

@huycozy huycozy closed this as not planned Won't fix, can't repro, duplicate, stale Mar 29, 2024
@huycozy huycozy added r: duplicate Issue is closed as a duplicate of an existing issue and removed in triage Presently being triaged by the triage team labels Mar 29, 2024
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
r: duplicate Issue is closed as a duplicate of an existing issue
Projects
None yet
Development

No branches or pull requests

2 participants