@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)); } }
@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."); } }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_CODE_PAYPAL) { if (resultCode == Activity.RESULT_OK) { PaymentConfirmation confirm = data.getParcelableExtra( com.paypal.android.sdk.payments.PaymentActivity.EXTRA_RESULT_CONFIRMATION); if (confirm != null) { try { String proofOfPayment = confirm .toJSONObject() .getJSONObject("proof_of_payment") .getJSONObject("adaptive_payment") .getString("pay_key"); submitOrderForPrinting(proofOfPayment); } catch (JSONException e) { showErrorDialog(e.getMessage()); } } } } else if (requestCode == REQUEST_CODE_CREDITCARD) { if (data != null && data.hasExtra(CardIOActivity.EXTRA_SCAN_RESULT)) { CreditCard scanResult = data.getParcelableExtra(CardIOActivity.EXTRA_SCAN_RESULT); if (!scanResult.isExpiryValid()) { showErrorDialog("Sorry it looks like that card has expired. Please try again."); return; } PayPalCard card = new PayPalCard(); card.setNumber(scanResult.cardNumber); card.setExpireMonth(scanResult.expiryMonth); card.setExpireYear(scanResult.expiryYear); card.setCvv2(scanResult.cvv); card.setCardType(PayPalCard.CardType.getCardType(scanResult.getCardType())); if (card.getCardType() == PayPalCard.CardType.UNSUPPORTED) { showErrorDialog( "Sorry we couldn't recognize your card. Please try again manually entering your card details if necessary."); return; } final ProgressDialog dialog = new ProgressDialog(this); dialog.setCancelable(false); dialog.setTitle("Processing"); dialog.setMessage("One moment"); dialog.show(); card.storeCard( paypalEnvironment, new PayPalCardVaultStorageListener() { @Override public void onStoreSuccess(PayPalCard card) { dialog.dismiss(); payWithExistingCard(card); } @Override public void onError(PayPalCard card, Exception ex) { dialog.dismiss(); showErrorDialog(ex.getMessage()); } }); } else { // card scan cancelled } } else if (requestCode == REQUEST_CODE_RECEIPT) { setResult(Activity.RESULT_OK); finish(); } }
@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."); } } }