无法使用 PayPal Android SDK 进行付款
Can't make payments with PayPal Android SDK
我正在为使用 PayPal 付款的朋友开发一个简单的订餐应用程序。
为此,我观看了 YouTube 教程(此 https://www.youtube.com/watch?v=ae82zSy4CSM&t=78s )并在我的应用程序中实现了代码。问题是,如果我看到 JSON 输出文件,一切正常,但是当我尝试用我的信用卡付款时,钱没有到达我朋友的 paypal 帐户,当我去检查我的钱时卡,它实际上并没有减少。相反,如果我尝试使用 paypal 线路付款,即使我的凭据正确无误,它也会在登录时显示错误 "incorrect username / password, please try again"。
{
"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();
}
}
}
}
}
}
在详细信息中,我没有注意到任何可归因于 paypal 的错误 API。有什么建议吗?
我认为您是在沙盒中工作。这就是为什么你不能在真实账户上玩真钱游戏。
我正在为使用 PayPal 付款的朋友开发一个简单的订餐应用程序。
为此,我观看了 YouTube 教程(此 https://www.youtube.com/watch?v=ae82zSy4CSM&t=78s )并在我的应用程序中实现了代码。问题是,如果我看到 JSON 输出文件,一切正常,但是当我尝试用我的信用卡付款时,钱没有到达我朋友的 paypal 帐户,当我去检查我的钱时卡,它实际上并没有减少。相反,如果我尝试使用 paypal 线路付款,即使我的凭据正确无误,它也会在登录时显示错误 "incorrect username / password, please try again"。
{
"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();
}
}
}
}
}
}
在详细信息中,我没有注意到任何可归因于 paypal 的错误 API。有什么建议吗?
我认为您是在沙盒中工作。这就是为什么你不能在真实账户上玩真钱游戏。