Paypal从php中的支付密钥获取交易详细信息


Paypal get transaction details from pay key in php

我从IOS-sdk获得支付密钥,我需要从该支付密钥检查交易状态。

我已经使用了PHP的PayPal Merchant SDK。其中我可以从交易id获得交易详细信息,但不能从支付密钥获得。

我还检查了从IOS收到的Paypal自适应支付支付密钥验证,但IPN选项,但在我的情况下没有用处。

但我的要求是,我有一个ios应用程序,用户可以在其中向贝宝存款。那么对于服务器端,我需要验证事务状态,然后执行进一步的操作。

但我无法从支付密钥中找到交易详细信息。

有人这样做过吗??谢谢

终于找到了从支付密钥获取交易详细信息的方法

首先使用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中删除,当您正在使用它进行直播时。