Magento 1.9 – Validate PayPal Pay ID Passed by Android

androidapimagento-1.9paymentpaypal

we are doing andriod app for our site. in site we configured paypal successfully.

in app, customer will do payments, than using paypal sdk we are getting transaction id in app. than andriod team will pass the transaction id to magento & in magento we need to validate payment.

our andriod team want an API from magento side.

by default, is there any API is there for this?

how to achieve this ?

Edit

please visit github link & search for "server for verification" using CTRL +F ,

there they mentioned we have to verify with server, i want to know how to verify with server after payment is done through app?

i saw this , what i understood is we need to create an API for validating payments done through app. how to do this ?

Edit 2

paypal team sent Request Sample as below :

$apiContext = new ApiContext(new OAuthTokenCredential(
        "<CLIENT_ID>", "<CLIENT_SECRET>"));

$payment = Payment::get('PAY-5YK922393D847794YKER7MUI', $apiContext);

they telling we have to request to PayPal using above sample code.

once we pass pay id, then PayPal will respond with full payment details.

Edit 3

paypal team gave this git hub code & they are telling i have to use whole SDK for getting payment details. i want to know how i have to use it in magento ?

Reply from Paypal team

The following explanations are based on the use case that, you've PayPal (either Express Checkout or Payment Pro) enabled in your Magento Web store, yet additionally integrating Mobile Native SDK in your client APP (rather than using the exsing Magento PayPal flow, embedded into a webview in your APP).

  1. Verifying the payment (after your Client APP got the payment-id in the response) is important for fraud prevention. Mobile APP interacts with PayPal servers independently, and you would not want to deliver the goods/service upon a mobile API response (which is easy to replicate) without server (your Magento server) verification against the actual payment contents.

  2. Apparently Magento doesn't come with this part of codes in the PayPal module and you need to implement your own, but yet you won't necessarily have to import the whole RESTful SDK just for a single payment look-up API call.
    Everything is based on JSON requests & JSON parsing, it works as long as you follow the PayPal RESTful payload scheme HERE, and initiate the request with curl statements.

  3. Checklist on a payment after your server obtains the details can be also found HERE.

Additional best practice for server-end implementation:

  • Store the payment-id e.g. id": "PAY-564191241M8701234KL57LXI" in your database along with the order data entry;
  • Store the debug-id in the error object (if there's an error response) from the verification (payment lookup) API response into your database for further trouble shooting purpose with PayPal support.

Sample API tests by curl commands would be like:

Step#1 – Getting access token for authentication

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

Parse the sample response and obtain the access token:

{
  "scope": "https://api.paypal.com/v1/payments/.* https://api.paypal.com/v1/vault/credit-card https://api.paypal.com/v1/vault/credit-card/.*",
  "access_token": "<Your-Access-Token-for-further-calls>",
  "token_type": "Bearer",
  "app_id": "APP-6XR95014SS315863X",
  "expires_in": 28800
}

Step#2 – Making the look-up call with the access-token and payment ID (returned by you APP, e.g. PAY-123456789)

curl https://api.sandbox.paypal.com/v1/payments/payment/PAY-123456789 \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <the access token from Step#1>"

And you'll get the response similar with this, which contains the payment details you would compare & verify with your order information in the database

{
  "proof_of_payment": {
    "adaptive_payment": {
      "pay_key": "AP-70M68096ML426802W",
      "payment_exec_status": "COMPLETED",
      "timestamp": "2013-02-20T00:26:25Z",
      "app_id": "APP-91B933855X481767M"
    }
  },
  "payment": {
    "short_description": "Hipster t-shirt",
    "amount": "9.95",
    "currency_code": "USD"
  },
  "client": {
    "platform": "iOS",
    "paypal_sdk_version": "1.0.0",
    "environment": "live",
    "product_name": "PayPal iOS SDK"
  }
}

Replay from paypal team end

when i tried above step as above , i created payment successfully.

than we need to complete payment resource with payment id using link how to do this ?

Best Answer

If payment method doesn't support online capturing (like Paypal Standard) there is no way to get a full order creation flow like on Checkout via Magento API interface. It is impossible to change the order state and process payments. As a workaround try the following:

  1. create an order with "pending" status
  2. then get order info using sales_order.info API method
  3. use order info to validate all the necessary data as described here. It should be done on the Mobile App side.
  4. if it passed the validation step then create an invoice and capture it

UPD Some Payment methods support online capturing (i.e. Authorize or Paypal Payments Pro). In theory it means that, you can create a cart via API, add payment method data to it (i.e. CC details), create an order and capture it online. So all the order processing steps (including payment validation) will be on Magento side.

Related Topic