微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

将PayPal Checkout集成到Android应用中

如何解决将PayPal Checkout集成到Android应用中

  • 我正在使用load_profile_data提供的REST APIs将Paypal结帐功能集成到Android应用中,并且我的国家是印度,因此我关注PayPal的this guide
  • 我如何按照文档进行操作:
    1. 获取访问令牌Paypal)以进行进一步的api调用
    2. 使用/v1/oauth2/token创建付款(Create Order API),然后在响应中我们将获得批准 v2/checkout/orders ,您需要在此处重定向用户以进行付款付款。
    3. url是如何知道移动应用程序中的付款交易是否成功的原因,因为我正在应用程序中使用WebView来加载批准Now my question

订单是这样创建的,我将href加载到webview中

url

解决方法

我这样做:

  • 客户成功完成付款后,将使用查询参数return_urlPayerID orderID )调用token。届时,我们可以在数据库中更新用户的付款状态(由于尚未批准或捕获订单,因此尚未扣除金额。)

  • 此后,我们可以捕获我们的订单(确保发票编号不重复),否则状态将不会完成。

  • 如果在截获时未批准订单,则会出现此类错误:

     {
     "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"
         }
     ]
    

    }

  • 如果发票号重复,则捕获时会看到错误:

     {
     "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."
         }
     ],"debug_id": "86e0cc7f....","links": [
         {
             "href": "https://developer.paypal.com/docs/api/orders/v2/#error-DUPLICATE_INVOICE_ID","method": "GET"
         }
     ]
    

    }

如果存在基于货币的问题:

    {
    "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."
        }
    ],"debug_id": "d666b5e5eb0c0","links": [
        {
            "href": "https://developer.paypal.com/docs/api/orders/v2/#error-CURRENCY_NOT_SUPPORTED","method": "GET"
        }
    ]
}

如果成功捕获到状态为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": "testg32@gmail.com","payer_id": "VW87TYSM2GMZ4","address": {
      "address_line_1": "10,"country_code": "NZ"
    }
  },"links": [
    {
      "href": "https://api.sandbox.paypal.com/v2/checkout/orders/8G0042477K865063U","method": "GET"
    }
  ]
}

之后,您可以将用户重定向到“谢谢”页面,并根据数据库值更新移动应用程序屏幕。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。