简体   繁体   中英

Paypal - post product to shopping cart from Java Servlet - how to?

I have a product page on my website and for each item there is an encrypted Paypal Add to Cart button. An example of the <form> from Paypal is below :

<form target="_self" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="encrypted" value="-----BEGIN PKCS7----------END PKCS7-----
">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_cart_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>

I want to add the onSubmit handler to the form so when a customer clicks the add to cart button they will be shown a form/questionnaire on the product page that they must fill out and submit before the item is added to the cart.

Upon a successful submission of the form, of which is processed by my Java Servlet, can I put some sort of code in the Servlet to add the item to the cart? A direct post to Paypal? Otherwise, the only way I see getting the item into the cart is by requesting that the customer click on the Add to Cart button again.

The flow of my concept would like this -

Product page >

Add to Cart button clicked (onSubmit handler in paypal form code) >

div with my form, not paypal, has fields for user to fill out, this form isshown on the page >

user fills in my form and submits >

servlet processes form field information >

form successfully filled out and processed >

at this point I need to add the item to the cart and send the user back to the Products page.

I am assuming you are sending user email id with custom attribute ..

up on successfull submission .In do post of your servlet

String emailId = req.getParameter("custom");

here the magic code you want

    if (emailId != null && transactionID != null) {
            if (!(paymentStatus.equals("Completed")
                    || paymentStatus.equals("Processed") || paymentStatus
                        .equals("Pending"))) {
                log.info("Paypal not completed.");
                sendInfo("Your process is not completed", req, resp);
            } else {
                if (transactionType.equals("subscr_cancel")) {
                    removeClientSubscription(emailId);  //This will hit my DB to update user
                } else {
                    log.info("Payment completed with Status - "
                            + paymentStatus);
                    upgradeClient(params, emailId);//this line hit my DB to update user
                }
            }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM