通常在网站上,我们可以设置通知网址来检查使用paypal服务器付款。但是我们如何在应用程序中设置它?我是paypal app付款的新手。
我正在使用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下,我想将帖子发送到我的通知网址,以便网址中的代码可以验证付款。
另外,我知道paykey可以返回交易详情。如果是这样,那么我将使用它来进行验证,而不是使用通知网址。但经过多次阅读后,我仍然无法找到返回交易详情的答案,例如data.getStringExtra('transaction_id'),data.getStringExtra('merchant_name')等。
答案 0 :(得分:0)
在此阅读此帖后Transaction details from paypal using Pay-key in android
我能够提出我的解决方案。但我必须创建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
}
}
}
只是一个粗略的解决方案。需要调整。