private void checkout() {

    if ((isThirdParty && this.ppPaymentM != null) || this.ppPayment != null) {
      PayPal pp = PayPal.getInstance();

      Intent checkoutIntent;

      if (isThirdParty) {
        checkoutIntent =
            pp.checkout(
                this.ppPaymentM,
                cordova.getActivity().getApplicationContext(),
                new PayPalMPLResultDelegate());
      } else {
        checkoutIntent =
            pp.checkout(
                this.ppPayment,
                cordova.getActivity().getApplicationContext(),
                new PayPalMPLResultDelegate());
      }

      cordova.getActivity().startActivityForResult(checkoutIntent, REQUEST_PAYPAL_CHECKOUT);
    } else {
      Log.d(LOGTAG, "payment info not set, call setPaymentInfo first.");
    }
  }
 public void initLibrary() {
   PayPal pp = PayPal.getInstance();
   if (pp == null) {
     pp = PayPal.initWithAppID(getActivity(), Util.sand_box_id, PayPal.ENV_SANDBOX);
     pp.setLanguage("en_US");
   }
 }
Esempio n. 3
0
 // Get PayPal library initialization status
 public String getStatus() {
   PayPal pp = PayPal.getInstance();
   Log.i("mpl", "getStatus: after instance");
   if (pp == null) return "0";
   if (pp.isLibraryInitialized()) {
     Log.i("mpl", "getStatus: after instance1");
     return "1";
   } else return "0";
 }
  public void PayPalButtonClick(String primary_id) {
    PayPalPayment payment = new PayPalPayment();
    // Set the currency type
    payment.setCurrencyType("USD");
    // Set the recipient for the payment (can be a phone number)
    payment.setRecipient(primary_id);
    amount = AmountDonating.getText().toString();
    fname = firstName.getText().toString();
    lname = lastName.getText().toString();
    emailid = email.getText().toString();
    phone = phoneNo.getText().toString();

    if (amount.equals("")
        || fname.equals("")
        || lname.equals("")
        || emailid.equals("")
        || phone.equals("")) {
      Toast.makeText(getActivity(), "Required Fields", Toast.LENGTH_LONG).show();
      Intent intent = getActivity().getIntent();
      getActivity().setIntent(intent);
    } else {
      // Set the payment amount, excluding tax and shipping costs
      payment.setSubtotal(new BigDecimal(amount));

      Intent paypalIntent = PayPal.getInstance().checkout(payment, getActivity());
      this.startActivityForResult(paypalIntent, PAYPAL_RESPONSE);
    }
  }
  private boolean executeGetStatus(JSONArray inputs, CallbackContext callbackContext) {
    String status = "0";
    PayPal pp = PayPal.getInstance();
    Log.i("mpl", "getStatus: after instance");
    if ((pp != null) && pp.isLibraryInitialized()) {
      status = "1";
    }

    JSONObject json = new JSONObject();
    try {
      json.put("str", status);
    } catch (JSONException e) {
    }
    callbackContext.sendPluginResult(new PluginResult(Status.OK, json));
    return true;
  }
  private boolean executeInitWithAppID(JSONArray inputs, CallbackContext callbackContext) {
    JSONObject args;

    // Get the input data.
    String strEnv = "ENV_NONE";
    try {
      args = inputs.getJSONObject(0);
      this.appId = args.getString("appId");
      strEnv = args.getString("appEnv");
    } catch (JSONException exception) {
      Log.w(LOGTAG, String.format("Got JSON Exception: %s", exception.getMessage()));
      callbackContext.sendPluginResult(new PluginResult(Status.JSON_EXCEPTION));
      return true;
    }

    if (strEnv.equals("ENV_LIVE")) {
      this.appEnv = PayPal.ENV_LIVE;
    } else if (strEnv.equals("ENV_SANDBOX")) {
      this.appEnv = PayPal.ENV_SANDBOX;
    } else {
      this.appEnv = PayPal.ENV_NONE;
    }

    Log.d(LOGTAG, "init paypal for " + this.appId + " with " + strEnv);

    PayPal.initWithAppID(cordova.getActivity(), this.appId, this.appEnv);
    callbackContext.sendPluginResult(new PluginResult(Status.OK));

    return true;
  }
Esempio n. 7
0
 public void preapproval() {
   PayPalPreapproval preapproval = new PayPalPreapproval();
   preapproval.setCurrencyType("USD");
   preapproval.setMerchantName("Preapproval Merchant");
   Intent preapproveIntent =
       PayPal.getInstance().preapprove(preapproval, mpl_context, new ResultDelegate());
   mpl_activity.startActivityForResult(preapproveIntent, 1);
 }
Esempio n. 8
0
  /**
   * The initLibrary function takes care of all the basic Library initialization.
   *
   * @return The return will be true if the initialization was successful and false if
   */
  private void initLibrary() {
    Log.i("mpl", "initLibrary");
    PayPal pp = PayPal.getInstance();

    // If the library is already initialized, then we don't need to
    // initialize it again.
    if (pp == null) {
      // This is the main initialization call that takes in your Context,
      // the Application ID, and the server you would like to connect to.
      try {
        pp = PayPal.initWithAppID(mpl_context, appID, server);
      } catch (IllegalStateException e) {
        throw new RuntimeException(e);
      }

      // -- These are required settings.
      if (mpjs_language.equals("")) pp.setLanguage("en_US"); // Sets the language for the library.
      else pp.setLanguage(mpjs_language); // Sets the language for the
      // library.

      // Set to true if the transaction will require shipping.
      if (mpjs_shipping.equals("1")) pp.setShippingEnabled(true);
      else pp.setShippingEnabled(false);

      // Dynamic Amount Calculation allows you to set tax and shipping
      // amounts based on the user's shipping address. Shipping must be
      // enabled for Dynamic Amount Calculation. This also requires you to
      // create a class that implements PaymentAdjuster and Serializable.
      // pp.setDynamicAmountCalculationEnabled(false);
      // --
    }
  }
  private void showPayPalButton() {

    // Generate the PayPal checkout button and save it for later use
    PayPal pp = PayPal.getInstance();
    launchPayPalButton = pp.getCheckoutButton(this, PayPal.BUTTON_278x43, CheckoutButton.TEXT_PAY);

    // The OnClick listener for the checkout button
    launchPayPalButton.setOnClickListener(this);

    // Add the listener to the layout
    RelativeLayout.LayoutParams params =
        new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    params.bottomMargin = 10;
    launchPayPalButton.setLayoutParams(params);
    launchPayPalButton.setId(PAYPAL_BUTTON_ID);
    ((LinearLayout) findViewById(R.id.about_the_app)).addView(launchPayPalButton);
    ((LinearLayout) findViewById(R.id.about_the_app)).setGravity(Gravity.CENTER_HORIZONTAL);
  }
Esempio n. 10
0
  // Submit payment (i.e. "checkout")
  public void pay(Integer btype) {
    PayPalPayment payment;

    PayPal pp = PayPal.getInstance();
    if (pp == null) return;

    // mpjs_buttonType;

    // TBD: payment type: simple, parallel, chained
    payment = getSimplePayment();

    // Intent checkoutIntent = PayPal.getInstance().checkout(payment, this);
    Intent checkoutIntent = pp.checkout(payment, mpl_context, new ResultDelegate());

    // The next two lines should be exchanged for the following commented
    // line when PhoneGap is not used
    DroidGap dgActivity = (DroidGap) mpl_activity;
    dgActivity.startActivityForResult(PayPalPlugin.thisPlugin, checkoutIntent, 1);
    // mpl_activity.startActivityForResult(checkoutIntent, 1);
  }
Esempio n. 11
0
  private void showPayPalButton(View v) {

    // Generate the PayPal checkout button and save it for later use
    PayPal pp = PayPal.getInstance();
    launchPayPalButton =
        pp.getCheckoutButton(this.getContext(), PayPal.BUTTON_278x43, CheckoutButton.TEXT_PAY);

    // The OnClick listener for the checkout button
    launchPayPalButton.setOnClickListener(this);

    // Add the listener to the layout
    RelativeLayout.LayoutParams params =
        new RelativeLayout.LayoutParams(
            RecyclerView.LayoutParams.WRAP_CONTENT, RecyclerView.LayoutParams.WRAP_CONTENT);
    params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    params.bottomMargin = 10;
    launchPayPalButton.setLayoutParams(params);
    launchPayPalButton.setId(launchPayPalButton.getId());
    ((RelativeLayout) v.findViewById(R.id.payment_layout)).addView(launchPayPalButton);
    ((RelativeLayout) v.findViewById(R.id.payment_layout)).setGravity(Gravity.CENTER_HORIZONTAL);
  }
Esempio n. 12
0
  public void initLibrary() {
    PayPal pp = PayPal.getInstance();

    if (pp == null) { // Test to see if the library is already initialized

      // This main initialization call takes your Context, AppID, and target server
      pp =
          PayPal.initWithAppID(
              this,
              "AZ2HgxDaSTTKy6ALdkinZ4GoOiwOgu9YlR3TDhcxiTU3XrDQLMRfbRvwAOLK",
              PayPal.ENV_LIVE);

      // Required settings:

      // Set the language for the library
      pp.setLanguage("en_US");

      // Some Optional settings:

      // Sets who pays any transaction fees. Possible values are:
      // FEEPAYER_SENDER, FEEPAYER_PRIMARYRECEIVER, FEEPAYER_EACHRECEIVER, and
      // FEEPAYER_SECONDARYONLY
      pp.setFeesPayer(PayPal.FEEPAYER_EACHRECEIVER);

      // true = transaction requires shipping
      pp.setShippingEnabled(true);

      _paypalLibraryInit = true;
    }
  }
Esempio n. 13
0
  public void initLibrary() {
    PayPal pp = PayPal.getInstance();

    if (pp == null) { // Test to see if the library is already initialized

      // This main initialization call takes your Context, AppID, and target server
      pp = PayPal.initWithAppID(getContext(), "APP-80W284485P519543T", PayPal.ENV_NONE);

      // Required settings:

      // Set the language for the library
      pp.setLanguage("en_US");

      // Some Optional settings:

      // Sets who pays any transaction fees. Possible values are:
      // FEEPAYER_SENDER, FEEPAYER_PRIMARYRECEIVER, FEEPAYER_EACHRECEIVER, and
      // FEEPAYER_SECONDARYONLY
      pp.setFeesPayer(PayPal.FEEPAYER_EACHRECEIVER);

      // true = transaction requires shipping
      pp.setShippingEnabled(true);

      _paypalLibraryInit = true;
    }
  }
Esempio n. 14
0
  public void PayPalButtonClick(View arg0) {
    dialog.hide();
    // Create a basic PayPal payment
    PayPalPayment payment = new PayPalPayment();

    // Set the currency type
    payment.setCurrencyType("USD");

    // Set the recipient for the payment (can be a phone number)
    payment.setRecipient("*****@*****.**");

    // Set the payment amount, excluding tax and shipping costs
    payment.setSubtotal(new BigDecimal(cost.getAmount()));

    // Set the payment type--his can be PAYMENT_TYPE_GOODS,
    // PAYMENT_TYPE_SERVICE, PAYMENT_TYPE_PERSONAL, or PAYMENT_TYPE_NONE
    payment.setPaymentType(PayPal.PAYMENT_TYPE_GOODS);

    // PayPalInvoiceData can contain tax and shipping amounts, and an
    // ArrayList of PayPalInvoiceItem that you can fill out.
    // These are not required for any transaction.
    PayPalInvoiceData invoice = new PayPalInvoiceData();
    // Set the tax amount
    invoice.setTax(new BigDecimal(0));
    PayPalInvoiceItem item = new PayPalInvoiceItem();
    item.setID("1");
    item.setName(cost.getCategory().getName());
    item.setTotalPrice(new BigDecimal(cost.getAmount()));
    item.setQuantity(1);
    ArrayList<PayPalInvoiceItem> items = new ArrayList<>();
    items.add(item);
    invoice.setInvoiceItems(items);
    payment.setMerchantName("House Share");
    payment.setInvoiceData(invoice);

    Intent checkoutIntent = PayPal.getInstance().checkout(payment, this.getContext());
    startActivityForResult(checkoutIntent, REQUEST_PAYPAL_CHECKOUT);
  }
  private boolean executeSetPaymentInfo(JSONArray inputs, CallbackContext callbackContext) {
    JSONObject args = null;

    String strType = "TYPE_GOODS";
    String currencyType = "", strLang = "en_US";
    int nButton = PayPal.BUTTON_152x33;
    boolean bHideButton = false;

    this.isThirdParty = false;

    try {
      args = inputs.getJSONObject(0);
      isThirdParty = args.getBoolean("isThirdParty");
      strLang = args.getString("lang");
      strType = args.getString("paymentType");
      nButton = args.getInt("showPayPalButton");

      if (nButton < PayPal.BUTTON_152x33 || nButton > PayPal.BUTTON_294x45) {
        nButton = PayPal.BUTTON_152x33;
        bHideButton = true;
      }
      currencyType = args.getString("paymentCurrency");

      if (isThirdParty) {
        this.ppPaymentM = new PayPalAdvancedPayment();

        JSONArray array = args.getJSONArray("receivers");
        for (int i = 0; i < array.length(); i++) {

          JSONObject item = array.getJSONObject(i);
          PayPalReceiverDetails receiver = new PayPalReceiverDetails();

          receiver.setRecipient(item.getString("recipient"));

          BigDecimal amt = new BigDecimal(args.getString("subTotal"));
          amt.round(new MathContext(2, RoundingMode.HALF_UP));
          receiver.setSubtotal(amt);

          receiver.setIsPrimary(item.getBoolean("isPrimary"));
          int receiverPType;
          String rPType = item.getString("paymentType");
          if (rPType.equals("TYPE_GOODS")) {
            receiverPType = PayPal.PAYMENT_TYPE_GOODS;
          } else if (rPType.equals("TYPE_SERVICE")) {
            receiverPType = PayPal.PAYMENT_TYPE_SERVICE;
          } else if (rPType.equals("TYPE_PERSONAL")) {
            receiverPType = PayPal.PAYMENT_TYPE_PERSONAL;
          } else {
            receiverPType = PayPal.PAYMENT_TYPE_NONE;
          }
          receiver.setPaymentType(receiverPType);

          this.ppPaymentM.getReceivers().add(receiver);
        }

        this.ppPaymentM.setCurrencyType(currencyType);
        this.ppPaymentM.setMerchantName(args.getString("merchantName"));

      } else {
        this.ppPayment = new PayPalPayment();
        this.ppPayment.setPaymentType(this.pType);

        this.ppPayment.setCurrencyType(currencyType);
        this.ppPayment.setRecipient(args.getString("recipient"));

        this.ppPayment.setMerchantName(args.getString("merchantName"));
        BigDecimal amount = new BigDecimal(args.getString("subTotal"));
        amount.round(new MathContext(2, RoundingMode.HALF_UP));
        this.ppPayment.setSubtotal(amount);

        if (strType.equals("TYPE_GOODS")) {
          this.pType = PayPal.PAYMENT_TYPE_GOODS;
        } else if (strType.equals("TYPE_SERVICE")) {
          this.pType = PayPal.PAYMENT_TYPE_SERVICE;
        } else if (strType.equals("TYPE_PERSONAL")) {
          this.pType = PayPal.PAYMENT_TYPE_PERSONAL;
        } else {
          this.pType = PayPal.PAYMENT_TYPE_NONE;
        }
      }

    } catch (JSONException e) {
      Log.d(LOGTAG, "Got JSON Exception " + e.getMessage());
      callbackContext.sendPluginResult(new PluginResult(Status.JSON_EXCEPTION));
      return true;
    }

    PayPal pp = PayPal.getInstance();
    pp.setLanguage(strLang);
    pp.setShippingEnabled(false);
    pp.setFeesPayer(PayPal.FEEPAYER_EACHRECEIVER);
    pp.setDynamicAmountCalculationEnabled(false);

    if (this.ppButton != null) {
      webView.removeView(this.ppButton);
      this.ppButton = null;
    }

    // Back in the UI thread -- show the "Pay with PayPal" button
    // Generate the PayPal Checkout button and save it for later use
    this.ppButton =
        pp.getCheckoutButton(this.cordova.getActivity(), nButton, CheckoutButton.TEXT_PAY);

    // You'll need to have an OnClickListener for the CheckoutButton.
    this.ppButton.setOnClickListener(this);
    this.ppButton.setId(PAYPAL_BUTTON_ID);
    webView.addView(this.ppButton);
    this.ppButton.setVisibility(bHideButton ? View.INVISIBLE : View.VISIBLE);

    callbackContext.sendPluginResult(new PluginResult(Status.OK));
    return true;
  }