贝宝整合 android
PayPal integration android
我遵循的集成贝宝的步骤。
- 在沙盒中创建帐户。
- 为应用程序创建了 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 保持不变。请告诉我为什么会这样?
- 如何实现这一点 -
From your server, use the payment id value to look up the payment details with the REST API.
?
- 是否可以仅使用 PayPal SDK 中的 "Pay with Card" 选项?
找到答案并且犯了很小的错误。
- 响应保持不变,因为我在没有 sandbox/Real Money 选项的情况下进行检查,即
[这是为了不与 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
** 不确定还有两点
我遵循的集成贝宝的步骤。
- 在沙盒中创建帐户。
- 为应用程序创建了 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 保持不变。请告诉我为什么会这样?
- 如何实现这一点 -
From your server, use the payment id value to look up the payment details with the REST API.
? - 是否可以仅使用 PayPal SDK 中的 "Pay with Card" 选项?
找到答案并且犯了很小的错误。
- 响应保持不变,因为我在没有 sandbox/Real Money 选项的情况下进行检查,即
[这是为了不与 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
** 不确定还有两点