尝试这种方式
Intent intent = new Intent(this, PayPalService.class);
intent.putExtra(PaymentActivity.EXTRA_PAYPAL_ENVIRONMENT, CONFIG_ENVIRONMENT);
intent.putExtra(PaymentActivity.EXTRA_CLIENT_ID, CONFIG_CLIENT_ID);
intent.putExtra(PaymentActivity.EXTRA_RECEIVER_EMAIL, CONFIG_RECEIVER_EMAIL);
startService(intent);
外onCreate()
public void onBuyPressed(View pressed) {
Double amount=Double.parseDouble(Amount.toString());
PayPalPayment thingToBuy = new PayPalPayment(new BigDecimal(String.valueOf(amount)), "NOK","ITEM_S");
Intent intent = new Intent(this, PaymentActivity.class);
intent.putExtra(PaymentActivity.EXTRA_PAYPAL_ENVIRONMENT, CONFIG_ENVIRONMENT);
intent.putExtra(PaymentActivity.EXTRA_CLIENT_ID, CONFIG_CLIENT_ID);
intent.putExtra(PaymentActivity.EXTRA_RECEIVER_EMAIL, CONFIG_RECEIVER_EMAIL);
intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy);
startActivityForResult(intent, 0);
}
public void onBuyPressed(View pressed) {
Double amount=Double.parseDouble(Amount.toString());
PayPalPayment thingToBuy = new PayPalPayment(new BigDecimal(String.valueOf(amount)), "NOK","ITEM_S");
Intent intent = new Intent(this, PaymentActivity.class);
intent.putExtra(PaymentActivity.EXTRA_PAYPAL_ENVIRONMENT, CONFIG_ENVIRONMENT);
intent.putExtra(PaymentActivity.EXTRA_CLIENT_ID, CONFIG_CLIENT_ID);
intent.putExtra(PaymentActivity.EXTRA_RECEIVER_EMAIL, CONFIG_RECEIVER_EMAIL);
intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy);
startActivityForResult(intent, 0);
}
@Override
protected void onActivityResult (int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK) {
PaymentConfirmation confirm = data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
if (confirm != null) {
try {
Log.i("paymentExample", confirm.toJSONObject().toString(4));
JSONObject json=confirm.toJSONObject();
JSONObject payment=json.getJSONObject("payment");
String product=payment.getString("short_description");
String amount=payment.getString("amount").substring(0, 5);
String currency_code=payment.getString("currency_code");
//Toast.makeText(getBaseContext(), "Payment for "+product+" is done sucessfully. Amount of "+amount+" "+currency_code+" has been charged ..!!" , Toast.LENGTH_LONG).show();
tv.setText(getResources().getString(R.string.Payment_for)+product+""+getResources().getString(R.string.has_been_charge)+""+getResources().getString(R.string.Amount)+amount+
" "+currency_code+getResources().getString(R.string.has_been_charge));
new ACtivate_POST().execute();
} catch (JSONException e) {
Log.e("paymentExample", "an extremely unlikely failure occurred: ", e);
}
}
}
else if (resultCode == Activity.RESULT_CANCELED) {
Log.i("paymentExample", "The user canceled.");
Toast.makeText(this,"transaksjonen avbrutt.",Toast.LENGTH_LONG).show();
}
else if (resultCode == PaymentActivity.RESULT_PAYMENT_INVALID) {
Log.i("paymentExample", "An invalid payment was submitted. Please see the docs.");
Toast.makeText(this,"En ugyldig betalingen ble sendt. Vennligst se docs.",Toast.LENGTH_LONG).show();
}
}
THX你的答案。现在,我可以采取“付款密钥” – 2014-10-07 10:41:57
@CarlosSierraGarcia你会得到一个“交易ID”(支付ID)成功支付后 – Gattsu 2014-10-07 10:43:27