0

通常在网站上,我们可以设置一个通知 URL 来使用 paypal 服务器检查付款。但是我们如何在应用程序中设置它?我是贝宝应用程序支付的超级新手。

我正在使用 MEP.PayPal

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch(resultCode) {
    case Activity.RESULT_OK:
        String payKey = data.getStringExtra(PayPalActivity.EXTRA_PAY_KEY);
        data.getStringExtra(PayPalActivity.EXTRA_PAY_KEY);
        Toast.makeText(this,"Paymnet Successful : " + payKey,Toast.LENGTH_LONG).show();
        //finish();
        break;
    case Activity.RESULT_CANCELED:
        Toast.makeText(this,"Paymnet Cancel",Toast.LENGTH_LONG).show();
        //finish();
        break;
    case PayPalActivity.RESULT_FAILURE:
        Toast.makeText(this,"Paymnet Failed",Toast.LENGTH_LONG).show();
        String errorID = 
        data.getStringExtra(PayPalActivity.EXTRA_ERROR_ID);
        String errorMessage = 
        data.getStringExtra(PayPalActivity.EXTRA_ERROR_MESSAGE);
        //Toast.makeText(getApplicationContext(),errorMessage, Toast.LENGTH_LONG).show();
        //finish();
        break;
    }
}

因此,在 Activity.RESULT_OK 下,我想向我的通知 URL 发送一个帖子,以便 URL 中的代码可以验证付款。

另外,我知道paykey可以返回交易细节。如果是这样,那么我将使用它来进行验证,而不是使用通知 url。但是经过大量阅读,我仍然找不到返回交易详细信息的答案,例如 data.getStringExtra('transaction_id')、data.getStringExtra('merchant_name') 等。

4

1 回答 1

0

在这里阅读这篇文章后,在 android 中使用 Pay-key 来自 paypal 的交易详情

我能够想出我的解决方案。但我必须创建 ASYNC 类才能使其工作。

所以它是这样的

public class MyPaypalActivity extends Activity implements OnClickListener {
String resultExtra;

//some methods you can fill in yourself to integrate with paypal

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch(resultCode) {
    case Activity.RESULT_OK:
        String payKey = data.getStringExtra(PayPalActivity.EXTRA_PAY_KEY);
        data.getStringExtra(PayPalActivity.EXTRA_PAY_KEY);
        resultExtra = data.getStringExtra(PayPalActivity.EXTRA_PAY_KEY);
        new RetreivePaypalData().execute(resultExtra);

        break;
    case Activity.RESULT_CANCELED:

        break;
    case PayPalActivity.RESULT_FAILURE:
        Toast.makeText(this,"Paymnet Failed",Toast.LENGTH_LONG).show();
        String errorID = 
        data.getStringExtra(PayPalActivity.EXTRA_ERROR_ID);
        String errorMessage = 
        data.getStringExtra(PayPalActivity.EXTRA_ERROR_MESSAGE);

        break;
    }
}

    class RetreivePaypalData extends AsyncTask<String, Void, String> {

           private Exception exception;

           protected String doInBackground(String... args) {
               try{

                   HttpPost httppost = null;
                   httppost = new HttpPost("https://svcs.sandbox.paypal.com/AdaptivePayments/PaymentDetails");



                   httppost.setHeader("X-PAYPAL-SECURITY-USERID", "mybusiness_blalbal.fff.cm");
                   httppost.setHeader("X-PAYPAL-SECURITY-PASSWORD", "3243535554");
                   httppost.setHeader("X-PAYPAL-SECURITY-SIGNATURE", "AR908E09RG7H0G0GREJ3GH9GHGHDFKGHGIHE99GFDIGHIH34ERGHI");
                   httppost.setHeader("X-PAYPAL-APPLICATION-ID", "APP-80W284485P519543T");
                   httppost.setHeader("X-PAYPAL-REQUEST-DATA-FORMAT", "NV");
                   httppost.setHeader("X-PAYPAL-RESPONSE-DATA-FORMAT", "NV");








                       // Add your data
                       List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();

                       nameValuePairs.add(new BasicNameValuePair("payKey", resultExtra));
                       nameValuePairs.add(new BasicNameValuePair("requestEnvelope.errorLanguage", "en_US"));

                       httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                   HttpResponse response = Client.getInstance().execute(httppost);
                   HttpEntity entity = response.getEntity();
                   InputStream is = entity.getContent();
                   byte[] data1;
                   data1 = new byte[256];
                   StringBuffer 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("Got Error","error "+ e );
                   }
                   Log.e("Paykey","resultExtra "+ resultExtra );
                   return null;
           }

           protected void onPostExecute(String d) {
               // TODO: check this.exception 
               // TODO: do something with the data
           }
        }
}

只是一个粗略的解决方案。需要调整。

于 2013-05-07T02:12:29.107 回答