dongmei8071 2014-12-24 09:10
浏览 130

从paypal沙箱到真正的“直播支付”

HÍ have this code that are currently sending the payer to the sandbox test account. But I need it to send the payer the real live paypal.com

Do someone know how to make it to the real payment.? I have tried to delete the "sandbox" (empty) and also inserted "live".

Paypal are giving me this error: This transaction has expired. Please return to the recipient's website to complete your transaction using their regular checkout flow.

Here are the code:

<?php
        include_once("paypal.class.php");
        //$dbPayer = new Payer();
        $paypalmode = ($PayPalMode=='sandbox') ? '.sandbox' : '';

        if($_POST) //Post Data received from product list page.
        {

            $ItemName       = $_POST["itemname"]; //Item Name
            $ItemPrice      = $_POST["itemprice"]; //Item Price
            $ItemNumber     = $_POST["itemnumber"]; //Item Number
            $ItemDesc       = $_POST["itemdesc"]; //Item Number
            $ItemQty        = $_POST["itemQty"]; // Item Quantity
            $ItemTotalPrice = ($ItemPrice*$ItemQty); //(Item Price x Quantity = Total) Get total amount of product;

            //Other important variables like tax, shipping cost
            /*$TotalTaxAmount   = 2.58;  //Sum of tax for all items in this order.
            $HandalingCost      = 2.00;  //Handling cost for this order.
            $InsuranceCost      = 1.00;  //shipping insurance cost for this order.
            $ShippinDiscount    = -3.00; //Shipping discount for this order. Specify this as negative number.
            $ShippinCost        = 3.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);
            //if(isset($_POST['ischecked']) and $_POST['ischecked'] == 'on')
            $ShippinCost = $_POST['frightprice'];
            //else
              //  $ShippinCost = 0;
            $GrandTotal = ($ItemTotalPrice + $ShippinCost);
            $customs = $_POST['Name'].'|'.$_POST['Email'].'|'.$_POST['Phone'].'|'.$_POST['address'].'|'.$ItemName.'|'.$ItemPrice.'|'.$ItemNumber.'|'.$ItemQty.'|'.$ShippinCost.'|'.$ItemTotalPrice.'|'.$GrandTotal;
            //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=0'. //set 1 to hide buyer's shipping address, in-case products that does not require shipping

                '&PAYMENTREQUEST_0_ITEMAMT='.urlencode($ItemTotalPrice).
                '&PAYMENTREQUEST_0_SHIPPINGAMT='.urlencode($ShippinCost).
                '&PAYMENTREQUEST_0_AMT='.urlencode($GrandTotal).
                '&PAYMENTREQUEST_0_CURRENCYCODE='.urlencode($PayPalCurrencyCode).
                '&PAYMENTREQUEST_0_ADDRESSNORMALIZATIONSTATUS ='.urlencode($customs).
                '&LOCALECODE=da_DK'. //PayPal pages to match the language on your website.
                '&LOGOIMG=http://au-aktioner.com/images/7.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['ShippinCost']        =   $ShippinCost;
            $_SESSION['GrandTotal']         =   $GrandTotal;
            $_SESSION['customs'] = $customs;


            //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>';
            }

        }

        //Paypal redirects back to this page using ReturnURL, We should receive TOKEN and Payer ID
        if(isset($_GET["token"]) && isset($_GET["PayerID"]))
        {
            //we will be using these two variables to execute the "DoExpressCheckoutPayment"
            //Note: we haven't received any payment yet.

            $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.*/
            $ShippinCost        = $_SESSION['ShippinCost'];
            $GrandTotal         = $_SESSION['GrandTotal'];
            $customs        = $_SESSION['customs'];

            $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_SHIPPINGAMT='.urlencode($ShippinCost).
                '&PAYMENTREQUEST_0_ADDRESSNORMALIZATIONSTATUS ='.urlencode($customs).
                '&PAYMENTREQUEST_0_AMT='.urlencode($GrandTotal).

                '&PAYMENTREQUEST_0_CURRENCYCODE='.urlencode($PayPalCurrencyCode);

            //We need to execute the "DoExpressCheckoutPayment" at this point to Receive payment from user.
            $paypal= new MyPayPal();
            $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>';
                $_SESSION['payer_id'] = urldecode($httpParsedResponseAr["PAYMENTINFO_0_TRANSACTIONID"]);
                echo 'Your Transaction ID : '.urldecode($httpParsedResponseAr["PAYMENTINFO_0_TRANSACTIONID"]);

                /*
                //Sometimes Payment are kept pending even when transaction is complete.
                //hence we need to notify user about it and ask him manually approve the transiction
                */

                if('Completed' == $httpParsedResponseAr["PAYMENTINFO_0_PAYMENTSTATUS"])
                {
                    echo '<div style="color:green" >Betaling modtaget - Dine vare vil blive sendt til din adresse!</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"]))
                {

                    //echo '<br /><b>Stuff to store in database :</b><br /><pre>';
                    /*
                    #### SAVE BUYER INFORMATION IN DATABASE ###




                    */

                    $data = json_encode($httpParsedResponseAr);
                    $mysqli = new mysqli('au-aktioner.com.mysql','au_aktioner_com','','au_aktioner_com');
                   // $mysqli = new mysqli('localhost','root','','auctionsales');

                    //Output any connection error
                    if ($mysqli->connect_error) {
                        die('Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error);
                    }
                    $query = "INSERT INTO tblPayPal_Ipn_Details (ieverything_else) values ('$data')";
                    $insert_row = $mysqli->query($query);

                    if($insert_row){
                        print 'Success! ID of last inserted record is : ' .$mysqli->insert_id .'<br />';
                         header('location:confirmation.php');
                    }else{
                        die('Error : ('. $mysqli->errno .') '. $mysqli->error);
                    }


                }
                else
                {
                    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"><b>Error : </b>'.urldecode($httpParsedResponseAr["L_LONGMESSAGE0"]).'</div>';
                echo '<pre>';
                print_r($httpParsedResponseAr);
                echo '</pre>';
            }
        }
        ?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Oracle触发器记录修改前后的字段值
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 stm32开发clion时遇到的编译问题
    • ¥15 lna设计 源简并电感型共源放大器