JSONException: No value for id after completing paypal payment - android

After a user has payed via PayPal on my android app I want the PaymentId to be displayed, with the state and the amount they have just payed. When i'm trying to get the id from the JSONObject it keeps saying "No value for id" when the id in the logcat has a value.
ID Has A Value As Shown
When I get to the line textViewId.setText(jsonObject.getString("id")); it jumps to the catch and displayed the error "No value for id". Even though in the logcat there is a value.
Below is my code.
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (requestCode == PAYPAL_REQUEST_CODE)
{
if (resultCode == RESULT_OK)
{
PaymentConfirmation confirmation = data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
if (confirmation != null)
{
try
{
String paymentDetails = confirmation.toJSONObject().toString(4);
JSONObject jsonObject = new JSONObject(paymentDetails);
// String id = jsonObject.getString("id");
// String status = jsonObject.getString("state");
// startActivity(new Intent(getActivity(), PaymentDetails.class)
// .putExtra("PaymentDetails", paymentDetails)
// .putExtra("PaymentAmount", totalAmount + commisionAmount));
final AlertDialog.Builder alertDialog = new AlertDialog.Builder(getActivity());
View mView = getLayoutInflater().inflate(R.layout.popup_payment_successful, null);
alertDialog.setTitle("Payment Successful");
alertDialog.setView(mView);
final AlertDialog dialog = alertDialog.create();
dialog.show();
TextView textViewId = mView.findViewById(R.id.textId);
TextView textViewAmount = mView.findViewById(R.id.textAmount);
TextView textViewStatus = mView.findViewById(R.id.textStatus);
jsonObject.has("id");
textViewId.setText(jsonObject.getString("id"));
textViewAmount.setText((int) (totalAmount + commisionAmount));
textViewStatus.setText(jsonObject.getString("state"));
} catch (JSONException e)
{
e.printStackTrace();
}
}
} else if (resultCode == Activity.RESULT_CANCELED)
{
Toast.makeText(getActivity(), "Cancel", Toast.LENGTH_SHORT).show();
}
} else if (resultCode == PaymentActivity.RESULT_EXTRAS_INVALID)
{
Toast.makeText(getActivity(), "Invalid", Toast.LENGTH_SHORT).show();
}
}

Apparently your id is inside response jsonobject so do
JSONObject jsonObject = new JSONObject(paymentDetails);
JSONObject jsonObject1 = jsonObject.optJSONObject("response");// return null or found object
if(jsonObject1 != null){
String id = jsonObject1.optString("id",""); //return value or empty string
String status = jsonObject1.optString("state","");
}

Related

I want to get value inside my String JsonObject

try {
JSONObject jobj = new JSONObject(response);
String status = jobj.getString("status");
String error = jobj.getString("result");
if(status == "1"){
builder.setTitle("Server Message");
builder.setMessage("Please validate your ID in registered email.");
}else if(status == "0")
{
builder.setTitle("Server Message");
builder.setMessage(error);
}else{
builder.setTitle("Server Message");
builder.setMessage(response);
}
} catch (JSONException e) {
e.printStackTrace();
}
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
Intent mainIntent = new Intent(RegisterActivity.this, LoginActivity.class);
startActivity(mainIntent);
}
});
AlertDialog alertDialog = builder.create();
alertDialog.show();
}
my response is {"status":"1","result":"true")
But I can't do if else to the "status" mean I can't get value of "1" inside the status.
Two mistakes
Getting integer and boolean as string
Comparing string with ==
Do this
int status = jobj.getInt("status");
Boolean error = jobj.getBoolean("result");
if(status == 1){
builder.setTitle("Server Message");
builder.setMessage("Please validate your ID in registered email.");
}else if(status == 0)
{
...
...
"==" is reference compare.
So, replace "==" to equals()
status.equals("1")
I hope this will work for you.
By using String
String status = jobj.getString("status");
String error = jobj.getString("result");
if(status.equalsIgnoreCase("1")){
builder.setTitle("Server Message");
builder.setMessage("Please validate your ID in registered email.");
}else if(status.equalsIgnoreCase("0")){
// your other code.
}

Android cascading dropdown not working sometimes

I have an app wherein there are two dropdown's. The first is for "Society" and the second one is for "house numbers". The "house numbers" dropdown is populated based on the "Society" selected.
The problem I am facing is that in few phone's, when user selects the "House Number", the "Society" dropdown is reset to blank value. I don't understand how is this possible as I have not updated society dropdown on house number selection and this is happening in few phones only out of almost 100 I have tested.
Here is my code.
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// Check which request we're responding to
if (requestCode == Society_REQUEST) {
// Make sure the request was successful
if (resultCode == RESULT_OK) {
// The user picked a contact.
// The Intent's data Uri identifies which contact was selected.
try {
String cityObj = data.getExtras().getString("cityObj");
CommonClass.writelog(tag,
"onActivityResult()102 Reqestcode:" + requestCode
+ " ResultCode:" + resultCode + " data:"
+ data.getStringExtra("cityObj"));
try {
JSONObject cObj = new JSONObject(cityObj);
// common.setSession("selected_city_id",cObj.getString("Id"));
TextView txtSocity = (TextView) findViewById(R.id.txtSocity);
CommonClass
.writelog(tag,
"onActivityResult()109:Society_REQUEST: txtSocity TextView Variable Create:");
txtSocity.setText(cObj.getString("Name"));
CommonClass.writelog(tag,
"onActivityResult()111:Society_REQUEST: txtSocity.setText:"
+ cObj.getString("Name")
+ " txtSocity.getText:"
+ txtSocity.getText().toString());
socity_id = cObj.getString("Id");
CommonClass.writelog(tag,
"onActivityResult()114:Society_REQUEST: socity_id:"
+ cObj.getString("Id"));
} catch (JSONException e) {
CommonClass.writelog(
tag,
"onActivityResult()117:Society_REQUEST: Reqestcode:"
+ requestCode + " ResultCode:"
+ resultCode + " data:"
+ data.getStringExtra("cityObj") + "\n"
+ e.getMessage());
e.printStackTrace();
}
// Do something with the contact here (bigger example below)
} catch (Exception ex) {
String cityObj = data.getExtras().getString("cityObjOther");
CommonClass.writelog(
tag,
"onActivityResult()102 Reqestcode:" + requestCode
+ " data:"
+ data.getStringExtra("cityObjOther"));
try {
flg = 1;
String[] tmep = cityObj.split("##");
TextView txtSocity = (TextView) findViewById(R.id.txtSocity);
txtSocity.setText(tmep[1].toString());
socity_id = tmep[0].toString();
} catch (Exception e) {
e.printStackTrace();
}
}
}
} else if (requestCode == Homeno_REQUEST) {
// Make sure the request was successful
if (resultCode == RESULT_OK) {
// Make sure the request was successful
if (resultCode == RESULT_OK) {
// The user picked a contact.
// The Intent's data Uri identifies which contact was
// selected.
try {
String cityObj1 = data.getExtras().getString("homeObj");
try {
JSONObject cObj = new JSONObject(cityObj1);
TextView txtHomeNo = (TextView) findViewById(R.id.txtHomeno);
txtHomeNo.setText(cObj.getString("Name"));
home_id = cObj.getString("Id");
} catch (JSONException e) {
e.printStackTrace();
}
// Do something with the contact here (bigger example
// below)
} catch (Exception ex) {
String cityObj = data.getExtras().getString(
"homeObjOther");
try {
flg = 1;
String[] tmep = cityObj.split("##");
TextView txtHomeNo = (TextView) findViewById(R.id.txtHomeno);
txtHomeNo.setText(tmep[1].toString());
home_id = tmep[0].toString();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
listView.setAdapter(selectHomenoAdapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Intent returnIntent = getIntent();
returnIntent.putExtra("homeObj",
selectHomenoAdapter.getItem(position).toString());
setResult(RESULT_OK, returnIntent);
finish();
}
});
}

Where do I get response in Citrus payment integration in Android

I have integrated citrus payment gateway in an android app..I am not getting where do I get the response..if the the transaction is successfull or failed.
Here is my code..the problem is whenever the transaction is completed or succesfull the citrus pay library display a screen with appropriate message and when I click back then I get the result in onActivityResult...I want the result immediately after the transaction is completed..Thanks
I am following steps from here : http://www.citruspay.com/DevelopersGuide/android/plugandplay.html
if (res.equalsIgnoreCase("true")) {
setupCitrusConfigs();
CitrusFlowManager.startShoppingFlow(CheckOut.this,
User_Email, Txt_Phone.getText().toString(), String.valueOf(Amt_Payable));
}
private void setupCitrusConfigs() {
CitrusFlowManager.initCitrusConfig("kkkkkkk-signup",
"dfdffgfdgfdgffdgdfgdfgdfgdfgfdg", "fgfgfdgfdg-signin",
"fgfdgdfgfdgfgfdgfgdfffd", getResources().getColor(R.color.white),
CheckOut.this, Environment.SANDBOX, "vvvvvvvvd", sandboxBillGeneratorURL,
returnUrlLoadMoney);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
// check if the request code is same as what is passed here it is 2
Log.d("CheckOut","request code " + requestCode + " resultcode " + resultCode);
if(requestCode == Constants.REQUEST_CODE_PAYMENT && resultCode == RESULT_OK && data != null) {
// You will get data here if transaction flow is started through pay options other than wallet
TransactionResponse transactionResponse = data.getParcelableExtra(Constants
.INTENT_EXTRA_TRANSACTION_RESPONSE);
// You will get data here if transaction flow is started through wallet
ResultModel resultModel = data.getParcelableExtra(ResultFragment.ARG_RESULT);
// Check which object is non-null
if(transactionResponse != null && transactionResponse.getJsonResponse() != null) {
try {
JSONObject json = new JSONObject(transactionResponse.getJsonResponse());
String Status = json.getString("TxStatus");
if(Status.equalsIgnoreCase("SUCCESS")){
db.EmptyCart();
Intent i = new Intent(CheckOut.this, MainActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(i);
Log.e("Trans", "Transaction Successfull " + Status);
}else {
Log.e("Trans","Transaction Failed "+Status);
}
} catch (JSONException e1) {
e1.printStackTrace();
}
// Decide what to do with this data
Log.d(TAG, "transaction response" + transactionResponse.getJsonResponse());
} else if(resultModel != null && resultModel.getTransactionResponse() != null){
// Decide what to do with this data
try {
JSONObject json = new JSONObject(resultModel.getTransactionResponse().getJsonResponse());
String Status = json.getString("TxStatus");
if(Status.equalsIgnoreCase("SUCCESS")){
db.EmptyCart();
Intent i = new Intent(CheckOut.this, MainActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(i);
Log.e("Trans", "Transaction Successfull " + Status);
}else {
Log.e("Trans","Transaction Failed "+Status);
}
} catch (JSONException e1) {
e1.printStackTrace();
}
} else {
Log.d(TAG, "Both objects are null!");
}
}
}
Pay using Debit Card
CitrusClient citrusClient = CitrusClient.getInstance(context); // Activity Context
// No need to call init on CitrusClient if already done.
DebitCardOption debitCardOption = new DebitCardOption("Card Holder Name", "4111111111111111", "123", Month.getMonth("12"), Year.getYear("18"));
Amount amount = new Amount("5");
// Init PaymentType
PaymentType.PGPayment pgPayment = new PaymentType.PGPayment(amount, BILL_URL, debitCardOption, new CitrusUser("developercitrus#gmail.com","9876543210"));
citrusClient.simpliPay(pgPayment, new Callback<TransactionResponse>() {
#Override
public void success(TransactionResponse transactionResponse) { }
#Override
public void error(CitrusError error) { }
});
Pay using Credit Card
CitrusClient citrusClient = CitrusClient.getInstance(context); // Activity Context
// No need to call init on CitrusClient if already done.
CreditCardOption creditCardOption = new CreditCardOption("Card Holder Name", "4111111111111111", "123", Month.getMonth("12"), Year.getYear("18"));
Amount amount = new Amount("5");
// Init PaymentType
PaymentType.PGPayment pgPayment = new PaymentType.PGPayment(amount, BILL_URL, creditCardOption, new CitrusUser("developercitrus#gmail.com","9876543210"));
citrusClient.simpliPay(pgPayment, new Callback<TransactionResponse>() {
#Override
public void success(TransactionResponse transactionResponse) { }
#Override
public void error(CitrusError error) { }
});
Pay using Net Banking Option
CitrusClient citrusClient = CitrusClient.getInstance(context); // Activity Context
// No need to call init on CitrusClient if already done.
NetbankingOption netbankingOption = new NetbankingOption("ICICI Bank","CID001");
// Init Net Banking PaymentType
PaymentType.PGPayment pgPayment = new PaymentType.PGPayment(amount, BILL_URL, netbankingOption, new CitrusUser("developercitrus#gmail.com","9876543210"));
citrusClient.simpliPay(pgPayment, new Callback<TransactionResponse>() {
#Override
public void success(TransactionResponse transactionResponse) { }
#Override
public void error(CitrusError error) { }
});

Android payapal integration

this is my first question on stackoverflow.hope i can find my solutuon .i am integrating paypal in android.my device is showing "payment of this marchent are not allowed(invalid client id).here is my code
private static final String CONFIG_ENVIRONMENT = PayPalConfiguration.ENVIRONMENT_PRODUCTION;
// note that these credentials will differ between live & sandbox
// environments.
private static final String CONFIG_CLIENT_ID ="my client id";
private static final int REQUEST_CODE_PAYMENT = 1;
private static final int REQUEST_CODE_FUTURE_PAYMENT = 2;
private static PayPalConfiguration config = new PayPalConfiguration()
.environment(CONFIG_ENVIRONMENT)
.clientId(CONFIG_CLIENT_ID)
// The following are only used in PayPalFuturePaymentActivity.
.merchantName("Rajeev Lochan Sharma")
.merchantPrivacyPolicyUri(
Uri.parse("https://www.example.com/privacy"))
.merchantUserAgreementUri(
Uri.parse("https://www.example.com/legal"));
PayPalPayment thingToBuy;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_afcl);
final GlobalClass globalVariable = (GlobalClass) getApplicationContext();
Intent intent = new Intent(this, PayPalService.class);
intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startService(intent);
ButterKnife.inject(this);
_request3.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// signup();
new Test().execute(_names.getText().toString(), _placeofbirth.getText().toString(), _timeofbirth.getText().toString()
);
thingToBuy = new PayPalPayment(new BigDecimal("10"), "USD",
"quote", PayPalPayment.PAYMENT_INTENT_SALE);
Intent intent = new Intent(AfcRequest1Activity.this,
PaymentActivity.class);
intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivityForResult(intent, REQUEST_CODE_PAYMENT);
}
});
}
public void onBackPressed() {
new AlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_alert).setTitle("Exit")
.setMessage("Are you sure you want to exit?")
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
}).setNegativeButton("No", null).show();
}
private class Test extends AsyncTask {
protected void onPreExecute() {
super.onPreExecute();
//here you can some progress dialog or some view
}
#Override
protected String doInBackground(String... Params) {
String res = "";
try {
byte[] result = null;
String str = "";
HttpClient client;
HttpPost post;
ArrayList<NameValuePair> nameValuePair;
HashMap<String, String> mData;
Iterator<String> it;
HttpResponse response;
StatusLine statusLine;
//here is url api call url
post = new HttpPost("http://astro360horoscope.com/backend/api/form_amc_afc.php");
nameValuePair = new ArrayList<NameValuePair>();
mData = new HashMap<String, String>();
mData.put("username", Params[0]);
mData.put("placeofbirth", Params[1]);
mData.put("timeofbirth", Params[2]);
//for now nothing is there
it = mData.keySet().iterator();
while (it.hasNext()) {
String key = it.next();
nameValuePair.add(new BasicNameValuePair(key, mData.get(key)));
}
post.setEntity(new UrlEncodedFormEntity(nameValuePair, "utf-8"));
client = new DefaultHttpClient();
response = client.execute(post);
statusLine = response.getStatusLine();
result = EntityUtils.toByteArray(response.getEntity());
str = new String(result, "utf-8");
if (statusLine.getStatusCode() == HttpURLConnection.HTTP_OK) {
//here we get the response if all is correct
res = str;
} else {
res = str;
return res;
}
} catch (Exception e1) {
res = "error:" + e1.getMessage().toString();
e1.printStackTrace();
}
return res;
}
protected void onPostExecute(String response) {
super.onPostExecute(response);
}
}
public void onFuturePaymentPressed(View pressed) {
Intent intent = new Intent(AfcRequest1Activity.this,
PayPalFuturePaymentActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivityForResult(intent, REQUEST_CODE_FUTURE_PAYMENT);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE_PAYMENT) {
if (resultCode == Activity.RESULT_OK) {
PaymentConfirmation confirm = data
.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
if (confirm != null) {
try {
System.out.println(confirm.toJSONObject().toString(4));
System.out.println(confirm.getPayment().toJSONObject()
.toString(4));
Toast.makeText(getApplicationContext(), "Order placed",
Toast.LENGTH_LONG).show();
} catch (JSONException e) {
e.printStackTrace();
}
}
} else if (resultCode == Activity.RESULT_CANCELED) {
System.out.println("The user canceled.");
} else if (resultCode == PaymentActivity.RESULT_EXTRAS_INVALID) {
System.out
.println("An invalid Payment or PayPalConfiguration was submitted. Please see the docs.");
}
} else if (requestCode == REQUEST_CODE_FUTURE_PAYMENT) {
if (resultCode == Activity.RESULT_OK) {
PayPalAuthorization auth = data
.getParcelableExtra(PayPalFuturePaymentActivity.EXTRA_RESULT_AUTHORIZATION);
if (auth != null) {
try {
Log.i("FuturePaymentExample", auth.toJSONObject()
.toString(4));
String authorization_code = auth.getAuthorizationCode();
Log.i("FuturePaymentExample", authorization_code);
sendAuthorizationToServer(auth);
Toast.makeText(getApplicationContext(),
"Future Payment code received from PayPal",
Toast.LENGTH_LONG).show();
} catch (JSONException e) {
Log.e("FuturePaymentExample",
"an extremely unlikely failure occurred: ", e);
}
}
} else if (resultCode == Activity.RESULT_CANCELED) {
Log.i("FuturePaymentExample", "The user canceled.");
} else if (resultCode == PayPalFuturePaymentActivity.RESULT_EXTRAS_INVALID) {
Log.i("FuturePaymentExample",
"Probably the attempt to previously start the PayPalService had an invalid PayPalConfiguration. Please see the docs.");
}
}
}
private void sendAuthorizationToServer(PayPalAuthorization authorization) {
}
public void onFuturePaymentPurchasePressed(View pressed) {
// Get the Application Correlation ID from the SDK
String correlationId = PayPalConfiguration
.getApplicationCorrelationId(this);
Log.i("FuturePaymentExample", "Application Correlation ID: "
+ correlationId);
// TODO: Send correlationId and transaction details to your server for
// processing with
// PayPal...
Toast.makeText(getApplicationContext(),
"App Correlation ID received from SDK", Toast.LENGTH_LONG)
.show();
}
#Override
public void onDestroy() {
// Stop service when done
stopService(new Intent(this, PayPalService.class));
super.onDestroy();
}

In App Purchase Error in Static codes

I am using current code for purchase for calling purchase intent
Bundle buyIntentBundle = mService.getBuyIntent(3, pContext.getPackageName(), "android.test.canceled", "inapp", "bGoa+V7g/yqDXv");
Set<String> allKeys = buyIntentBundle.keySet();
Object responseCode= buyIntentBundle.get("RESPONSE_CODE");
Object intent= buyIntentBundle.get("BUY_INTENT");
Log.i(TAG,"buyIntentBundle"+buyIntentBundle.keySet()+"responseCode"+responseCode+"intent"+intent);
PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT");
if (pendingIntent != null) {
pContext.startIntentSenderForResult(pendingIntent.getIntentSender(), 2013, new Intent(), Integer.valueOf(0), Integer.valueOf(0),Integer.valueOf(0));
}
Now onActivityResult i am checking
if (requestCode == 2013) {
Log.i(TAG, "onactivity result called inside request code");
int responseCode = intent.getIntExtra("RESPONSE_CODE", 0);
String purchaseData = intent.getStringExtra("INAPP_PURCHASE_DATA");
String dataSignature = intent.getStringExtra("INAPP_DATA_SIGNATURE");
if (responseCode == Constants.BILLING_RESPONSE_RESULT_OK) {
try {
JSONObject jo = new JSONObject(purchaseData);
String sku = jo.getString("productId");
Toast.makeText(pContext, "You have bought the " + sku + ". Excellent choice, adventurer!", Toast.LENGTH_SHORT);
JSONObject o = new JSONObject(purchaseData);
String mOrderId = o.optString("orderId");
String mPackageName = o.optString("packageName");
String mSku = o.optString("productId");
long mPurchaseTime = o.optLong("purchaseTime");
int mPurchaseState = o.optInt("purchaseState");
String mDeveloperPayload = o.optString("developerPayload");
String mToken = o.optString("token", o.optString("purchaseToken"));
try {
mService.consumePurchase(3, pContext.getPackageName(), mToken);
} catch (RemoteException e) {
e.printStackTrace();
}//consumePurchase
}
catch (JSONException e) {
Toast.makeText(pContext, "Failed to parse purchase data.", Toast.LENGTH_SHORT);
e.printStackTrace();
}
}else if (responseCode == Constants.BILLING_RESPONSE_RESULT_USER_CANCELED) {
Toast.makeText(pContext, "User cancelled purchase.", Toast.LENGTH_SHORT);
}else if (responseCode == Constants.BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE) {
Toast.makeText(pContext, "Your Device doesn't support inapp billing.", Toast.LENGTH_SHORT);
}else if (responseCode == Constants.BILLING_RESPONSE_RESULT_ITEM_UNAVAILABLE) {
Toast.makeText(pContext, "Item is not available for billing.", Toast.LENGTH_SHORT);
}else if (responseCode == Constants.BILLING_RESPONSE_RESULT_DEVELOPER_ERROR) {
Toast.makeText(pContext, "Can't purchase item due to some developer error.", Toast.LENGTH_SHORT);
}else if (responseCode == Constants.BILLING_RESPONSE_RESULT_ERROR) {
Toast.makeText(pContext, "Can't purchase item due to some error in response.", Toast.LENGTH_SHORT);
}else if (responseCode == Constants.BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED) {
Toast.makeText(pContext, "You already own this item.", Toast.LENGTH_SHORT);
}else if (responseCode == Constants.BILLING_RESPONSE_RESULT_ITEM_NOT_OWNED) {
Toast.makeText(pContext, "You don't own this item.", Toast.LENGTH_SHORT);
}
}
Since i am calling "android.test.canceled" so i should be getting BILLING_RESPONSE_RESULT_USER_CANCELED this response but it shows as payment successful and returns responseCode as BILLING_RESPONSE_RESULT_OK with no other parameter in that intent.getExtras.
I am trying static responses
http://developer.android.com/google/play/billing/billing_testing.html#billing-testing-static
Thanks & Regards!!
You are not checking:
if (resultCode == Activity.RESULT_OK) {
....
}
It's possible that the process does not complete successfully. And since the default value for responseCode in case that key "RESPONSE_CODE" is not present in intent is "0"....
int responseCode = intent.getIntExtra("RESPONSE_CODE", 0);
.... responseCode is initialized to Constants.BILLING_RESPONSE_RESULT_OK == > 0.
Try using:
int responseCode = intent.getIntExtra("RESPONSE_CODE", -1);
And add a final else block to handle -1.

Categories

Resources