com.paypal.android.sdk.payments.PaymentActivity Java Examples

The following examples show how to use com.paypal.android.sdk.payments.PaymentActivity. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BasePurchaseActivity.java    From aptoide-client with GNU General Public License v2.0 6 votes vote down vote up
@Override
        public void onClick(View view) {
            valuesToVerify = new ValuesToVerify();
            valuesToVerify.currency = this.currency;
            valuesToVerify.price = this.price;
            valuesToVerify.tax = this.tax;
            valuesToVerify.repo = this.repo;
            PayPalPayment thingToBuy = new PayPalPayment(new BigDecimal(price), currency, description,
                    PayPalPayment.PAYMENT_INTENT_SALE);

            Intent intent = new Intent(BasePurchaseActivity.this, PaymentActivity.class);
            intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy);

            startActivityForResult(intent, REQUEST_CODE_PAYMENT);
//            FlurryAgent.logEvent("Purchase_Page_Clicked_On_Paypal_Button");
        }
 
Example #2
Source File: PayPal.java    From react-native-paypal with MIT License 6 votes vote down vote up
public void handleActivityResult(final int requestCode, final int resultCode, final Intent data) {
  if (requestCode != paymentIntentRequestCode) { return; }

  if (resultCode == Activity.RESULT_OK) {
    PaymentConfirmation confirm =
      data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
    if (confirm != null) {
      successCallback.invoke(
        confirm.toJSONObject().toString(),
        confirm.getPayment().toJSONObject().toString()
      );
    }
  } else if (resultCode == Activity.RESULT_CANCELED) {
    errorCallback.invoke(ERROR_USER_CANCELLED);
  } else if (resultCode == PaymentActivity.RESULT_EXTRAS_INVALID) {
    errorCallback.invoke(ERROR_INVALID_CONFIG);
  }

  currentActivity.stopService(new Intent(currentActivity, PayPalService.class));
}
 
Example #3
Source File: ShoppingCardActivity.java    From android-paypal-example with Apache License 2.0 5 votes vote down vote up
@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.
                     *
                     * For sample mobile backend interactions, see
                     * https://github.com/paypal/rest-api-sdk-python/tree/master/samples/mobile_backend
                     */

                    String payment_id = confirm.toJSONObject().getJSONObject("response").getString("id");

                    verifyPaymentOnServer(payment_id , confirm);

                    displayResultText("PaymentConfirmation info received from PayPal");

                } 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.");
        }
    }
}
 
Example #4
Source File: HistorySingleActivity.java    From UberClone with MIT License 5 votes vote down vote up
private void payPalPayment() {
    PayPalPayment payment = new PayPalPayment(new BigDecimal(ridePrice), "USD", "Uber Ride",
            PayPalPayment.PAYMENT_INTENT_SALE);

    Intent intent = new Intent(this, PaymentActivity.class);

    intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);
    intent.putExtra(PaymentActivity.EXTRA_PAYMENT, payment);

    startActivityForResult(intent, PAYPAL_REQUEST_CODE);
}
 
Example #5
Source File: HistorySingleActivity.java    From UberClone with MIT License 5 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == PAYPAL_REQUEST_CODE){
        if(resultCode == Activity.RESULT_OK){
            PaymentConfirmation confirm = data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
            if(confirm != null){
                try{
                    JSONObject jsonObj = new JSONObject(confirm.toJSONObject().toString());

                    String paymentResponse = jsonObj.getJSONObject("response").getString("state");

                    if(paymentResponse.equals("approved")){
                        Toast.makeText(getApplicationContext(), "Payment successful", Toast.LENGTH_LONG).show();
                        historyRideInfoDb.child("customerPaid").setValue(true);
                        mPay.setEnabled(false);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

        }else{
            Toast.makeText(getApplicationContext(), "Payment unsuccessful", Toast.LENGTH_LONG).show();
        }
    }
}
 
Example #6
Source File: PayPal.java    From react-native-paypal with MIT License 5 votes vote down vote up
@ReactMethod
public void paymentRequest(
  final ReadableMap payPalParameters,
  final Callback successCallback,
  final Callback errorCallback
) {
  this.successCallback = successCallback;
  this.errorCallback = errorCallback;

  final String environment = payPalParameters.getString("environment");
  final String clientId = payPalParameters.getString("clientId");
  final String price = payPalParameters.getString("price");
  final String currency = payPalParameters.getString("currency");
  final String description = payPalParameters.getString("description");

  PayPalConfiguration config =
    new PayPalConfiguration().environment(environment).clientId(clientId);

  startPayPalService(config);

  PayPalPayment thingToBuy =
    new PayPalPayment(new BigDecimal(price), currency, description,
                      PayPalPayment.PAYMENT_INTENT_SALE);

  Intent intent =
    new Intent(activityContext, PaymentActivity.class)
    .putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config)
    .putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy);

  currentActivity.startActivityForResult(intent, paymentIntentRequestCode);
}
 
Example #7
Source File: Utils.java    From flickr-uploader with GNU General Public License v2.0 5 votes vote down vote up
public static boolean onActivityResult(int requestCode, int resultCode, Intent data) {
	boolean consumed = false;
	if (requestCode == PAYPAL_REQUEST_CODE_PAYMENT) {
		consumed = true;
		if (resultCode == Activity.RESULT_OK) {
			PaymentConfirmation confirm = data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
			if (confirm != null) {
				String paypal_result_confirmation = confirm.toJSONObject().toString();
				LOG.info(paypal_result_confirmation);
				Utils.setStringProperty("paypal_result_confirmation", paypal_result_confirmation);
				validatePaypalPayment(paypal_result_confirmation);
				// TODO: send 'confirm' to your server for verification
				// or consent
				// completion.
				// see
				// https://developer.paypal.com/webapps/developer/docs/integration/mobile/verify-mobile-payment/
				// for more details.
			}
		} else if (resultCode == Activity.RESULT_CANCELED) {
			LOG.info("The user canceled.");
		} else if (resultCode == PaymentActivity.RESULT_EXTRAS_INVALID) {
			LOG.warn("An invalid Payment was submitted. Please see the docs.");
		}
	} else if (IabHelper.get(false) != null && IabHelper.get(false).handleActivityResult(requestCode, resultCode, data)) {
		consumed = true;
	}
	return consumed;
}
 
Example #8
Source File: ShoppingCardActivity.java    From android-paypal-example with Apache License 2.0 3 votes vote down vote up
/**
 * Launching PalPay payment activity to complete the payment
 * */
private void launchPayPalPayment() {

    PayPalPayment thingsToBuy = prepareFinalCart();

    Intent intent = new Intent(this, PaymentActivity.class);

    intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, paypalConfig);

    intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingsToBuy);

    startActivityForResult(intent, REQUEST_CODE_PAYMENT);
}