【问题标题】:Android Studio Integration with PayPal not workingAndroid Studio 与 PayPal 的集成不起作用
【发布时间】:2020-11-12 17:32:18
【问题描述】:

我完全按照集成paypal与Android studio的教程,但是当我点击按钮时,它并没有进入paypal,系统仍然停留在同一页面,请问是什么问题? 教程:https://www.youtube.com/watch?v=k5lPy_50f0Y&t=1068s

public class PayPal extends AppCompatActivity {
private static final int PAYPAL_REQUEST_CODE = 7171;

private static PayPalConfiguration config = new PayPalConfiguration()
        .environment(PayPalConfiguration.ENVIRONMENT_SANDBOX)
        .clientId(Config.PAYPAL_CLIENT_ID);
Button btnPayNow;
EditText edtAmount;

String amount = "";

@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_pay_pal);
    Intent intent = new Intent(this,PayPalService.class);
    intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION,config);
    startService(intent);

    btnPayNow = findViewById(R.id.btnPayNow);
    edtAmount = findViewById(R.id.edtAmount);

   btnPayNow.setOnClickListener(new View.OnClickListener() {
       @Override
       public void onClick(View v) {
           processPayment();
       }
   });
}

private void processPayment() {
    amount = edtAmount.getText().toString();
    PayPalPayment payPalPayment = new PayPalPayment(new BigDecimal(String.valueOf(amount)),"RM",
            "Registration Fee",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) {
    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("Payment Details", paymentDetails)
                            .putExtra("Amount", amount));
                } 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", Toast.LENGTH_SHORT).show();
}

}

【问题讨论】:

    标签: android paypal


    【解决方案1】:

    该视频适用于不再受支持且不应使用的已弃用 Android SDK

    将 PayPal 与本机 SDK 集成的唯一受支持方法是通过 Braintree 进行 Express Checkout。这是指南:https://developer.paypal.com/docs/accept-payments/express-checkout/ec-braintree-sdk/get-started/

    此集成的服务器端部分需要 Web 服务。

    它使用来自 developer.paypal.com(沙盒模式)或 https://www.paypal.com/api(实时模式)的 Braintree 访问令牌

    【讨论】:

    • 这是否意味着我不能再通过视频中的 Android Studio 使用 PayPal?
    猜你喜欢
    • 2017-07-09
    • 2013-12-13
    • 2014-05-20
    • 2012-06-29
    • 2013-06-01
    • 2018-11-16
    • 2021-12-28
    • 1970-01-01
    • 2012-06-28
    相关资源
    最近更新 更多