ورود

View Full Version : سوال پیرامون پرداخت درون برنامه ای



milad00007
جمعه 09 خرداد 1393, 19:29 عصر
سلام دوستان ، من یک پرداخت درون برنامه ای رو پیدا کردم حالا یه مشکل دارم ، برنامه در بخش ارتقا اول چک میکنه و وصل میشه به بازار از طریق اینترنت ، بعد که قیمت رو نمایش داد دکمه فعال میشه و قابل کلیک میشه . میشه بگید چجوری این روند رو کنسل کنم تا چک نکنه و از اول دکمه فعال باشه و نیاز نباشه قیمت رو نشون بده تا دکمه فعال بشه .
کدش به این شکل هست :


butBuy = (Button) findViewById(R.id.button_buy);






// [...]


// Initially, disable the "buy me" button
butBuy.setEnabled(false);



buyHelper = new IabHelper(this,Billing. PUBLIC_KEY);
buyHelper.startSetup(new OnIabSetupFinishedListener() {
@Override
public void onIabSetupFinished(IabResult result) {
if(result.isSuccess()) {
// Fill a list of SKUs that we want the price infos for
// (SKU = "stockable unit" = buyable things)
ArrayList<String> moreSkus = new ArrayList<String>();
moreSkus.add(Billing.SKU_NAME_PREMIUM);


// We initialize the price field with a "retrieving price" message while we wait
// for the price
final TextView tvPrice = (TextView) findViewById(R.id.price);
tvPrice.setText("پس از مشاهده قیمت روی دکمه بالا کلیک کنید");


// Start the query for the details for the SKUs. This runs asynchronously, so
// it may be that the price appears a bit later after the rest of the Activity is shown.
buyHelper.queryInventoryAsync(true, moreSkus, new QueryInventoryFinishedListener() {
@Override
public void onQueryInventoryFinished(IabResult result, Inventory inv) {
if(result.isSuccess()) {


// If we successfully got the price, show it in the text field
SkuDetails details = inv.getSkuDetails(Billing.SKU_NAME_PREMIUM);
String price = details.getPrice();


tvPrice.setText(price);


// On successful init and price getting, enable the "buy me" button
butBuy.setEnabled(true);
} else {
// Error getting the price... show a sorry text in the price field now
tvPrice.setText("خطا در برقراری ارتباط ! لطفا اینترنت گوشی یا تبلت خود را روشن کرده و مجدد به این صفحه مراجعه کنید .");
//
butBuy.setEnabled(true);
//
}
}


});
}
}
});


// [...]
//Buying an In-App Item
// [...]


butBuy.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// Disable the button after the click to prevent double clicks
butBuy.setEnabled(false);


// Start the purchase flow
buyHelper.launchPurchaseFlow(Upgrade.this,
Billing.SKU_NAME_PREMIUM, BUY_REQUEST_CODE,
new OnIabPurchaseFinishedListener() {
@Override
public void onIabPurchaseFinished(IabResult result, Purchase info) {
if (result.isSuccess()) {
// Successful - the item has been payed for


// We set a vale in the shared preferences to mark this app as
SharedPreferences shared = getSharedPreferences("Prefs", MODE_PRIVATE);
SharedPreferences.Editor editor = shared.edit();
editor.putBoolean(Billing.KEY_PREMIUM_VERSION, true);
editor.apply();



//
// The flag "CLEAR_TASK" is important, so the user is not sent
// back to this buy activity when he presses the back button.
//
Toast.makeText(getBaseContext(), "تبریک ، ارتقا به نسخه کامل با موفقیت انجام شد .",Toast.LENGTH_LONG).show();
Intent intentz = new Intent(
Upgrade.this,
MainActivity.class);
intentz.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK
| Intent.FLAG_ACTIVITY_NEW_TASK);



startActivity(intentz);
}

}
});
}
});
}

hamedjj
جمعه 09 خرداد 1393, 20:15 عصر
سوالات درباره پرداخت درون برنامه ای را در تاپیک خودش مطرح کن
همونجا هم پروژه آموزشی همرا با آموزش هست که مشکلی نداره و میتونی ازش استفاده کنی

http://barnamenevis.org/showthread.php?429143-%D9%BE%D8%B1%D8%AF%D8%A7%D8%AE%D8%AA-%D8%AF%D8%B1%D9%88%D9%86-%D8%A8%D8%B1%D9%86%D8%A7%D9%85%D9%87-%D8%A7%DB%8C/