如何正确实施Google Play结算库

时间:2019-11-17 17:44:51

标签: java android google-play play-billing-library

因此,我正在尝试在自己的应用中实现Google Play Billing Library,以便允许用户进行应用内购买。到目前为止,我觉得一切顺利,我已经很好地遵循了指南,但是最后一步使我感到困惑,我不知道如何实现const db = require('../../../data') const EasyGraphQLTester = require('easygraphql-tester') const schema = ` type Mutation { createMovie(data: CreateMovieInput!): Movie! } input CreateMovieInput { movie_id: ID! genres: [Int!] } type Movie { movie_id: ID! genres: [MovieGenre] } type MovieGenre { movie_genre_id: ID! id: Int! name: String } ` describe('Movie Mutations', () => { it('Should return the correct array of movie genres', async () => { const args = { data: { genres: [12, 16, 36], }, } const mutation = ` mutation { createMovie( data:{ id: 500, adult: false, genres: [12,16,36] } ) { genres{ movie_genre_id name id } } } ` const createMovie = (parent, args, { db }) => { const { data: { adult, id, genres }, } = args const movie = { movie_id: uuidv4(), adult, id, genres, } db.movies.push(movie) return movie } const tester = new EasyGraphQLTester(schema, { createMovie }) await tester.graphql(mutation, {}, {}, args) }) }) 来更精确苦苦挣扎的BillingFlowParams,我知道它说

  

通过调用querySkuDetailsAsync()检索“ skuDetails”的值

但是我不知道该在哪里传递什么参数,我尝试查看文档,但这使我更加困惑。

这是我到目前为止所拥有的

setSkuDetails

1 个答案:

答案 0 :(得分:0)

您必须在onBillingSetupFinished中启用按钮“ btnPurchase”,并在onBillingServiceDisconnected上禁用它(在启动时将其禁用)。 因此,在“ btnPurchase.setOnClickListene / onClick”中,您必须调用“ billing_client.querySkuDetailsAsync”(您的代码正确),然后

for( SkuDetails skuDetails : sku_details_list ){
    if( ITEM_SKU_ADREMOVAL.equals( skuDetails.getSku() ) ){
        BillingFlowParams flow_params = BillingFlowParams.newBuilder()
                .setSkuDetails( skuDetails )
                .build();
        billing_client.launchBillingFlow( MyActivity.this, flow_params );
    }
}

别忘了“ billing_client.acknowledge购买”