@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));
            /**
             * TODO: send 'confirm' (and possibly confirm.getPayment() to your server for
             * verification or consent completion. See https://developer.paypal.com
             * /webapps/developer/docs/integration /mobile/verify-mobile-payment/ for more details.
             *
             * <p>For sample mobile backend interactions, see https://github
             * .com/paypal/rest-api-sdk-python/tree/master /samples/mobile_backend
             */
            /*
            Toast.makeText(
            		getApplicationContext(),
            		"PaymentConfirmation info received from PayPal",
            		Toast.LENGTH_LONG).show();
            		*/

            Intent intent = new Intent(mContext, ReceiptActivity.class);
            mContext.startActivity(intent);
            finish();

          } 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.");
      }
    } else {
      Log.d(TAG, "an impossible requestCode occurred: " + Integer.toString(requestCode));
    }
  }
Exemple #2
0
  @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));
            /**
             * TODO: send 'confirm' (and possibly confirm.getPayment() to your server for
             * verification or consent completion. See
             * https://developer.paypal.com/webapps/developer/docs/integration/mobile/verify-mobile-payment/
             * for more details.
             *
             * <p>For sample mobile backend interactions, see
             * https://github.com/paypal/rest-api-sdk-python/tree/master/samples/mobile_backend
             */
            ParseUser.getCurrentUser().remove("cart");
            Toast.makeText(getApplicationContext(), "Payments Success!", Toast.LENGTH_LONG).show();
            finish();

          } 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.");
      }
    } 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.");
      }
    } else if (requestCode == REQUEST_CODE_PROFILE_SHARING) {
      if (resultCode == Activity.RESULT_OK) {
        PayPalAuthorization auth =
            data.getParcelableExtra(PayPalProfileSharingActivity.EXTRA_RESULT_AUTHORIZATION);
        if (auth != null) {
          try {
            Log.i("ProfileSharingExample", auth.toJSONObject().toString(4));

            String authorization_code = auth.getAuthorizationCode();
            Log.i("ProfileSharingExample", authorization_code);

            sendAuthorizationToServer(auth);
            Toast.makeText(
                    getApplicationContext(),
                    "Profile Sharing code received from PayPal",
                    Toast.LENGTH_LONG)
                .show();

          } catch (JSONException e) {
            Log.e("ProfileSharingExample", "an extremely unlikely failure occurred: ", e);
          }
        }
      } else if (resultCode == Activity.RESULT_CANCELED) {
        Log.i("ProfileSharingExample", "The user canceled.");
      } else if (resultCode == PayPalFuturePaymentActivity.RESULT_EXTRAS_INVALID) {
        Log.i(
            "ProfileSharingExample",
            "Probably the attempt to previously start the PayPalService had an invalid PayPalConfiguration. Please see the docs.");
      }
    }
  }