doulan7166 2015-01-06 21:52
浏览 28

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

I have integrate the Paypal express checkout with PHP and tested in Sandbox mode... Its work fine and give me Success message and Transaction ID : 57332826CB040504R.

But when i implement the same code in WordPress plugin its always shows

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

Here is my code and followed by 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>';
        }

I have debug every thing since last 2 days but could not found what is wrong please help to complete it.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信小程序协议怎么写
    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看