Example #1
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;
  }