【问题标题】:What is the best way to submit a PayPal invoice on behalf of a third party in android在android中代表第三方提交PayPal发票的最佳方式是什么
【发布时间】:2015-12-06 08:45:28
【问题描述】:

我一直在尝试使用 Volley 来访问 Invoice REST 服务。想知道我是否还需要使用无数 PayPal SDK 之一来完成这项工作,或者我是否应该自己动手。任何示例将不胜感激。

非常感谢, 大卫

【问题讨论】:

    标签: android paypal android-volley


    【解决方案1】:

    好吧,我至少已经成功地使用 Volley 对 PayPal REST 服务进行身份验证。这是一个可以帮助其他 Volley 用户的 sn-p。有关设置和使用 Volley 的更多信息:http://www.androidhive.info/2014/05/android-working-with-volley-library-1/

                        String tag_string_req = "string_req";
                        String url = "https://api.sandbox.paypal.com/v1/oauth2/token";
    
                        final ProgressDialog pDialog = new ProgressDialog(context);
                        pDialog.setMessage("Requesting Authorization...");
                        pDialog.show();
    
                        JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.POST,
                                url,
                                new Response.Listener<JSONObject>() {
    
                                    @Override
                                    public void onResponse(JSONObject response) {
    
                                        try {
                                            createInvoice(response.get("access_token").toString());
                                        } catch (JSONException e) {
                                            Log.e("MFM", e.getLocalizedMessage());
                                        }
                                        //Toast.makeText(context, response.toString(), Toast.LENGTH_LONG).show();
                                        pDialog.hide();
                                    }
                                }, new Response.ErrorListener() {
    
                            @Override
                            public void onErrorResponse(VolleyError error) {
                                Toast.makeText(context, error.getMessage(), Toast.LENGTH_LONG).show();
                                pDialog.hide();
                            }
                        }) {
    
    
                            @Override
                            public Map<String, String> getHeaders() throws AuthFailureError {
                                HashMap<String, String> headers = new HashMap<>();
                                headers.put("Accept", "application/json");
                                headers.put("Accept-Language", "en_US");
                                headers.put("content-type", "application/x-www-form-urlencoded; charset=utf-8");
                                String credentials = "<client-id-from-paypal-sandbox>:<client-secret-from-paypal-sandbox>";
                                String encodedCredentials = Base64.encodeToString(credentials.getBytes(), Base64.URL_SAFE | Base64.NO_WRAP);
                                headers.put("Authorization", "Basic " + encodedCredentials);
                                return headers;
                            }
    
                            @Override
                            public byte[] getBody() {
                                String httpPostBody = "grant_type=client_credentials";
                                return httpPostBody.getBytes();
                            }
                        };
    
                        // Adding request to request queue
                        getInstance().addToRequestQueue(jsonObjReq, tag_string_req);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-28
      • 1970-01-01
      • 1970-01-01
      • 2020-11-02
      • 1970-01-01
      • 2017-01-03
      • 1970-01-01
      • 2011-04-17
      相关资源
      最近更新 更多