android - 在我们上线 android 后,使用 Paypal sdk 的付款不起作用
问题描述
我在 android 中使用 Paypal 商家 sdk 使用 Paypal 帐户和信用卡付款
- 我在 Paypal 上有一个企业帐户(尚未与信用卡关联)
- 我创建了一个沙盒帐户并在上线前测试了付款,一切正常
- 我使用我的应用程序从 Paypal 帐户正确进行了一笔交易,之后我收到了错误消息:
paypal因风险被拒绝
我们无法设置此付款,请查看您的 Paypal 帐户
这个用信用卡
商家不接受此类付款
商家是在工作还是已弃用?应用程序和Paypal中的货币是否应该相同?
请注意,我已经阅读了有关 Braintree sdk 作为替代方式的信息,但它需要服务器代码(我没有)
这是我的代码:
public class PaypalActivity extends AppCompatActivity {
private static final String CONFIG_ENVIRONMENT = PayPalConfiguration.ENVIRONMENT_PRODUCTION;
private static final String CONFIG_CLIENT_ID = "AZE***";
private static final int REQUEST_CODE_PAYMENT = 1;
private static final int REQUEST_CODE_FUTURE_PAYMENT = 2;
private static PayPalConfiguration config = new PayPalConfiguration()
.environment(CONFIG_ENVIRONMENT)
.clientId(CONFIG_CLIENT_ID)
// The following are only used in PayPalFuturePaymentActivity.
.merchantName("Hipster Store")
.merchantPrivacyPolicyUri(
Uri.parse("https://www.example.com/privacy"))
.merchantUserAgreementUri(
Uri.parse("https://www.example.com/legal"));
PayPalPayment thingToBuy;
Button OrderBu;
EditText amount;
String amout_str;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_paypal);
Intent intent = new Intent(this, PayPalService.class);
intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);
startService(intent);
OrderBu = (Button) findViewById(R.id.order);
amount = (EditText) findViewById(R.id.et_id);
OrderBu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
amout_str = amount.getText().toString();
if (amout_str.equals("")) {
Toast.makeText(PaypalActivity.this, "حدد المبلغ", Toast.LENGTH_LONG).show();
} else {
thingToBuy = new PayPalPayment(new BigDecimal(amout_str), "USD",
"amount", PayPalPayment.PAYMENT_INTENT_SALE);
Intent intent = new Intent(PaypalActivity.this,
PaymentActivity.class);
intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy);
startActivityForResult(intent, REQUEST_CODE_PAYMENT);
}
}
});
}
public void onFuturePaymentPressed(View pressed) {
Intent intent = new Intent(PaypalActivity.this,
PayPalFuturePaymentActivity.class);
startActivityForResult(intent, REQUEST_CODE_FUTURE_PAYMENT);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE_PAYMENT) {
if (resultCode == Activity.RESULT_OK) {
PaymentConfirmation confirm = data
.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
if (confirm != null) {
try {
System.out.println(confirm.toJSONObject().toString(4));
System.out.println(confirm.getPayment().toJSONObject()
.toString(4));
Toast.makeText(getApplicationContext(), "Order placed",
Toast.LENGTH_LONG).show();
} catch (JSONException e) {
e.printStackTrace();
}
}
} else if (resultCode == Activity.RESULT_CANCELED) {
System.out.println("The user canceled.");
} else if (resultCode == PaymentActivity.RESULT_EXTRAS_INVALID) {
System.out
.println("An invalid Payment or PayPalConfiguration was submitted. Please see the docs.");
}
} else if (requestCode == REQUEST_CODE_FUTURE_PAYMENT) {
if (resultCode == Activity.RESULT_OK) {
PayPalAuthorization auth = data
.getParcelableExtra(PayPalFuturePaymentActivity.EXTRA_RESULT_AUTHORIZATION);
if (auth != null) {
try {
Log.i("FuturePaymentExample", auth.toJSONObject()
.toString(4));
String authorization_code = auth.getAuthorizationCode();
Log.i("FuturePaymentExample", authorization_code);
sendAuthorizationToServer(auth);
Toast.makeText(getApplicationContext(),
"Future Payment code received from PayPal",
Toast.LENGTH_LONG).show();
} catch (JSONException e) {
Log.e("FuturePaymentExample",
"an extremely unlikely failure occurred: ", e);
}
}
} else if (resultCode == Activity.RESULT_CANCELED) {
Log.i("FuturePaymentExample", "The user canceled.");
} else if (resultCode == PayPalFuturePaymentActivity.RESULT_EXTRAS_INVALID) {
Log.i("FuturePaymentExample",
"Probably the attempt to previously start the PayPalService had an invalid PayPalConfiguration. Please see the docs.");
}
}
}
private void sendAuthorizationToServer(PayPalAuthorization authorization) {
}
public void onFuturePaymentPurchasePressed(View pressed) {
// Get the Application Correlation ID from the SDK
String correlationId = PayPalConfiguration
.getApplicationCorrelationId(this);
Log.i("FuturePaymentExample", "Application Correlation ID: "
+ correlationId);
// TODO: Send correlationId and transaction details to your server for
// processing with
// PayPal...
Toast.makeText(getApplicationContext(),
"App Correlation ID received from SDK", Toast.LENGTH_LONG)
.show();
}
@Override
public void onDestroy() {
// Stop service when done
stopService(new Intent(this, PayPalService.class));
super.onDestroy();
}
}
解决方案
推荐阅读
- java - 在tableview组合框中将模型中的一组对象显示为字符串?
- kotlin - 使用类中的几个函数实现扩展函数 Kotlin
- scala - 在scala中,如果案例类在家庭外部类型中声明,如何调用它的通用复制函数?
- php - 如何使文件在 laravel 中可下载?
- c - 函数返回时文件是否在 c 中关闭?
- python - 如何在 Anaconda 中安装 PyQt6?
- r - 如何将重复的行与缺少的字段结合起来R
- exception - 工作表中的 AVPlayer:“CALayer 位置包含 NaN:[nan nan]”(包括 MRE)
- r - 无法分配给不存在的列——使用 ARTool 包
- python - 返回 n 叉树中从根到叶的所有路径