Reputation: 78004
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.
Upvotes: 2
Views: 3071
Reputation: 147
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¤cy=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>
Upvotes: 0
Reputation: 1569
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);
Upvotes: 0
Reputation: 381
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:
Upvotes: 3