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