PayPal沙盒API不允许买家登录

Posted

技术标签:

【中文标题】PayPal沙盒API不允许买家登录【英文标题】:PayPal sandbox API don't allow buyers to log in 【发布时间】:2020-03-01 02:38:58 【问题描述】:

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

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

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

confirmOrder.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();

    


Config.java:


package com.example.my1stapplication.config;

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

【问题讨论】:

@randstraw 你能帮帮我吗 如果有任何方法可以使用不显示此问题的任何类型的帐户,请告诉我。我只需要一种方法来测试它,因为它只是一个大学课程项目。 【参考方案1】:

要登录 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 左侧有一个通知选项卡

【讨论】:

以上是关于PayPal沙盒API不允许买家登录的主要内容,如果未能解决你的问题,请参考以下文章

PayPal 定期付款未显示在我的买家或商家沙盒帐户中?

不使用沙盒的 PayPal 测试

Paypal 沙盒订阅按钮 - 测试没有 Paypal 帐户的买家?

无法将PayPal沙盒帐户链接到第三方权限

如何在paypal买家沙箱帐户中创建eCheck帐户类型?而且,如何使用ebay沙盒订单进行测试?

PayPal沙盒立即购买问题