I'm developing a simple food order app for a friend with PayPal payment.
To do this, I've watched a YouTube tutorial ( this https://www.youtube.com/watch?v=ae82zSy4CSM&t=78s ) and I've implemented the code in my app. The problem is that if i see the JSON output file, it's all ok but when I try to pay with my credit card, the money does not arrive on my friend's paypal account and when i go to check the money on my card, it does not actually decrease. If instead I try to pay with the paypal circuit, it refers to the error "incorrect username / password, please try again" when logging in, even though my credentials are correct.
{
"client": {
"environment": "sandbox",
"paypal_sdk_version": "2.16.0",
"platform": "Android",
"product_name": "PayPal-Android-SDK"
},
"response": {
"create_time": "2019-09-07T22:05:25Z",
"id": "PAY-6M507615CG866572Lxxxxxxx",
"intent": "sale",
"state": "approved"
},
"response_type": "payment"
}
{
"amount": "1.0",
"currency_code": "EUR",
"short_description": "Pagamento ordine Itaca Bistrot",
"intent": "sale"
}
public static final String PAYPAL_KEY = "AaJWo...";
public static final int REQUEST_CODE_PAYEMENT = 1;
public static final int REQUEST_CODE_FUTURE_PAYEMENT = 2;
public static final String CONFIG_ENVIRONMENT = PayPalConfiguration.ENVIRONMENT_SANDBOX;
public static PayPalConfiguration config;
PayPalPayment order;
----------------------------
private void configPaypal(){
config = new PayPalConfiguration()
.environment(CONFIG_ENVIRONMENT)
.clientId(PAYPAL_KEY)
.merchantName("Paypal Login")
.merchantPrivacyPolicyUri(Uri.parse("https://www.example.com/privacy"))
.merchantUserAgreementUri(Uri.parse("https://www.example.com/legal"));
}
private void makePayement(String amount){
Intent intent = new Intent(this, PayPalService.class);
intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION,config);
startService(intent);
order = new PayPalPayment(new BigDecimal(String.valueOf(amount)),"EUR","Pagamento ordine Itaca Bistrot",PayPalPayment.PAYMENT_INTENT_SALE);
Intent payment = new Intent(this, PaymentActivity.class);
payment.putExtra(PaymentActivity.EXTRA_PAYMENT, order);
payment.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION,config);
startActivityForResult(payment,REQUEST_CODE_PAYEMENT);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == REQUEST_CODE_PAYEMENT){
if(resultCode == Activity.RESULT_OK){
PaymentConfirmation confirmation = data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
if (confirmation != null){
try{
System.out.println(confirmation.toJSONObject().toString(4));
System.out.println(confirmation.getPayment().toJSONObject().toString(4));
}catch (JSONException e){
Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show();
}
final AppDB db = Room.databaseBuilder(Carrello.this.getApplicationContext(),AppDB.class,"AppDB").allowMainThreadQueries().build();
ProdottoDAO prodottodao = db.getProdottoDAO();
//estrapolo da tutti i prodotti la sommatoria del prezzo e il nome dei singoli prodotti ordinati;
List<String> nomeProdotti = new ArrayList<>();
for (int i = 0; i < prodottiDB.size(); i++) {
nomeProdotti.add(prodottiDB.get(i).nomeDB + " (" + prodottiDB.get(i).getQuantitaDB() + ")");
}
//riempio l'oggetto di tipo OrdinePassatoDB;
Date currentTime = Calendar.getInstance().getTime();
OrdiniPassatiDB ordinePassato = new OrdiniPassatiDB(00, String.valueOf(currentTime), Double.parseDouble(tot.getText().toString()), "In Preparazione", nomeProdotti);
OrdiniPassatiDAO ordinidao = db.getOrdiniPassatiDAO();
ordinidao.insertProduct(ordinePassato);
Toast.makeText(Carrello.this, "Ordine inviato con successo!", Toast.LENGTH_SHORT).show();
//pulisco la lista del carrello;
prodottodao.deleteAll();
Intent home = new Intent(Carrello.this, MainActivity.class);
startActivity(home);
}else if(resultCode == Activity.RESULT_CANCELED){
Toast.makeText(this, "Pagamento cancellato, nessun addebito", Toast.LENGTH_SHORT).show();
}else if(resultCode == PaymentActivity.RESULT_EXTRAS_INVALID){
Toast.makeText(this, "Si è verificato un errore!", Toast.LENGTH_SHORT).show();
}
}else if(requestCode == REQUEST_CODE_FUTURE_PAYEMENT){
if(resultCode == Activity.RESULT_OK){
PayPalAuthorization authorization = data.getParcelableExtra(PayPalFuturePaymentActivity.EXTRA_RESULT_AUTHORIZATION);
if (authorization != null){
try{
Log.i("FuturePaymentExample",authorization.toJSONObject().toString(4));
Log.d("FuturePaymentExample",authorization.getAuthorizationCode());
}catch(Exception e){
e.printStackTrace();
}
}
}
}
}
}
In the verbose I don't notice any errors attributable to the paypal API. Any suggestions?
I think you're working in sandbox. Thats why you can't play with real money on real accounts.