来自paypal的交易详情使用Android中的Pay-key

时间:2012-01-09 13:26:55

标签: java android android-widget android-ndk android-manifest

我在我的应用程序中集成了paypal,一切正常。现在我想在我的android中拥有paypal的所有交易细节,所以使用paykey我试着编写代码。我的代码获取交易细节如下:

if(resultTitle == "SUCCESS")
        {
            try{


                HttpClient httpclient = new DefaultHttpClient();
                HttpPost httppost = null;
                httppost = new HttpPost("https://svcs.sandbox.paypal.com/AdaptivePayments/PaymentDetails");
                httppost.setHeader("Content-Type", "application/x-www-form-urlencoded");


                    // Add your data
                    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
                    nameValuePairs.add(new BasicNameValuePair("X-PAYPAL-SECURITY-USERID", "parth_1325956186_biz_api1.bcod.co.in"));
                    nameValuePairs.add(new BasicNameValuePair("X-PAYPAL-SECURITY-PASSWORD", "334367211"));
                    nameValuePairs.add(new BasicNameValuePair("X-PAYPAL-SECURITY-SIGNATURE", "An5ns1Kso7MUDHR4ErQKJJJ4qi4-AI0T5BBCHc3gWzBV9Q81jcP6LFD6")); 
                    nameValuePairs.add(new BasicNameValuePair("X-PAYPAL-APPLICATION-ID", "APP-80W284485P519543T"));
                    nameValuePairs.add(new BasicNameValuePair("X-PAYPAL-REQUEST-DATA-FORMAT", "nv"));
                    nameValuePairs.add(new BasicNameValuePair("X-PAYPAL-RESPONSE-DATA-FORMAT", "nv"));
                    nameValuePairs.add(new BasicNameValuePair("payKey", resultExtra));
                    nameValuePairs.add(new BasicNameValuePair("requestEnvelope.errorLanguage", "en_US"));
                    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                HttpResponse response = httpclient.execute(httppost);
                HttpEntity entity = response.getEntity();
                InputStream is = entity.getContent();
                byte[] data1;
                data1 = new byte[256];
                buffer = new StringBuffer();
                int len = 0;
                while (-1 != (len = is.read(data1)) )
                  {
                     buffer.append(new String(data1, 0, len));
                  }
                Log.e("log_tag",""+buffer.toString());

                //Make the comparison case-insensitive.
                is.close();
                }catch(Exception e)
                {
                    Log.e("","error "+ e );
                }
                Log.e("","resultExtra "+ resultExtra );
                Intent go = new Intent(getBaseContext(),membership_pack_clear.class);
                startActivity(go);

                finish();

        }

我正在接受他们的回复

<?xml version='1.0' encoding='UTF-8'?>
<ns3:FaultMessage xmlns:ns3="http://svcs.paypal.com/types/common" xmlns:ns2="http://svcs.paypal.com/types/ap">
<responseEnvelope><timestamp>2012-01-09T05:16:35.886-08:00</timestamp>
<ack>Failure</ack>
<correlationId>aa06daf9a0985</correlationId>
<build>2279004</build>
</responseEnvelope><error><errorId>520003</errorId>

<domain>PLATFORM</domain>
<subdomain>Application</subdomain>
<severity>Error</severity>
<category>Application</category>
<message>Authentication failed. API credentials are incorrect.</message>

</error></ns3:FaultMessage>

任何人都可以帮助我,为什么我会收到此错误,或者可以给我一些示例如何从paypal获取交易详情。

1 个答案:

答案 0 :(得分:2)

请求付款明细的正确方法是:

httppost.setHeader("X-PAYPAL-SECURITY-USERID", "parth_1325956186_biz_api1.bcod.co.in");
httppost.setHeader("X-PAYPAL-SECURITY-PASSWORD", "334367211");
httppost.setHeader("X-PAYPAL-SECURITY-SIGNATURE", "An5ns1Kso7MUDHR4ErQKJJJ4qi4-AI0T5BBCHc3gWzBV9Q81jcP6LFD6");
httppost.setHeader("X-PAYPAL-APPLICATION-ID", "APP-80W284485P519543T");
httppost.setHeader("X-PAYPAL-REQUEST-DATA-FORMAT", "NV");
httppost.setHeader("X-PAYPAL-RESPONSE-DATA-FORMAT", "NV");

并设置正文内容:

List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("payKey", "AP-4DJ54615WA356150J"));
nameValuePairs.add(new BasicNameValuePair("requestEnvelope.errorLanguage", "en_US"));

然后正常执行。