1
votes

I get pay-key from IOS sdk, I need to check transaction status from that pay-key.

I have used PayPal Merchant SDK for PHP. in which i can get transaction details from transaction id but not from pay-key.

I also check for this Paypal Adaptive payment Pay key validation received from IOS But IPN option but its not useful in my case.

But my requirement is that, I have ios app in which user deposit amount to paypal. then for server side I need to validate transaction status and then perform further operations.

But i am unable to find transaction details from pay-key.

Have anyone done this?? Thanks.

1
Have you checked the PaymentDetails API?Drew Angell
Thanks @AndrewAngell I implemented this and its work fine .Satish Shinde

1 Answers

4
votes

Finally found the way to get transaction details from pay-key

First get access token using you clientId and 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);

After Getting access token, I get transaction detail using following code

 $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);

With this we can validate transaction.

remove sandbox work from url when you are using it for live.