Paypal Payment Gateway Integration using Java

Paypal Payment Gateway Integration using Java

In this Post We Will Explain About is Paypal Payment Gateway Integration using Java With Example and Demo.Welcome on – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to Accept PayPal with the Payments API using Java Example

In this post we will show you Best way to implement Integrate Paypal in Web Application using Java, hear for How to integrate Paypal Website Payment in Javawith Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

Integrate Paypal in Web Application using Java

Paypal is most and very popular payment gateway system available.Paypal provides all the currency exchange Rest API implementation step by step to simple integrate gateway to your ad web-application or website.We Are here using Java Based Restful API to integrate some account Paypal and payment will be simple made on our web-site.

In this laexample example we’re learn to cart total and some total_shiiping as HTML input, We can calculate them some as per your own.

We can download simple project with source code also at the all end of this tutorials.

Paypal is providing the developer guideline and url where we can test our local application.we will use the express checkout method for payment in this example.

paypal payment gateway integration in java source code

Step 1. Open the simple paypal developer link
Step 2. We need to make two different some email address , One for Merchant account and other for buyer account respectively.
Step 3. Simple push on Like as a“Sign Up Now” button.
Step 4. Enter the your some information to access the data sandbox environment.
Step 5. Simple push on “Agree and Submit” simple button.
Step 6. Now login with given like as a username/password.
Step 7. Simple push on “Test Account” link
Step 8. make a new test account and provide the some Informations in textfields also.
Step 9. choose the “Account Type” as we want either “Merchant” or “buyer”
Step 10.It will created the default some email id for us.
Step 11.simple data set Credit card data information as “NONE” .
Step 12.Set the some balance amount for your any account.

Also Read :  Bitcoin Altcoin Ethereum Cryptocurrency Exchange Script


<project xmlns="" xmlns:xsi="" xsi:schemaLocation="">
  <name>livePaypal_example Maven Webapp</name>
<!--Devloped By Servlet and JSP API Jars -->
<!--Devloped By JSTL Jars -->

Paypal API Credentials

We simple need to create a devloper app under developer account using simple paypal web-site and simple client id and secret need to Put in

Step 1 : Client ID
Step 2 : Client Secret


Here We have larning HTML inputs simple cart total as well as total_shiiping. We can calculate them as some own way.

Also Read :  Create RESTful API using PHP

<h2>Step by setpPaypal Payment Example by</h2>
<form action="http://localhost:8080/livePaypal_example/LiveDirectPay" method="post">
<td>Live Cart Sub Total</td>
<td><input type="text" name="total_Cart"></td>
<td>Total Shipping</td>
<td><input type="text" name="total_shiiping"></td>
<td><input type="submit" value="Submit"></td>

This simple class simple defines the functions for paypal payment integrate processing.

package com.liveJavaPaypal.livePaypal_example;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.paypal.api.payments.Amount;
import com.paypal.api.payments.Details;
import com.paypal.api.payments.Links;
import com.paypal.api.payments.Payer;
import com.paypal.api.payments.Payment;
import com.paypal.api.payments.PaymentExecution;
import com.paypal.api.payments.RedirectUrls;
import com.paypal.api.payments.Transaction;
public class LiveServicePayment {
    private APIContext apiContext;
    public LiveServicePayment(String clientId,String clientSecret,String mode) {
        apiContext = new APIContext(clientId, clientSecret, mode);  
    public void proecssPayment(HttpServletRequest request,HttpServletResponse response) {
        //Devloped By Set payer details
        Payer payer = new Payer();
        //Devloped By Set redirect URLs
        RedirectUrls redirectUrls = new RedirectUrls();
        //Devloped By Set payment details
        double total_shiiping = Double.parseDouble(request.getParameter("total_shiiping"));
        double total_Cart = Double.parseDouble(request.getParameter("total_Cart"));
        double tax  = (total_Cart*14)/100;
        Details details = new Details();
        double total = total_Cart+total_shiiping+tax;
        //Devloped By Payment amount
        Amount amount = new Amount();
        //Devloped By Total must be equal to sum of total_shiiping, tax and subtotal.
        //Devloped By Transaction information
        Transaction transaction = new Transaction();
          .setDescription("This is the payment transaction description.");
        //Devloped By Add transaction to a list
        List<Transaction> live_tansactions = new ArrayList<Transaction>();
        //Devloped By Add payment details
        Payment payment = new Payment();
        //Devloped By Create payment
        try {
          Payment liveCreatedPay = payment.create(apiContext);

          Iterator<Links> links = liveCreatedPay.getLinks().iterator();
          while (links.hasNext()) {
            Links link =;
            if (link.getRel().equalsIgnoreCase("approval_url")) {
              // REDIRECT USER TO link.getHref()    
        } catch (PayPalRESTException e) {
        } catch (IOException e) {
    public void totalPaymentMethod(HttpServletRequest req) {
        Payment payment = new Payment();
        PaymentExecution paymentExecution = new PaymentExecution();
        try {
          Payment liveCreatedPay = payment.execute(apiContext, paymentExecution);
        } catch (PayPalRESTException e) {

This java servlet will process step by step the HTML form and create rest api call to the implementation paypal for further some package processing. The Paypal implementation API response shall be printed in cmd console. we can use them some accordingly as per your some need.

Also Read :  PHP Timestamp Date Time format Function

package com.liveJavaPaypal.livePaypal_example;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class PaypalServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //Devloped By TODO Auto-generated method stub
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        LiveServicePayment livepaypal_Service;
        if (request.getParameter("PayerID") != null) {
            livepaypal_Service = new LiveServicePayment("live_YOUR_CLIENT_ID","live_YOUR_CLIENT_SECRET","sandbox");
        } else {
            livepaypal_Service = new LiveServicePayment("live_YOUR_CLIENT_ID","live_YOUR_CLIENT_SECRET","sandbox");


I hope you have Got What is paypal payment gateway integration in java source code And how it works.I would Like to have FeadBack From My Blog( readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article( Are Most Always Welcome.

Recommended For You.

frontaccounting Customization create module form Components
frontaccounting Customization create module form Components In this Post We Will Explain About is frontaccounting Customization create module form Components With