When purchasing an item through google store using a test user, is there some kind of parameter that points out that this specific purchase was done by a test user?
Yes there is. Firstly read this official document
The variable you are looking for is called
productId
Check the following code. If payment is successful then,display that product(which you define).
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 1001) {
String purchaseData = data.getStringExtra("INAPP_PURCHASE_DATA");
String dataSignature = data.getStringExtra("INAPP_DATA_SIGNATURE");
if (resultCode == RESULT_OK) {
entryFee.setVisibility(View.GONE);
paymentButton.setVisibility(View.GONE);
paymentText.setVisibility(View.GONE);
teamTextField.setVisibility(View.VISIBLE);
btn.setVisibility(View.VISIBLE);
aSwitch.setVisibility(View.VISIBLE);
try {
JSONObject jo = new JSONObject(purchaseData);
String sku = jo.getString("productId");
Toast.makeText(
CreateLeague.this,
"You have bought the " + sku
+ ". Excellent choice,adventurer!",
Toast.LENGTH_LONG).show();
} catch (JSONException e) {
Toast.makeText(
CreateLeague.this,
"Failed to make purchase",
Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
}
}
Hope this is going to be helpful.
Related
I want to get nonce from server. i wrote backend in PHP that will giving token. after receiving token PaymentMethodNonce returning null.
I want to get nonce from server.
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE) {
if (resultCode == RESULT_OK) {
DropInResult result = data.getParcelableExtra(DropInResult.EXTRA_DROP_IN_RESULT);
PaymentMethodNonce nonce = result.getPaymentMethodNonce();
String stringNonce = nonce.getNonce();
Log.d("mylog", "Result: " + stringNonce);
// Send payment price with the nonce
// use the result to update your UI and send the payment method nonce to your server
paramHash = new HashMap<>();
paramHash.put("couponPrice", couponPrice);
paramHash.put("nonce", stringNonce);
sendPaymentDetails();
} else if (resultCode == Activity.RESULT_CANCELED) {
// the user canceled
Log.d("mylog", "user canceled");
} else {
// handle errors here, an exception may be available in
Exception error = (Exception) data.getSerializableExtra(DropInActivity.EXTRA_ERROR);
Log.d("mylog", "Error : " + error.toString());
}
}
}
DropInResultobject is result. That is returning null but that should be some valid information
Here's the answer:
val result = intent.getParcelableExtra<DropInResult>(DropInResult.EXTRA_DROP_IN_RESULT)
return null
I have a problem with google map api. I used Api Key in my project and also i linked release SHA1 Key. It is working correctly in debug apk, but in release apk place autocompleteview is close automatically. I checked the Logcat, in logcat the api key is different from the key i used in meta-data in android manifest file.
private void manualLocation() {
try {
Intent intent = new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_FULLSCREEN).build((Activity) context);
startActivityForResult(intent, 1);
} catch (GooglePlayServicesRepairableException e) {
// TODO: Handle the error.
} catch (GooglePlayServicesNotAvailableException e) {
// TODO: Handle the error.
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 1) {
if (resultCode == RESULT_OK) {
Place place = PlaceAutocomplete.getPlace(this, data);
Log.e("Tag", "Place: " + place.getAddress() + place.getPhoneNumber());
Log.e("Tag", "Place: " + place.getLatLng() + place.getPlaceTypes());
if (signup.matches("1")) {
latitude = String.valueOf(place.getLatLng().latitude);
longitude = String.valueOf(place.getLatLng().longitude);
} else if (resultCode == PlaceAutocomplete.RESULT_ERROR) {
Status status = PlaceAutocomplete.getStatus(this, data);
// TODO: Handle the error.
Log.e("Tag", status.getStatusMessage());
locationStatus = "0";
AppPreferences.savePreferences(Location.this, "locationStatus", locationStatus);
} else if (resultCode == RESULT_CANCELED) {
locationStatus = "0";
AppPreferences.savePreferences(Location.this, "locationStatus", locationStatus);
// The user canceled the operation.
}
}
}
}
I used the key in meta-data "AIzaSyBH9saN7RRHev1QNKWqtIjejojvqJuCswU" but in Logcat the key is different. i show you the Logcat. Can anyone help me?
BasicNetwork.performRequest: Unexpected response code 403 for https://www.googleapis.com/placesandroid/v1/autocompleteWidget?key=AIzaSyBb2MNLJEmWt-FLJqN28D_-WuxQiMwzUhU
this is the Logcat response
I am new to in-app purchase system. I just watched some tutorials, then implemented in-app purchase. However, when my in-app purchase was successful, it did not run my code. Does it have to run the following code?:
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 1001) {
String purchaseData = data.getStringExtra("INAPP_PURCHASE_DATA");
if (resultCode == RESULT_OK) {
try {
JSONObject jo = new JSONObject(purchaseData);
String sku = jo.getString(inappid);
Toast.makeText(
MainActivity.this,
"You have bought the " + sku
+ ". Excellent choice,adventurer!",
Toast.LENGTH_LONG).show();
writeInApp("1");
playGroundMain.bonus_pop_up(R.drawable.rich_big, "\"VIP Монстр\"");
playGroundMain.reWriteBonus("1", 6);
} catch (JSONException e) {
System.out.println("Failed to parse purchase data.");
e.printStackTrace();
}
}
}
}
I've made a fair few apps with the payment system, you should take a look at this listener
IabHelper.OnConsumeFinishedListener mConsumeFinishedListener = new IabHelper.OnConsumeFinishedListener()
{
public void onConsumeFinished(Purchase purchase, IabResult result) {
Log.d(TAG, "Consumption finished. JSON: " + purchase.getOriginalJson() + ", signature: " + purchase.getSignature());
if (mHelper == null) return;
if (result.isSuccess())
{
Log.i(TAG, "BOUGHT THE ITEM :-)")
}
else
{
Log.e(TAG, "Error while consuming: " + result);
}
Log.d(TAG, "End consumption flow.");
}
};
you could add this listener in the consumeAsync function of the IabHelper like so:
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener()
{
public void onIabPurchaseFinished(IabResult result, Purchase purchase)
{
if (purchase.getSku().equals(SKU_21500))
{
// bought 21500 credits
Log.d(TAG, "Purchase is 21500 credits. Starting credits consumption.");
try
{
mHelper.consumeAsync(purchase, mConsumeFinishedListener);
}
catch (IabHelper.IabAsyncInProgressException e)
{
Log.d(TAG, "Error consuming 21500 credits. Another async operation in progress.");
return;
}
}
}
}
And then you can put the "mPurchaseFinishedListener" in the "launchPurchaseFlow " function as so:
mHelper.launchPurchaseFlow(activity, item, REQUEST_CODE, mPurchaseFinishedListener);
REQUEST_CODE being 10001
Hope this helps!
If you are trying to do a non-consumable inapp purchase the code is fine.
When doing test purchases sometimes the onActivityResult() does not gets called. In a real purchase this may not happen.
To handle the purchase in that case you have to check result code == user already owns this item //resultCode 7, so that the user will not have to pay again in a situation like this.
Maybe I overlooked something, but through Play Games Services documentation https://developers.google.com/games/services/android/quickstart,I did not yet get any idea about how to implement backend server authentication like how to get a token from Google's server and pass it to my own backend server to verify a login. I wish someone can give me a clue. Thanks !
Step 1:
Create a button with standard google Login button
Step2 : Add a buttonclick listener
Step 3 : In listner check for google play services availablity
public void googleLoginClicked(View v){
if (checkPlayServices()) {
pickUserAccount();
}else{
showToast("Google Play Services is not installed or updated in your deivce", Toast.LENGTH_LONG);
}
}
protected boolean checkPlayServices() {
int resultCode =
GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (resultCode != ConnectionResult.SUCCESS) {
if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
GooglePlayServicesUtil.getErrorDialog(resultCode, this,
PLAY_SERVICES_RESOLUTION_REQUEST).show();
} else {
// Log.i("GCM", "This device is not supported.");
finish();
}
return false;
}
return true;
}
Step 4:
search for google accounts in phone:
private void pickUserAccount() {
String[] accountTypes = new String[]{"com.google"};
Intent intent = AccountPicker.newChooseAccountIntent(null, null,
accountTypes, false, null, null, null, null);
startActivityForResult(intent, REQUEST_CODE_PICK_ACCOUNT);
}
Step5:
onActivityResult:
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_CODE_PICK_ACCOUNT) {
if (resultCode == RESULT_OK) {
mEmail = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
getUsername(null);
} else if (resultCode == RESULT_CANCELED) {
showToast("You must pick an account",
Toast.LENGTH_SHORT);
}
} else if (requestCode == REQUEST_CODE_RECOVER_FROM_PLAY_SERVICES_ERROR && resultCode == RESULT_OK) {
Bundle extra = data.getExtras();
String oneTimeToken = extra.getString("authtoken");
getUsername(oneTimeToken);
}
}
Step6: ON success get username from google using a background task
AsyncTask:
doinbackground(){
...
fetchToken
...
}
protected String fetchToken() throws IOException {
try {
return GoogleAuthUtil.getToken(mActivity, mEmail, mScope);
} catch (UserRecoverableAuthException userRecoverableException) {
// GooglePlayServices.apk is either old, disabled, or not present, which is
// recoverable, so we need to show the user some UI through the activity.
mActivity.handleException(userRecoverableException);
} catch (GoogleAuthException fatalException) {
onError("Unrecoverable error " + fatalException.getMessage(), fatalException);
}
return null;
}
My app using in-app billing v3 (UNMANAGED PRODUCT) and fully test with a signed apk, it works perfect on my android phone. After i release to production, got one purchase today, its my first purchase, but no signature received! i use my test account purchase again, got signature, but how come this buyer device submit blank signature to me?! Weird!
i check my Google Wallet records, its Green color icon, mean "The customer's credit card was successfully charged"! Im following the implementation below:
http://developer.android.com/google/play/billing/billing_integrate.html
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 1001) {
int responseCode = data.getIntExtra("RESPONSE_CODE", 0);
String purchaseData = data.getStringExtra("INAPP_PURCHASE_DATA");
String dataSignature = data.getStringExtra("INAPP_DATA_SIGNATURE");
if (resultCode == RESULT_OK) {
try {
//JSONObject jo = new JSONObject(purchaseData);
//String sku = jo.getString("productId");
//alert("You have bought the " + sku + ". Excellent choice, adventurer!");
/////////////////////////////////////////////////////////
// submit 'purchaseData' and 'dataSignature' to my server
/////////////////////////////////////////////////////////
}
catch (JSONException e) {
//alert("Failed to parse purchase data.");
e.printStackTrace();
}
}
}
}
my server only receive purchaseData but dataSignature is blank. anyone can help ? in what case will cause this issue?
make sure if you haven't change in the RC_REQUEST constants then it should be 10001 instead of 1001, and if you have manually changed it then you have to change the constants for these three code.
Constants:
// (arbitrary) request code for the purchase flow
static final int RC_REQUEST = 10001;
Purchase Request:
mHelper.launchPurchaseFlow(this, SKU_GAS, RC_REQUEST,
mPurchaseFinishedListener, payload_consumeItem);
onActivityResult:
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d(TAG, "onActivityResult(" + requestCode + "," + resultCode + ","
+ data);
if (mHelper == null)
return;
if (requestCode == 10001) {
int responseCode = data.getIntExtra("RESPONSE_CODE", 0);
String purchaseData = data.getStringExtra("INAPP_PURCHASE_DATA");
Log.d("INAPP_PURCHASE_DATA", ">>>" + purchaseData);
String dataSignature = data.getStringExtra("INAPP_DATA_SIGNATURE");
Log.d("INAPP_DATA_SIGNATURE", ">>>" + dataSignature);
String continuationToken = data
.getStringExtra("INAPP_CONTINUATION_TOKEN");
Log.d("INAPP_CONTINUATION_TOKEN", ">>>" + continuationToken);
if (resultCode == RESULT_OK) {
try {
Log.d("purchaseData", ">>>" + purchaseData);
JSONObject jo = new JSONObject(purchaseData);
String sku = jo.getString("productId");
alert("You have bought the " + sku
+ ". Excellent choice, adventurer!");
} catch (JSONException e) {
alert("Failed to parse purchase data.");
e.printStackTrace();
}
} else if (resultCode == RESULT_CANCELED) {
// } else if (resultCode == RESULT_CANCELED) {
Toast.makeText(AppMainTest.this,
"Sorry, you have canceled purchase Subscription.",
Toast.LENGTH_SHORT).show();
} else if (resultCode == IabHelper.BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED) {
Toast.makeText(AppMainTest.this, "Item already owned",
Toast.LENGTH_SHORT).show();
}
}
}
Let me know it will solve your problem or not.
Hope it will solve your problem.