Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to pass data in a class to another member?
    primarykey
    data
    text
    <p>I have this code and I am trying to pass <code>this.thecost</code> to the <code>public void click()</code> method but it looks like it is not working because I receive "Paymnet Failed" when click the paypal button.</p> <p>What did i go wrong?</p> <p>by the way, what do you call the <code>private {}</code>, <code>private void {}</code> - all those function() looking thing?</p> <pre><code>private void initUI(int theprice) { launchPayPalButton = mPayPal.getCheckoutButton(this, PayPal.BUTTON_278x43, CheckoutButton.TEXT_PAY); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); params.bottomMargin = theprice; this.thecost = theprice; launchPayPalButton.setLayoutParams(params); launchPayPalButton.setOnClickListener(this); ((LinearLayout)findViewById(R.id.main_layout2)).addView(launchPayPalButton); } public void onClick(View v) { payWithPaypal(this.thecost); } private void payWithPaypal(Integer gg) { PayPalPayment newPayment = new PayPalPayment(); BigDecimal bigDecimal=new BigDecimal(gg); newPayment.setSubtotal(bigDecimal); newPayment.setCurrencyType(Currency.getInstance(Locale.US)); newPayment.setRecipient("email@hotmail.com"); newPayment.setMerchantName("My Merchant"); Intent paypalIntent = PayPal.getInstance().checkout(newPayment, this); this.startActivityForResult(paypalIntent, 1); } @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",Toast.LENGTH_LONG).show(); break; case Activity.RESULT_CANCELED: Toast.makeText(this,"Paymnet Cancel",Toast.LENGTH_LONG).show(); 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; } </code></pre> <p>EDITED: I call initUI() at the oncreate method</p> <p>EDITED AGAIN: I change the global variable to 'double' because the price usually have decimal place. Now i tried to toast the value and i see the error much clearer. The toast display a message that the value that was passed is "0.0". And because of that, there is an error of 'Payment Failed' and invalid payment.</p> <pre><code>int eprice; double thecost; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.detail); //Data mSource = new Data; Intent myLocalIntent = getIntent(); Bundle myBundle = myLocalIntent.getExtras(); eprice = myBundle.getInt("eprice"); String epricetxt = myBundle.getString("eprice"); Adapter mAdapter = new Adapter(this, mSource); //details = (Data) mAdapter.getItem(pos); TextView theprice = (TextView) findViewById(R.id.priceTxt); theprice.setText("Price: $" + epricetxt); this.setCost(eprice); this.thecost = eprice; //Paypal mPayPal=PayPal.initWithAppID(this,Constants.PAYPAL_APP_ID,PayPal.ENV_SANDBOX); initUI(eprice); } private void initUI(int theprice) { launchPayPalButton = mPayPal.getCheckoutButton(this, PayPal.BUTTON_278x43, CheckoutButton.TEXT_PAY); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); params.bottomMargin = theprice; this.thecost = theprice; launchPayPalButton.setLayoutParams(params); launchPayPalButton.setOnClickListener(this); ((LinearLayout)findViewById(R.id.main_layout2)).addView(launchPayPalButton); } public void onClick(View v) { // payWithPaypal(getCost()); } public void setCost(int cost) { this.thecost = cost; } public double getCost() { return this.thecost; } private void payWithPaypal(Double gg) { PayPalPayment newPayment = new PayPalPayment(); Toast.makeText(getApplicationContext(),gg.toString(), Toast.LENGTH_LONG).show(); BigDecimal bigDecimal=new BigDecimal(gg); newPayment.setSubtotal(bigDecimal); newPayment.setCurrencyType(Currency.getInstance(Locale.US)); newPayment.setRecipient("email@hotmail.com"); newPayment.setMerchantName("My Merchant"); Intent paypalIntent = PayPal.getInstance().checkout(newPayment, this); this.startActivityForResult(paypalIntent, 1); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload