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);
    }
  }
Ejemplo n.º 2
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);
  }
Ejemplo n.º 3
0
  // Helper for: Submit payment
  private PayPalPayment getSimplePayment() {
    int ptype = PayPal.PAYMENT_TYPE_GOODS;
    PayPalPayment payment = new PayPalPayment();
    payment.setSubtotal(new BigDecimal(mpjs_subtotal));
    payment.setCurrencyType(mpjs_currency);
    payment.setRecipient(mpjs_recipient);
    if (mpjs_paymentType.equals("goods")) ptype = PayPal.PAYMENT_TYPE_GOODS;
    else if (mpjs_paymentType.equals("service")) ptype = PayPal.PAYMENT_TYPE_SERVICE;
    else if (mpjs_paymentType.equals("personal")) ptype = PayPal.PAYMENT_TYPE_PERSONAL;
    else if (mpjs_paymentType.equals("none")) ptype = PayPal.PAYMENT_TYPE_NONE;
    payment.setPaymentType(ptype);

    if (!mpjs_tax.equals("") || !mpjs_shipping.equals("")) {
      // PayPalInvoiceData can contain tax and shipping amounts. It also
      // contains an ArrayList of PayPalInvoiceItem which can
      // be filled out. These are not required for any transaction.
      PayPalInvoiceData invoice = new PayPalInvoiceData();
      // Sets the tax amount.
      invoice.setTax(new BigDecimal(mpjs_tax));
      // Sets the shipping amount.
      invoice.setShipping(new BigDecimal(mpjs_shipping));

      // PayPalInvoiceItem has several parameters available to it.
      // None of these parameters is required.
      PayPalInvoiceItem item1 = new PayPalInvoiceItem();
      // Sets the name of the item.
      item1.setName(mpjs_name);
      // Sets the ID. This is any ID that you would like to have
      // associated with the item.
      item1.setID(mpjs_id);
      // Sets the total price which should be (quantity * unit price).
      // The total prices of all PayPalInvoiceItem should add up
      // to less than or equal the subtotal of the payment.
      item1.setTotalPrice(new BigDecimal(mpjs_totalPrice));
      // Sets the unit price.
      item1.setUnitPrice(new BigDecimal(mpjs_unitPrice));
      // Sets the quantity.
      item1.setQuantity(Integer.parseInt(mpjs_quantity));
      // Add the PayPalInvoiceItem to the PayPalInvoiceData.
      // Alternatively, you can create an ArrayList<PayPalInvoiceItem>
      // and pass it to the PayPalInvoiceData function
      // setInvoiceItems().
      invoice.getInvoiceItems().add(item1);

      // Sets the PayPalPayment invoice data.
      payment.setInvoiceData(invoice);
    }

    if (mpjs_merchantName.equals("")
        || mpjs_description.equals("")
        || mpjs_customID.equals("")
        || mpjs_ipnUrl.equals("")
        || mpjs_memo.equals("")) {;
    } else {
      // Sets the merchant name. This is the name of your Application or
      // Company.
      payment.setMerchantName(mpjs_merchantName);
      // Sets the description of the payment.
      payment.setDescription(mpjs_description);
      // Sets the Custom ID. This is any ID that you would like to have
      // associated with the payment.
      payment.setCustomID(mpjs_customID);
      // Sets the Instant Payment Notification url. This url will be hit
      // by the PayPal server upon completion of the payment.
      payment.setIpnUrl(mpjs_ipnUrl);
      // Sets the memo. This memo will be part of the notification sent by
      // PayPal to the necessary parties.
      payment.setMemo(mpjs_memo);
    }

    return payment;
  }