使用 Android Studio 实现 Paypal SDK - 无法从应用程序登录
Posted
技术标签:
【中文标题】使用 Android Studio 实现 Paypal SDK - 无法从应用程序登录【英文标题】:Implementing Paypal SDK with Android studio - Unable to login from application 【发布时间】:2021-07-03 08:41:38 【问题描述】:调用 PaypalService.class 的活动:
//PAYPAL SDK VARIABLES
public static final int PAYPAL_REQUEST_CODE = 7171;
private static PayPalConfiguration config = new PayPalConfiguration()
.environment(PayPalConfiguration.ENVIRONMENT_SANDBOX)
.clientId(Config.PAYPAL_CLIENT_ID);
Intent payPalIntent = new Intent(this, PayPalService.class);
payPalIntent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);
startService(payPalIntent);
payment = (Button) findViewById(R.id.payment);
payment.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View v)
processPayment();
);
//END OF ON CREATE
@Override
protected void onDestroy()
stopService(new Intent(this, PayPalService.class));
super.onDestroy();
@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,GetTheBike.class)
.putExtra("PaymentDetails", paymentDetails)
.putExtra("PaymentAmount", amount_to_pay)
);
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_LONG).show();
private void processPayment()
PayPalPayment payPalPayment = new PayPalPayment(new BigDecimal(amount_to_pay), "USD",
"Pay for parking", 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);
Config.java 位于不同的文件夹中。它能够连接到应用程序(Client_id 是一个有效的密钥)
package com.example.becoapk21.Config;
public class Config
public static final String PAYPAL_CLIENT_ID="CLIENT_ID";
我正在使用有效的客户沙盒帐户登录(在 sandbox.paypal.com 上测试登录),这是我在登录后得到的错误
E/paypal.sdk: request failure with http statusCode:404,exception:Not Found
E/paypal.sdk: Exception parsing server response
org.json.JSONException: End of input at character 0 of
at org.json.JSONTokener.syntaxError(JSONTokener.java:460)
at org.json.JSONTokener.nextValue(JSONTokener.java:101)
at com.paypal.android.sdk.cw.m(Unknown Source:7)
at com.paypal.android.sdk.fm.d(Unknown Source:0)
at com.paypal.android.sdk.ci.a(Unknown Source:21)
at com.paypal.android.sdk.cm.a(Unknown Source:62)
at com.paypal.android.sdk.cq.onResponse(Unknown Source:45)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:153)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:923)
E/paypal.sdk: request failed with server response:
E/paypal.sdk: INTERNAL_SERVER_ERROR
注意:paypal 沙盒帐户位于 IL。我也尝试创建美国帐户,但没有成功
【问题讨论】:
使用以下 paypal sdk 版本` implementation 'com.paypal.sdk:paypal-android-sdk:2.16.0'` 【参考方案1】:这似乎是一个已弃用的 Android SDK,用于现已结束生命周期的服务。
请参阅新的Native Checkout SDK。
【讨论】:
谢谢!以上是关于使用 Android Studio 实现 Paypal SDK - 无法从应用程序登录的主要内容,如果未能解决你的问题,请参考以下文章
使用 Android Studio 实现 Paypal SDK - 无法从应用程序登录
如何使用 php 在 android studio 中使用 GCM 实现推送通知?