title: paypal REST API transaction approved
body: <p>I making an integration with paypal. I'm using REST API for java. Currently, I have a problem with pending payments. When I look up a payment (<a href="https://api.paypal.com/v1/payments/payment/" rel="nofollow">https://api.paypal.com/v1/payments/payment/</a>{paymentId}) to sandbox environment to check the payment status the responses are different. 
  When I approved payment as a seller the payment is in status</p>
  
  <blockquote>
    <p>approved</p>
  </blockquote>
  
  <p>and sale is in status</p>
  
  <blockquote>
    <p>completed</p>
  </blockquote>
  
  <p>example response:
      <code>
      {
        "id": "PAY-5YK922393D847794YKER7MUI",
        "create_time": "2013-02-19T22:01:53Z",
        "update_time": "2013-02-19T22:01:55Z",
        "state": "approved",
        "intent": "sale",
        "payer": {
          "payment_method": "credit_card",
          "funding_instruments": [
            {
              "credit_card": {
                "type": "mastercard",
                "number": "xxxxxxxxxxxx5559",
                "expire_month": "2",
                "expire_year": "2018",
                "first_name": "Betsy",
                "last_name": "Buyer"
              }
            }
          ]
        },
        "transactions": [
          {
            "amount": {
              "total": "7.47",
              "currency": "USD",
              "details": {
                "subtotal": "7.47"
              }
            },
            "description": "This is the payment transaction description.",
            "related_resources": [
              {
                "sale": {
                  "id": "36C38912MN9658832",
                  "create_time": "2013-02-19T22:01:53Z",
                  "update_time": "2013-02-19T22:01:55Z",
                  "state": "completed",
                  "amount": {
                    "total": "7.47",
                    "currency": "USD"
                  },
                  "parent_payment": "PAY-5YK922393D847794YKER7MUI",
                  "links": [
                    {
                      "href": "https://api.sandbox.paypal.com/v1/payments/sale/36C38912MN9658832",
                      "rel": "self",
                      "method": "GET"
                    },
                    {
                      "href": "https://api.sandbox.paypal.com/v1/payments/sale/36C38912MN9658832/refund",
                      "rel": "refund",
                      "method": "POST"
                    },
                    {
                      "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-5YK922393D847794YKER7MUI",
                      "rel": "parent_payment",
                      "method": "GET"
                    }
                  ]
                }
              }
            ]
          }
        ],
        "links": [
          {
            "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-5YK922393D847794YKER7MUI",
            "rel": "self",
            "method": "GET"
          }
        ]
      }
  </code><br>
  and sometimes payment is </p>
  
  <blockquote>
    <p>pending</p>
  </blockquote>
  
  <p>and the sale status in</p>
  
  <blockquote>
    <p>completed
    example respose:
        <code>
        {
          "id": "PAY-5YK922393D847794YKER7MUI",
          "create_time": "2013-02-19T22:01:53Z",
          "update_time": "2013-02-19T22:01:55Z",
          "state": "pending",
          "intent": "sale",
          "payer": {
            "payment_method": "credit_card",
            "funding_instruments": [
              {
                "credit_card": {
                  "type": "mastercard",
                  "number": "xxxxxxxxxxxx5559",
                  "expire_month": "2",
                  "expire_year": "2018",
                  "first_name": "Betsy",
                  "last_name": "Buyer"
                }
              }
            ]
          },
          "transactions": [
            {
              "amount": {
                "total": "7.47",
                "currency": "USD",
                "details": {
                  "subtotal": "7.47"
                }
              },
              "description": "This is the payment transaction description.",
              "related_resources": [
                {
                  "sale": {
                    "id": "36C38912MN9658832",
                    "create_time": "2013-02-19T22:01:53Z",
                    "update_time": "2013-02-19T22:01:55Z",
                    "state": "completed",
                    "amount": {
                      "total": "7.47",
                      "currency": "USD"
                    },
                    "parent_payment": "PAY-5YK922393D847794YKER7MUI",
                    "links": [
                      {
                        "href": "https://api.sandbox.paypal.com/v1/payments/sale/36C38912MN9658832",
                        "rel": "self",
                        "method": "GET"
                      },
                      {
                        "href": "https://api.sandbox.paypal.com/v1/payments/sale/36C38912MN9658832/refund",
                        "rel": "refund",
                        "method": "POST"
                      },
                      {
                        "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-5YK922393D847794YKER7MUI",
                        "rel": "parent_payment",
                        "method": "GET"
                      }
                    ]
                  }
                }
              ]
            }
          ],
          "links": [
            {
              "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-5YK922393D847794YKER7MUI",
              "rel": "self",
              "method": "GET"
            }
          ]
        }
    </code></p>
  </blockquote>
  
  <p>Similarly, Sanbox works when I reject the transaction. Once the payment status is failed and sale status is reversed and another time is pending and reserved.</p>
  
  <p>My question is when can be 100% sure about the transaction is completed or failed?
  Should I check the payment status or the sale status?
   Maybe this this problem is related only with sandbox not with production.</p>
  
  <p>PS. This code is only the sample, do NOT analyze it.</p>