2014-09-30 35 views
0

我正在做一个android应用程序。我使用PayPalPayment.class与贝宝连接,我想报告她出售的描述,因为它出现在更多细节中。我的代码如何从android应用程序报告paypal中的描述?

部分:

PayPalPayment thingToBuy = new PayPalPayment(new BigDecimal("4.99"), "EUR", "Datos de contacto - "+pro.getTitulo()); 

Intent intent = new Intent(InfoProyecto.this, PaymentActivity.class); 

intent.putExtra(PaymentActivity.EXTRA_PAYPAL_ENVIRONMENT, CONFIG_ENVIRONMENT); 
intent.putExtra(PaymentActivity.EXTRA_CLIENT_ID, CONFIG_CLIENT_ID); 
intent.putExtra(PaymentActivity.EXTRA_RECEIVER_EMAIL, CONFIG_RECEIVER_EMAIL); 
// It's important to repeat the clientId here so that the SDK has it if Android restarts your 
// app midway through the payment UI flow. 
intent.putExtra(PaymentActivity.EXTRA_CLIENT_ID, "APP-80W284485P519543T"); 
intent.putExtra(PaymentActivity.EXTRA_PAYER_ID, "your-customer-id-in-your-system"); 
intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy); 

startActivityForResult(intent, 0); 

回答

0

尝试这种方式

Intent intent = new Intent(this, PayPalService.class);   
intent.putExtra(PaymentActivity.EXTRA_PAYPAL_ENVIRONMENT, CONFIG_ENVIRONMENT); 
intent.putExtra(PaymentActivity.EXTRA_CLIENT_ID, CONFIG_CLIENT_ID); 
intent.putExtra(PaymentActivity.EXTRA_RECEIVER_EMAIL, CONFIG_RECEIVER_EMAIL);   
startService(intent); 

onCreate()

public void onBuyPressed(View pressed) { 
    Double amount=Double.parseDouble(Amount.toString()); 

    PayPalPayment thingToBuy = new PayPalPayment(new BigDecimal(String.valueOf(amount)), "NOK","ITEM_S");   
    Intent intent = new Intent(this, PaymentActivity.class);   
    intent.putExtra(PaymentActivity.EXTRA_PAYPAL_ENVIRONMENT, CONFIG_ENVIRONMENT); 
    intent.putExtra(PaymentActivity.EXTRA_CLIENT_ID, CONFIG_CLIENT_ID); 
    intent.putExtra(PaymentActivity.EXTRA_RECEIVER_EMAIL, CONFIG_RECEIVER_EMAIL); 
    intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy); 

    startActivityForResult(intent, 0); 
} 



public void onBuyPressed(View pressed) { 
    Double amount=Double.parseDouble(Amount.toString()); 

    PayPalPayment thingToBuy = new PayPalPayment(new BigDecimal(String.valueOf(amount)), "NOK","ITEM_S");   
    Intent intent = new Intent(this, PaymentActivity.class);   
    intent.putExtra(PaymentActivity.EXTRA_PAYPAL_ENVIRONMENT, CONFIG_ENVIRONMENT); 
    intent.putExtra(PaymentActivity.EXTRA_CLIENT_ID, CONFIG_CLIENT_ID); 
    intent.putExtra(PaymentActivity.EXTRA_RECEIVER_EMAIL, CONFIG_RECEIVER_EMAIL); 
    intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy); 

    startActivityForResult(intent, 0); 
} 

@Override 
protected void onActivityResult (int requestCode, int resultCode, Intent data) { 
    if (resultCode == Activity.RESULT_OK) { 
     PaymentConfirmation confirm = data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION); 
     if (confirm != null) { 
      try { 
       Log.i("paymentExample", confirm.toJSONObject().toString(4)); 


       JSONObject json=confirm.toJSONObject(); 
       JSONObject payment=json.getJSONObject("payment"); 
       String product=payment.getString("short_description"); 
       String amount=payment.getString("amount").substring(0, 5); 
       String currency_code=payment.getString("currency_code"); 
       //Toast.makeText(getBaseContext(), "Payment for "+product+" is done sucessfully. Amount of "+amount+" "+currency_code+" has been charged ..!!" , Toast.LENGTH_LONG).show(); 
       tv.setText(getResources().getString(R.string.Payment_for)+product+""+getResources().getString(R.string.has_been_charge)+""+getResources().getString(R.string.Amount)+amount+ 
         " "+currency_code+getResources().getString(R.string.has_been_charge)); 
       new ACtivate_POST().execute(); 
      } catch (JSONException e) { 
       Log.e("paymentExample", "an extremely unlikely failure occurred: ", e); 
      } 
     } 
    } 
    else if (resultCode == Activity.RESULT_CANCELED) { 
     Log.i("paymentExample", "The user canceled."); 
     Toast.makeText(this,"transaksjonen avbrutt.",Toast.LENGTH_LONG).show(); 
    } 
    else if (resultCode == PaymentActivity.RESULT_PAYMENT_INVALID) { 
     Log.i("paymentExample", "An invalid payment was submitted. Please see the docs."); 
     Toast.makeText(this,"En ugyldig betalingen ble sendt. Vennligst se docs.",Toast.LENGTH_LONG).show(); 
    } 
} 
+0

THX你的答案。现在,我可以采取“付款密钥” – 2014-10-07 10:41:57

+0

@CarlosSierraGarcia你会得到一个“交易ID”(支付ID)成功支付后 – Gattsu 2014-10-07 10:43:27

相关问题