آقا من پرداخت درون برنامه ای رو تو برنامه اولم بدرستی اجرا کردم.
الان عین همون کارها رو برای 3 برنامه دیگه انجام دادم ولی کار نمیده.
این لینک یکی از برنامه هایی که ساختم لطفا تست کنید.
قیمت هم صفر گذاشتم.
از منوی سمت راست گزینه یکی به آخر مونده "افزایش لایک فیسبوک" رو بزنید تا وارد صفحه پرداخت بشید.
اینم اکتیویتی خرید درون برنامه ای:
package com.example.smsbaaz;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.entity.BufferedHttpEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import com.example.facebooklike.R;
import util.IabHelper;
import util.IabResult;
import util.Inventory;
import util.Purchase;
import android.app.ActionBar.LayoutParams;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundExce ption;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.View;
import android.view.View.MeasureSpec;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
public class UpdateActivity extends Activity {
int update = 0;
public ProgressDialog dialog ;
ImageButton btn1;
ImageButton btn2;
SharedPreferences sp;
//Debug tag, for logging
static final String TAG = "SmsBaaz";
//SKUs for our products: the premium upgrade (non-consumable)
static final String SKU_PREMIUM = "jhgiopjogyu2hu";
//Does the user have the premium upgrade?
boolean mIsPremium = false;
//(arbitrary) request code for the purchase flow
static final int RC_REQUEST = 10001;
//The helper object
IabHelper mHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.update);
// show loading dialog with ProgressDialog
dialog = new ProgressDialog(this);
dialog.setCancelable(false);
dialog.setInverseBackgroundForced(false);
btn1 = (ImageButton) findViewById(R.id.button1);
btn1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
finish();
startActivity(new Intent(UpdateActivity.this,MainActivity.class));
}
});
btn2 = (ImageButton) findViewById(R.id.button2);
sp = PreferenceManager.getDefaultSharedPreferences(this );
if(!isPackageInstalled("com.farsitel.bazaar", UpdateActivity.this)){
Toast.makeText(getApplicationContext(),"نرم افزار بازار هنوز نصب نشده است",Toast.LENGTH_LONG).show();
}
else{
if(isNetworkConnected()){
dialog.setMessage("بررسی سبد خرید");
dialog.show();
String base64EncodedPublicKey = "MIHNMA0GCSqGSIb3DQEBAQUAA4G7ADCBtwKBrwC9eqtpO4UqF bumNBZsFtCM+knU+9kcFNGX3mgD87fojwiXlwvfk8SigLmCVny ahPwAgqBWTYZNwj7ae/B5ZlFft4JyYKIvi/PJPx5he6okOyLjy+wIYQ3/7sTpe3sqgqln266spL3MfOxa3xYVC038Ig04Cuy0rW6QFGnQFI riZCHEcb2bymWJCVy2YP5Omw1PrQRD6Z+R816p1DQn6b3mOQb2 ggCFDRL/PKmHfGcCAwEAAQ==";
// You can find it in your Bazaar console, in the Dealers section.
// It is recommended to add more security than just pasting it in your source code;
mHelper = new IabHelper(this, base64EncodedPublicKey);
Log.d(TAG, "Starting setup.");
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {
Log.d(TAG, "Setup finished.");
if (!result.isSuccess()) {
Toast.makeText(getApplicationContext(),"وارد اکانت حساب کاربری خود در بازار شوید."+"\n"+"یا اتصال به اینترنت را بررسی کنید.",Toast.LENGTH_LONG).show();
// Oh noes, there was a problem.
Log.d(TAG, "Problem setting up In-app Billing: " + result);
}
// Hooray, IAB is fully set up!
mHelper.queryInventoryAsync(mGotInventoryListener) ;
}
});
}
}
}
//با آغاز اکتیویتی کد زیر اجرا میشود که برای جستجو premium بودن میباشد.
//اگر کاربر premium باشد دیالوگ loading مخفی میشه dialog.hide() متد UpdateUi() اجرا میشه و محتوای این متد را در باتن قرار میده.
//اگر کاربر premium نباشه هم منتظر لمس کردن کاربر بر روی دکمه میشه که متد onOnlineUpgradeAppButtonClicked را فراخوانی کند.
IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
Log.d(TAG, "Query inventory finished.");
if (result.isFailure()) {
Log.d(TAG, "Failed to query inventory: " + result);
dialog.hide();
Toast.makeText(getApplicationContext(),"خطا در ارتباط با سرور."+"\n"+"وارد اکانت حساب کاربری خود در بازار شوید."+"\n"+"یا اتصال به اینترنت را بررسی کنید.",Toast.LENGTH_LONG).show();
return;
}
else {
Log.d(TAG, "Query inventory was successful.");
// does the user have the premium upgrade?
mIsPremium = inventory.hasPurchase(SKU_PREMIUM);
// update UI accordingly
Log.d(TAG, "User is " + (mIsPremium ? "PREMIUM" : "NOT PREMIUM"));
}
dialog.hide();
updateUi();
Log.d(TAG, "Initial inventory query finished; enabling main UI.");
}
};
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d(TAG, "onActivityResult(" + requestCode + "," + resultCode + "," + data);
// Pass on the activity result to the helper for handling
if (!mHelper.handleActivityResult(requestCode, resultCode, data)) {
super.onActivityResult(requestCode, resultCode, data);
} else {
Log.d(TAG, "onActivityResult handled by IABUtil.");
}
}
boolean verifyDeveloperPayload(Purchase p) {
String payload = p.getDeveloperPayload();
return true;
}
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
Log.d(TAG, "Purchase finished: " + result + ", purchase: " + purchase);
if (result.isFailure()) {
Toast.makeText(getApplicationContext(),"وارد اکانت حساب کاربری خود در بازار شوید."+"\n"+"یا اتصال به اینترنت را بررسی کنید.",Toast.LENGTH_LONG).show();
Log.d(TAG, "Error purchasing: " + result);
return;
}
if (!verifyDeveloperPayload(purchase)) {
Toast.makeText(getApplicationContext(),"وارد اکانت حساب کاربری خود در بازار شوید."+"\n"+"یا اتصال به اینترنت را بررسی کنید.",Toast.LENGTH_LONG).show();
complain("Error purchasing. Authenticity verification failed.");
return;
}
Log.d(TAG, "Purchase successful.");
if (purchase.getSku().equals(SKU_PREMIUM)) {
Log.d(TAG, "Purchase is premium upgrade. Congratulating user.");
mIsPremium = true;
updateUi();
Toast.makeText(getApplicationContext(),"با تشکر از خرید شما",Toast.LENGTH_LONG).show();
}
}
};
@Override
public void onDestroy() {
super.onDestroy();
Log.d(TAG, "Destroying helper.");
if (mHelper != null) mHelper.dispose();
mHelper = null;
}
// اگر کاربر پریمیوم باشد دستورات آپدیت را انجام میدهد در غیر اینصورت به صفحه خرید هدایت می شود.
public void updateUi() {
if (mIsPremium) {
update = 224;
Editor e = sp.edit();
e.putInt("update", 224);
e.commit();
Toast.makeText(getApplicationContext(),"شما کاربر ویژه هستید",Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(getApplicationContext(),"نرم افزار خریداری نشده است",Toast.LENGTH_LONG).show();
}
}
void complain(String message) {
Log.e(TAG, "**** testbilling Error: " + message);
}
private boolean isNetworkConnected() {
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo ni = cm.getActiveNetworkInfo();
if (ni == null) {
Toast.makeText(getApplicationContext(), "اتصال به اینترنت برقرار نیست", Toast.LENGTH_LONG).show();
return false;
} else
return true;
}
public static boolean isPackageInstalled(String packagename,Context context) {
PackageManager pm = context.getPackageManager();
try {
pm.getPackageInfo(packagename, PackageManager.GET_ACTIVITIES);
return true;}
catch (NameNotFoundException e) {
return false;}
}
public void onOnlineUpgradeAppButtonClicked(View arg0) {
if(!isPackageInstalled("com.farsitel.bazaar", UpdateActivity.this)){
Toast.makeText(getApplicationContext(),"نرم افزار بازار هنوز نصب نشده است",Toast.LENGTH_LONG).show();
}
else{
if(isNetworkConnected()){
Log.d(TAG, "Upgrade button clicked; launching purchase flow for upgrade.");
/* TODO: for security, generate your payload here for verification. See the comments on
* verifyDeveloperPayload() for more info. Since this is a SAMPLE, we just use
* an empty string, but on a production app you should carefully generate this. */
String payload = "inbarnametavasotehamedjjsakhteshodeast";
mHelper.launchPurchaseFlow(UpdateActivity.this, SKU_PREMIUM, RC_REQUEST,
mPurchaseFinishedListener, payload);
}
}
}
private static long back_pressed = 0L;
@Override
public void onBackPressed()
{
finish();
startActivity(new Intent(UpdateActivity.this,MainActivity.class));
}
}