биллинг андроид-студии не может получить купленный токен - PullRequest
0 голосов
/ 11 июня 2019

Я работаю с «Billing», вся система работает, но я не могу получить токен покупки и DeveloperPayload, когда завершаю покупку, каждый раз, когда я пытаюсь это сделать, я получаю нулевые значения ThePurchaseToken и DeveloperPayLoad

Я пытался с

Purchase purchase;
ConsumeParams consumeparams;

purchase.getPurchaseToken();
purchase.getDeveloperPayload();
consumeparams.getPurchaseToken();
consumeparams.getDeveloperPayload();

все на OnPurchasesUpdated

 protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_poner_dinero);

    LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver,
                new IntentFilter("custom-message"));
        loadProduct.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (billingClient.isReady())
                {
                    SkuDetailsParams  params = SkuDetailsParams.newBuilder()
                            .setSkusList(Arrays.asList("a" , "b" ,  "c" , "d" , "3" , "e", "f", "g",  "h", "i", "j", "k"))
                            .setType(BillingClient.SkuType.INAPP) 
                            .build();
                    billingClient.querySkuDetailsAsync(params, new SkuDetailsResponseListener() {
                        @Override
                        public void onSkuDetailsResponse(BillingResult responseCode, List<SkuDetails> skuDetailsList) {
                            if (responseCode.getResponseCode() == BillingClient.BillingResponseCode.OK)
                            {
                                loadProductToRecyclerView(skuDetailsList);
                            }
                            else
                            {
                                Toast.makeText(ponerDineroActivity.this, "not found", Toast.LENGTH_SHORT).show();
                            }
                        }
                    });
                }
                else
                {
                    Toast.makeText(ponerDineroActivity.this, "Try again", Toast.LENGTH_SHORT).show();
                }
            }
        });
        setupBillingClient();
    }

    public BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            // Get extra data included in the Intent
            String ItemName = intent.getStringExtra("item");
            Toast.makeText(ponerDineroActivity.this,  ItemName ,Toast.LENGTH_SHORT).show();
            ultimacompra.setText(ItemName);
        }
    };
    private void setupBillingClient() {

        billingClient = BillingClient.newBuilder (this).setListener(this).enablePendingPurchases().build();

        billingClient.startConnection(new BillingClientStateListener() {
            @Override
            public void onBillingSetupFinished(BillingResult responseCode) {
                if (responseCode.getResponseCode() == BillingClient.BillingResponseCode.OK)
                {
                    Toast.makeText(ponerDineroActivity.this, "works", Toast.LENGTH_SHORT).show();
                }
                else
                {
                    Toast.makeText(ponerDineroActivity.this, "works denied", Toast.LENGTH_SHORT).show();
                }
            }
            @Override
            public void onBillingServiceDisconnected() {
                Toast.makeText(ponerDineroActivity.this, "Disconnected", Toast.LENGTH_SHORT).show();
            }
        });
    }

    private void loadProductToRecyclerView(List<SkuDetails> skuDetailsList) {
        MyProductAdapter adapter  = new MyProductAdapter(ponerDineroActivity.this, skuDetailsList,billingClient);
        recyclerProduct.setAdapter(adapter);

    }
    @Override
    public void onPurchasesUpdated(BillingResult responseCode, @Nullable List<Purchase> purchases) {

Toast.LENGTH_SHORT).show();
        if (responseCode.getResponseCode() == BillingClient.BillingResponseCode.OK)
        {
            String  wml = purchase.getPurchaseToken();
         String  fit = conssumeparams.getDeveloperPayload();

            final ConsumeParams consumeParams =
                    ConsumeParams.newBuilder()
                            .setPurchaseToken(wml)
                            .setDeveloperPayload(fit)
                            .build();

            new ConsumeResponseListener() {
                @Override
                public void onConsumeResponse(BillingResult billingResult, String outToken) {
                    if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {

                        if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK)
                        {
                            currentusermoneyFB = FirebaseDatabase.getInstance().getReference().child("Usuarios").child(currentuserid);
                            currentusermoneyFB.addListenerForSingleValueEvent(new ValueEventListener() {
                                @Override
                                public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                                    String currentusermoneyextra = (String) dataSnapshot.child("Dinero").getValue();

                                    itemName = ultimacompra.getText().toString();
                                    myNum = Integer.parseInt(itemName);
                                    myNum2 = Integer.parseInt(currentusermoneyextra);

                                    int total = myNum + myNum2;
                                    String strI = String.valueOf(total);
                                    DatabaseReference ref = FirebaseDatabase.getInstance().getReference().child("Usuarios");
                                    HashMap<String, Object> userMap = new HashMap<>();
                                    userMap.put("Dinero", strI);
                                    ref.child(Prevalent.currentOnlineUser.getTelefono()).updateChildren(userMap);
                                }

                                @Override
                                public void onCancelled(@NonNull DatabaseError databaseError) {

                                }
                            });
                        }
                        else
                        {
                            Toast.makeText(ponerDineroActivity.this, "ERROR", Toast.LENGTH_SHORT).show();
                        }
                    }
                    else
                    {
                        Toast.makeText(ponerDineroActivity.this, "Try again", Toast.LENGTH_SHORT).show();
                    }
                    billingClient.consumeAsync(consumeParams, listener);

                }
            };

        }
        else
        {
            Toast.makeText(this, "ERROR", Toast.LENGTH_SHORT).show();
        }
}
}

Мне нужно получить DeveloperPayload и getPurchaseToken от покупки, чтобы иметь возможность потреблять продукт

Я руководствовался документацией:

https://developer.android.com/google/play/billing/billing_onetime

Есть идеи?спасибо

...