Sumit Shukla
Sumit Shukla

Reputation: 4494

Integrating PayPal Checkout in an Android app

Order is created like this and I load href inside webview:

{
  "id": "1KK44573EX7352015",
  "status": "CREATED",
  "links": [
    {
      "href": "https://www.sandbox.paypal.com/checkoutnowtoken=1KK44573EX7352015",
      "rel": "approve",
      "method": "GET"
    }
  ]
}

Upvotes: 2

Views: 1862

Answers (1)

Sumit Shukla
Sumit Shukla

Reputation: 4494

I did this way:

  • As soon as Payment is successfully completed by customer the return_url gets called with query parameters : PayerID & token(orderID). At that time we can update user's payment status in our database (Amount is not deducted yet still because order is yet not approved or captured).

  • After that we can capture our order (Make sure invoice-id is not duplicate) otherwise status will be not completed.

  • If order is not approved on the time of capture we get this kind of error:

     {
     "name": "UNPROCESSABLE_ENTITY",
     "details": [
         {
             "issue": "ORDER_NOT_APPROVED",
             "description": "Payer has not yet approved the Order for payment. Please redirect the payer to the 'rel':'approve' url returned as part of the HATEOAS links within the Create Order call or provide a valid payment_source in the request."
         }
     ],
     "message": "The requested action could not be performed, semantically incorrect, or failed business validation.",
     "debug_id": "47af43e..",
     "links": [
         {
             "href": "https://developer.paypal.com/docs/api/orders/v2/#error-ORDER_NOT_APPROVED",
             "rel": "information_link",
             "method": "GET"
         }
     ]
    

    }

  • If there is duplicate invoice-id you will see error at the time of capture:

     {
     "name": "UNPROCESSABLE_ENTITY",
     "details": [
         {
             "issue": "DUPLICATE_INVOICE_ID",
             "description": "Duplicate Invoice ID detected. To avoid a potential duplicate transaction your account setting requires that Invoice Id be unique for each transaction."
         }
     ],
     "message": "The requested action could not be performed, semantically incorrect, or failed business validation.",
     "debug_id": "86e0cc7f....",
     "links": [
         {
             "href": "https://developer.paypal.com/docs/api/orders/v2/#error-DUPLICATE_INVOICE_ID",
             "rel": "information_link",
             "method": "GET"
         }
     ]
    

    }

If there is currency based issue:

    {
    "name": "UNPROCESSABLE_ENTITY",
    "details": [
        {
            "location": "body",
            "issue": "CURRENCY_NOT_SUPPORTED",
            "description": "Currency code is not currently supported. Please refer https://developer.paypal.com/docs/integration/direct/rest/currency-codes/ for list of supported currency codes."
        }
    ],
    "message": "The requested action could not be performed, semantically incorrect, or failed business validation.",
    "debug_id": "d666b5e5eb0c0",
    "links": [
        {
            "href": "https://developer.paypal.com/docs/api/orders/v2/#error-CURRENCY_NOT_SUPPORTED",
            "rel": "information_link",
            "method": "GET"
        }
    ]
}

If your order is successfully captured with status as COMPLETED:

{
  "id": "8G0042477K865063U",
  "status": "COMPLETED",
  "purchase_units": [
    {
      "reference_id": "default",
      "shipping": {
        "name": {
          "full_name": "John Doe"
        },
        "address": {
          "address_line_1": "10, east street",
          "address_line_2": "first building",
          "admin_area_2": "Mumbai",
          "admin_area_1": "Maharashtra",
          "postal_code": "400029",
          "country_code": "NZ"
        }
      },
      "payments": {
        "captures": [
          {
            "id": "4K670967VH2547504",
            "status": "PENDING",
            "status_details": {
              "reason": "RECEIVING_PREFERENCE_MANDATES_MANUAL_ACTION"
            },
            "amount": {
              "currency_code": "NZD",
              "value": "170.00"
            },
            "final_capture": true,
            "seller_protection": {
              "status": "ELIGIBLE",
              "dispute_categories": [
                "ITEM_NOT_RECEIVED",
                "UNAUTHORIZED_TRANSACTION"
              ]
            },
            "invoice_id": "INV-1234567888",
            "links": [
              {
                "href": "https://api.sandbox.paypal.com/v2/payments/captures/4K670967VH2547504",
                "rel": "self",
                "method": "GET"
              },
              {
                "href": "https://api.sandbox.paypal.com/v2/payments/captures/4K670967VH2547504/refund",
                "rel": "refund",
                "method": "POST"
              },
              {
                "href": "https://api.sandbox.paypal.com/v2/checkout/orders/8G0042477K865063U",
                "rel": "up",
                "method": "GET"
              }
            ],
            "create_time": "2020-10-31T13:35:58Z",
            "update_time": "2020-10-31T13:35:58Z"
          }
        ]
      }
    }
  ],
  "payer": {
    "name": {
      "given_name": "Sumit",
      "surname": "Shukla"
    },
    "email_address": "[email protected]",
    "payer_id": "VW87TYSM2GMZ4",
    "address": {
      "address_line_1": "10, east street",
      "admin_area_2": "Mumbai",
      "admin_area_1": "Maharashtra",
      "postal_code": "400029",
      "country_code": "NZ"
    }
  },
  "links": [
    {
      "href": "https://api.sandbox.paypal.com/v2/checkout/orders/8G0042477K865063U",
      "rel": "self",
      "method": "GET"
    }
  ]
}

After that you can redirect user to thank you page and update mobile app screen based on database values.

Upvotes: 1

Related Questions