无法使用 PayPal Android SDK 付款

Posted

技术标签:

【中文标题】无法使用 PayPal Android SDK 付款【英文标题】:Can't make payments with PayPal Android SDK 【发布时间】:2020-01-10 06:28:43 【问题描述】:

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

为此,我观看了 YouTube 教程 (https://www.youtube.com/watch?v=ae82zSy4CSM&t=78s),并在我的应用中实现了代码。问题是,如果我看到 JSON 输出文件,一切正常,但是当我尝试用信用卡付款时,钱没有到达我朋友的 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 的错误。有什么建议吗?

【问题讨论】:

【参考方案1】:

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

【讨论】:

CONFIG_ENVIRONMENT = PayPalConfiguration.ENVIRONMENT_SANDBOX;是的,因为这是我的环境配置,所以我该怎么办?

以上是关于无法使用 PayPal Android SDK 付款的主要内容,如果未能解决你的问题,请参考以下文章

使用 Android Studio 实现 Paypal SDK - 无法从应用程序登录

Android Paypal 用户使用 sdk 登录

在 Paypal 移动 SDK 中禁用信用卡

PayPal Android SDK 保险库

使用 Braintree SDK 在 Android 中支付 PayPal

无需 PayPal 帐户或信用卡的 PayPal Android SDK 付款