简体   繁体   中英

Paypal integration with a DIY shopping cart

Can some one PLEASE give a simple woking example of paypal integration with a DIY shopping cart that bloody well works.

I have implemented my own shopping cart and sinmply want to pass a total cost to paypal and direct the user there for payment.

This package ( https://github.com/drewjoh/phpPayPal ) seems to fit my requirements:

1) It involves using a simple php include statement to incorporate it - no Composer or any other irritating baggage that I also have to figure out.

2) PHP impementation.

3) Simple class and function calls.

Only problem is that it doesn't bloody well work!

I get this from paypal sandbox:

Not Found

The requested URL \\cgi-bin\\ppapi was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

Apache Server at api-3t.sandbox.paypal.com Port 443

This is my code. How do I make it bloody well work?

Some body really needs to write a comprehensive step by step tutorial on how to use paypal API etc with real working exmples in specific each specific scripting language, and not just useless paypal variable defintiions. The Paypal developer pages are utterley useless - confusing, no concrete examples and scattered all over the place.

<?php
        header('Content-Type: text/html; charset=utf8');
        session_start();
        require_once "phpPayPal.php";
/*
        echo "<pre>";
        print_r($_POST);
        echo "</pre><br><br>";
*/        
        function doPaypalExpressCheckout()
        {
            // Create instance of the phpPayPal class
            $paypal = new phpPayPal(true);

            // Set the amount total for this order.
            $paypal->amount_total = '50.49';
/*        
            $paypal->email = $_SESSION["Email"];
            $paypal->first_name = $_SESSION["GivenName"];
            $paypal->middle_name = $_SESSION["MiddleName"];
            $paypal->last_name = $_SESSION["Surname"];
            $paypal->suffix = "";
            $paypal->address1 = $_SESSION["Address"];
            $paypal->address2 = "";
            $paypal->city = $_SESSION["Suburb"];
            $paypal->state = $_SESSION["State"];
            $paypal->postal_code = $_SESSION["Postcode"];
            $paypal->phone_number = $_SESSION["Phone"]." / ".$_SESSION["Mobile"];

            $paypal->country_code = get_country_code($_SESSION["UserCountry"]);
            $paypal->currency_code = get_currency_code($_SESSION["UserCountry"]);
*/    
            // Make the request
            $paypal->set_express_checkout();

            // If successful, we need to store the token, and then redirect the user to PayPal
            if (!$paypal->_error)
            {
                // Store your token
                $_SESSION['token'] = $paypal->token;

                // Now go to PayPal
                $paypal->set_express_checkout_successful_redirect();
            }
/*
            for ($nI = 0; $nI < count($_SESSION["arrayShoppingCart"]); $nI++)
            {
                //**********************************************************************
                //  array("CategoryIndex"=>$nCategoryIndex,
                //          "ItemIndex"=>$nItemIndex,
                //        "Description"=>$arrayItems[$nItemIndex]["Description"],
                //        "Quantity"=>intval($nQuantity),
                //        "Price"=>floatval($arrayItems[$nItemIndex]["Price"]),
                //        "Volume"=>floatval($arrayItems[$nItemIndex]["Volume"]),
                //        "Postage"=>floatval($arrayItems[$nItemIndex]["Postage"]),
                //        "Options"=>$arrayOptions);
                //***********************************************************************                                                                                                    
                $arrayCartItem = $_SESSION["arrayShoppingCart"][$nI];
                $strCategory = $_SESSION["arrayCategories"][$arrayCartItem["CategoryIndex"]][0];
                $nInventoryIndex = $arrayCartItem["ItemIndex"];
                $arraInventoryItem = $_SESSION["arrayInventory"][$strCategory][$nInventoryIndex];
                $arrayItemCartOptions = $arrayCartItem["Options"];
            }
*/    
        }

        if (isset($_POST["Paypal"]))
        {
            doPaypalExpressCheckout();
        }

?>

Take a look at Opencart PayPal Standard implementation ( controller and view ).

It is very well done and simple to understand.

In controller ControllerPaymentPPStandard , method index it will create the paypal products form and redirect (submit form) to paypal. Then paypal will make a callback request on notify_url , method callback and depending on payment status you do various things.

I hope this helps.

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