java - How to pass data in a class to another member? -
i have code , trying pass this.thecost
public void click()
method looks not working because receive "paymnet failed" when click paypal button.
what did go wrong?
by way, phone call private {}
, private void {}
- function() looking thing?
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; }
edited: phone call initui() @ oncreate method
edited again: alter global variable 'double' because cost have decimal place. tried toast value , see error much clearer. toast display message value passed "0.0". , because of that, there error of 'payment failed' , invalid payment.
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() { homecoming 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); }
we don't have plenty info tell went wrong here. reason, paypal api returned failure status code. maybe don't have net connection?
check value of error message string retrieved in line:
string errormessage = data.getstringextra(paypalactivity.extra_error_message);
you can utilize debugger inspect it, or utilize log.e function in logger class log logcat can read it.
as sec question:
by way, phone call private {}, private void {} - function() looking thing?
in java, "function looking things" called methods.
edit: okay, you've showed oncreate method, can see getting value pass oninit here:
eprice = mybundle.getint("eprice");
doing implies saved value in bundle in onsaveinstancestate(bundle)
did that? how value when starting activity first time?
java android paypal this
No comments:
Post a Comment