1

我将在我的 iphone 本机应用程序中实现 paypal。但我对此有一个问题。

我想获取关于我的 PayKey 的交易 ID。在 PayPal 库中有一种直接获取支付密钥的方法来获取 PayKey,但没有获取transactionId的方法。

这是那个方法:

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

我在想 IPN(即时付款通知)可以帮助解决这个问题,但我不知道如何在我的应用程序中实现这个问题?

请帮我解决这个问题。

谢谢,钱德拉普拉卡什

4

3 回答 3

2

最后,我已经解决了我的问题。

我有使用 IPN 的交易 ID。

当我从我的 PayPal 帐户中选择启用 IPN选项时,我收到的所有详细信息都通过我从那里提供的 URL 上的 paypal 发送,我得到了所有必填字段。

这里有几个链接可以帮助你

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

于 2012-04-23T13:43:54.020 回答
2

我有类似的问题,但无法依赖 IPN,所以我想我会分享另一种方法。

你不需要使用IPN,你可以通过payKey获取交易ID,这对于验证移动支付很有用。这是一个 php 块,它将从 payKey 获取所有交易信息。您需要从您的移动应用程序中调用它。对于 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"]

注意:您可以在 developer.paypal.com 上的“沙盒帐户”下找到您应该用于沙盒的 API 凭据。展开 xxxfacilitator@xxx 的个人资料以获取它们

于 2013-08-17T12:54:37.050 回答
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);

有了这个,我们可以验证交易。

当您将其用于现场直播时,从 url 中删除沙盒工作。

于 2014-10-03T06:15:25.610 回答