gpt4 book ai didi

android - Paypal 集成安卓

转载 作者:行者123 更新时间:2023-11-30 02:24:34 25 4
gpt4 key购买 nike

我遵循的集成 Paypal 的步骤。

  • 在沙盒中创建帐户。
  • 为应用创建了 ClientId。
  • 下载了 paypal sdk 并与我的应用集成。
  • 按照 https://devblog.paypal.com/working-with-the-new-android-sdk/ 中的步骤进行集成。

代码:

public class MainActivity extends Activity {

private static final String CONFIG_ENVIRONMENT = PayPalConfiguration.ENVIRONMENT_NO_NETWORK;
private static final String CONFIG_CLIENT_ID = "***************************";
private static final String CONFIG_RECEIVER_EMAIL = "test-facilitator@officialgates.com";
private static final int REQUEST_CODE_PAYMENT = 1;
private static final String TAG = "paymentExample";


private static PayPalConfiguration config = new PayPalConfiguration()
.environment(CONFIG_ENVIRONMENT)
.clientId(CONFIG_CLIENT_ID)
.merchantName("Store");


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


public void onBuyPressed(View pressed) {
PayPalPayment thingToBuy = getThingToBuy(PayPalPayment.PAYMENT_INTENT_SALE);


Intent intent = new Intent(MainActivity.this, PaymentActivity.class);
intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);
intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy);
startActivityForResult(intent, REQUEST_CODE_PAYMENT);
}

private PayPalPayment getThingToBuy(String paymentIntent) {
return new PayPalPayment(new BigDecimal("100.75"), "USD", "my product",
paymentIntent);
}

@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 {
Log.i(TAG, confirm.toJSONObject().toString(4));
Log.i(TAG, confirm.getPayment().toJSONObject().toString(4));


JSONObject jsonObj=new JSONObject(confirm.toJSONObject().toString());

String paymentId=jsonObj.getJSONObject("response").getString("id");
System.out.println("payment id:-=="+paymentId);


Toast.makeText(
getApplicationContext(),
"payment id"+paymentId, Toast.LENGTH_LONG)
.show();


Toast.makeText(
getApplicationContext(),
"PaymentConfirmation info received from PayPal", Toast.LENGTH_LONG)
.show();

} catch (JSONException e) {
Log.e(TAG, "an extremely unlikely failure occurred: ", e);
}
}
} else if (resultCode == Activity.RESULT_CANCELED) {
Log.i(TAG, "The user canceled.");
} else if (resultCode == PaymentActivity.RESULT_EXTRAS_INVALID) {
Log.i(
TAG,
"An invalid Payment or PayPalConfiguration was submitted. Please see the docs.");
}
}

}
@Override
public void onDestroy() {
// Stop service when done
stopService(new Intent(this, PayPalService.class));
super.onDestroy();
}
}

响应:

01-20 01:14:43.072: I/paymentExample(17759): {
01-20 01:14:43.072: I/paymentExample(17759): "response": {
01-20 01:14:43.072: I/paymentExample(17759): "state": "approved",
01-20 01:14:43.072: I/paymentExample(17759): "id": "PAY-6PU626847BSKPEWXHY",
01-20 01:14:43.072: I/paymentExample(17759): "create_time": "2014-07-18T18:46:55Z",
01-20 01:14:43.072: I/paymentExample(17759): "intent": "sale"
01-20 01:14:43.072: I/paymentExample(17759): },
01-20 01:14:43.072: I/paymentExample(17759): "client": {
01-20 01:14:43.072: I/paymentExample(17759): "platform": "Android",
01-20 01:14:43.072: I/paymentExample(17759): "paypal_sdk_version": "2.8.4",
01-20 01:14:43.072: I/paymentExample(17759): "product_name": "PayPal-Android-SDK",
01-20 01:14:43.072: I/paymentExample(17759): "environment": "mock"
01-20 01:14:43.072: I/paymentExample(17759): },
01-20 01:14:43.072: I/paymentExample(17759): "response_type": "payment"
01-20 01:14:43.072: I/paymentExample(17759): }
01-20 01:14:43.073: I/paymentExample(17759): {
01-20 01:14:43.073: I/paymentExample(17759): "short_description": "YRYCN",
01-20 01:14:43.073: I/paymentExample(17759): "amount": "100.75",
01-20 01:14:43.073: I/paymentExample(17759): "intent": "sale",
01-20 01:14:43.073: I/paymentExample(17759): "currency_code": "USD"
01-20 01:14:43.073: I/paymentExample(17759): }

我的问题:

  • 无论我运行多少次,响应都保持不变,即 PaymentId 和 create_time 保持不变。请告诉我为什么会这样?
  • 如何实现这一点 - 从您的服务器,使用付款 ID 值通过 REST API 查找付款详细信息。 ?
  • 是否可以仅使用 PayPal SDK 中的“用卡付款”选项?

最佳答案

找到答案并犯了很小的错误。

  • 响应保持不变,因为我在没有沙盒/真钱选项的情况下进行检查。

[这是为了不与 PayPal 服务器通信]

private static final String CONFIG_ENVIRONMENT = PayPalConfiguration.ENVIRONMENT_NO_NETWORK

改为

[这是为了您的测试凭据 来自 https://developer.paypal.com ]

private static final String CONFIG_ENVIRONMENT = PayPalConfiguration.ENVIRONMENT_SANDBOX

或更改为

[这是为了转移真钱]

private static final String CONFIG_ENVIRONMENT = PayPalConfiguration.ENVIRONMENT_PRODUCTION

** 不确定还有两点

关于android - Paypal 集成安卓,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28043316/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com