مشکل کوچک اما عجیب در پرداخت درون برنامه ای ...

ساخت وبلاگ

package com.varesapp.testforpardakhtbazaar;

import utils.IabHelper;
import utils.IabResult;
import utils.Inventory;
import utils.Purchase;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
import android.app.Activity;
import android.content.Intent;

public class MainActivity extends Activity {

// Debug tag, for logging
// Debug tag, for logging
static final String TAG = "Esfandune.ir";

// SKUs for our products: the premium upgrade (non-consumable)
static final String SKU_PREMIUM = "EsfanduneCo";

// Does the user have the premium upgrade?
boolean mIsPremium = false;

// (arbitrary) request code for the purchase flow
static final int RC_REQUEST = 1372;

// The helper object
IabHelper mHelper;
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener;
IabHelper.QueryInventoryFinishedListener mGotInventoryListener;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

String base64EncodedPublicKey = "MIHNMA0GCSqGSIb3DQEBAQUAA4G7ADCBtwKBrwCYWwX4dYPAG +ixtXURSAjenEqRtI0AmPtFL3gp6so+eSCr2lTc7o4KswlKEcH 7oGwOIiuwsWV9xXIiGav2wx3fc1A4qzk4r3NI+4oUDnEFpQXoL oTFYqj1YPzuyj8rJ3TAj9KKiRyahEmNir3OgCUt1Hd02oARb3K diln+AuRAwKUmWKiuKYCjt2fjHAJCia8vwz2fqxe6+qhfg2ffh atT2naz0XrJ2daupSLp2ScCAwEAAQ==";

mHelper = new IabHelper(this, base64EncodedPublicKey);

mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {

@Override
public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
Log.d(TAG, "Query inventory finished.");
if (result.isFailure()) {
Log.d(TAG, "Failed to query inventory: " + result);
retu;
}
else {
Log.d(TAG, "Query inventory was successful.");
// does the user have the premium upgrade?
mIsPremium = inventory.hasPurchase(SKU_PREMIUM);
if (mIsPremium){
MasrafSeke(inventory.getPurchase(SKU_PREMIUM));
}
// update UI accordingly

Log.d(TAG, "User is " + (mIsPremium ? "PREMIUM" : "NOT PREMIUM"));
}
}
};

mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() {

@Override
public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
if (result.isFailure()) {
Log.d(TAG, "Error purchasing: " + result);
retu;
}
else if (purchase.getSku().equals(SKU_PREMIUM)) {
// give user access to premium content and update the UI
Toast.makeText(MainActivity.this,"خرید موفق",Toast.LENGTH_SHORT).show();
MasrafSeke(purchase);
}
}
};

Log.d(TAG, "Starting setup.");
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {
Log.d(TAG, "Setup finished.");

if (!result.isSuccess()) {
Log.d(TAG, "Problem setting up In-app Billing: " + result);
}
// Hooray, IAB is fully set up!
mHelper.queryInventoryAsync(mGotInventoryListener) ;
}
});

}

@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.");
}
}

@Override
public void onDestroy() {
//از سرویس در زمان اتمام عمر activity قطع شوید
super.onDestroy();
if (mHelper != null) mHelper.dispose();
mHelper = null;
}

private void MasrafSeke(Purchase kala){
// برای اینکه کاربر فقط یکبار بتواند از کالای فروشی استفاده کند
// باید بعد از خرید آن کالا را مصرف کنیم
// در غیر اینصورت کاربر با یکبار خرید محصول می تواند چندبار از آن استفاده کند
mHelper.consumeAsync(kala, new IabHelper.OnConsumeFinishedListener() {
@Override
public void onConsumeFinished(Purchase purchase, IabResult result) {
if (result.isSuccess()) Toast.makeText(MainActivity.this,"مصرف شد",Toast.LENGTH_SHORT).show();
Log.d(TAG, "NATIJE masraf: "+result.getMessage()+result.getResponse());

}
});
}

public void onClick(View view){
mHelper.launchPurchaseFlow(this, SKU_PREMIUM, RC_REQUEST, mPurchaseFinishedListener, "payload-string");
}

}

برنامه نویس...
ما را در سایت برنامه نویس دنبال می کنید

برچسب : نویسنده : محمد رضا جوادیان programers بازدید : 113 تاريخ : چهارشنبه 15 ارديبهشت 1395 ساعت: 23:56