public class Compra extends ActivityBase{
private static String noAd = "";
private IabHelper mHelper;
private int codigoCompra = 1001;
private ProgressDialog progresso;
private ActivityBase tela;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.compra); //Criar this
noAd = "MINHA CHAVE"
mHelper = new IabHelper(this,"MEU PAYLOAD");
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {
if (!result.isSuccess()) {
return;
}
if (mHelper == null) return;
mHelper.queryInventoryAsync(getInventarioListener);
}
});
tela = this;
String compra = getIntent().getStringExtra("Compra");
}
public void comprar(View v)
{
removerAnuncios();
}
IabHelper.QueryInventoryFinishedListener getInventarioListener = new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
if (mHelper == null) return;
if (result.isFailure()) {
return;
}
consultarCompras();
// Produto comprado
Purchase noAdProduto = inventory.getPurchase(noAd);
boolean noAdComprado = (noAd != null &&
verifyDeveloperPayload(noAdProduto));
if (noAdComprado)
{
salvarCompra(tela.getString(R.string.noAd));
}
}
};
IabHelper.OnIabPurchaseFinishedListener compraFinalizadaListener = new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
progresso.dismiss();
if (mHelper == null) return;
if (result.isFailure()) {
Suporte.alertar(tela, "Falha ao realizar compra!");
//EasyTracker.getInstance(tela).send(MapBuilder.createEvent("Compra",
//"Falha ao comprar", "Produto: "+purchase.getSku(), null).build());
return;
}
if (!verifyDeveloperPayload(purchase)) {
Suporte.alertar(tela.getApplicationContext(), "Falha ao realizar compra. Foi detectada uma tentativa de fraude!");
//EasyTracker.getInstance(tela).send(MapBuilder.createEvent("Compra",
//"Tentativa de fraude", "Produto: "+purchase.getSku()+" - Payload: "+purchase.getDeveloperPayload(), null).build());
return;
}
if (purchase.getSku().equals(noAd)) {
Suporte.alertar(tela, "Compra realizada com sucesso!");
salvarCompra(noAd);
//tela.desabilitarAdPosCompra();
}
}
};
private boolean verifyDeveloperPayload(Purchase p) {
return p != null && p.getDeveloperPayload().equals("MEU PAYLOAD");
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.i("AA","onActivityResult(" + requestCode + "," + resultCode + "," + data);
// Pass on the activity result to the helper for handling
if (!mHelper.handleActivityResult(requestCode, resultCode, data)) {
this.setOnActivityResultCompra(requestCode, resultCode, data);
}
else {
Log.i("BB", "onActivityResult handled by IABUtil.");
}
}
public void removerAnuncios() {
mostrarCarregando();
String payload = "CHAVE");
mHelper.launchPurchaseFlow(this, noAd, codigoCompra,
compraFinalizadaListener, payload);
}
private void salvarCompra(String key)
{
SharedPreferences sharedPref = this.getPreferences(Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();
editor.putBoolean(key, true);
editor.commit();
if(sharedPref.getInt(key+"_ID", -1) < 1)
{
enviarCompra(key);
}
}
private void enviarCompra(String key)
{
new ControleCompra(this).execute(key);
}
private void consultarCompras()
{
new ControleCompra(this).execute(this.getString(R.string.GETCOMPRAS));
}
public boolean comprado(Activity cx, String key)
{
return cx.getPreferences(Context.MODE_PRIVATE).getBoolean(key, false);
}
private void mostrarCarregando()
{
progresso = new ProgressDialog(this);
progresso.setTitle(R.string.solicitandoCompra);
CharSequence carregando = this.getString(R.string.carregando)+"...";
progresso.setMessage(carregando);
progresso.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progresso.show();
}--
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
...
String<span style="color: #000;" class="styled-by-p
--
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Pelo que entendi ele verifica se o codigo que voce enviou a google para emitir o pagamento é o mesmo que retornou.
You received this message because you are subscribed to a topic in the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/androidbrasil-dev/ffHO0rk4Xmc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to androidbrasil-...@googlegroups.com.
Security Recommendation: It’s good practice to pass in a string that helps your application to identify the user who made the purchase, so that you can later verify that this is a legitimate purchase by that user. For consumable items, you can use a randomly generated string, but for non-consumable items you should use a string that uniquely identifies the user.
Não. Quando envia uma solicitação de compra, vc passa um codigo, e a google retorna esse codigo para voce ter certeza que nenhum outro agente se infiltrou no meio de uma transação para burlar.