Paypal快递结账不在wordpress插件中工作

时间:2015-01-06 21:52:28

标签: php wordpress paypal

我已将Paypal快速结账与PHP集成并在沙盒模式下测试...其工作正常并给我成功消息和交易ID:57332826CB040504R。

但是当我在WordPress插件中实现相同的代码时,它始终显示

Error : You do not have permissions to make this API call

这是我的代码,然后是this tutorial

if (session_status() == PHP_SESSION_NONE) { session_start(); } 
        $PayPalMode             = 'sandbox'; // sandbox or live
        $PayPalApiUsername      = 'pygy_1283buyer_api1.hotmail.com'; //PayPal API Username
        $PayPalApiPassword      = 'KYUN3ZA297SGL6YB'; //Paypal API password
        $PayPalApiSignature     = 'AFcWxV21C7fd0v3bYYYRCpSSRl31AwnBlZgLEUm0ZHz.hFqZsrlyifV4'; //Paypal API Signature
        $PayPalCurrencyCode     = 'USD'; //Paypal Currency Code
        $PayPalReturnURL        = 'http://localhost/paypal/process.php'; //Point to process.php page
        $PayPalCancelURL        = 'http://localhost/paypal/cancel_url.php'; 
        $ItemName       = 'Enable the live link'; //Item Name
        $ItemPrice      = '1.00'; //Item Price
        $ItemNumber     = '1000'; //Item Number
        $ItemDesc       = 'Buy and enable the live link'; //Item Number
        $ItemQty        = '1'; // Item Quantity
        $ItemTotalPrice = ($ItemPrice*$ItemQty); //(Item Price x Quantity = Total) Get total amount of product; 

        //Other important variables like tax, shipping cost
        $TotalTaxAmount     = 1.00;  //Sum of tax for all items in this order. 
        $HandalingCost      = 1.00;  //Handling cost for this order.
        $InsuranceCost      = 0.90;  //shipping insurance cost for this order.
        $ShippinDiscount    = -1.00; //Shipping discount for this order. Specify this as negative number.
        $ShippinCost        = 2.00; //Although you may change the value later, try to pass in a shipping amount that is reasonably accurate.

        //Grand total including all tax, insurance, shipping cost and discount
        $GrandTotal = ($ItemTotalPrice + $TotalTaxAmount + $HandalingCost + $InsuranceCost + $ShippinCost + $ShippinDiscount);

    //Parameters for SetExpressCheckout, which will be sent to PayPal
    $padata =   '&METHOD=SetExpressCheckout'.
            '&RETURNURL='.urlencode($PayPalReturnURL ).
            '&CANCELURL='.urlencode($PayPalCancelURL).
            '&PAYMENTREQUEST_0_PAYMENTACTION='.urlencode("SALE").

            '&L_PAYMENTREQUEST_0_NAME0='.urlencode($ItemName).
            '&L_PAYMENTREQUEST_0_NUMBER0='.urlencode($ItemNumber).
            '&L_PAYMENTREQUEST_0_DESC0='.urlencode($ItemDesc).
            '&L_PAYMENTREQUEST_0_AMT0='.urlencode($ItemPrice).
            '&L_PAYMENTREQUEST_0_QTY0='. urlencode($ItemQty).

            '&NOSHIPPING=1'. //set 1 to hide buyer's shipping address, in-case products that does not require shipping

            '&PAYMENTREQUEST_0_ITEMAMT='.urlencode($ItemTotalPrice).
            '&PAYMENTREQUEST_0_TAXAMT='.urlencode($TotalTaxAmount).
            '&PAYMENTREQUEST_0_SHIPPINGAMT='.urlencode($ShippinCost).
            '&PAYMENTREQUEST_0_HANDLINGAMT='.urlencode($HandalingCost).
            '&PAYMENTREQUEST_0_SHIPDISCAMT='.urlencode($ShippinDiscount).
            '&PAYMENTREQUEST_0_INSURANCEAMT='.urlencode($InsuranceCost).
            '&PAYMENTREQUEST_0_AMT='.urlencode($GrandTotal).
            '&PAYMENTREQUEST_0_CURRENCYCODE='.urlencode('USD').
            '&LOCALECODE=GB'. //PayPal pages to match the language on your website.
            '&LOGOIMG=http://websolutionsoft.com/wp-content/uploads/2014/05/logo2-300x105.png'. //site logo
            '&CARTBORDERCOLOR=FFFFFF'. //border color of cart
            '&ALLOWNOTE=1';

            ############# set session variable we need later for "DoExpressCheckoutPayment" #######
            $_SESSION['ItemName']           =  $ItemName; //Item Name
            $_SESSION['ItemPrice']          =  $ItemPrice; //Item Price
            $_SESSION['ItemNumber']         =  $ItemNumber; //Item Number
            $_SESSION['ItemDesc']           =  $ItemDesc; //Item Number
            $_SESSION['ItemQty']            =  $ItemQty; // Item Quantity
            $_SESSION['ItemTotalPrice']     =  $ItemTotalPrice; //(Item Price x Quantity = Total) Get total amount of product; 
            $_SESSION['TotalTaxAmount']     =  $TotalTaxAmount;  //Sum of tax for all items in this order. 
            $_SESSION['HandalingCost']      =  $HandalingCost;  //Handling cost for this order.
            $_SESSION['InsuranceCost']      =  $InsuranceCost;  //shipping insurance cost for this order.
            $_SESSION['ShippinDiscount']    =  $ShippinDiscount; //Shipping discount for this order. Specify this as negative number.
            $_SESSION['ShippinCost']        =   $ShippinCost; //Although you may change the value later, try to pass in a shipping amount that is reasonably accurate.
            $_SESSION['GrandTotal']         =  $GrandTotal;


            //We need to execute the "SetExpressCheckOut" method to obtain paypal token
            $paypal= new MyPayPal();
            $httpParsedResponseAr = $paypal->PPHttpPost('SetExpressCheckout', $padata, $PayPalApiUsername, $PayPalApiPassword, $PayPalApiSignature, $PayPalMode);

            //Respond according to message we receive from Paypal
            if("SUCCESS" == strtoupper($httpParsedResponseAr["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($httpParsedResponseAr["ACK"]))
            {

                    //Redirect user to PayPal store with Token received.
                    $paypalurl ='https://www'.$paypalmode.'.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token='.$httpParsedResponseAr["TOKEN"].'';
                    header('Location: '.$paypalurl);

            }else{
                //Show error message
                echo '<div style="color:red"><b>Error :            </b>'.urldecode($httpParsedResponseAr["L_LONGMESSAGE0"]).'</div>';

                echo '<pre>';
                print_r($httpParsedResponseAr);
                echo '</pre>';
            }

    }
    if(isset($_GET["token"]) && isset($_GET["PayerID"]))
    {
        $token = $_GET["token"];
        $payer_id = $_GET["PayerID"];

        //get session variables
        $ItemName           = $_SESSION['ItemName']; //Item Name
        $ItemPrice          = $_SESSION['ItemPrice'] ; //Item Price
        $ItemNumber         = $_SESSION['ItemNumber']; //Item Number
        $ItemDesc           = $_SESSION['ItemDesc']; //Item Number
        $ItemQty            = $_SESSION['ItemQty']; // Item Quantity
        $ItemTotalPrice     = $_SESSION['ItemTotalPrice']; //(Item Price x Quantity = Total) Get total amount of product; 
        $TotalTaxAmount     = $_SESSION['TotalTaxAmount'] ;  //Sum of tax for all items in this order. 
        $HandalingCost      = $_SESSION['HandalingCost'];  //Handling cost for this order.
        $InsuranceCost      = $_SESSION['InsuranceCost'];  //shipping insurance cost for this order.
        $ShippinDiscount    = $_SESSION['ShippinDiscount']; //Shipping discount for this order. Specify this as negative number.
        $ShippinCost        = $_SESSION['ShippinCost']; //Although you may change the value later, try to pass in a shipping amount that is reasonably accurate.
        $GrandTotal         = $_SESSION['GrandTotal'];

        $padata =   '&TOKEN='.urlencode($token).
                    '&PAYERID='.urlencode($payer_id).
                    '&PAYMENTREQUEST_0_PAYMENTACTION='.urlencode("SALE").

                    //set item info here, otherwise we won't see product details later  
                    '&L_PAYMENTREQUEST_0_NAME0='.urlencode($ItemName).
                    '&L_PAYMENTREQUEST_0_NUMBER0='.urlencode($ItemNumber).
                    '&L_PAYMENTREQUEST_0_DESC0='.urlencode($ItemDesc).
                    '&L_PAYMENTREQUEST_0_AMT0='.urlencode($ItemPrice).
                    '&L_PAYMENTREQUEST_0_QTY0='. urlencode($ItemQty).

                    '&PAYMENTREQUEST_0_ITEMAMT='.urlencode($ItemTotalPrice).
                    '&PAYMENTREQUEST_0_TAXAMT='.urlencode($TotalTaxAmount).
                    '&PAYMENTREQUEST_0_SHIPPINGAMT='.urlencode($ShippinCost).
                    '&PAYMENTREQUEST_0_HANDLINGAMT='.urlencode($HandalingCost).
                    '&PAYMENTREQUEST_0_SHIPDISCAMT='.urlencode($ShippinDiscount).
                    '&PAYMENTREQUEST_0_INSURANCEAMT='.urlencode($InsuranceCost).
                    '&PAYMENTREQUEST_0_AMT='.urlencode($GrandTotal).
                    '&PAYMENTREQUEST_0_CURRENCYCODE='.urlencode('USD');

                        //We need to execute the "DoExpressCheckoutPayment" at this point to Receive payment from user.
                        $paypal= new MyPayPal();
                        print_r($padata);
                        $httpParsedResponseAr = $paypal->PPHttpPost('DoExpressCheckoutPayment', $padata, $PayPalApiUsername, $PayPalApiPassword, $PayPalApiSignature, $PayPalMode);

                //Check if everything went ok..
                if("SUCCESS" == strtoupper($httpParsedResponseAr["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($httpParsedResponseAr["ACK"])) 
                {

                    echo '<h2>Success</h2>';
                    echo 'Your Transaction ID : '.urldecode($httpParsedResponseAr["PAYMENTINFO_0_TRANSACTIONID"]);

                    if('Completed' == $httpParsedResponseAr["PAYMENTINFO_0_PAYMENTSTATUS"])
                    {
                        echo '<div style="color:green">Payment Received! Your product will be sent to you very soon!</div>';
                    }
                    elseif('Pending' == $httpParsedResponseAr["PAYMENTINFO_0_PAYMENTSTATUS"])
                    {
                        echo '<div style="color:red">Transaction Complete, but payment is still pending! '.
                        'You need to manually authorize this payment in your <a target="_new" href="http://www.paypal.com">Paypal Account</a></div>';
                    }

                    // we can retrive transection details using either GetTransactionDetails or GetExpressCheckoutDetails
                    // GetTransactionDetails requires a Transaction ID, and GetExpressCheckoutDetails requires Token returned by SetExpressCheckOut
                    $padata =   '&TOKEN='.urlencode($token);
                    $paypal= new MyPayPal();
                    $httpParsedResponseAr = $paypal->PPHttpPost('GetExpressCheckoutDetails', $padata, $PayPalApiUsername, $PayPalApiPassword, $PayPalApiSignature, $PayPalMode);

                    if("SUCCESS" == strtoupper($httpParsedResponseAr["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($httpParsedResponseAr["ACK"])) 
                    {


                        update_option('is_enable',1);

                        echo '<pre>';
                        print_r($httpParsedResponseAr);
                        echo '</pre>';

                    } else  {
                        update_option('is_enable',0);
                        echo '<div style="color:red"><b>GetTransactionDetails failed:</b>'.urldecode($httpParsedResponseAr["L_LONGMESSAGE0"]).'</div>';
                        echo '<pre>';
                        print_r($httpParsedResponseAr);
                        echo '</pre>';

                    }

        }else{

                echo '<div style="color:red">'.$payer_id.'<br/><b>Error : </b>'.urldecode($httpParsedResponseAr["L_LONGMESSAGE0"]).'</div>';
                echo '<pre>';
                print_r($httpParsedResponseAr);
                echo '</pre>';
        }

我已经调试过去2天以来的所有事情但是找不到有什么问题请帮助完成它。

0 个答案:

没有答案