2012-04-13 169 views
1

我將在我的iPhone本機應用程序中實現貝寶。但我在這方面是個棘手的問題。如何在使用paypal進行PayPal集成後獲取PayPal交易ID?

我想獲取有關我的PayKey的交易ID。有一種直接的方法可以在PayPal庫中獲得支付密鑰以獲得PayKey,但不能獲得transactionId的方法。

這裏是一個方法:

-(void)paymentSuccessWithKey:(NSString *)payKey andStatus:(PayPalPaymentStatus)paymentStatus; 

正如我在想IPN(即時付款通知),可以幫助解決這個問題,但我不知道如何實現一個在我的應用程序?

請幫我解決這個問題。

感謝, 錢德拉·普拉卡什

+0

您是否將該軟件用於應用程序購買?在我進行更進一步之前,我會檢查Apple的政策,因爲他們有自己的應用購買機制。 – Openside 2012-04-13 13:40:31

+0

我正在開發一個應用程序,您可以從其成員購買活動通行證的目的。並通過Paypal付款。 – 2012-04-13 13:58:38

回答

1

我的問題的Fianlly我有解決方案。

我有使用IPN的交易ID。

當我選擇ENABLE IPN從我的貝寶帳戶選項,然後所有細節發送貝寶我收到了我從那裏給我的URL我已經得到所有必填字段。

這裏有幾個環節,以幫助您

IPN概述: https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/howto_html_instantpaymentnotif

IPN文件: https://cms.paypal.com/cms_content/US/en_US/files/developer/IPNGuide.pdf

IPN變量: https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_html_IPNandPDTVariables

IPN腳本示例: https://cms.paypal.com/us/cgi-bin/?&cmd=_render-content&content_ID=developer/e_howto_admin_IPNImplementation

IPN腳本生成: https://www.paypaltech.com/SG2/

感謝, 的Cp

1

我也有類似的問題,但無法依靠IPN所以我想我將分享另一種方法。

您不需要使用IPN,您可以使用payKey獲取交易ID,這對驗證移動支付很有用。這是一個將從payKey獲取所有交易信息的php塊。你需要從你的移動應用程序中調用它。對於iOS,你可以使用此教程:http://www.raywenderlich.com/13511/how-to-create-an-app-like-instagram-with-a-web-service-backend-part-12

<? 
header("Content-Type: application/json"); 

//DEBUG TO CHECK PAYKEY 
//turn php errors on 
ini_set("track_errors", true); 

//Example payKey (got from iOS app) 
$payKey = "<snip>"; 

//set PayPal Endpoint to sandbox 
$url = trim("https://svcs.sandbox.paypal.com/AdaptivePayments/PaymentDetails?payKey=".$payKey."&requestEnvelope.errorLanguage=en_US"); 

//PayPal API Credentials 

//to do: change these for production credentials in the production app 
$API_UserName = "<snip>"; 
$API_Password = "<snip>"; 
$API_Signature = "<snip>"; 

//Default App ID for Sandbox 
$API_AppID = "APP-80W284485P519543T"; 

$API_RequestFormat = "NV"; 
$API_ResponseFormat = "NV"; 

try 
{ 
    //Create payload for this query 
    $bodyparams = array ("requestEnvelope.errorLanguage" => "en_US"); 
    // convert payload array into url encoded query string 
    $body_data = http_build_query($bodyparams, "", chr(38)); // Generates body data 

    //create request and add headers 
    $params = array("http" => array(
     "method" => "POST", 
     "content" => $body_data, 
     "header" => "X-PAYPAL-SECURITY-USERID: " . $API_UserName . "\r\n" . 
     "X-PAYPAL-SECURITY-PASSWORD: " . $API_Password . "\r\n" . 
     "X-PAYPAL-SECURITY-SIGNATURE: " . $API_Signature . "\r\n" . 
     "X-PAYPAL-APPLICATION-ID: " . $API_AppID . "\r\n" . 
     "X-PAYPAL-REQUEST-DATA-FORMAT: " . $API_RequestFormat . "\r\n" . 
     "X-PAYPAL-RESPONSE-DATA-FORMAT: " . $API_ResponseFormat 
)); 


    //create stream context 
    $ctx = stream_context_create($params); 

    //open the stream and send request 
    $fp = @fopen($url, "r", false, $ctx); 

    //get response 
    $response = stream_get_contents($fp); 

    //check to see if stream is open 
    if ($response === false) { 
     throw new Exception("php error message = " . "$php_errormsg"); 
    } 

    //close the stream 
    fclose($fp); 

    //parse the ap key from the response 

    $keyArray = explode("&", $response); 

    foreach ($keyArray as $rVal){ 
     list($qKey, $qVal) = explode ("=", $rVal); 
     $kArray[$qKey] = $qVal; 
    } 

    //print the response to screen for testing purposes 
    If ($kArray["responseEnvelope.ack"] == "Success") 
    { 

     foreach ($kArray as $key =>$value){ 
      echo $key . ": " .$value . "<br/>"; 
     } 
    } 
    else { 
     echo 'ERROR Code: ' . $kArray["error(0).errorId"] . " <br/>"; 
     echo 'ERROR Message: ' . urldecode($kArray["error(0).message"]) . " <br/>"; 
    } 
} 


catch(Exception $e) 
{ 
    echo "Message: ||" .$e->getMessage()."||"; 
} 

//End check paykey 

?> 

我會附上顯示所有你可以用$ kArray得到場的圖像,但我沒有信譽。您需要:$ kArray [「paymentInfoList.paymentInfo(0).transactionId」]

注意:您應該用於沙箱的API憑證可以在developer.paypal.com上的「沙箱帳戶」下找到。展開xxxfacilitator @ XXX的輪廓,讓他們

+0

我正在使用android sdk的android和集成paypal。我拿到了paykey,但現在我想獲得它的transactionId。您正在使用PHP代碼來獲取它並傳遞用戶憑證,但我沒有用戶憑證,那麼我如何才能使用付款鍵獲取這些詳細信息?你有什麼想法嗎? – Scorpion 2013-10-20 06:03:20

1

我們可以得到這樣的交易明細 -

首先使用您的clientId和ClientSecret

$ch = curl_init(); 
      $clientId = PAYPAL_CLIENT_ID; //client Id 
      $secret = PAYPAL_CLIENT_SECRET; client secrete key 
      curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/oauth2/token"); 
      curl_setopt($ch, CURLOPT_HEADER, false); 
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
      curl_setopt($ch, CURLOPT_POST, true); 
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
      curl_setopt($ch, CURLOPT_USERPWD, $clientId . ":" . $secret); 
      curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials"); 
      $result = curl_exec($ch); 
      $accessToken = null; 
      if (empty($result)) 
       die('invalid access token'); 
      else { 
       $json = json_decode($result); 
       $accessToken = $json->access_token; 
      } 
      curl_close($ch); 

獲得訪問令牌後獲得訪問令牌,我得到交易詳細使用以下代碼

$curl = curl_init("https://api.sandbox.paypal.com/v1/payments/payment/<paykey>"); 
      curl_setopt($curl, CURLOPT_POST, false); 
      curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 
      curl_setopt($curl, CURLOPT_HEADER, false); 
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
      curl_setopt($curl, CURLOPT_HTTPHEADER, array(
       'Authorization: Bearer ' . $accessToken, 
       'Accept: application/json', 
       'Content-Type: application/json' 
      )); 
      $response = curl_exec($curl); 
      $result = json_decode($response); 

有了這個,我們可以驗證交易。

當您將它用於實時時,從網址中刪除沙盒工作。