बिलिंग के विकल्प के लिए, ऐप्लिकेशन में इंटिग्रेशन से जुड़ी गाइडलाइन

इस गाइड में, अपने ऐप्लिकेशन को Play Billing Library के एपीआई के साथ इंटिग्रेट करने का तरीका बताया गया है. इससे, उपयोगकर्ताओं को बिलिंग का विकल्प दिया जा सकता है.

पीबीएल के साथ इंटिग्रेशन

बिलिंग के विकल्प को पीबीएल के साथ चार स्थितियों में इंटिग्रेट किया जा सकता है. ये स्थितियां इस बात पर निर्भर करती हैं कि विकल्प वाली स्क्रीन कौन रेंडर करता है और पेमेंट कहां होगा. यहां दिए गए टेबल में, इंटिग्रेशन की स्थितियों के बारे में बताया गया है:

पेमेंट कहां होगा?
इन-ऐप्लिकेशन बाहरी वेब लिंक
आपको बिलिंग के विकल्प वाली कौनसी स्क्रीन रेंडर करनी है? Google Play की पहली स्थिति (ए)

Google, विकल्प वाली स्क्रीन रेंडर करता है और बिलिंग के अन्य विकल्प को आपके ऐप्लिकेशन में मैनेज किया जाता है.

पहली स्थिति (बी)

ऐप्लिकेशन डेवलपर, विकल्प वाली स्क्रीन रेंडर करता है और बिलिंग के अन्य विकल्प को आपके ऐप्लिकेशन में मैनेज किया जाता है.

आपकी (यूएक्स से जुड़े दिशा-निर्देशों के मुताबिक) दूसरी स्थिति (ए)

Google, विकल्प वाली स्क्रीन रेंडर करता है और खरीदारी के लिए, उपयोगकर्ता को आपके ऐप्लिकेशन से बाहर, आपकी वेबसाइटों पर ले जाया जाता है.

दूसरी स्थिति (बी)

ऐप्लिकेशन डेवलपर, विकल्प वाली स्क्रीन रेंडर करता है और खरीदारी के लिए, उपयोगकर्ता को आपके ऐप्लिकेशन से बाहर, आपकी वेबसाइटों पर ले जाया जाता है.

यहां दी गई इमेज में, इन सभी स्थितियों के लिए बिलिंग के विकल्प के फ़्लो के बारे में बताया गया है:

बिलिंग के विकल्प चुनने का फ़्लो. इसमें इंटिग्रेशन के चार अलग-अलग तरीकों के लिए, एपीआई कॉल और उपयोगकर्ता के इंटरैक्शन का क्रम दिखाया गया है.
पहली इमेज. बिलिंग के विकल्प को इंटिग्रेट करने की स्थितियां

पीबीएल को इंटिग्रेट करने की स्थितियां

अपने ऐप्लिकेशन में बिलिंग का विकल्प उपलब्ध कराने के लिए, इंटिग्रेशन की स्थिति के हिसाब से इस सेक्शन में दिए गए चरणों को अपनाएं.

पहली स्थिति (ए) को मैनेज करना

Google, विकल्प वाली स्क्रीन रेंडर करता है और बिलिंग के अन्य विकल्प को आपके ऐप्लिकेशन में **मैनेज किया जाता है**. इस स्थिति में, बिलिंग का विकल्प उपलब्ध कराने के लिए, ये चरण पूरे करें:

  1. BillingClient का इंस्टेंस बनाते समय, EnableBillingProgramParams के साथ enableBillingProgram को कॉल करें. इसके बाद, कनेक्शन शुरू करें. उदाहरण के लिए:

    Kotlin

    
    // Build the parameters to enable the Billing Choice program and assign the listener
    // to handle user selection of the developer-provided billing option.
    val params = EnableBillingProgramParams.newBuilder()
        .setBillingProgram(BillingProgram.BILLING_CHOICE)
        .setDeveloperProvidedBillingListener(developerProvidedBillingListener)
        .build()
    
    // Build the parameters to enable support for pending purchases.
    val pendingPurchasesParams = PendingPurchasesParams.newBuilder()
        .enableOneTimeProducts()
        .build()
    
    // Construct the BillingClient instance with the purchases updated listener,
    // pending purchases support, and the billing choice params.
    val billingClient = BillingClient.newBuilder(context)
        .setListener(purchasesUpdatedListener)
        .enablePendingPurchases(pendingPurchasesParams)
        .enableBillingProgram(params)
        .build()
    
    // Establish a connection to Google Play
    val billingResult = suspendCancellableCoroutine { continuation ->
        billingClient.startConnection(object : BillingClientStateListener {
            // Called when the connection setup process completes.
            override fun onBillingSetupFinished(billingResult: BillingResult) {
                // Resume the coroutine and pass back the BillingResult to the caller.
                continuation.resume(billingResult)
            }
    
            // Called if the connection to the Play Store service is dropped.
            // This prevents the await or suspension point from hanging indefinitely.
            override fun onBillingServiceDisconnected() {
                continuation.resume(
                    BillingResult.newBuilder()
                        .setResponseCode(BillingClient.BillingResponseCode.SERVICE_DISCONNECTED)
                        .setDebugMessage("Billing service disconnected during connection setup")
                        .build()
                )
            }
        })
    }
    
    

    Java

    
    EnableBillingProgramParams params = EnableBillingProgramParams.newBuilder()
            .setBillingProgram(BillingProgram.BILLING_CHOICE)
            .setDeveloperProvidedBillingListener(developerProvidedBillingListener)
            .build();
    
    BillingClient billingClient = BillingClient.newBuilder(context)
            .setListener(purchasesUpdatedListener)
            .enablePendingPurchases(
                    PendingPurchasesParams.newBuilder()
                            .enableOneTimeProducts()
                            .build()
            )
            .enableBillingProgram(params)
            .build();
    
    
  2. पुष्टि करें कि Google की ओर से रेंडर किया गया बिलिंग का विकल्प, उपयोगकर्ता के लिए उपलब्ध है.

    प्रोग्राम की उपलब्धता की जांच करने के लिए, isBillingProgramAvailableAsync को कॉल करें. इसके बाद, उपलब्ध प्रॉडक्ट दिखाने के लिए, queryProductDetailsAsync को कॉल करें. उदाहरण के लिए:

    Kotlin

    
    val (billingResult, billingProgramAvailabilityDetails) = billingClient.isBillingProgramAvailable(BillingProgram.BILLING_CHOICE)
    
    if (billingResult.responseCode == BillingResponseCode.OK) {
        val billingChoiceAvailabilityDetails = billingProgramAvailabilityDetails.billingChoiceAvailabilityDetails
        if (billingChoiceAvailabilityDetails != null &&
            billingChoiceAvailabilityDetails.choiceScreenType == ChoiceScreenType.GOOGLE_RENDERED
        ) {
            // Billing choice is available. Query products and proceed.
    
        } else {
            // Fallback to other available programs.
        }
    } else {
        // Fallback to other available programs.
    }
    
    
    

    Java

    
    // ...
    billingClient.isBillingProgramAvailableAsync(
        BillingProgram.BILLING_CHOICE,
        (billingResult, billingProgramAvailabilityDetails) -> {
            if (billingResult.getResponseCode() == BillingResponseCode.OK) {
                BillingChoiceAvailabilityDetails billingChoiceAvailabilityDetails =
                    billingProgramAvailabilityDetails.getBillingChoiceAvailabilityDetails();
    
                if (billingChoiceAvailabilityDetails != null &&
                    billingChoiceAvailabilityDetails.getChoiceScreenType() == ChoiceScreenType.GOOGLE_RENDERED) {
                    // Billing choice is available. Query products and proceed.
                } else {
                    // Fallback to other available programs.
                }
            } else {
                // Fallback to other available programs.
            }
        }
    );
    
    

    ध्यान दें: billingProgramAvailabilityDetails से पता चलता है कि Google या डेवलपर की ओर से रेंडर किया गया बिलिंग का विकल्प उपलब्ध है या नहीं.

  3. जब उपयोगकर्ता 'खरीदें' पर क्लिक करे, तो खरीदारी का फ़्लो ट्रिगर करने के लिए, launchBillingFlow को कॉल करें. अगर बिलिंग का विकल्प उपलब्ध है, तो DeveloperBillingOptionParams को BillingFlowParams पास करें. उदाहरण के लिए:

    Kotlin

    
    val developerBillingOptionParams = DeveloperBillingOptionParams.newBuilder()
        .setBillingProgram(BillingProgram.BILLING_CHOICE)
        .build()
    
    val billingFlowParams = BillingFlowParams.newBuilder()
        .setProductDetailsParamsList(productDetailsParamsList)
        .enableDeveloperBillingOption(developerBillingOptionParams)
        .build()
    
    val billingResult = billingClient.launchBillingFlow(activity, billingFlowParams)
    
    

    Java

    
    DeveloperBillingOptionParams developerBillingOptionParams =
        DeveloperBillingOptionParams.newBuilder()
            .setBillingProgram(BillingProgram.BILLING_CHOICE)
            .build();
    BillingFlowParams billingFlowParams =
        BillingFlowParams.newBuilder()
            .setProductDetailsParamsList(productDetailsParamsList)
            .enableDeveloperBillingOption(developerBillingOptionParams)
            .build();
    
    BillingResult billingResult = billingClient.launchBillingFlow(activity, billingFlowParams);
    
    

    ध्यान दें: निगरानी में रखे गए उपयोगकर्ताओं के लिए, माता-पिता के कंट्रोल की सुविधा दिखती है.

  4. बिलिंग के टाइप के लिए, उपयोगकर्ता के चुने गए विकल्प को इस तरह मैनेज करें:

    • अगर उपयोगकर्ता Play Billing को चुनता है, तो बिलिंग का नतीजा, पहले चरण में रजिस्टर किए गए PurchasesUpdatedListener को भेजा जाता है.
    • अगर उपयोगकर्ता, आपके अन्य बिलिंग सिस्टम को चुनता है, तो बिलिंग का नतीजा, पहले चरण में रजिस्टर किए गए DeveloperProvidedBillingListener को भेजा जाता है. इस मामले में, भेजे गए DeveloperProvidedBillingDetails में externalTransactionToken शामिल होता है. इस टोकन का इस्तेमाल, लेन-देन की रिपोर्टिंग के लिए किया जाएगा.

पहली स्थिति (बी) को मैनेज करना

डेवलपर, विकल्प वाली स्क्रीन रेंडर करता है और बिलिंग के अन्य विकल्प को आपके ऐप्लिकेशन में मैनेज किया जाता है. इस स्थिति में, बिलिंग का विकल्प उपलब्ध कराने के लिए, ये चरण पूरे करें:

  1. BillingClient का इंस्टेंस बनाते समय, EnableBillingProgramParams में DeveloperProvidedBillingListener के बिना enableBillingProgram को कॉल करें. इसके बाद, कनेक्शन शुरू करें. उदाहरण के लिए:

    Kotlin

    
    // Build the parameters to enable the Billing Choice program.
    val params = EnableBillingProgramParams.newBuilder()
        .setBillingProgram(BillingProgram.BILLING_CHOICE)
        .build()
    
    // Construct the BillingClient instance with the purchases updated listener,
    // pending purchases support, and the billing choice params.
    val billingClient = BillingClient.newBuilder(context)
        .setListener(purchasesUpdatedListener)
        .enablePendingPurchases()
        .enableBillingProgram(params)
        .build()
    
    // Establish a connection to Google Play
    val billingResult = suspendCancellableCoroutine<BillingResult> { continuation ->
        billingClient.startConnection(object : BillingClientStateListener {
            // Called when the connection setup process completes.
            override fun onBillingSetupFinished(billingResult: BillingResult) {
                // Resume the coroutine and pass back the BillingResult to the caller.
                continuation.resume(billingResult)
            }
    
            // Called if the connection to the Play Store service is dropped.
            // This prevents the await or suspension point from hanging indefinitely.
            override fun onBillingServiceDisconnected() {
                continuation.resume(
                    BillingResult.newBuilder()
                        .setResponseCode(BillingClient.BillingResponseCode.SERVICE_DISCONNECTED)
                        .setDebugMessage("Billing service disconnected during connection setup")
                        .build()
                )
            }
        })
    }
    
    

    Java

    
    EnableBillingProgramParams params = EnableBillingProgramParams.newBuilder()
            .setBillingProgram(BillingProgram.BILLING_CHOICE)
            .build();
    
    BillingClient billingClient = BillingClient.newBuilder(context)
            .setListener(purchasesUpdatedListener)
            .enablePendingPurchases()
            .enableBillingProgram(params)
            .build();
    
    
  2. पुष्टि करें कि डेवलपर की ओर से रेंडर किया गया बिलिंग का विकल्प, उपयोगकर्ता के लिए उपलब्ध है.

    प्रोग्राम की उपलब्धता की जांच करने के लिए, isBillingProgramAvailableAsync को कॉल करें. इसके बाद, उपलब्ध प्रॉडक्ट दिखाने के लिए, queryProductDetailsAsync को कॉल करें. उदाहरण के लिए:

    Kotlin

    
    val (billingResult, billingProgramAvailabilityDetails) =
        billingClient.isBillingProgramAvailable(BillingProgram.BILLING_CHOICE)
    
    if (billingResult.responseCode == BillingResponseCode.OK) {
        val billingChoiceAvailabilityDetails =
            billingProgramAvailabilityDetails.billingChoiceAvailabilityDetails
    
        if (billingChoiceAvailabilityDetails != null &&
            billingChoiceAvailabilityDetails.choiceScreenType == ChoiceScreenType.DEVELOPER_RENDERED
        ) {
            // Billing choice is available. Query products and proceed.
            // You can inspect details such as:
            // - billingChoiceAvailabilityDetails.choiceScreenType
            // - billingChoiceAvailabilityDetails.isExternalLinkAvailable
        } else {
            // Fallback to other available programs.
        }
    } else {
        // Fallback to other available programs.
    }
    
    

    Java

    
    // ...
    billingClient.isBillingProgramAvailableAsync(
        BillingProgram.BILLING_CHOICE,
        (billingResult, billingProgramAvailabilityDetails) -> {
            if (billingResult.getResponseCode() == BillingResponseCode.OK) {
                BillingChoiceAvailabilityDetails billingChoiceAvailabilityDetails =
                    billingProgramAvailabilityDetails.getBillingChoiceAvailabilityDetails();
    
                if (billingChoiceAvailabilityDetails != null
                        && billingChoiceAvailabilityDetails.getChoiceScreenType() == ChoiceScreenType.DEVELOPER_RENDERED) {
                    // Billing choice is available. Query products and proceed.
                    // You can inspect details such as:
                    // - billingChoiceAvailabilityDetails.getChoiceScreenType()
                    // - billingChoiceAvailabilityDetails.isExternalLinkAvailable()
                } else {
                    // Fallback to other available programs.
                }
            } else {
                // Fallback to other available programs.
            }
        }
    );
    
    

    ध्यान दें: billingProgramAvailabilityDetails से पता चलता है कि Google या डेवलपर की ओर से रेंडर किया गया बिलिंग का विकल्प उपलब्ध है या नहीं.

  3. Play Billing का बैनर और लॉयल्टी की जानकारी पाने के लिए, getBillingChoiceInfoAsync तरीके को कॉल करें. उदाहरण के लिए:

    Kotlin

    
    // 1. Create the params required for the request
    val params = GetBillingChoiceInfoParams.newBuilder()
        .setBillingProgram(BillingClient.BillingProgram.BILLING_CHOICE)
        .setPlayBillingChoiceImageLayout(GetBillingChoiceInfoParams.ImageLayout.RECTANGULAR_FOUR_BY_ONE)
        .build()
    
    // 2. Call the suspend method on your billingClient instance
    val (billingResult, playBillingChoiceInfo) = billingClient.getBillingChoiceInfo(params)
    
    if (billingResult.responseCode == BillingResponseCode.OK && playBillingChoiceInfo != null) {
        // Access the URL of the image associated with the Play Billing Choice
        val imageUrl = playBillingChoiceInfo.playBillingChoiceImageUrl
    
        // Access the Play Loyalty string information, if available
        val loyaltyInfo = playBillingChoiceInfo.playBillingLoyaltyInfo
    
        // Populate your developer-rendered UI elements
        playBillingLoyaltyTextView.text = loyaltyInfo
        loadImage(imageUrl, playBillingImageView)
    } else {
        // Handle error scenarios
    }
    
    

    Java

    
    // 1. Create the params required for the request
    GetBillingChoiceInfoParams params = GetBillingChoiceInfoParams.newBuilder()
        .setBillingProgram(BillingClient.BillingProgram.BILLING_CHOICE)
        .setPlayBillingChoiceImageLayout(GetBillingChoiceInfoParams.ImageLayout.RECTANGULAR_FOUR_BY_ONE)
        .build();
    // 2. Call the method asynchronously on your billingClient instance
    billingClient.getBillingChoiceInfoAsync(params, (billingResult, playBillingChoiceInfo) -> {
        if (billingResult.getResponseCode() == BillingResponseCode.OK && playBillingChoiceInfo != null) {
          // Access the URL of the image associated with the Play Billing Choice
            String imageUrl = playBillingChoiceInfo.getPlayBillingChoiceImageUrl();
            // Access the Play Loyalty string information, if available
            String loyaltyInfo = playBillingChoiceInfo.getPlayBillingLoyaltyInfo();
    
            // Populate your developer-rendered UI elements
            playBillingLoyaltyTextView.setText(loyaltyInfo);
              loadImage(imageUrl, playBillingImageView);
          } else {
              // Handle error scenarios
          }
    });
    
    
  4. DeveloperBillingType को IN_APP पर सेट करके, बाहरी लेन-देन का टोकन बनाएं. उदाहरण के लिए:

    Kotlin

    
    // Build the parameters specifying the billing program and that the billing type is IN_APP.
    val params = BillingProgramReportingDetailsParams.newBuilder()
        .setBillingProgram(BillingProgram.BILLING_CHOICE)
        .setDeveloperBillingType(DeveloperBillingType.IN_APP)
        .build()
    
    // Call the suspending extension function to request the reporting details
    val (billingResult, billingProgramReportingDetails) =
        billingClient.createBillingProgramReportingDetails(params)
        
    if (billingResult.responseCode != BillingResponseCode.OK) {
        // Handle failures such as retrying due to network errors.
        return
    }
    
    // Extract the transaction token from the returned reporting details
    val transactionToken = billingProgramReportingDetails?.externalTransactionToken
    
    // Persist the external transaction token locally. Pass it to
    // DeveloperBillingOptionParams when launchBillingFlow is called.
    // It can also be used as part of your external website
    
    

    Java

    
    BillingProgramReportingDetailsParams params =
        BillingProgramReportingDetailsParams.newBuilder()
            .setBillingProgram(BillingProgram.BILLING_CHOICE)
            .setDeveloperBillingType(DeveloperBillingType.IN_APP)
            .build();
    
    billingClient.createBillingProgramReportingDetailsAsync(
        params,
        new BillingProgramReportingDetailsListener() {
            @Override
            public void onCreateBillingProgramReportingDetailsResponse(
                BillingResult billingResult,
                @Nullable BillingProgramReportingDetails billingProgramReportingDetails
            ) {
                if (billingResult.getResponseCode() != BillingResponseCode.OK) {
                    // Handle failures such as retrying due to network errors.
                    return;
                }
    
                String transactionToken =
                    billingProgramReportingDetails.getExternalTransactionToken();
    
                // Persist the external transaction token locally. Pass it to
                // DeveloperBillingOptionParams when launchBillingFlow is called.
                // It can also be used as part of your external website
            }
        }
    );
    
    
    
  5. जब उपयोगकर्ता 'खरीदें' पर क्लिक करे, तो जानकारी वाला डायलॉग दिखाने के लिए, showBillingProgramInformationDialog को कॉल करें. उदाहरण के लिए, उपयोगकर्ताओं के लिए जानकारी वाला डायलॉग देखें. अनुरोध में, चौथे चरण से BillingProgram और transactionToken सेट करना ज़रूरी है.

    ध्यान दें: निगरानी में रखे गए उपयोगकर्ताओं के लिए, माता-पिता के कंट्रोल की सुविधा दिखती है.

  6. अगर पिछले चरण का नतीजा OK है, तो बिलिंग के अन्य विकल्प वाली स्क्रीन लॉन्च करें.

  7. बिलिंग के टाइप के लिए, उपयोगकर्ता के चुने गए विकल्प को इस तरह मैनेज करें:

    • अगर उपयोगकर्ता Play Billing को चुनता है, तो launchBillingFlow Play Billing के स्टैंडर्ड दिशा-निर्देशों के मुताबिक, `launchBillingFlow` को कॉल करें. बिलिंग का नतीजा PurchasesUpdatedListener को भेजा जाता है, जिसे पहले चरण में रजिस्टर किया गया था.
    • अगर उपयोगकर्ता, बिलिंग के किसी अन्य विकल्प को चुनता है, तो आपको लेन-देन को खुद मैनेज करना होगा. साथ ही, चौथे चरण में जनरेट किए गए टोकन का इस्तेमाल करके, इसकी जानकारी Play को देनी होगी.

दूसरी स्थिति (ए) को मैनेज करना

Google, विकल्प वाली स्क्रीन रेंडर करता है और बिलिंग के अन्य विकल्प को आपके ऐप्लिकेशन सेबाहर मैनेज किया जाता है. इस स्थिति में, बिलिंग का विकल्प उपलब्ध कराने के लिए, ये चरण पूरे करें:

  1. BillingClient का इंस्टेंस बनाते समय, EnableBillingProgramParams के साथ enableBillingProgram को कॉल करें. इसके बाद, कनेक्शन शुरू करें. उदाहरण के लिए:

    Kotlin

    
    // Build the parameters to enable the Billing Choice program and assign the listener
    // to handle user selection of the developer-provided billing option.
    val params = EnableBillingProgramParams.newBuilder()
        .setBillingProgram(BillingProgram.BILLING_CHOICE)
        .setDeveloperProvidedBillingListener(developerProvidedBillingListener)
        .build()
    
    // Build the parameters to enable support for pending purchases.
    val pendingPurchasesParams = PendingPurchasesParams.newBuilder()
        .enableOneTimeProducts()
        .build()
    
    // Construct the BillingClient instance with the purchases updated listener,
    // pending purchases support, and the billing choice params.
    val billingClient = BillingClient.newBuilder(context)
        .setListener(purchasesUpdatedListener)
        .enablePendingPurchases(pendingPurchasesParams)
        .enableBillingProgram(params)
        .build()
    
    // Establish a connection to Google Play
    val billingResult = suspendCancellableCoroutine { continuation ->
        billingClient.startConnection(object : BillingClientStateListener {
            // Called when the connection setup process completes.
            override fun onBillingSetupFinished(billingResult: BillingResult) {
                // Resume the coroutine and pass back the BillingResult to the caller.
                continuation.resume(billingResult)
            }
    
            // Called if the connection to the Play Store service is dropped.
            // This prevents the await or suspension point from hanging indefinitely.
            override fun onBillingServiceDisconnected() {
                continuation.resume(
                    BillingResult.newBuilder()
                        .setResponseCode(BillingClient.BillingResponseCode.SERVICE_DISCONNECTED)
                        .setDebugMessage("Billing service disconnected during connection setup")
                        .build()
                )
            }
        })
    }
    
    

    Java

    
    EnableBillingProgramParams params = EnableBillingProgramParams.newBuilder()
            .setBillingProgram(BillingProgram.BILLING_CHOICE)
            .setDeveloperProvidedBillingListener(developerProvidedBillingListener)
            .build();
    
    BillingClient billingClient = BillingClient.newBuilder(context)
            .setListener(purchasesUpdatedListener)
            .enablePendingPurchases(
                    PendingPurchasesParams.newBuilder()
                            .enableOneTimeProducts()
                            .build()
            )
            .enableBillingProgram(params)
            .build();
    
    
  2. इनकी उपलब्धता की पुष्टि करें:

    • Google की ओर से रेंडर किया गया बिलिंग का विकल्प
    • बाहरी वेब लिंक

    प्रोग्राम की उपलब्धता की जांच करने के लिए, isBillingProgramAvailableAsync को कॉल करें. इसके बाद, उपलब्ध प्रॉडक्ट दिखाने के लिए, queryProductDetailsAsync को कॉल करें. उदाहरण के लिए:

    Kotlin

    
    // Check the availability of the billing choice program asynchronously using coroutines
    val (billingResult, billingProgramAvailabilityDetails) =
        billingClient.isBillingProgramAvailable(BillingProgram.BILLING_CHOICE)
    
    // Ensure the billing program query succeeded
    if (billingResult.responseCode == BillingResponseCode.OK) {
        // Retrieve the availability details specific to the billing choice program
        val billingChoiceAvailabilityDetails =
            billingProgramAvailabilityDetails.billingChoiceAvailabilityDetails
    
        // Check if billing choice is available, renders via Google Play, and external link is supported
        if (billingChoiceAvailabilityDetails != null &&
            billingChoiceAvailabilityDetails.choiceScreenType == ChoiceScreenType.GOOGLE_RENDERED &&
            billingChoiceAvailabilityDetails.isExternalLinkAvailable
        ) {
            // Billing choice is available and external transaction links are supported. Query products and proceed.
        } else {
            // Fallback to other available programs.
        }
    } else {
        // Fallback to other available programs.
    }
    
    
    

    Java

    
    // ...
    billingClient.isBillingProgramAvailableAsync(
        BillingProgram.BILLING_CHOICE,
        (billingResult, billingProgramAvailabilityDetails) -> {
            if (billingResult.getResponseCode() == BillingResponseCode.OK) {
                BillingChoiceAvailabilityDetails billingChoiceAvailabilityDetails =
                    billingProgramAvailabilityDetails.getBillingChoiceAvailabilityDetails();
    
                if (billingChoiceAvailabilityDetails != null
                        && billingChoiceAvailabilityDetails.getChoiceScreenType() == ChoiceScreenType.GOOGLE_RENDERED
                        && billingChoiceAvailabilityDetails.isExternalLinkAvailable()) {
                    // Billing choice is available and external transaction links are supported.
                    // Query products and proceed.
                } else {
                    // Fallback to other available programs.
                }
            } else {
                // Fallback to other available programs.
            }
        }
    );
    
    
    
  3. जब उपयोगकर्ता खरीदारी करने का इरादा दिखाए, तो बाहरी लेन-देन का टोकन बनाने के लिए, createBillingProgramReportingDetailsAsync को कॉल करें. उदाहरण के लिए:

    Kotlin

    
    // Build the parameters for creating reporting details
    val params =
        BillingProgramReportingDetailsParams.newBuilder()
            .setBillingProgram(BillingProgram.BILLING_CHOICE)
            .setDeveloperBillingType(DeveloperBillingType.EXTERNAL_LINK)
            .build()
    
    // Call the suspend function to create billing program reporting details
    val (billingResult, billingProgramReportingDetails) =
        billingClient.createBillingProgramReportingDetails(params)
    
    // Handle response failure cases
    if (billingResult.responseCode != BillingResponseCode.OK) {
        // Handle failures such as retrying due to network errors.
        return
    }
    
    // Retrieve the external transaction token
    val transactionToken =
        billingProgramReportingDetails?.externalTransactionToken
    
    // Persist the external transaction token locally. Pass it to
    // DeveloperBillingOptionParams when launchBillingFlow is called.
    // It can also be used as part of your external website
    
    

    Java

    
    BillingProgramReportingDetailsParams params =
        BillingProgramReportingDetailsParams.newBuilder()
            .setBillingProgram(BillingProgram.BILLING_CHOICE)
            .setDeveloperBillingType(DeveloperBillingType.EXTERNAL_LINK)
            .build();
    
    billingClient.createBillingProgramReportingDetailsAsync(
        params,
        new BillingProgramReportingDetailsListener() {
            @Override
            public void onCreateBillingProgramReportingDetailsResponse(
                BillingResult billingResult,
                @Nullable BillingProgramReportingDetails billingProgramReportingDetails
            ) {
                if (billingResult.getResponseCode() != BillingResponseCode.OK) {
                    // Handle failures such as retrying due to network errors.
                    return;
                }
    
                String transactionToken =
                    billingProgramReportingDetails.getExternalTransactionToken();
    
                // Persist the external transaction token locally. Pass it to
                // DeveloperBillingOptionParams when launchBillingFlow is called.
                // It can also be used as part of your external website.
            }
        }
    );
    
    
  4. जब उपयोगकर्ता 'खरीदें' पर क्लिक करे, तो खरीदारी का फ़्लो ट्रिगर करने के लिए, launchBillingFlow को कॉल करें. अगर उपयोगकर्ता के लिए बिलिंग का विकल्प उपलब्ध है, तो यह तरीका अपनाएं:

    1. BillingFlowParams को DeveloperBillingOptionParams पास करें.
    2. तीसरे चरण से मिले बाहरी लेन-देन के टोकन को DeveloperBillingOptionParams पास करें.

    उदाहरण के लिए:

    Kotlin

    
    // Build the developer billing option parameters with the external link URI,
    // the transaction token, and browser/app launch mode.
    val developerBillingOptionParams =
        DeveloperBillingOptionParams.newBuilder()
            .setBillingProgram(BillingProgram.BILLING_CHOICE)
            .setLinkUri(Uri.parse("https://www.example.com/external/purchase"))
            .setExternalTransactionToken(transactionToken)
            .setLaunchMode(
                DeveloperBillingOptionParams.LaunchMode.LAUNCH_IN_EXTERNAL_BROWSER_OR_APP
            )
            .build()
    
    

    Java

    
    DeveloperBillingOptionParams developerBillingOptionParams =
        DeveloperBillingOptionParams.newBuilder()
            .setBillingProgram(BillingProgram.BILLING_CHOICE)
            .setLinkUri(Uri.parse("https://www.example.com/external/purchase"))
            .setExternalTransactionToken(transactionToken)
            .setLaunchMode(
              DeveloperBillingOptionParams.LaunchMode.LAUNCH_IN_EXTERNAL_BROWSER_OR_APP)
            .build();
    
    

    ध्यान दें: निगरानी में रखे गए उपयोगकर्ताओं के लिए, माता-पिता के कंट्रोल की सुविधा दिखती है.

  5. बिलिंग के टाइप के लिए, उपयोगकर्ता के चुने गए विकल्प को इस तरह मैनेज करें:

    • अगर उपयोगकर्ता Play Billing को चुनता है, तो launchBillingFlow Play Billing के स्टैंडर्ड दिशा-निर्देशों के मुताबिक, `launchBillingFlow` को कॉल करें. बिलिंग का नतीजा PurchasesUpdatedListener को भेजा जाता है, जिसे पहले चरण में रजिस्टर किया गया था.
    • अगर उपयोगकर्ता, आपके अन्य बिलिंग सिस्टम को चुनता है, तो बिलिंग का नतीजा, DeveloperProvidedBillingListener को भेजा जाता है, जिसे पहले चरण में
        रजिस्टर किया गया था.
      1. भेजे गए DeveloperProvidedBillingDetails में, externalTransactionToken शामिल होता है. यह टोकन, चौथे चरण में DeveloperBillingOptionParams को पास किया गया था. हालांकि, यह तभी शामिल होता है, जब यह मान्य टोकन हो.

दूसरी स्थिति (बी) को मैनेज करना

डेवलपर, विकल्प वाली स्क्रीन रेंडर करता है और बिलिंग के अन्य विकल्प को ऐप्लिकेशन सेबाहर मैनेज किया जाता है. इस स्थिति में, बिलिंग का विकल्प उपलब्ध कराने के लिए, ये चरण पूरे करें:

  1. BillingClient का इंस्टेंस बनाते समय, EnableBillingProgramParams में DeveloperProvidedBillingListener के बिना enableBillingProgram को कॉल करें. इसके बाद, कनेक्शन शुरू करें. उदाहरण के लिए:

    Kotlin

    
    // Build the parameters to enable the Billing Choice program.
    val params = EnableBillingProgramParams.newBuilder()
        .setBillingProgram(BillingProgram.BILLING_CHOICE)
        .build()
    
    // Construct the BillingClient instance with the purchases updated listener,
    // pending purchases support, and the billing choice params.
    val billingClient = BillingClient.newBuilder(context)
        .setListener(purchasesUpdatedListener)
        .enablePendingPurchases()
        .enableBillingProgram(params)
        .build()
    
    // Establish a connection to Google Play
    val billingResult = suspendCancellableCoroutine<BillingResult> { continuation ->
        billingClient.startConnection(object : BillingClientStateListener {
            // Called when the connection setup process completes.
            override fun onBillingSetupFinished(billingResult: BillingResult) {
                // Resume the coroutine and pass back the BillingResult to the caller.
                continuation.resume(billingResult)
            }
    
            // Called if the connection to the Play Store service is dropped.
            // This prevents the await or suspension point from hanging indefinitely.
            override fun onBillingServiceDisconnected() {
                continuation.resume(
                    BillingResult.newBuilder()
                        .setResponseCode(BillingClient.BillingResponseCode.SERVICE_DISCONNECTED)
                        .setDebugMessage("Billing service disconnected during connection setup")
                        .build()
                )
            }
        })
    }
    
    

    Java

    
    EnableBillingProgramParams params = EnableBillingProgramParams.newBuilder()
            .setBillingProgram(BillingProgram.BILLING_CHOICE)
            .build();
    
    BillingClient billingClient = BillingClient.newBuilder(context)
            .setListener(purchasesUpdatedListener)
            .enablePendingPurchases()
            .enableBillingProgram(params)
            .build();
    
    
  2. इनकी उपलब्धता की पुष्टि करें:

    • Google की ओर से रेंडर किया गया बिलिंग का विकल्प
    • बाहरी वेब लिंक

    प्रोग्राम की उपलब्धता की जांच करने के लिए, isBillingProgramAvailableAsync को कॉल करें. इसके बाद, उपलब्ध प्रॉडक्ट दिखाने के लिए, queryProductDetailsAsync को कॉल करें. उदाहरण के लिए:

    Kotlin

    
    // Check the availability of the billing choice program asynchronously using a coroutine
    val (billingResult, billingProgramAvailabilityDetails) =
        billingClient.isBillingProgramAvailable(BillingProgram.BILLING_CHOICE)
    
    // Ensure the response code is OK
    if (billingResult.responseCode == BillingResponseCode.OK) {
        // Retrieve the billing choice availability details
        val billingChoiceAvailabilityDetails =
            billingProgramAvailabilityDetails.billingChoiceAvailabilityDetails
    
        // Check if billing choice details are available, choice screen is developer-rendered,
        // and external transaction links are supported.
        if (billingChoiceAvailabilityDetails != null &&
            billingChoiceAvailabilityDetails.choiceScreenType == ChoiceScreenType.DEVELOPER_RENDERED &&
            billingChoiceAvailabilityDetails.isExternalLinkAvailable
        ) {
            // Billing choice is available and external transaction links are supported.
            // Query products and proceed.
        } else {
            // Fallback to other available programs.
        }
    } else {
        // Fallback to other available programs.
    }
    
    

    Java

    
    // ...
    
    billingClient.isBillingProgramAvailableAsync(
        BillingProgram.BILLING_CHOICE,
        (billingResult, billingProgramAvailabilityDetails) -> {
            if (billingResult.getResponseCode() == BillingResponseCode.OK) {
                BillingChoiceAvailabilityDetails billingChoiceAvailabilityDetails =
                    billingProgramAvailabilityDetails.getBillingChoiceAvailabilityDetails();
                if (billingChoiceAvailabilityDetails != null &&
                    billingChoiceAvailabilityDetails.getChoiceScreenType() == ChoiceScreenType.DEVELOPER_RENDERED &&
                    billingChoiceAvailabilityDetails.isExternalLinkAvailable()) {
                    // Billing choice is available and external transaction links are supported. Query products and proceed.
                } else {
                    // Fallback to other available programs.
                }
            } else {
                // Fallback to other available programs.
            }
        }
    );
    
    
  3. Play Billing का बैनर और लॉयल्टी की जानकारी पाने के लिए, getBillingChoiceInfoAsync तरीके को कॉल करें.

    Kotlin

    
    // 1. Create the params required for the request
    val params = GetBillingChoiceInfoParams.newBuilder()
        .setBillingProgram(BillingClient.BillingProgram.BILLING_CHOICE)
        .setPlayBillingChoiceImageLayout(GetBillingChoiceInfoParams.ImageLayout.RECTANGULAR_FOUR_BY_ONE)
        .build()
    
    // 2. Call the suspend method on your billingClient instance
    val (billingResult, playBillingChoiceInfo) = billingClient.getBillingChoiceInfo(params)
    
    if (billingResult.responseCode == BillingResponseCode.OK && playBillingChoiceInfo != null) {
        // Access the URL of the image associated with the Play Billing Choice
        val imageUrl = playBillingChoiceInfo.playBillingChoiceImageUrl
    
        // Access the Play Loyalty string information, if available
        val loyaltyInfo = playBillingChoiceInfo.playBillingLoyaltyInfo
    
        // Populate your developer-rendered UI elements
        playBillingLoyaltyTextView.text = loyaltyInfo
        loadImage(imageUrl, playBillingImageView)
    } else {
        // Handle error scenarios
    }
    
    

    Java

    
    // 1. Create the params required for the request
    GetBillingChoiceInfoParams params = GetBillingChoiceInfoParams.newBuilder()
        .setBillingProgram(BillingClient.BillingProgram.BILLING_CHOICE)
        .setPlayBillingChoiceImageLayout(GetBillingChoiceInfoParams.ImageLayout.RECTANGULAR_FOUR_BY_ONE)
        .build();
    // 2. Call the method asynchronously on your billingClient instance
    billingClient.getBillingChoiceInfoAsync(params, (billingResult, playBillingChoiceInfo) -> {
        if (billingResult.getResponseCode() == BillingResponseCode.OK && playBillingChoiceInfo != null) {
          // Access the URL of the image associated with the Play Billing Choice
            String imageUrl = playBillingChoiceInfo.getPlayBillingChoiceImageUrl();
            // Access the Play Loyalty string information, if available
            String loyaltyInfo = playBillingChoiceInfo.getPlayBillingLoyaltyInfo();
    
            // Populate your developer-rendered UI elements
            playBillingLoyaltyTextView.setText(loyaltyInfo);
              loadImage(imageUrl, playBillingImageView);
          } else {
              // Handle error scenarios
          }
    });
    
    
  4. जब उपयोगकर्ता खरीदारी करने का इरादा दिखाए, तो बाहरी लेन-देन का टोकन बनाने के लिए, createBillingProgramReportingDetailsAsync को कॉल करें. उदाहरण के लिए:

    Kotlin

    
    // Build the parameters for creating reporting details
    val params =
        BillingProgramReportingDetailsParams.newBuilder()
            .setBillingProgram(BillingProgram.BILLING_CHOICE)
            .setDeveloperBillingType(DeveloperBillingType.EXTERNAL_LINK)
            .build()
    
    // Call the suspend function to create billing program reporting details
    val (billingResult, billingProgramReportingDetails) =
        billingClient.createBillingProgramReportingDetails(params)
    
    // Handle response failure cases
    if (billingResult.responseCode != BillingResponseCode.OK) {
        // Handle failures such as retrying due to network errors.
        return
    }
    
    // Retrieve the external transaction token
    val transactionToken =
        billingProgramReportingDetails?.externalTransactionToken
    
    // Persist the external transaction token locally. Pass it to
    // DeveloperBillingOptionParams when launchBillingFlow is called.
    // It can also be used as part of your external website
    
    

    Java

    
    BillingProgramReportingDetailsParams params =
        BillingProgramReportingDetailsParams.newBuilder()
            .setBillingProgram(BillingProgram.BILLING_CHOICE)
            .setDeveloperBillingType(DeveloperBillingType.EXTERNAL_LINK)
            .build();
    
    billingClient.createBillingProgramReportingDetailsAsync(
        params,
        new BillingProgramReportingDetailsListener() {
            @Override
            public void onCreateBillingProgramReportingDetailsResponse(
                BillingResult billingResult,
                @Nullable BillingProgramReportingDetails billingProgramReportingDetails
            ) {
                if (billingResult.getResponseCode() != BillingResponseCode.OK) {
                    // Handle failures such as retrying due to network errors.
                    return;
                }
    
                String transactionToken =
                    billingProgramReportingDetails.getExternalTransactionToken();
    
                // Persist the external transaction token locally. Pass it to
                // DeveloperBillingOptionParams when launchBillingFlow is called.
                // It can also be used as part of your external website.
            }
        }
    );
    
    
  5. जब उपयोगकर्ता 'खरीदें' पर क्लिक करे, तो बिलिंग के अन्य विकल्प वाली स्क्रीन लॉन्च करें.

  6. बिलिंग के टाइप के लिए, उपयोगकर्ता के चुने गए विकल्प को इस तरह मैनेज करें:

    • अगर उपयोगकर्ता Play Billing को चुनता है, तो launchBillingFlow Play Billing के स्टैंडर्ड दिशा-निर्देशों के मुताबिक, `launchBillingFlow` को कॉल करें. बिलिंग का नतीजा PurchasesUpdatedListener को भेजा जाता है, जिसे पहले चरण में रजिस्टर किया गया था.

      निगरानी में रखे गए उपयोगकर्ताओं के लिए, माता-पिता के कंट्रोल की सुविधा दिखती है.

    • अगर उपयोगकर्ता, अन्य बिलिंग सिस्टम को चुनता है, तो launchExternalLink को कॉल करें. उदाहरण के लिए:

      Kotlin

      
      // An activity reference from which the purchase flow will be launched.
      val activity: Activity = ...
      
      val params = LaunchExternalLinkParams.newBuilder()
          .setBillingProgram(BillingProgram.BILLING_CHOICE)
          // You can pass along the external transaction token from
          // BillingProgramReportingDetails as a URL parameter in the URI
          .setLinkUri(yourLinkUri)
          .setLinkType(LaunchExternalLinkParams.LinkType.LINK_TO_DIGITAL_CONTENT_OFFER)
          .setLaunchMode(
              LaunchExternalLinkParams.LaunchMode.LAUNCH_IN_EXTERNAL_BROWSER_OR_APP
          )
          .build()
      
      // Call launchExternalLink with a callback
      billingClient.launchExternalLink(activity, params) { billingResult ->
          if (billingResult.responseCode == BillingResponseCode.OK) {
              // Proceed with the rest of the purchase flow. If the user
              // purchases an item, be sure to report the transaction to Google
              // Play.
          } else {
              // Handle failures such as retrying due to network errors.
          }
      }
      
      

      Java

      
      // An activity reference from which the purchase flow will be launched.
      Activity activity = ...;
      
      LaunchExternalLinkParams params = LaunchExternalLinkParams.newBuilder()
          .setBillingProgram(BillingProgram.BILLING_CHOICE)
          // You can pass along the external transaction token from
          // BillingProgramReportingDetails as a URL parameter in the URI
          .setLinkUri(yourLinkUri)
          .setLinkType(LaunchExternalLinkParams.LinkType.LINK_TO_DIGITAL_CONTENT_OFFER)
          .setLaunchMode(
              LaunchExternalLinkParams.LaunchMode.LAUNCH_IN_EXTERNAL_BROWSER_OR_APP)
          .setExternalTransactionToken(transactionToken)
          .build();
      
      LaunchExternalLinkResponseListener listener =
          new LaunchExternalLinkResponseListener() {
            @Override
            public void onLaunchExternalLinkResponse(BillingResult billingResult) {
              if (billingResult.getResponseCode() == BillingResponseCode.OK) {
                // Proceed with the rest of the purchase flow. If the user
                // purchases an item, be sure to report the transaction to Google
                // Play.
              } else {
                // Handle failures such as retrying due to network errors.
              }
            }
          };
      
      billingClient.launchExternalLink(activity, params, listener);
      
      
    • चौथे चरण से मिले बाहरी लेन-देन के टोकन को LaunchExternalLinkParams पास करें. अगर यह OK दिखाता है, तो लेन-देन की प्रोसेस जारी रखें और Google Play को लेन-देन की जानकारी दें.

      निगरानी में रखे गए उपयोगकर्ताओं के लिए, माता-पिता के कंट्रोल की सुविधा दिखती है.

सदस्यता बदलने के दौरान बिलिंग का विकल्प

सदस्यता बदलने के दौरान, उपयोगकर्ता की पसंद की स्क्रीन नहीं दिखनी चाहिए. ऐसा इसलिए, क्योंकि अपग्रेड और डाउनग्रेड के लिए, ओरिजनल खरीदारी के लिए उपयोगकर्ता की पसंद को सेव रखा जाता है.

अगर ओरिजनल खरीदारी, Google Play Billing के ज़रिए प्रोसेस की गई थी, तो आपको launchBillingFlow के साथ, स्टैंडर्ड Google Play Billing सदस्यता बदलने की जानकारी के साथ, कॉल करना चाहिए.

हालांकि, अगर ओरिजनल खरीदारी बिलिंग के किसी अन्य तरीके से प्रोसेस की गई थी , तो सदस्यता बदलने की प्रोसेस, स्थितियों के हिसाब से थोड़ी अलग होती है .

पहली स्थिति (ए) में सदस्यता बदलना

अपग्रेड या डाउनग्रेड का अनुरोध करने वाले उपयोगकर्ताओं को, उपयोगकर्ता के लिए उपलब्ध अनुभव से दोबारा गुज़रने के बजाय, डेवलपर के अन्य बिलिंग सिस्टम से आगे बढ़ना चाहिए.

इसके लिए, जब उपयोगकर्ता अपग्रेड या a डाउनग्रेड का अनुरोध करे, तो launchBillingFlow को कॉल करें. पैरामीटर में, SubscriptionUpdateParams ऑब्जेक्ट में setOriginalExternalTransactionId का इस्तेमाल करके, ओरिजनल खरीदारी के लिए बाहरी लेन-देन का आईडी दें. इससे, उपयोगकर्ता की पसंद की स्क्रीन नहीं दिखती. ऐसा इसलिए, क्योंकि अपग्रेड और डाउनग्रेड के लिए, ओरिजनल खरीदारी के लिए उपयोगकर्ता की पसंद को सेव रखा जाता है. इस मामले में, launchBillingFlow को कॉल करने पर, लेन-देन के लिए बाहरी लेन-देन का नया टोकन जनरेट होता है. इसे कॉलबैक से वापस पाया जा सकता है.

Kotlin


// The external transaction ID from the current
// alternative billing subscription.
val externalTransactionId = //... ;

val developerBillingOptionParams = DeveloperBillingOptionParams.newBuilder()
    .setBillingProgram(BillingProgram.BILLING_CHOICE)
    .build()

val billingFlowParams = BillingFlowParams.newBuilder()
    .setProductDetailsParamsList(
        listOf(
            BillingFlowParams.ProductDetailsParams.newBuilder()
                // Fetched using queryProductDetailsAsync.
                .setProductDetails(productDetailsNewPlan)
                // offerIdToken can be found in
                // ProductDetails=>SubscriptionOfferDetails.
                .setOfferToken(offerTokenNewPlan)
                .build()
        )
    )
    .setSubscriptionUpdateParams(
        BillingFlowParams.SubscriptionUpdateParams.newBuilder()
            .setOriginalExternalTransactionId(externalTransactionId)
            .build()
    )
    .enableDeveloperBillingOption(developerBillingOptionParams)
    .build()

val billingResult = billingClient.launchBillingFlow(activity, billingFlowParams)

// When the user selects the alternative billing flow,
// the DeveloperProvidedBillingListener is triggered.

Java


// The external transaction ID from the current
// alternative billing subscription.
String externalTransactionId = //... ;

DeveloperBillingOptionParams developerBillingOptionParams =
    DeveloperBillingOptionParams.newBuilder()
        .setBillingProgram(BillingProgram.BILLING_CHOICE)
        .build();

List<ProductDetailsParams> productDetailsParamsList = new ArrayList<>();
productDetailsParamsList.add(
    ProductDetailsParams.newBuilder()
        // Fetched using queryProductDetailsAsync.
        .setProductDetails(productDetailsNewPlan)
        // offerIdToken can be found in
        // ProductDetails=>SubscriptionOfferDetails
        .setOfferToken(offerTokenNewPlan)
        .build());

BillingFlowParams billingFlowParams =
    BillingFlowParams.newBuilder()
        .setProductDetailsParamsList(productDetailsParamsList)
        .setSubscriptionUpdateParams(
            SubscriptionUpdateParams.newBuilder()
                .setOriginalExternalTransactionId(externalTransactionId)
                .build())
        .enableDeveloperBillingOption(developerBillingOptionParams)
        .build();

BillingResult billingResult = billingClient.launchBillingFlow(activity, billingFlowParams);

// When the user selects the alternative billing flow,
// the DeveloperProvidedBillingListener is triggered.


अपग्रेड या डाउनग्रेड पूरा होने के बाद, आपको नई सदस्यता की खरीदारी के लिए, पिछली कॉल से मिले बाहरी लेन-देन के टोकन का इस्तेमाल करके, नए लेन-देन की जानकारी देनी होगी.

पहली स्थिति (बी) में सदस्यता बदलना

इस स्थिति में, बाहरी लेन-देन का नया टोकन जनरेट करना ज़रूरी है. सामान्य खरीदारी से सिर्फ़ इतना अंतर है कि इस स्थिति में, उपयोगकर्ता की पसंद को सेव रखा जाता है. साथ ही, अपग्रेड या डाउनग्रेड के लिए, आपको विकल्प वाली स्क्रीन दिखाने की ज़रूरत नहीं होती. हालांकि, आपको एक बार दिखने वाला जानकारी वाला डायलॉग और माता-पिता की सहमति दिखानी होगी.

इंटिग्रेशन के सैंपल कोड के लिए, पहली स्थिति (बी) में चौथा चरण देखें: डेवलपर, विकल्प वाली स्क्रीन रेंडर करता है और बिलिंग के अन्य विकल्प को आपके ऐप्लिकेशन में मैनेज किया जाता है.

अपग्रेड या डाउनग्रेड पूरा होने के बाद, आपको नई सदस्यता की खरीदारी के लिए, पिछली कॉल से मिले बाहरी लेन-देन के टोकन का इस्तेमाल करके, नए लेन-देन की जानकारी देनी होगी.

दूसरी स्थिति (ए) में सदस्यता बदलना

उपयोगकर्ता के लिए उपलब्ध विकल्प के बाद, डेवलपर की वेबसाइट या पेमेंट ऐप्लिकेशन से खरीदी गई सदस्यताओं के लिए, अपग्रेड या डाउनग्रेड का अनुरोध करने वाले उपयोगकर्ताओं को, उपयोगकर्ता के लिए उपलब्ध विकल्प की स्क्रीन पर दोबारा जाने के बजाय, डेवलपर की वेबसाइट या पेमेंट ऐप्लिकेशन से आगे बढ़ना चाहिए.

इसके लिए, जब उपयोगकर्ता अपग्रेड या a डाउनग्रेड का अनुरोध करे, तो launchBillingFlow को कॉल करें. SubscriptionUpdateParams ऑब्जेक्ट में अन्य पैरामीटर तय करने के बजाय, setOriginalExternalTransactionId का इस्तेमाल करें. साथ ही, ओरिजनल खरीदारी के लिए बाहरी लेन-देन का आईडी दें. इस कॉल में, DeveloperBillingOptionParams भी देना ज़रूरी है. इससे, उपयोगकर्ता की पसंद की स्क्रीन नहीं दिखती. ऐसा इसलिए, क्योंकि अपग्रेड और डाउनग्रेड के लिए, ओरिजनल खरीदारी के लिए उपयोगकर्ता की पसंद को सेव रखा जाता है. उदाहरण के लिए:

Kotlin


val externalTransactionId = //... ;

// 1. Construct DeveloperBillingOptionParams indicating the billing program
val developerBillingOptionParams = DeveloperBillingOptionParams.newBuilder()
    .setBillingProgram(BillingClient.BillingProgram.BILLING_CHOICE)
    .build()

// 2. Build BillingFlowParams combining DeveloperBillingOptionParams and SubscriptionUpdateParams
val billingFlowParams = BillingFlowParams.newBuilder()
    .setProductDetailsParamsList(
        listOf(
            BillingFlowParams.ProductDetailsParams.newBuilder()
                // Fetched using queryProductDetailsAsync.
                .setProductDetails(productDetailsNewPlan)
                // offerIdToken can be found in ProductDetails=>SubscriptionOfferDetails.
                .setOfferToken(offerTokenNewPlan)
                .build()
        )
    )
    .setSubscriptionUpdateParams(
        SubscriptionUpdateParams.newBuilder()
            .setOriginalExternalTransactionId(externalTransactionId)
            .build()
    )
    .enableDeveloperBillingOption(developerBillingOptionParams)
    .build()

Java


String externalTransactionId = //... ;

// 1. Construct DeveloperBillingOptionParams indicating the billing program
DeveloperBillingOptionParams developerBillingOptionParams =
    DeveloperBillingOptionParams.newBuilder()
        .setBillingProgram(BillingClient.BillingProgram.BILLING_CHOICE)
        .build();

// 2. Add ProductDetailsParams
List productDetailsParamsList = new ArrayList<>();
productDetailsParamsList.add(
    ProductDetailsParams.newBuilder()
        // Fetched using queryProductDetailsAsync.
        .setProductDetails(productDetailsNewPlan)
        // offerIdToken can be found in ProductDetails=>SubscriptionOfferDetails
        .setOfferToken(offerTokenNewPlan)
        .build());

// 3. Build BillingFlowParams combining DeveloperBillingOptionParams and SubscriptionUpdateParams
BillingFlowParams billingFlowParams =
    BillingFlowParams.newBuilder()
        .setProductDetailsParamsList(productDetailsParamsList)
        .setSubscriptionUpdateParams(
            SubscriptionUpdateParams.newBuilder()
                .setOriginalExternalTransactionId(externalTransactionId)
                .build())
        .enableDeveloperBillingOption(developerBillingOptionParams)
        .build();


आपको बाहरी लेन-देन का नया टोकन भी जनरेट करना होगा. उदाहरण के लिए:

Kotlin


val params =
    BillingProgramReportingDetailsParams.newBuilder()
        .setBillingProgram(BillingProgram.BILLING_CHOICE)
        .setDeveloperBillingType(DeveloperBillingType.EXTERNAL_LINK)
        .build()

billingClient.createBillingProgramReportingDetailsAsync(
    params,
    object : BillingProgramReportingDetailsListener {
        override fun onCreateBillingProgramReportingDetailsResponse(
            billingResult: BillingResult,
            billingProgramReportingDetails: BillingProgramReportingDetails?
        ) {
            if (billingResult.responseCode != BillingResponseCode.OK) {
                // Handle failures such as retrying due to network errors.
                return
            }
            val externalTransactionToken =
                billingProgramReportingDetails?.externalTransactionToken
            // Persist the external transaction token locally. Pass it to
            // the external website using DeveloperBillingOptionParams when
            // launchBillingFlow is called.
        }
    }
)

Java


BillingProgramReportingDetailsParams params =
    BillingProgramReportingDetailsParams.newBuilder()
        .setBillingProgram(BillingProgram.BILLING_CHOICE)
        .setDeveloperBillingType(DeveloperBillingType.EXTERNAL_LINK)
        .build();

billingClient.createBillingProgramReportingDetailsAsync(
    params,
    new BillingProgramReportingDetailsListener() {
      @Override
      public void onCreateBillingProgramReportingDetailsResponse(
          BillingResult billingResult,
          @Nullable BillingProgramReportingDetails billingProgramReportingDetails) {
        if (billingResult.getResponseCode() != BillingResponseCode.OK) {
          // Handle failures such as retrying due to network errors.
          return;
        }
        String transactionToken =
            billingProgramReportingDetails.getExternalTransactionToken();
        // Persist the external transaction token locally. Pass it to
        // the external website using DeveloperBillingOptionParams when
        // launchBillingFlow is called.
      }
    });

नया टोकन जनरेट करने के बाद, खरीदारी का फ़्लो लॉन्च करने के लिए, आपको launchBillingFlow तरीके को कॉल करना होगा.

अपग्रेड या डाउनग्रेड पूरा होने के बाद, आपको नई सदस्यता की खरीदारी के लिए, पिछली कॉल से मिले बाहरी लेन-देन के टोकन का इस्तेमाल करके, नए लेन-देन की जानकारी देनी होगी.

दूसरी स्थिति (बी) में सदस्यता बदलना

इस स्थिति में सदस्यता बदलने के लिए, वही चरण अपनाने होंगे जो दूसरी स्थिति (ए) में सदस्यता बदलना में बताए गए हैं. सिर्फ़ इतना अंतर है कि लेन-देन का टोकन जनरेट करने के बाद, launchBillingFlow तरीके को कॉल करने के बजाय, आपको लिंकआउट के अस्वीकरण वाला डायलॉग दिखाने के लिए, launchExternalLink को कॉल करना होगा. इस स्थिति में, उपयोगकर्ता की पसंद को सेव रखा जाता है. साथ ही, अपग्रेड या डाउनग्रेड के लिए, आपको विकल्प वाली स्क्रीन दिखाने की ज़रूरत नहीं होती.

इंटिग्रेशन के सैंपल कोड के लिए, दूसरी स्थिति (बी) में छठा चरण देखें: डेवलपर, विकल्प वाली स्क्रीन रेंडर करता है और बिलिंग के अन्य विकल्प को आपके ऐप्लिकेशन में मैनेज किया जाता है.

अपग्रेड या डाउनग्रेड पूरा होने के बाद, आपको नई सदस्यता की खरीदारी के लिए, पिछली कॉल से मिले बाहरी लेन-देन के टोकन का इस्तेमाल करके, नए लेन-देन की जानकारी देनी होगी.