i am working on android studio developing mobile application. i have a payment feature and i integrated PayPal sandbox and when user clicks check out the PayPal page appears. however, when any buyers tries to log in using the appeared page it "incorrect username/password. please try again" although i am sure it is correct and tried multiple accounts and one of them has a valid real credit card but same output. I wonder why this happens? please can someone help me as soon as possible.
this what appears when user tries to log in: screen shot of PayPal error message
three java classes are related to payment part are provided:
confirmOrder.java:
package com.example.my1stapplication;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Button;
import android.content.Intent;
import com.example.my1stapplication.config.Config;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.paypal.android.sdk.payments.PayPalConfiguration;
import com.paypal.android.sdk.payments.PayPalPayment;
import com.paypal.android.sdk.payments.PayPalPaymentDetails;
import com.paypal.android.sdk.payments.PayPalService;
import com.paypal.android.sdk.payments.PaymentActivity;
import com.paypal.android.sdk.payments.PaymentConfirmation;
import android.text.TextUtils;
import android.widget.Toast;
import org.json.JSONException;
import java.io.Serializable;
import java.util.HashMap;
import java.math.BigDecimal;
public class confirmOrder extends AppCompatActivity {
EditText district, streetName, houseNo, phoneNo;
Button checkout;
DatabaseReference ordersref= FirebaseDatabase.getInstance().getReference("Orders");
final HashMap<String, Object> ordersMap=new HashMap<>();
public static final int PAYPAL_REQUEST_CODE=7171;
private static PayPalConfiguration config = new PayPalConfiguration().environment(PayPalConfiguration.ENVIRONMENT_SANDBOX).clientId(Config.PAYPAL_CLIENT_ID);
//Double totalPrice=getIntent().getDoubleExtra("totalPrice",0);
@Override
protected void onDestroy() {
stopService(new Intent(this, PayPalService.class));
super.onDestroy();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_confirm_order);
Double totalPrice=getIntent().getDoubleExtra("totalPrice",0);
Intent intent = new Intent(this, PayPalService.class);
intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION,config);
startService(intent);
district = (EditText) findViewById(R.id.district);
streetName = (EditText) findViewById(R.id.streetName);
houseNo = (EditText) findViewById(R.id.houseNo);
phoneNo = (EditText) findViewById(R.id.phoneNo);
checkout = (Button) findViewById(R.id.checkout);
String buyerID = getIntent().getStringExtra("buyerID");
// Double totalPrice=getIntent().getDoubleExtra("totalPrice",0);
//HashMap cart=(HashMap) getIntent().getSerializableExtra("cart");
checkout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String district1 = district.getText().toString();
String streetName1 = district.getText().toString();
String houseNo1 = district.getText().toString();
String phoneNo1 = district.getText().toString();
if (!TextUtils.isEmpty(district1) && !TextUtils.isEmpty(district1)
&& !TextUtils.isEmpty(district1) && !TextUtils.isEmpty(district1)) {
Double totalPrice = getIntent().getDoubleExtra("totalPrice", 0);
HashMap<String, Object> cart = (HashMap<String, Object>) getIntent().getSerializableExtra("cart");
String Orderid = ordersref.push().getKey();
ordersMap.put("orderID", Orderid);
ordersMap.put("totalPrice", (totalPrice));
ordersMap.put("buyerID", FirebaseAuth.getInstance().getCurrentUser().getUid());
ordersMap.put("district", district1);
ordersMap.put("streetName", streetName1);
ordersMap.put("houseNo", houseNo1);
ordersMap.put("phoneNo", phoneNo1);
ordersMap.put("paied", false);
ordersMap.put("shipped", false);
ordersMap.put("takenFromOwner", false);
//ordersMap.put("inCart", adapter);
ordersref.child(Orderid).updateChildren(ordersMap);
ordersref.child(Orderid).child("cart").updateChildren(cart);
processPayment();
} else {
Toast.makeText(getApplicationContext(), "please enter all fields", Toast.LENGTH_LONG).show();
}
}
});
}
private void processPayment(){
Double totalPrice=getIntent().getDoubleExtra("totalPrice",0);
PayPalPayment payPalPayment =new PayPalPayment(new BigDecimal(totalPrice),"USD", "Pay for the material/s" , PayPalPayment.PAYMENT_INTENT_SALE);
Intent intent = new Intent(this, PaymentActivity.class);
intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION,config);
intent.putExtra(PaymentActivity.EXTRA_PAYMENT,payPalPayment);
startActivityForResult(intent,PAYPAL_REQUEST_CODE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
Double totalPrice=getIntent().getDoubleExtra("totalPrice",0);
super.onActivityResult(requestCode, resultCode, 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);
startActivity(new Intent(this, PaymentDetails.class).putExtra("PaymentDetails", paymentDetails).putExtra("PaymentAmount", totalPrice));
} catch (JSONException e) {
e.printStackTrace();
}
} else if (resultCode == Activity.RESULT_CANCELED) {
Toast.makeText(this, "Cancel", Toast.LENGTH_SHORT).show();
}
} else if (resultCode == PaymentActivity.RESULT_EXTRAS_INVALID) {
Toast.makeText(this, "Invalid Payment", Toast.LENGTH_SHORT).show();
}
}
}
}
PaymentDetails.java:
package com.example.my1stapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import org.json.JSONObject;
import android.content.Intent;
import org.json.JSONException;
public class PaymentDetails extends AppCompatActivity {
TextView txtId,txtAmount,txtStatus;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_payment_details);
txtId = (TextView)findViewById(R.id.txtId);
txtStatus = (TextView)findViewById(R.id.txtStatus);
txtAmount = (TextView)findViewById(R.id.txtAmount);
Intent intent=getIntent();
try{
JSONObject jsonObject = new JSONObject(intent.getStringExtra("PaymentDetails"));
showDetails(jsonObject.getJSONObject("response"),intent.getStringExtra("PaymentAmount"));
}
catch (JSONException e){
e.printStackTrace();
}
}
private void showDetails(JSONObject response , String paymentAmount) throws JSONException {
try {
txtId.setText(response.getString("id"));
txtStatus.setText(response.getString("status"));
txtAmount.setText("SR"+paymentAmount);
}
catch(JSONException e){
e.printStackTrace();
}
}
}
Config.java:
package com.example.my1stapplication.config;
public class Config {
public static final String PAYPAL_CLIENT_ID = "AR1bLXBzCYYWa4BCkEyTTcbijrtWPh9u15b3sxQbHQZ-ymhEonDq9zwMo1CqqM95fwHPp-pNjbRF99Am";
}
In order to log into a PayPal Sandbox page, you must use a PayPal Sandbox ( www.sandbox.paypal.com ) account , not a live ( www.paypal.com ) account.
You can create as many PayPal Sandbox accounts as you need within https://developer.paypal.com/dashboard/accounts
Their email identifiers are fictitious and can be anything not previously used in sandbox. No real emails are ever sent to those addresses; instead, there is a Testing Tools -> Sandbox Notifications tab in that developer dashboard.