2014-02-22 1 views
0

개인 웹 사이트에서 첫 번째 PayPal 익스프레스 체크를 학습 목적으로 사용하고 있으며 Express 체크 아웃이 어떻게 구축되었는지 설명하는 온라인 튜토리얼을 발견했습니다. 이 자습서에서 사용할 수있는 샘플 페이지를 사용하여 더 나은 이해를 얻으 려하지만 오류 : PaymentAction : Required 매개 변수가 누락되어 문제를 추적하지 못하는 것 같습니다.PaymentAction Error 받기

그래서 PaymentAction 매개 변수를 보내야하고 판매로 보내야한다는 것을 이해합니다. 나는 왜 내가 그것을 보내지 않는다고 말하는지 이해하지 못한다. 누군가 코딩의 오류를 잡아낼 수 있기를 바랍니다. 또는이 문제의 원인에 대해 제안 할 수 있기를 바랍니다.

$ paymentType은 아래 코드에서 사용되는 다른 변수와 함께 config.php에 저장됩니다.

이 내 $의 paymentType 내 config.php에의 모습입니다 :

$ paymentType = '판매'; // 지불 유형

<?php 
session_start(); 
include_once("config.php"); 
include_once("paypal.class.php"); 
include ("../inc/settings.php"); 





$paypalmode = ($PayPalMode=='sandbox') ? '.sandbox' : ''; 

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


    //Mainly we need 4 variables from product page Item Name, Item Price, Item Number and Item Quantity. 

    //Please Note : People can manipulate hidden field amounts in form, 
    //In practical world you must fetch actual price from database using item id. Eg: 
    //$ItemPrice = $mysqli->query("SELECT item_price FROM products WHERE id = Product_Number"); 

    // Connect to DB 
    mysql_connect($server, $user, $pass) or die(mysql_error()); 
    mysql_select_db($name) or die(mysql_error()); 

    // Get the item price from the database 
    $result = mysql_query("SELECT * FROM admin_settings"); 
    while($row = mysql_fetch_array($result)) { 
     // Check how many credits they are buying 
     if ($_POST["itemnumber"] == 5) { 
      $ItemPrice = $row['five_credits']; 
     } else if ($_POST["itemnumber"] == 10) { 
      $ItemPrice = $row['ten_credits']; 
     } else if ($_POST["itemnumber"] == 20) { 
      $ItemPrice = $row['twenty_credits'];  
     } else if ($_POST["itemnumber"] == 30) { 
      $ItemPrice = $row['thirty_credits'];  
     } 
    }// end while 

    $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  = 0; //2.58; //Sum of tax for all items in this order. 
    $HandalingCost = 0; //2.00; //Handling cost for this order. 
    $InsuranceCost = 0; //1.00; //shipping insurance cost for this order. 
    $ShippinDiscount = 0; //-3.00; //Shipping discount for this order. Specify this as negative number. 
    $ShippinCost  = 0; //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); 
    $GrandTotal = $ItemTotalPrice; 

    //Parameters for SetExpressCheckout, which will be sent to PayPal 
    $padata = '&METHOD=SetExpressCheckout'. 
       '&RETURNURL='.urlencode($PayPalReturnURL). 
       '&CANCELURL='.urlencode($PayPalCancelURL). 
       '&PAYMENTREQUEST_0_PAYMENTACTION='.urlencode($paymentType). 
       '&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_AMT='.urlencode($GrandTotal). 
       '&PAYMENTREQUEST_0_CURRENCYCODE='.urlencode($PayPalCurrencyCode). 
       '&LOCALECODE=US'. //PayPal pages to match the language on your website. 
       '&LOGOIMG=http://www.sanwebe.com/wp-content/themes/sanwebe/img/logo.png'. //site logo 
       '&CARTBORDERCOLOR=FFFFFF'. //border color of cart 
       '&ALLOWNOTE=0'; 



       ############# 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['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>'; 
     } 

} 

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

    $padata = '&TOKEN='.urlencode($token). 
       '&PAYERID='.urlencode($payer_id). 
       '&PAYMENTREQUEST_0_PAYMENTACTION='.urlencode($paymentType). 
       //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_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>'; 
      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">Payment Received! Your product will be sent to you very soon!</div>'; 
        echo '<div style="color:green">Add the code here to add credits to the user\'s account.</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>'; 
        echo '<div style="color:red">Once you have authorized your payment manually, you will need to contact me via [email protected] to apply the credits to your account. Due to your payment being blocked until authorized, credits can not be added automatically.</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 ### 
        //see (http://www.sanwebe.com/2013/03/basic-php-mysqli-usage) for mysqli usage 

        $buyerName = $httpParsedResponseAr["FIRSTNAME"].' '.$httpParsedResponseAr["LASTNAME"]; 
        $buyerEmail = $httpParsedResponseAr["EMAIL"]; 

        //Open a new connection to the MySQL server 
        $mysqli = new mysqli('host','username','password','database_name'); 

        //Output any connection error 
        if ($mysqli->connect_error) { 
         die('Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error); 
        }  

        $insert_row = $mysqli->query("INSERT INTO BuyerTable 
        (BuyerName,BuyerEmail,TransactionID,ItemName,ItemNumber, ItemAmount,ItemQTY) 
        VALUES ('$buyerName','$buyerEmail','$transactionID','$ItemName',$ItemNumber, $ItemTotalPrice,$ItemQTY)"); 

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

        */ 

        echo '<pre>'; 
        print_r($httpParsedResponseAr); 
        echo '</pre>'; 
       } 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>'; 
    } 
} 
?> 

그것은 내 웹 사이트에서 PayPal 's로 이동합니다. 나는 지불을 허용하기 위해 나의 PayPal 자격 증명을 넣었고, 나를 다시 내 웹 사이트로 보낸다. 그것이 나를 돌려 보낼 때 오류를 표시합니다.

여기에 정확한 오류 Obvoiusly PAYMENTREQUEST_0_PAYMENTACTION가 SetExpress 체크 아웃 또는 DoExpress 체크 아웃 API 호출에 전달되지

Error : PaymentAction : Required parameter missing 
Array 
(
    [TIMESTAMP] => 2014%2d02%2d22T14%3a41%3a42Z 
    [CORRELATIONID] => 57246c353bd81 
    [ACK] => Failure 
    [VERSION] => 109%2e0 
    [BUILD] => 9720069 
    [L_ERRORCODE0] => 81115 
    [L_SHORTMESSAGE0] => Missing%20Parameter 
    [L_LONGMESSAGE0] => PaymentAction%20%3a%20Required%20parameter%20missing 
    [L_SEVERITYCODE0] => Error 
) 

답변

0

입니다. $ paymentType을 인쇄하여 변수의 범위가 내부에 있는지 확인하십시오 ($ paymentType이 설정 파일에 선언 된 것처럼). 또는 이 파일 자체에 $ paymentType = 'Sale'을 선언하십시오 (교차 확인하기 위해).

+0

변수 대신 판매 단어를 입력했는데 작동하지 않았습니다. 정상적인 파일에서 선언했지만 작동하지 않았습니다. 화면에 $ paymentType을 인쇄하면 판매로 표시됩니다. 직접 코드를 작성하는 방법을 가르쳐주는 더 나은 튜토리얼을 발견 했으므로이 답변을 더 이상 필요하지 않습니다. – user3340895

0

나는 거의 4 시간을 보냈고 paypal이 돌아 오는 url로 되돌아 갈 때 토큰을 얻은 후에 세션이 파괴된다는 것을 알았다.

이 오류가 발생합니다.

해상도 : 내가 대신 문제가 성공적으로 해결 된 http://your-website.com

의 반환 URL로 http://www.your-website.com을 사용했다.