Billing Programs

Billing Programs (Android 8.2.0+)#

Google Play Billing Library 8.2.0+ introduces the Billing Programs API, which provides a more structured approach to external offers and content links. Version 8.3.0 adds External Payments for Japan, and 9.1.0 adds Billing Choice. OpenIAP exposes Billing Choice in Spec 2.1.0 and openiap-google 2.3.0.

Identifiers for Play Billing programs. Android only (Google docs).

BillingProgramAndroid#

Enum for different billing program types. Use with enableBillingProgramAndroid in InitConnectionConfig:

NameSummaryVersion
USER_CHOICE_BILLINGUser can select between Google Play or alternative billing7.0+
EXTERNAL_CONTENT_LINKFor apps that link to external content (reader apps, music streaming)8.2.0+
EXTERNAL_OFFERFor apps offering alternative payment options (replaces ALTERNATIVE_ONLY)8.2.0+
EXTERNAL_PAYMENTSSide-by-side choice between Google Play and developer billing (Japan only)8.3.0+
BILLING_CHOICEPresent Google Play Billing alongside an alternative in-app billing system or external web link9.1.0+

BillingProgramAvailabilityResultAndroid#

Result of isBillingProgramAvailableAndroid():

NameTypeSummary
isAvailablebooleanWhether the billing program is available for the user
billingProgramBillingProgramAndroidThe billing program that was checked
choiceScreenTypeBillingChoiceScreenTypeAndroid | nullBilling Choice renderer. Present only for available BILLING_CHOICE checks.
isExternalLinkAvailableboolean | nullWhether external-link developer billing is available for Billing Choice.

BillingChoiceScreenTypeAndroid#

How the Billing Choice screen should be rendered (9.1.0+):

NameSummary
UNSPECIFIEDUnspecified renderer.
DEVELOPER_RENDEREDThe app renders the Billing Choice screen using getBillingChoiceInfoAndroid().
GOOGLE_RENDEREDGoogle Play renders the Billing Choice screen and information dialog.

BillingProgramReportingDetailsAndroid#

Result of createBillingProgramReportingDetailsAndroid():

NameTypeSummary
billingProgramBillingProgramAndroidThe billing program associated with these details
externalTransactionTokenstringToken to report external transactions to Google (must report within 24 hours)

DeveloperBillingTypeAndroid#

Developer billing destination type used when creating Billing Choice reporting details (9.1.0+):

NameSummary
DEVELOPER_BILLING_TYPE_UNSPECIFIEDUnspecified type. Do not use.
IN_APPDeveloper-provided billing inside the app.
EXTERNAL_LINKDeveloper-provided billing via an external link.

BillingResultAndroid#

Billing operation result returned by Billing Choice dialogs:

NameTypeSummary
responseCodenumberPlay Billing response code.
debugMessagestring | nullOptional Play Billing debug message.
subResponseCodeSubResponseCodeAndroid | nullOptional granular response code.

BillingChoiceImageLayoutAndroid#

Image layout requested for developer-rendered Billing Choice:

NameSummary
RECTANGULAR_FOUR_BY_ONERectangular image with a 4:1 aspect ratio.
RECTANGULAR_THREE_BY_ONERectangular image with a 3:1 aspect ratio.
RECTANGULAR_TWO_BY_TWORectangular image with a 2:2 aspect ratio.

GetBillingChoiceInfoParamsAndroid#

Parameters for getBillingChoiceInfoAndroid():

NameTypeSummary
billingProgramBillingProgramAndroidBilling program. Defaults to BILLING_CHOICE.
playBillingChoiceImageLayoutBillingChoiceImageLayoutAndroidRequested image layout. Defaults to RECTANGULAR_FOUR_BY_ONE.
userLocalestring | nullOptional BCP 47 locale tag.

BillingChoiceInfoAndroid#

Display information for developer-rendered Billing Choice screens:

NameTypeSummary
playBillingChoiceImageUrlstringPlay Billing image URL for the requested layout.
playBillingLoyaltyInfostring | nullOptional Play loyalty information for the user.

BillingProgramInformationDialogParamsAndroid#

Parameters for showBillingProgramInformationDialogAndroid():

NameTypeSummary
billingProgramBillingProgramAndroidBilling program. Defaults to BILLING_CHOICE.
externalTransactionTokenstringBilling Choice reporting token.

Parameters for launchExternalLinkAndroid():

NameTypeSummary
billingProgramBillingProgramAndroidThe billing program (EXTERNAL_CONTENT_LINK, EXTERNAL_OFFER, or BILLING_CHOICE)
externalTransactionTokenstring | nullPre-generated token for a developer-rendered Billing Choice external-link flow (9.1.0+)
launchModeExternalLinkLaunchModeAndroidHow the external link is launched
linkTypeExternalLinkTypeAndroidThe type of the external link
linkUristringThe URI where the external content will be accessed

How the external URL is launched (Play Billing Library 8.2.0+):

NameSummary
UNSPECIFIEDUnspecified launch mode. Do not use.
LAUNCH_IN_EXTERNAL_BROWSER_OR_APPPlay launches the URL in an external browser or eligible app.
CALLER_WILL_LAUNCH_LINKPlay does not launch the URL — the app handles launching the URL after Play returns control.

Type of external link destination (Play Billing Library 8.2.0+):

NameSummary
UNSPECIFIEDUnspecified link type. Do not use.
LINK_TO_DIGITAL_CONTENT_OFFERThe link directs users to a digital content offer.
LINK_TO_APP_DOWNLOADThe link directs users to download an app.

DeveloperBillingOptionParamsAndroid#

Parameters for configuring developer billing option in purchase flow (8.3.0+; Billing Choice also uses this shape in 9.1.0+):

NameTypeSummary
billingProgramBillingProgramAndroidThe billing program (usually EXTERNAL_PAYMENTS or BILLING_CHOICE)
linkUristring | nullURL for an external-link flow. Omit it for an in-app Billing Choice flow.
launchModeDeveloperBillingLaunchModeAndroid | nullHow to launch an external link. Omit it when no link is used.
externalTransactionTokenstring | nullOptional pre-generated token for a Billing Choice external-link flow.

For an in-app Billing Choice flow, pass only billingProgram: BILLING_CHOICE. Add linkUri, launchMode, and optionally externalTransactionToken only for an external-link flow.

DeveloperBillingLaunchModeAndroid#

How the external payment URL is launched:

NameSummary
LAUNCH_IN_EXTERNAL_BROWSER_OR_APPGoogle Play launches the link in a browser or eligible app
CALLER_WILL_LAUNCH_LINKYour app handles launching the link after Play returns control

DeveloperProvidedBillingDetailsAndroid#

Details received when a user selects developer billing (8.3.0+; expanded in Billing 9.0 and 9.1):

NameTypeSummary
externalTransactionTokenstring | nullToken used for external transaction reporting when one is returned for the selected flow.
linkUristring | nullLink for a Billing Choice external-link flow.
originalExternalTransactionIdstring | nullOriginal developer-billed subscription transaction being replaced.
productsDeveloperProvidedBillingProductAndroid[]Products selected for the developer billing flow.

DeveloperProvidedBillingProductAndroid#

NameTypeSummary
idstringGoogle Play product identifier.
typeProductTypeNormalized product type: IN_APP or SUBS.
offerTokenstring | nullSubscription offer token, when applicable.

InAppMessageCategoryAndroid#

In-app billing message categories:

NameSummary
UNKNOWN_IN_APP_MESSAGE_CATEGORY_IDUnknown category. Do not use.
TRANSACTIONALTransactional billing messages, such as subscription status changes.

InAppMessageParamsAndroid#

Parameters for showInAppMessagesAndroid():

NameTypeSummary
categoriesInAppMessageCategoryAndroid[] | nullCategories to show. Defaults to TRANSACTIONAL.

InAppMessageResponseCodeAndroid#

Result code returned by Play billing in-app messages:

NameSummary
NO_ACTION_NEEDEDFlow finished and no developer action is needed.
SUBSCRIPTION_STATUS_UPDATEDSubscription status changed; refresh the purchase referenced by the returned token.

InAppMessageResultAndroid#

Result of showing Play billing in-app messages:

NameTypeSummary
responseCodeInAppMessageResponseCodeAndroidFlow result.
purchaseTokenstring | nullPurchase token returned when a subscription status changed.

Usage Example#

kt
import dev.hyo.openiap.store.OpenIapStore
import dev.hyo.openiap.*

val iapStore = OpenIapStore(context)

// Enable External Payments via InitConnectionConfig
check(iapStore.initConnection(
    InitConnectionConfig(
        enableBillingProgramAndroid = BillingProgramAndroid.ExternalPayments
    )
)) { "Store connection failed" }

// Listen for developer billing selection
iapStore.addDeveloperProvidedBillingListener { details ->
    Log.d("IAP", "External transaction token received; send it to your backend without logging it.")
    // Report token to Google via your backend within 24 hours
}

// Check availability (Japan only)
val result = iapStore.isBillingProgramAvailable(
    BillingProgramAndroid.ExternalPayments
)
if (result.isAvailable) {
    // Purchase with developer billing option
    val props = RequestPurchaseProps(
        request = RequestPurchaseProps.Request.Purchase(
            RequestPurchasePropsByPlatforms(
                google = RequestPurchaseAndroidProps(
                    skus = listOf("product_id"),
                    developerBillingOption = DeveloperBillingOptionParamsAndroid(
                        billingProgram = BillingProgramAndroid.ExternalPayments,
                        linkUri = "https://your-site.com/checkout",
                        launchMode = DeveloperBillingLaunchModeAndroid.LaunchInExternalBrowserOrApp
                    )
                )
            )
        ),
        type = ProductQueryType.InApp
    )
    iapStore.requestPurchase(props)
}

Token Reporting: When a user completes a purchase through developer billing, you must report the externalTransactionToken to Google Play within 24 hours. See External Payments documentation for complete implementation details.