2

I have recently implement paypal mobile payment tutorial using following tutorial: http://androiddevelopmentanddiscussion.blogspot.com/2014/05/paypal-integration-in-android.html

and in response i get following information:

{
    "response": {
        "state": "approved",
        "id": "PAY-1GM934738N157023RKR7OWYI",
        "create_time": "2014-12-03T10:52:17Z",
        "intent": "sale"
    },
    "client": {
        "platform": "Android",
        "paypal_sdk_version": "2.1.0",
        "product_name": "PayPal-Android-SDK",
        "environment": "sandbox"
    },
    "response_type": "payment"
}




{
    "short_description": "Painting 1",
    "amount": "8",
    "intent": "sale",
    "currency_code": "USD"
}

any one guide me how can i obtain transaction id and other information in mobile sdk? as i see payment from paypal mobile sdk id is different then the actual transaction id.

any help would be appreciated.

UMAR-MOBITSOLUTIONS
  • 77,236
  • 95
  • 209
  • 278

3 Answers3

3

You can retrieve a payment resource using the payment ID returned by the SDK: https://developer.paypal.com/webapps/developer/docs/api/#look-up-a-payment-resource

Typically, this would be done from your server and not from the mobile device. The GET operation will require an access token generated using both your client_id and client_secret.

Updated links:

Matt Jacunski
  • 381
  • 1
  • 4
  • After some research according to your directions i found that first i need to obtain token from paypal by calling another api, then i can pass that token in your mentioned api to get final transaction idea from other resources json attribute :) – UMAR-MOBITSOLUTIONS Dec 12 '14 at 12:27
  • Please tell anyone how to pass access token from sdk. Is there any function to pass the access token in sdk. – Aman Gupta - ΔMΔN Jun 22 '16 at 15:37
  • @AmanGupta - updated the answer with link for how to do REST authentication (the access token does not come from the SDK). – Matt Jacunski Jul 13 '16 at 14:14
  • Thanks @MattJacunski for the Updates. – Aman Gupta - ΔMΔN Jul 14 '16 at 10:56
  • Show payment details --> /v1/payments/payment/payment_id I tried with this REST Api but it does not return full response all the time. I need a transaction fee but it only returns some times. And I see it returns different response in different state of transaction like Pending/ Approved etc. Any one have any solution for that to get transaction id all the time? – Parth Pandya Sep 27 '16 at 05:19
0

You can get the token first in a separate call and then use it in another call to get the transaction id or you can combine both steps in just one step as following:

public void getPayPalTransactionId(String payPalPaymentId) {
    String PAYPAL_PAYMENT = "https://api.sandbox.paypal.com/v1/payments/payment/%s";
    String url = String.format(PAYPAL_PAYMENT, payPalPaymentId);
    Call<PayPalPaymentResponse> callPayment = webApiInterface.getPayPalTransactionId(url, Credentials.basic(PAYPAL_CLIENT_ID, PAYPAL_CLIENT_SECRET));
    callPayment.enqueue(new Callback<PayPalPaymentResponse>() {
        @Override
        public void onResponse(@NonNull Call<PayPalPaymentResponse> call, @NonNull Response<PayPalPaymentResponse> response) {
            if (response.isSuccessful() && response.body() != null)
                String payPalOrderId = response.body().getTransactions().get(0).getRelatedResources().get(0).getSale().getId();
        }

        @Override
        public void onFailure(@NonNull Call<PayPalPaymentResponse> call, @NonNull Throwable t) {
        }
    });
}

In WebApiInterface

@GET
Call<PayPalPaymentResponse> getPayPalTransactionId(@Url String url, @Header("Authorization") String authorization);
Hasan El-Hefnawy
  • 1,249
  • 1
  • 14
  • 20
0

Go to the onApprove function on the following code and go to where it says transaction ID:

<!-- Include the PayPal JavaScript SDK -->
<script src="https://www.paypal.com/sdk/js?client-id=CLIENT ID IS CORRECTLY ADDED&currency=USD"></script>

<script>
  paypal.Buttons({

    // Sets up the transaction when a payment button is clicked
    createOrder: function(data, actions) {
      return actions.order.create({
        purchase_units: [{
          
          amount: {
            value: '1'
          },
            
        }],
        application_context: {
            shipping_preference: "NO_SHIPPING",
        }
         
      });
    },

    // Finalize the transaction after payer approval
    onApprove: function(data, actions) {
      return actions.order.capture().then(function(orderData) {
        // Successful capture! For dev/demo purposes:
        //    console.log('Capture result', orderData, JSON.stringify(orderData, null, 2));

        // the transaction id is below this comment in the alert
        var transaction = orderData.purchase_units[0].payments.captures[0];
        alert('Transaction '+ transaction.status + ': ' + transaction.id + '\n\nSee console for all available details');

        // When ready to go live, remove the alert and show a success message within this page. For example:
        // var element = document.getElementById('paypal-button-container');
        // element.innerHTML = '';
        // element.innerHTML = '<h3>Thank you for your payment!</h3>';
        actions.redirect('https://wwwwebsite.com/att_thanks.php?id=1640035591');
      });
    }
  }).render('#paypal-button-container');

</script> 
Marcus
  • 75
  • 2
  • 8