DropInResult returning null in responce - android

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

Related

Google maps Autocomplete returns Place with null

I'm trying to get a Place from the Autocomplete of Google maps and then using its' longitude and latitude but every time I get a Place with the right name and all the other attributes got null in them. Does anyone know how to fix that?
Example of a Place I get:
I/System.out: Place{address=null, addressComponents=null, businessStatus=null, attributions=[], id=ChIJOwg_06VPwokRYv534QaPC8g, latLng=null, name=New York, openingHours=null, phoneNumber=null, photoMetadatas=null, plusCode=null, priceLevel=null, rating=null, types=null, userRatingsTotal=null, utcOffsetMinutes=null, viewport=null, websiteUri=null}
The code [the problem is at "setTargetPlace" (method is down the page)]:
#Override
protected void onActivityResult(int requestCode, int resultCode, #Nullable Intent data) {
if (requestCode == AUTOCOMPLETE_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
Place newTargetPlace = Autocomplete.getPlaceFromIntent(data);
System.out.println(newTargetPlace);
dataCenter.setTargetPlace(newTargetPlace);
dataCenter.createParty();
String response = dataCenter.getNextResponse();
System.out.println(response);
String[] commandAndPara = dataCenter.getCommandFromMsg(response);
String command = commandAndPara[0];
String para = commandAndPara[1];
if(command.equals(DataCenter.MSG_OK)) {
dataCenter.setPartyCode(para);
moveToParty();
}
else {
if(command.equals(DataCenter.MSG_FULL)) {
System.out.println("FULL");
}
else { //ERROR
System.out.println("ERROR");
}
}
} else if (resultCode == AutocompleteActivity.RESULT_ERROR) {
// TODO: Handle the error.
Status status = Autocomplete.getStatusFromIntent(data);
Log.i(TAG, status.getStatusMessage());
} else if (resultCode == RESULT_CANCELED) {
// The user canceled the operation.
}
return;
}
super.onActivityResult(requestCode, resultCode, data);
}
The method:
public void setTargetPlace(Place targetPlace) {
this.targetPlace = targetPlace;
this.target = this.targetPlace.getName();
LatLng targetCords = this.targetPlace.getLatLng();
this.targetX = targetCords.longitude;
this.targetY = targetCords.latitude;
}
The reason why you are getting the latitude and longitude as null is because you didn't include LAT_LNG as part of the fields you want to retrieve. See the code snippet below to see how you can include it
val fields = listOf(Place.Field.ID, Place.Field.NAME, Place.Field.LAT_LNG)
So when you create the intent and pass the field variable, and then go ahead to launch it like this
val intent = Autocomplete.IntentBuilder(AutocompleteActivityMode.FULLSCREEN, fields)
.build(requireContext())
startActivityForResult(intent, AUTOCOMPLETE_REQUEST_CODE)
it will return with the latitude and longitude in onActivityResult()

google placeautocomplete view close automatically

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

android google play in app billing error while subscription payment .. could not able to get purchase data

I am using in app purchase option in my application. After subscription completed , I could not able to get a Purchase data , data signeture and toen those things.But the payment was succeessfull for all the time. I release my apk in Beta testing account.
I was getting error like this:
IabResult: IAB returned null purchaseData or dataSignature (response: -1008:Unknown error)
Here's my relevant code:
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
billingHelper.handleActivityResult(requestCode, resultCode, data);
}
handleActivityResult Method:
public boolean handleActivityResult(int requestCode, int resultCode, Intent data) {
IabResult result;
if (requestCode != mRequestCode)
return false;
checkSetupDone("handleActivityResult");
Log.d("handleactivity","strat");
// end of async purchase operation
flagEndAsync();
if (data == null) {
logError("Null data in IAB activity result.");
result = new IabResult(IABHELPER_BAD_RESPONSE, "Null data in IAB result");
if (mPurchaseListener != null) {
mPurchaseListener.onIabPurchaseFinished(result, null);
}
return true;
}
int responseCode = getResponseCodeFromIntent(data);
String purchaseData = data.getStringExtra(RESPONSE_INAPP_PURCHASE_DATA);
String dataSignature = data.getStringExtra(RESPONSE_INAPP_SIGNATURE);
if (resultCode == Activity.RESULT_OK && responseCode == BILLING_RESPONSE_RESULT_OK) {
logDebug("Successful resultcode from purchase activity.");
logDebug("Purchase data: " + purchaseData);
logDebug("Data signature: " + dataSignature);
logDebug("Extras: " + data.getExtras());
if (purchaseData == null || dataSignature == null) {
logError("BUG: either purchaseData or dataSignature is null.");
logDebug("Extras: " + data.getExtras().toString());
result = new IabResult(IABHELPER_UNKNOWN_ERROR, "IAB returned null purchaseData or dataSignature");
if (mPurchaseListener != null) {
mPurchaseListener.onIabPurchaseFinished(result, null);
}
return true;
}
Purchase purchase = null;
try {
purchase = new Purchase(purchaseData, dataSignature);
String sku = purchase.getSku();
// Verify signature
if (!Security.verifyPurchase(mSignatureBase64, purchaseData, dataSignature)) {
logError("Purchase signature verification FAILED for sku " + sku);
result = new IabResult(IABHELPER_VERIFICATION_FAILED, "Signature verification failed for sku " + sku);
if (mPurchaseListener != null) {
mPurchaseListener.onIabPurchaseFinished(result, purchase);
}
return true;
}
logDebug("Purchase signature successfully verified.");
} catch (JSONException e) {
logError("Failed to parse purchase data.");
e.printStackTrace();
result = new IabResult(IABHELPER_BAD_RESPONSE, "Failed to parse purchase data.");
if (mPurchaseListener != null) {
mPurchaseListener.onIabPurchaseFinished(result, null);
}
return true;
}
if (mPurchaseListener != null) {
mPurchaseListener.onIabPurchaseFinished(new IabResult(BILLING_RESPONSE_RESULT_OK, "Success"), purchase);
}
}
else if (resultCode == Activity.RESULT_OK) {
// result code was OK, but in-app billing response was not OK.
logDebug("Result code was OK but in-app billing response was not OK: " + getResponseDesc(responseCode));
if (mPurchaseListener != null) {
result = new IabResult(responseCode, "Problem purchashing item.");
mPurchaseListener.onIabPurchaseFinished(result, null);
}
}
else if (resultCode == Activity.RESULT_CANCELED) {
logDebug("Purchase canceled - Response: " + getResponseDesc(responseCode));
result = new IabResult(IABHELPER_USER_CANCELLED, "User canceled.");
if (mPurchaseListener != null) {
mPurchaseListener.onIabPurchaseFinished(result, null);
}
}
else {
logError("Purchase failed. Result code: " + Integer.toString(resultCode)
+ ". Response: " + getResponseDesc(responseCode));
result = new IabResult(IABHELPER_UNKNOWN_PURCHASE_RESPONSE, "Unknown purchase response.");
if (mPurchaseListener != null) {
mPurchaseListener.onIabPurchaseFinished(result, null);
}
}
return true;
}
Logcat output:
E/SIAPv3: In-app billing error: BUG: either purchaseData or dataSignature is null.
D/SIAPv3: Extras: Bundle[{RESPONSE_CODE=0}]
E/Michael: onIabPurchaseFinished
D/Onpurchasefinished: start
E/Michael: Try to print NULL object
E/Michael: IabResult: IAB returned null purchaseData or dataSignature (response: -1008:Unknown error)
When a Subscription expires it no longer appears in the list of purchases.
See the docs "The getPurchases() method does not return failed or expired subscriptions."

How can I detect a test payment in google billing receipt

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.

Google Play in-app billing v3, signature blank

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.

Categories

Resources