Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8564881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:17:49+00:00 2026-06-11T17:17:49+00:00

I followed https://www.paypal-labs.com/integrationwizard/ecpaypal/main.php to implement paypal sandbox account in my application. My code is

  • 0

I followed https://www.paypal-labs.com/integrationwizard/ecpaypal/main.php to implement paypal sandbox account in my application. My code is spanned in 3 jsp pages such as index.jsp -> expresscheckout.jsp -> paypalfunctions.jsp .

expresscheckout.jsp

<%@ include file="paypalfunctions.jsp"%>
<%
    String paymentAmount = "25";

    String currencyCodeType = "USD";
    String paymentType = "Sale";



    String returnURL = "http://2.appid.appspot.com/sucess.jsp";

    String cancelURL = "http://2.appid.appspot.com/canceled.jsp";


    HashMap nvp = CallShortcutExpressCheckout(paymentAmount,
            currencyCodeType, paymentType, returnURL, cancelURL,
            session);
    String strAck = nvp.get("ACK").toString();
    if (strAck != null && strAck.equalsIgnoreCase("Success")) {
        //' Redirect to paypal.com
        RedirectURL(nvp.get("TOKEN").toString(), response);
    } else {


        String ErrorCode = nvp.get("L_ERRORCODE0").toString();
        String ErrorShortMsg = nvp.get("L_SHORTMESSAGE0").toString();
        String ErrorLongMsg = nvp.get("L_LONGMESSAGE0").toString();
        String ErrorSeverityCode = nvp.get("L_SEVERITYCODE0")
                .toString();
    }
%>

paypalfunctions.jsp is follows :

<%

    gv_APIUserName  = "myid_78955666_biz_api1.gmail.com";
    gv_APIPassword  = "1347856389";
    gv_APISignature = "AFcWxV21C7fd0v3bYYYRCpSSRl31AuP4KrN6UABOJ1fGdNRYoIpc.qjr";

    //BN Code is only applicable for partners
    gv_BNCode       = "PP-ECWizard"; 

    boolean bSandbox = true;



    if (bSandbox == true)
    {
        gv_APIEndpoint = "https://api-3t.sandbox.paypal.com/nvp";
        PAYPAL_URL = "https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=";
    }
    else
    {
        gv_APIEndpoint = "https://api-3t.paypal.com/nvp";
        PAYPAL_URL = "https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=";
    } 

    String HTTPREQUEST_PROXYSETTING_SERVER = "";
    String HTTPREQUEST_PROXYSETTING_PORT = "";
    boolean USE_PROXY = false;

    gv_Version  = "2.3";

    //WinObjHttp Request proxy settings.
    gv_ProxyServer  = HTTPREQUEST_PROXYSETTING_SERVER;
    gv_ProxyServerPort = HTTPREQUEST_PROXYSETTING_PORT;
    gv_Proxy        = 2;    //'setting for proxy activation
    gv_UseProxy     = USE_PROXY;


%>

<%!

    String gv_APIEndpoint;
    String gv_APIUserName;
    String gv_APIPassword;
    String gv_APISignature;
    String gv_BNCode;

    String gv_Version;
    String gv_nvpHeader;
    String gv_ProxyServer;  
    String gv_ProxyServerPort; 
    int gv_Proxy;
    boolean gv_UseProxy;
    String PAYPAL_URL;

    public HashMap CallShortcutExpressCheckout( String paymentAmount, String currencyCodeType, String paymentType, 
                                                String returnURL, String cancelURL,
                                                HttpSession session)
    {

        session.setAttribute("paymentType", paymentType);
        session.setAttribute("currencyCodeType", currencyCodeType);
ored in $nvpstr
        */
        String nvpstr = "&Amt=25&PAYMENTACTION=" + paymentType + "&ReturnUrl=" + URLEncoder.encode( returnURL ) + "&CANCELURL=" + URLEncoder.encode( cancelURL ) + "&CURRENCYCODE=" + currencyCodeType;

        /* 
        Make the call to PayPal to get the Express Checkout token
        If the API call succeded, then redirect the buyer to PayPal
        to begin to authorize payment.  If an error occured, show the
        resulting errors
        */

        HashMap nvp = httpcall("SetExpressCheckout", nvpstr);
        String strAck = nvp.get("ACK").toString();
        session.setAttribute("nvpstr", nvpstr);
        session.setAttribute("strAck", strAck);
        if(strAck !=null && strAck.equalsIgnoreCase("Success"))
        {
            session.setAttribute("TOKEN", nvp.get("TOKEN").toString());
        }

        return nvp;
    }

    public HashMap CallMarkExpressCheckout( String paymentAmount, String currencyCodeType, String paymentType, String returnURL, 
                                String cancelURL, String shipToName, String shipToStreet, String shipToCity, String shipToState,
                                String shipToCountryCode, String shipToZip, String shipToStreet2, String phoneNum,
                                HttpSession session)
    {

        session.setAttribute("paymentType", paymentType);
        session.setAttribute("currencyCodeType", currencyCodeType);

        String nvpStr = "ADDROVERRIDE=1&Amt=" + paymentAmount + "&PAYMENTACTION=" + paymentType;
        nvpStr = nvpStr + "&CURRENCYCODE=" + currencyCodeType + "&ReturnUrl=" + URLEncoder.encode( returnURL ) + "&CANCELURL=" + URLEncoder.encode( cancelURL );
        nvpStr = nvpStr + "&SHIPTONAME=" + shipToName + "&SHIPTOSTREET=" + shipToStreet + "&SHIPTOSTREET2=" + shipToStreet2;
        nvpStr = nvpStr + "&SHIPTOCITY=" + shipToCity + "&SHIPTOSTATE=" + shipToState + "&SHIPTOCOUNTRYCODE=" + shipToCountryCode;
        nvpStr = nvpStr + "&SHIPTOZIP=" + shipToZip + "&PHONENUM" + phoneNum;


        HashMap nvp = httpcall("SetExpressCheckout", nvpStr);//made a change from original code
        String strAck = nvp.get("ACK").toString();
        if(strAck !=null && (strAck.equalsIgnoreCase("Success") || strAck.equalsIgnoreCase("SuccessWithWarning")))
        {
            session.setAttribute("TOKEN", nvp.get("TOKEN").toString());
        }           
        return nvp;
    }

    public HashMap GetShippingDetails( String token, HttpSession session)
    {


        String nvpstr= "&TOKEN=" + token;


        HashMap nvp = httpcall("GetExpressCheckoutDetails", nvpstr);
        String strAck = nvp.get("ACK").toString();
        if(strAck !=null && (strAck.equalsIgnoreCase("Success") || strAck.equalsIgnoreCase("SuccessWithWarning")))
        {
            session.setAttribute("PAYERID", nvp.get("PAYERID").toString());
        }           
        return nvp;
    }

    public HashMap ConfirmPayment( String finalPaymentAmount, HttpSession session, HttpServletRequest request)
    {

        String token            =  session.getAttribute("TOKEN").toString();
        String currencyCodeType =  session.getAttribute("currencyCodeType").toString();
        String paymentType      =  session.getAttribute("paymentType").toString();
        String payerID          =  session.getAttribute("PAYERID").toString();
        String serverName       =  request.getServerName();

        String nvpstr  = "&TOKEN=" + token + "&PAYERID=" + payerID + "&PAYMENTACTION=" + paymentType + "&AMT=" + finalPaymentAmount;
        nvpstr = nvpstr + "&CURRENCYCODE=" + currencyCodeType + "&IPADDRESS=" + serverName;

        HashMap nvp = httpcall("DoExpressCheckoutPayment", nvpstr);

        return nvp;
    }


    HashMap DirectPayment ( String paymentType, String paymentAmount,
                        String creditCardType, String creditCardNumber, String expDate, String cvv2,
                        String firstName, String lastName, String street, String city, String state, String zip, String countryCode,
                        String currencyCode, String IPAddress)
    {
        String nvpStr = "Amt=" + paymentAmount + "&PAYMENTACTION=" + paymentType;
        nvpStr += "&IPADDRESS=" + IPAddress;
        nvpStr += "&CREDITCARDTYPE=" + creditCardType + "&ACCT=" + creditCardNumber + "&EXPDATE=" + expDate + "&CVV2=" + cvv2;
        nvpStr += "&FIRSTNAME=" + firstName + "&LASTNAME=" + lastName + "&STREET=" + street + "&CITY=" + city + "&STATE=" + state + "&COUNTRYCODE=" + countryCode + "&ZIP=" + zip;
        nvpStr += "&CURRENCYCODE=" + currencyCode;

        return httpcall("DoDirectPayment", nvpStr);
    }

    public HashMap httpcall( String methodName, String nvpStr)
    {

        String version = "2.3";
        String agent = "Mozilla/4.0";
        String respText = "";
        HashMap nvp=null;


        String encodedData = "METHOD=" + methodName + "&VERSION=" + gv_Version + "&PWD=" + gv_APIPassword + "&USER=" + gv_APIUserName + "&SIGNATURE=" + gv_APISignature + nvpStr + "&BUTTONSOURCE=" + gv_BNCode;

        try 
        {
            URL postURL = new URL( gv_APIEndpoint );
            HttpURLConnection conn = (HttpURLConnection)postURL.openConnection();

            // Set connection parameters. We need to perform input and output, 
            // so set both as true. 
            conn.setDoInput (true);
            conn.setDoOutput (true);

            // Set the content type we are POSTing. We impersonate it as 
            // encoded form data 
            conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
            conn.setRequestProperty( "User-Agent", agent );

            //conn.setRequestProperty( "Content-Type", type );
            conn.setRequestProperty( "Content-Length", String.valueOf( encodedData.length()) );
            conn.setRequestMethod("POST");

            // get the output stream to POST to. 
            DataOutputStream output = new DataOutputStream( conn.getOutputStream());
            output.writeBytes( encodedData );
            output.flush();
            output.close ();

            // Read input from the input stream.
            DataInputStream  in = new DataInputStream (conn.getInputStream()); 
            int rc = conn.getResponseCode();
            if ( rc != -1)
            {
                BufferedReader is = new BufferedReader(new InputStreamReader( conn.getInputStream()));
                String _line = null;
                while(((_line = is.readLine()) !=null))
                {
                    respText = respText + _line;
                }           
                nvp = deformatNVP( respText );
            }
            return nvp;
        }
        catch( IOException e )
        {
            // handle the error here
            return null;
        }
    }

    public HashMap deformatNVP( String pPayload )
    {
        HashMap nvp = new HashMap(); 
        StringTokenizer stTok = new StringTokenizer( pPayload, "&");
        while (stTok.hasMoreTokens())
        {
            StringTokenizer stInternalTokenizer = new StringTokenizer( stTok.nextToken(), "=");
            if (stInternalTokenizer.countTokens() == 2)
            {
                String key = URLDecoder.decode( stInternalTokenizer.nextToken());
                String value = URLDecoder.decode( stInternalTokenizer.nextToken());
                nvp.put( key.toUpperCase(), value );
            }
        }
        return nvp;
    }

    public void RedirectURL( String token, HttpServletResponse response )
    {
        String payPalURL = PAYPAL_URL + token; 

        //response.sendRedirect( payPalURL );
        response.setStatus(302);
        response.setHeader( "Location", payPalURL );
        response.setHeader( "Connection", "close" );
    }       

%>

When i click on express checkout it redirect to https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=EC-9CY1483461514290L .
But in ‘Your order summary’ , there is not showing current purchase amount.
Also after login with my buyer account and confirm the address and payment, following error messages show in my success.jsp page:

TIMESTAMP:2012-09-18T06:07:32Z
CORRELATIONID:b4fe3695b410a
ACK:Failure
VERSION:84.0
BUILD:3622349
L_ERRORCODE0:10401
L_SHORTMESSAGE0:Transaction refused because of an invalid argument. See additional error messages for details.
L_LONGMESSAGE0:Order total is invalid.
L_SEVERITYCODE0:Error

But when i printed my name-value-pair(nvp), it contains the amount

NVPSTR===>&Amt=25&PAYMENTACTION=Sale&ReturnUrl=http%3A%2F%2F2.appid.appspot.com%2Fsucess.jsp&CANCELURL=http%3A%2F%2F2.appid.appspot.com%2Fcanceled.jsp&CURRENCYCODE=USD

Please solve or suggest a solution.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T17:17:50+00:00Added an answer on June 11, 2026 at 5:17 pm

    You have to submit the amount in your DoExpressCheckoutPayment API call as well as your SetExpressCheckout API call. Currently, you are not submitting the amount for both your SetEC and DoEC, only for your SetEC. (if you didn’t set it for SetEC you would never have gotten a token.)

    Your DoEC call should be pretty much the same as your SetEC call except you don’t need RETURNURL and CANCELURL.

    Also, the amount will not show under order summary unless you submit the line item details for your transaction:

    L_PAYMENTREQUEST_0_NAME0=Books 
    L_PAYMENTREQUEST_0_AMT0=154.00 
    L_PAYMENTREQUEST_0_NUMBER0=ABC123 
    L_PAYMENTREQUEST_0_QTY0=2 
    L_PAYMENTREQUEST_0_NAME1=CDs 
    L_PAYMENTREQUEST_0_AMT1=50.00 
    L_PAYMENTREQUEST_0_NUMBER1=BY-Z4736 
    L_PAYMENTREQUEST_0_QTY1=3 
    PAYMENTREQUEST_0_ITEMAMT=458.00 
    PAYMENTREQUEST_0_SHIPPINGAMT=20.00 
    PAYMENTREQUEST_0_TAXAMT=46.20 
    PAYMENTREQUEST_0_AMT=524.20 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im using a linux machine, and I followed the instructions seen on https://www.php.net/manual/en/install.php to
I followed this tutorial here: http://www.dannyherran.com/2011/02/facebook-php-sdk-and-codeigniter-for-basic-user-authentication/ It works great but when I enable CSRF
I have followed this tutorial: http://www.phpjabbers.com/how-to-make-a-php-calendar-php26-6.html#comments to make a very basic calendar. My aim
So I followed the instructions per this link http://www.opencart.com/index.php?route=documentation/documentation&path=32_35_60 but my paypal account is
I've followed this tutorial ( https://www.windowsazure.com/en-us/develop/nodejs/tutorials/create-a-website-(mac)/ ) to the letter but I'm not getting
I keep getting Server error The website encountered an error while retrieving https://www.website.com/update.php?FName=asdd&PHONE=4444444444 .
I followed the example http://www.dealtaker.com/blog/2010/02/25/kohana-php-3-0-ko3-tutorial-part-5/ I get the following error: ErrorException [ Notice ]:
I wanted a sticky footer to I followed this guide: http://www.cssstickyfooter.com/using-sticky-footer-code.html I have in
i followed the following tutorial: https://www.windowsazure.com/en-us/develop/nodejs/tutorials/website-with-mongodb-(mac)/ and executed app.js just as the tutorial said
So I've followed the instructions in all the other questions. I did this: https://www.facebook.com/dialog/pagetab?app_id=YOUR_APP_ID&next=YOUR_URL

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.