Aman Gupta -  ΔMΔN
Aman Gupta - ΔMΔN

Reputation: 3007

How to get the full transaction details in paypal using the payment_id in paypal android sdk

I am using the paypal android sdk 2.14.1. When I make the payment by the sdk, then it give the following response,

{
"response": {
    "state": "approved",
    "id": "PAY-9A140896UE325390DK5VK4KI",
    "create_time": "2016-06-22T15:26:40Z",
    "intent": "sale"
},
"client": {
    "platform": "Android",
    "paypal_sdk_version": "2.14.1",
    "product_name": "PayPal-Android-SDK",
    "environment": "sandbox"
},
"response_type": "payment"

}

But I want the full transaction details

So please anyone can give the suggestion how to get the transaction details. by payment id.

Note: I am using soap APIs.

Upvotes: 3

Views: 3951

Answers (4)

Amandeep Singh
Amandeep Singh

Reputation: 29

Hi here is the solution after the 2 days Research. i was tired on this. now i found the proper solution for this.

import com.squareup.okhttp.MediaType
import com.squareup.okhttp.OkHttpClient
import com.squareup.okhttp.Request
import com.squareup.okhttp.Requl̥estBody

val client = OkHttpClient()
    val mediaType: MediaType = MediaType.parse("application/json; charset=utf-8")!!
    val body: RequestBody = RequestBody.create(mediaType, "grant_type=client_credentials")
    val request: Request = Request.Builder()
        .url("https://api.sandbox.paypal.com/v1/oauth2/token")
        .method("POST", body)
        .addHeader("Content-Type", "application/x-www-form-urlencoded")
        .addHeader(
            "Authorization",
            "Basic QVgzT24za***********************************lg="
        )
        .addHeader("Content-Type", "application/x-www-form-urlencoded")
        .build()
    val response = client.newCall(request).execute()
    val jsonObject = JSONObject(response.body().string())
    val accessToken = jsonObject.getString("access_token")

*QVgzT24za***********************************lg=* is here the converted code from ClientID:SecretID

val clientID = CommonObjects.PAYPAL_CLIENT_ID
    val clientSecret = CommonObjects.PAYPAL_SECRET_ID
    val text = "$cl4ientID:$clientSecret"
    var data = ByteArray(0)
    try {
        data = text.toByteArray(charset("UTF-8"))
    } catch (e: UnsupportedEncodingException) {
        e.printStackTrace()
    }
    val base64 =
        Base64.encodeToString(data, Base64.NO_WRAP)

Now, base64 = *QVgzT24za***********************************lg=*

Upvotes: 0

Aman Gupta -  ΔMΔN
Aman Gupta - ΔMΔN

Reputation: 3007

I got the answer,

First of all we have to generate the access-Token by the client_id and secret,

curl -v https://api.sandbox.paypal.com/v1/oauth2/token \
     -H "Accept: application/json" \  
     -H "Accept-Language: en_US" \  
     -u "client_id:secret" \  
     -d "grant_type=client_credentials"

After getting the access-Token I have to make another api call for getting the full transaction details,

curl -v -X GET https://api.sandbox.paypal.com/v1/payments/payment/Payment-Id \
     -H "Content-Type:application/json" \
     -H "Authorization: Bearer Access-Token"

After hitting this I will get the full transaction details.

For know more go to this link.

Upvotes: 2

Muhammad Usman
Muhammad Usman

Reputation: 355

Send the payment id to server API as:

url -v -X GET https://api.sandbox.paypal.com/v1/payments/payment/Payment-Id \

-H "Content-Type:application/json" \

-H "Authorization: Bearer Access-Token"

for more details, check here

Upvotes: 1

pp_pduan
pp_pduan

Reputation: 3402

Obtain the "id": "PAY-9A140896UE325390DK5VK4KI" retruned in the mSDK response, and then look up the payment resource with your server-end REST API. This is also a recommended implementation of verifying the mobile payment for fraud prevention.

Check the procedure here for Verify a mobile payment

Upvotes: 0

Related Questions