каждый я интегрировал PayPal API , но у меня возникает проблема, каждый раз, когда я нажимаю кнопку входа в систему и вставляю свою учетную запись PayPal (я создаю изолированную программную среду с бизнесом PayPal (учетная запись) выдает ошибку : неправильное имя пользователя или пароль , и я не могу понять, почему, поскольку я вхожу с этими учетными данными в свою учетную запись.
Может кто-нибудь объяснить мне, что я делаю не так? В первый раз я делаю это. Заранее спасибо.
Код:
package com.example.ipill;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.nfc.Tag;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;
import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.Query;
import com.google.firebase.database.ValueEventListener;
import com.paypal.android.sdk.payments.PayPalConfiguration;
import com.paypal.android.sdk.payments.PayPalPayment;
import com.paypal.android.sdk.payments.PayPalService;
import com.paypal.android.sdk.payments.PaymentActivity;
import com.paypal.android.sdk.payments.PaymentConfirmActivity;
import com.paypal.android.sdk.payments.PaymentConfirmation;
import org.json.JSONException;
import java.math.BigDecimal;
import java.net.HttpCookie;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
public class CartActivity extends AppCompatActivity implements OnRemoveItemClickListener{
private TextView total;
private ImageButton removeFromCartt;
private Button pay;
private RecyclerView mResultList2;
private DatabaseReference mUserDatabase;
public int Totalprice;
private UsersAdapter adapter;
private ArrayList<Users_get> array_data = new ArrayList<>();
final Handler handler = new Handler();
public static final int PAYPAL_REQUEST_CODE = 7171;
private static PayPalConfiguration config = new PayPalConfiguration()
.environment(PayPalConfiguration.ENVIRONMENT_SANDBOX)
.clientId(Config.PAYPAL_CLIENT_ID);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cart);
mUserDatabase = FirebaseDatabase.getInstance().getReference("Cart");
total = findViewById(R.id.TotalPrice);
total.setText(0+"");
removeFromCartt = findViewById(R.id.removeFromCart);
mResultList2 = findViewById(R.id.cartList);
pay = findViewById(R.id.pay);
mResultList2.setHasFixedSize(true);
mResultList2.setLayoutManager(new LinearLayoutManager(this));
Intent intent = new Intent (this,PayPalService.class);
intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION,config);
startService(intent);
// Attach a listener to read the data at our posts reference
mUserDatabase.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
int flag=1;
if (adapter == null) {
for (DataSnapshot childSnapshot : dataSnapshot.getChildren()) {
Users_get post = childSnapshot.getValue(Users_get.class);
array_data.add(new Users_get(post.getName(), post.getSurname(), post.getPrice(), childSnapshot.getKey()));
getTotalPrice(post.getPrice(),flag);
total.setText(Totalprice+"");
}
setAdapter();
} else {
adapter.notifyDataSetChanged();
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
System.out.println("The read failed: " + databaseError.getCode());
}
});
pay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
processPayment();
}
});
}
private void processPayment() {
PayPalPayment payPalPayment = new PayPalPayment(new BigDecimal(String.valueOf(Totalprice)),"EUR",
"Make the payment",PayPalPayment.PAYMENT_INTENT_SALE);
Intent intent = new Intent (CartActivity.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,Intent data) {
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 paymenDetails = confirmation.toJSONObject().toString(4);
startActivity(new Intent(this, PaymentDetails.class)
.putExtra("PaymentDetails", paymenDetails)
.putExtra("PaymentAmount", Totalprice));
} catch (JSONException e) {
e.printStackTrace();
}
}
} else if (requestCode == Activity.RESULT_CANCELED) {
Toast.makeText(this, "Cancel", Toast.LENGTH_SHORT).show();
}
} else if (resultCode == PaymentActivity.RESULT_EXTRAS_INVALID)
Toast.makeText(this, "Invalid", Toast.LENGTH_SHORT).show();
}
private void setAdapter() {
adapter = new UsersAdapter(array_data,CartActivity.this);
mResultList2.setAdapter(adapter);
}
public void getTotalPrice(Long price,int flag){
if(flag==1)
{
Totalprice+=price;
}
else {
Totalprice-=price;
}
System.out.println(Totalprice);
}
@Override
public void onRemoveItemClicked(final int position) {
int flag=0;
FirebaseDatabase.getInstance().getReference("Cart").child(array_data.get(position).getKey()).removeValue();
getTotalPrice(array_data.get(position).getPrice(),flag);
total.setText(Totalprice+"");
array_data.remove(position);
adapter.notifyItemRemoved(position);
}
@Override
protected void onDestroy() {
stopService(new Intent(this,PayPalService.class));
super.onDestroy();
if(adapter !=null){
adapter.removeListener();
}
}
}
Второе действие:
package com.example.ipill;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
import org.json.JSONException;
import org.json.JSONObject;
public class PaymentDetails extends AppCompatActivity {
TextView txtID, txtStatus,txtAmount;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_payment_details);
txtID = findViewById(R.id.txtID);
txtAmount= findViewById(R.id.txtAmount);
txtStatus=findViewById(R.id.txtStatus);
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) {
try {
txtID.setText(response.getString("id"));
txtStatus.setText(response.getString("state"));
txtAmount.setText("$"+PaymentAmount);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
Ошибка, которую я получаю:
E/paypal.sdk: request failure with http statusCode:401,exception:
E/paypal.sdk: request failed with server response:{"error":"invalid_user","error_description":"Invalid user credentials"}
E/paypal.sdk: invalid_user