Xamarin Forms(Android) - 升级和降级订阅

时间:2017-04-19 13:59:32

标签: android xamarin.forms google-play in-app-purchase subscription

我几天都在努力解决这个问题。我正在制作一款需要支持应用内订阅购买的应用。

我尝试了以下套餐:

-Xamarin.InAppBilling(Component)

-Plugin.InAppBilling(Nuget-beta)

-Android Publisher Service(Nuget)

但它们都不支持升级/降级订阅。

是否有任何完全支持订阅的软件包?

1 个答案:

答案 0 :(得分:1)

我们遇到了类似的问题。这些包只支持getBuyIntent。 getBuyIntent不支持升级和降级订阅。方法getBuyIntentExtraParams支持这一点。使用此方法,您可以使用skusToReplace参数指定用户正在升级或降级的先前订阅。

有关详细信息,请参阅google文档:https://developer.android.com/google/play/billing/billing_reference.html

getBuyIntentExtraParams方法在这些包中不可用,但您可以在插件的aidl文件中添加该方法。

Xamarin.InAppBilling包的aidl文件:https://github.com/hauptmedia/xamarin-inappbilling/blob/master/Droid/aidl/IInAppBillingService.aidl

您可以下载aidl文件并将getBuyIntentExtraParams方法附加到aidl文件。将aidl文件添加到您的android项目并使用它而不是插件。

方法定义:

/**
     * Returns a pending intent to launch the purchase flow for an in-app item. This method is
     * a variant of the {@link #getBuyIntent} method and takes an additional {@code extraParams}
     * parameter. This parameter is a Bundle of optional keys and values that affect the
     * operation of the method.
     * @param apiVersion billing API version that the app is using, must be 6 or later
     * @param packageName package name of the calling app
     * @param sku the SKU of the in-app item as published in the developer console
     * @param type of the in-app item being purchased ("inapp" for one-time purchases
     *        and "subs" for subscriptions)
     * @param developerPayload optional argument to be sent back with the purchase information
     * @extraParams a Bundle with the following optional keys:
     *        "skusToReplace" - List<String> - an optional list of SKUs that the user is
     *                          upgrading or downgrading from.
     *                          Pass this field if the purchase is upgrading or downgrading
     *                          existing subscriptions.
     *                          The specified SKUs are replaced with the SKUs that the user is
     *                          purchasing. Google Play replaces the specified SKUs at the start of
     *                          the next billing cycle.
     * "replaceSkusProration" - Boolean - whether the user should be credited for any unused
     *                          subscription time on the SKUs they are upgrading or downgrading.
     *                          If you set this field to true, Google Play swaps out the old SKUs
     *                          and credits the user with the unused value of their subscription
     *                          time on a pro-rated basis.
     *                          Google Play applies this credit to the new subscription, and does
     *                          not begin billing the user for the new subscription until after
     *                          the credit is used up.
     *                          If you set this field to false, the user does not receive credit for
     *                          any unused subscription time and the recurrence date does not
     *                          change.
     *                          Default value is true. Ignored if you do not pass skusToReplace.
     *            "accountId" - String - an optional obfuscated string that is uniquely
     *                          associated with the user's account in your app.
     *                          If you pass this value, Google Play can use it to detect irregular
     *                          activity, such as many devices making purchases on the same
     *                          account in a short period of time.
     *                          Do not use the developer ID or the user's Google ID for this field.
     *                          In addition, this field should not contain the user's ID in
     *                          cleartext.
     *                          We recommend that you use a one-way hash to generate a string from
     *                          the user's ID, and store the hashed string in this field.
     *                   "vr" - Boolean - an optional flag indicating whether the returned intent
     *                          should start a VR purchase flow. The apiVersion must also be 7 or
     *                          later to use this flag.
     */
    Bundle getBuyIntentExtraParams(int apiVersion, String packageName, String sku,
        String type, String developerPayload, in Bundle extraParams);