gpt4 book ai didi

java - 无法使用 PayPal Android SDK 进行付款

转载 作者:行者123 更新时间:2023-12-02 00:53:45 25 4
gpt4 key购买 nike

我正在为一位使用 PayPal 付款的 friend 开发一个简单的订餐应用。

为此,我观看了 YouTube 教程(此 https://www.youtube.com/watch?v=ae82zSy4CSM&t=78s),并在我的应用中实现了代码。问题是,如果我看到 JSON 输出文件,一切都正常,但是当我尝试用信用卡付款时,钱没有到达我 friend 的 paypal 帐户,而当我去查看卡上的钱时,它确实到达了实际上并没有减少。相反,如果我尝试使用 paypal 电路付款,则登录时会出现错误“用户名/密码不正确,请重试”,即使我的凭据正确。

{
"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 的错误。有什么建议吗?

最佳答案

我认为您正在沙箱中工作。这就是为什么您不能在真实账户上用真钱玩游戏的原因。

关于java - 无法使用 PayPal Android SDK 进行付款,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57837905/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com