PDA

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



dibdab
چهارشنبه 27 مرداد 1395, 22:21 عصر
سلام من از مستندات یه مشت کر برداشتم و درون برنامه اضافه کردم
پرداخت رو کامل انجام میده ولی توی نتیجه چه موفقیت آمیز باشه چه نباشه اون پرداخت فقط یه دستور رو اجرا میکنه


{complain("Error purchasing: " + result);}

اینم کد هایی که نوشتم
دوستان کسی هست راهنمایی کنه


String base64EncodedPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAkX7LsK n+bahjhhl;4xS9ZZ+xV04 +ezak4pPc3vSf6wQJH0n/+Mwif53IsLm/ydgwqeszM385rydRbUAR1GSMuVFpZ7m QHIs2pzz4+ALI7TOn8B4hGNdZv+neLmjIXYLBrv0Q7B1KcbD4P eaZm4ugnYaAIap VDZOcOasQfEYvUvfr9SZRCKlvj1O+tWhLP4SK/zXVbbOgS3SuHpZLfaifgVsIylo 9gmqzbd4sbsVum3Xb32PUq6bTeoTFazIuxGqSfkuCtFpWwmwP9 do0TP6AlHBALPb R2yO8UaHUfSSHtXokoR0yePQD/wjU6WzAmljXyKshE7uH5joFpaeQQFzofNtvyd0 uQIDAQAB";

// You can find it in your Avval market console.
// 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()) {
// 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) ;
}
});

btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mHelper.launchPurchaseFlow(pay.this, SKU_PREMIUM, RC_REQUEST,
mPurchaseFinishedListener, "payload-string");
}
});

}





IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
@Override

public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
Log.d(TAG, "Query inventory finished.");
rt.stop();
// Have we been disposed of in the meantime If so, quit.
if (mHelper == null) return;

// Is it a failure
if (result.isFailure()) {
complain("Failed to query inventory: " + result);
return;
}

Log.d(TAG, "Query inventory was successful.");

/*
* Check for items we own. Notice that for each purchase, we check
* the developer payload to see if it's correct! See
* verifyDeveloperPayload().
*/

// Do we have the premium upgrade
Purchase premiumPurchase = inventory.getPurchase(SKU_PREMIUM);
mIsPremium = (premiumPurchase != null && verifyDeveloperPayload(premiumPurchase));



Log.d(TAG, "Initial inventory query finished; enabling main UI.");
}
};

boolean verifyDeveloperPayload(Purchase p) {
String payload = p.getDeveloperPayload();

/*
* TODO: verify that the developer payload of the purchase is correct. It will be
* the same one that you sent when initiating the purchase.
*
* WARNING: Locally generating a random string when starting a purchase and
* verifying it here might seem like a good approach, but this will fail in the
* case where the user purchases an item on one device and then uses your app on
* a different device, because on the other device you will not have access to the
* random string you originally generated.
*
* So a good developer payload has these characteristics:
*
* 1. If two different users purchase an item, the payload is different between them,
* so that one user's purchase can't be replayed to another user.
*
* 2. The payload must be such that you can verify it even when the app wasn't the
* one who initiated the purchase flow (so that items purchased by the user on
* one device work on other devices owned by the user).
*
* Using your own server to store and verify developer payloads across app
* installations is recommended.
*/

return true;
}


// Callback for when a purchase is finished
public IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
Log.d(TAG, "Purchase finished: " + result + ", purchase: " + purchase);

// if we were disposed of in the meantime, quit.
if (mHelper == null) return;

if (result.isFailure()) {
complain("Error purchasing: " + result);
Toast.makeText(pay.this, "33033", Toast.LENGTH_SHORT).show();
return;
}
if (!verifyDeveloperPayload(purchase)) {
complain("Error purchasing. Authenticity verification failed.");
Toast.makeText(pay.this, "2222", Toast.LENGTH_SHORT).show();
return;
}

Log.d(TAG, "Purchase successful.");
Toast.makeText(pay.this, "001", Toast.LENGTH_SHORT).show();
}
};

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d(TAG, "onActivityResult(" + requestCode + "," + resultCode + "," + data);
if (mHelper == null) return;

// Pass on the activity result to the helper for handling
if (!mHelper.handleActivityResult(requestCode, resultCode, data)) {
// not handled, so handle it ourselves (here's where you'd
// perform any handling of activity results not related to in-app
// billing...
super.onActivityResult(requestCode, resultCode, data);
}
else {
Log.d(TAG, "onActivityResult handled by IABUtil.");
}
}
void complain(String message) {
Log.e(TAG, "**** TrivialDrive Error: " + message);
alert("Error: " + message);
}

void alert(String message) {
AlertDialog.Builder bld = new AlertDialog.Builder(this);
bld.setMessage(message);
bld.setNeutralButton("OK", null);
Log.d(TAG, "Showing alert dialog: " + message);
bld.create().show();
}

void saveData() {

/*
* WARNING: on a real application, we recommend you save data in a secure way to
* prevent tampering. For simplicity in this sample, we simply store the data using a
* SharedPreferences.
*/

SharedPreferences.Editor spe = getPreferences(MODE_PRIVATE).edit();

spe.apply();

}

void loadData() {
SharedPreferences sp = getPreferences(MODE_PRIVATE);


}
@Override
public void onDestroy() {
super.onDestroy();
// very important:
Log.d(TAG, "Destroying helper.");
if (mHelper != null) {
mHelper.dispose();
mHelper = null;
}
}
}

dibdab
شنبه 30 مرداد 1395, 23:07 عصر
کسی نیست کمک کنه

m.y2876
جمعه 12 شهریور 1395, 09:14 صبح
به نظرم در کلید عمومی RSA شما space وجود داره
اول اینکه این کلید رو در قسمت strings تعریف کنید و اینجا به صورت

String base64EncodedPublicKey = getResources().getString(R.string.key);
ازش استفاده کنید
همینطور از صحیح بودن SKU ها مطمئن شوید