java - PayPal 沙箱 API 不允许买家登录

标签 java android android-studio paypal paypal-sandbox

我正在使用 android studio 开发移动应用程序。我有一个支付功能,我集成了 PayPal 沙箱,当用户点击查看时,PayPal 页面出现。然而,当任何买家尝试使用出现的页面登录时,它显示“用户名/密码不正确。请重试”,尽管我确定它是正确的并尝试了多个帐户,其中一个有有效的真实信用卡但输出相同。我想知道为什么会这样?请有人尽快帮助我。

这是用户尝试登录时出现的内容: screen shot of PayPal error message

提供了三个与支付部分相关的java类:

确认订单.java:

package com.example.my1stapplication;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Button;
import android.content.Intent;
import com.example.my1stapplication.config.Config;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.paypal.android.sdk.payments.PayPalConfiguration;
import com.paypal.android.sdk.payments.PayPalPayment;
import com.paypal.android.sdk.payments.PayPalPaymentDetails;
import com.paypal.android.sdk.payments.PayPalService;
import com.paypal.android.sdk.payments.PaymentActivity;
import com.paypal.android.sdk.payments.PaymentConfirmation;

import android.text.TextUtils;
import android.widget.Toast;

import org.json.JSONException;

import java.io.Serializable;

import java.util.HashMap;
import java.math.BigDecimal;

public class confirmOrder extends AppCompatActivity {

    EditText district, streetName, houseNo, phoneNo;
    Button checkout;

    DatabaseReference ordersref= FirebaseDatabase.getInstance().getReference("Orders");
    final HashMap<String, Object> ordersMap=new HashMap<>();
public static final int PAYPAL_REQUEST_CODE=7171;

private static PayPalConfiguration config = new PayPalConfiguration().environment(PayPalConfiguration.ENVIRONMENT_SANDBOX).clientId(Config.PAYPAL_CLIENT_ID);
 //Double totalPrice=getIntent().getDoubleExtra("totalPrice",0);


    @Override
    protected void onDestroy() {
        stopService(new Intent(this, PayPalService.class));
        super.onDestroy();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_confirm_order);

        Double totalPrice=getIntent().getDoubleExtra("totalPrice",0);

        Intent intent = new Intent(this, PayPalService.class);
        intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION,config);
        startService(intent);

        district = (EditText) findViewById(R.id.district);
        streetName = (EditText) findViewById(R.id.streetName);
        houseNo = (EditText) findViewById(R.id.houseNo);
        phoneNo = (EditText) findViewById(R.id.phoneNo);
        checkout = (Button) findViewById(R.id.checkout);
        String buyerID = getIntent().getStringExtra("buyerID");
        // Double totalPrice=getIntent().getDoubleExtra("totalPrice",0);
        //HashMap cart=(HashMap) getIntent().getSerializableExtra("cart");


        checkout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                String district1 = district.getText().toString();
                String streetName1 = district.getText().toString();
                String houseNo1 = district.getText().toString();
                String phoneNo1 = district.getText().toString();

                if (!TextUtils.isEmpty(district1) && !TextUtils.isEmpty(district1)
                        && !TextUtils.isEmpty(district1) && !TextUtils.isEmpty(district1)) {

                    Double totalPrice = getIntent().getDoubleExtra("totalPrice", 0);
                    HashMap<String, Object> cart = (HashMap<String, Object>) getIntent().getSerializableExtra("cart");
                    String Orderid = ordersref.push().getKey();
                    ordersMap.put("orderID", Orderid);
                    ordersMap.put("totalPrice", (totalPrice));
                    ordersMap.put("buyerID", FirebaseAuth.getInstance().getCurrentUser().getUid());
                    ordersMap.put("district", district1);
                    ordersMap.put("streetName", streetName1);
                    ordersMap.put("houseNo", houseNo1);
                    ordersMap.put("phoneNo", phoneNo1);
                    ordersMap.put("paied", false);
                    ordersMap.put("shipped", false);
                    ordersMap.put("takenFromOwner", false);
                    //ordersMap.put("inCart", adapter);
                    ordersref.child(Orderid).updateChildren(ordersMap);
                    ordersref.child(Orderid).child("cart").updateChildren(cart);

                    processPayment();


                } else {
                    Toast.makeText(getApplicationContext(), "please enter all fields", Toast.LENGTH_LONG).show();
                }
            }

        });

    }

    private void processPayment(){

        Double totalPrice=getIntent().getDoubleExtra("totalPrice",0);
        PayPalPayment payPalPayment =new PayPalPayment(new BigDecimal(totalPrice),"USD", "Pay for the material/s" , PayPalPayment.PAYMENT_INTENT_SALE);


        Intent intent = new Intent(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, @Nullable Intent data) {
        Double totalPrice=getIntent().getDoubleExtra("totalPrice",0);


        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 paymentDetails = confirmation.toJSONObject().toString(4);
                        startActivity(new Intent(this, PaymentDetails.class).putExtra("PaymentDetails", paymentDetails).putExtra("PaymentAmount", totalPrice));
                    } catch (JSONException e) {
                        e.printStackTrace();


                    }

                } else if (resultCode == Activity.RESULT_CANCELED) {
                    Toast.makeText(this, "Cancel", Toast.LENGTH_SHORT).show();
                }


            } else if (resultCode == PaymentActivity.RESULT_EXTRAS_INVALID) {
                Toast.makeText(this, "Invalid Payment", Toast.LENGTH_SHORT).show();


            }

        }


    }
}


PaymentDetails.java:


package com.example.my1stapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.TextView;
import org.json.JSONObject;
import android.content.Intent;
import org.json.JSONException;
public class PaymentDetails extends AppCompatActivity {


    TextView txtId,txtAmount,txtStatus;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_payment_details);


        txtId = (TextView)findViewById(R.id.txtId);
        txtStatus = (TextView)findViewById(R.id.txtStatus);
        txtAmount = (TextView)findViewById(R.id.txtAmount);

        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) throws JSONException {

try {
    txtId.setText(response.getString("id"));
    txtStatus.setText(response.getString("status"));
    txtAmount.setText("SR"+paymentAmount);
}

catch(JSONException e){
    e.printStackTrace();
}
    }

}

配置.java:


package com.example.my1stapplication.config;

public class Config {
    public static final String PAYPAL_CLIENT_ID = "AR1bLXBzCYYWa4BCkEyTTcbijrtWPh9u15b3sxQbHQZ-ymhEonDq9zwMo1CqqM95fwHPp-pNjbRF99Am";
}

最佳答案

要登录 PayPal 沙盒页面,您必须使用 PayPal 沙盒 (www.sandbox.paypal.com) 帐户,而不是真实帐户 (www.paypal.com)。

您可以在 https://www.paypal.com/signin?returnUri=https%3A%2F%2Fdeveloper.paypal.com%2Fdeveloper%2Faccounts 内根据需要创建任意数量的 PayPal 沙盒帐户。

他们的电子邮件标识符是虚构的,可以是以前未在沙箱中使用过的任何东西。从来没有真正的电子邮件发送到这些地址;相反,在 developer.paypal.com 的左侧有一个通知选项卡

关于java - PayPal 沙箱 API 不允许买家登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58699202/

相关文章:

java - 如何更改 freemarker 中的 DOCTYPE?

android-studio - Flutter Web 应用程序错误 : CHROME_EXECUTABLE= "..." is not executable

java - 如何将Repository自动生成的ID返回到MainActivity?

java - 如何使用runner来运行FutureTask<V>中的Callable

Java Iterator循环一次,从中间开始

java - 如何检查线程内主线程的变量?

android - 如何从上下文操作栏中删除项目android

java - android系统是否包含JVM?

java - Android TV 模拟器无法识别媒体键事件

android - 在 Android Studio 上构建应用程序时出错