如何在android中授权paypal支付

时间:2014-05-20 12:59:04

标签: android paypal

private static final String CONFIG_ENVIRONMENT = PaymentActivity.ENVIRONMENT_PRODUCTION;

// note that these credentials will differ between live & sandbox environments.
private static final String CONFIG_CLIENT_ID = "live api";
// when testing in sandbox, this is likely the -facilitator email address. 
private static final String CONFIG_RECEIVER_EMAIL = "abc@yahoo.com"; 

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

    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);

    onBuyPressed(null);
}

public void onBuyPressed(View pressed) {

    PayPalPayment thingToBuy = getThingToBuy();
    String bookId = getIntent().getStringExtra("BookId");

    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);

    // It's important to repeat the clientId here so that the SDK has it if Android restarts your 
    // app midway through the payment UI flow.
    intent.putExtra(PaymentActivity.EXTRA_CLIENT_ID, CONFIG_CLIENT_ID);
    intent.putExtra(PaymentActivity.EXTRA_PAYER_ID, bookId);
    intent.putExtra(PaymentActivity.EXTRA_SKIP_CREDIT_CARD, false);
    intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy);



    startActivityForResult(intent, 0);
}

private PayPalPayment getThingToBuy() {

    String Price    = getIntent().getStringExtra("Price");
    String BookName = getIntent().getStringExtra("BookName");
    String Currency = getIntent().getStringExtra("CurrencyCode");
    return new PayPalPayment(new BigDecimal(Price), Currency, BookName);
}

@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));

                // TODO: send 'confirm' to your server for verification.
                // see https://developer.paypal.com/webapps/developer/docs/integration/mobile/verify-mobile-payment/
                // for more details.

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

当我想通过Android在PayPal中付款时,会出现一个对话框,其中包含付款失败和UNAUTHORIZED_PAYMENT。我该如何解决这个问题?我使用了PayPal Android SDK。

0 个答案:

没有答案