android - Saving offer to Google Wallet -
android - Saving offer to Google Wallet -
in app, need implement saving offer app google wallet. found tutorial: https://developers.google.com/wallet/objects/savetowalletnative#4_create_an_object , when tried implement it, encountered problem. there code page:
offerwalletobject wob = offerwalletobject .newbuilder()...
but environment says class doesn't have method. there nil written method in page: https://developer.android.com/reference/com/google/android/gms/wallet/offerwalletobject.html
can help solve problem or other method save offer in google wallet.
i have successful integrate google wallet, video. link
public class mainactivity extends actionbaractivity implements googleapiclient.connectioncallbacks, googleapiclient.onconnectionfailedlistener{ private googleapiclient mgoogleapiclient; private supportwalletfragment mwalletfregment; private supportwalletfragment mxmlwalletfregment; private maskedwallet mmaskedwallet; private fullwallet mfullwallet; public static final int masked_wallet_request_code=888; public static final int full_wallet_request_code=889; public static final string wallet_fragment_id="wallet_fragment"; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); mwalletfregment=(supportwalletfragment) getsupportfragmentmanager() .findfragmentbytag(wallet_fragment_id); walletfragmentinitparams startparams; walletfragmentinitparams.builder startparamsbuilder=walletfragmentinitparams.newbuilder() .setmaskedwalletrequest(generatemaskedwalletrequest()) .setmaskedwalletrequestcode(masked_wallet_request_code); startparams=startparamsbuilder.build(); log.e("fregment",""+mwalletfregment); if(mwalletfregment==null){ walletfragmentstyle walletfragmentstyle=new walletfragmentstyle() .setbuybuttontext(buybuttontext.buy_with_google) .setbuybuttonwidth(dimension.match_parent); walletfragmentoptions walletfragmentoptions=walletfragmentoptions.newbuilder() .setenvironment(walletconstants.environment_sandbox) .setfragmentstyle(walletfragmentstyle) .settheme(walletconstants.theme_holo_light) .setmode(walletfragmentmode.buy_button) .build(); mwalletfregment=supportwalletfragment.newinstance(walletfragmentoptions); mwalletfregment.initialize(startparams); } log.e("fregment",""+mwalletfregment); getsupportfragmentmanager().begintransaction() .replace(r.id.wallet_button_holder,mwalletfregment,wallet_fragment_id) .commit(); mgoogleapiclient=new googleapiclient.builder(this) .addconnectioncallbacks(this) .addonconnectionfailedlistener(this) .addapi(wallet.api,new wallet.walletoptions.builder() .setenvironment(walletconstants.environment_sandbox) .settheme(walletconstants.theme_holo_light) .build()) .build(); setcontentview(r.layout.activity_main); } @override protected void onstart() { mgoogleapiclient.connect(); super.onstart(); } @override protected void onactivityresult(int requestcode, int resultcode, intent data) { super.onactivityresult(requestcode, resultcode, data); switch (requestcode){ case masked_wallet_request_code : switch (resultcode){ case activity.result_ok : mmaskedwallet=data.getparcelableextra(walletconstants.extra_masked_wallet); break; case activity.result_canceled : break; default: toast.maketext(this,"an error occured",toast.length_long).show(); break; } break; case full_wallet_request_code : switch (resultcode){ case activity.result_ok : mfullwallet= data.getparcelableextra(walletconstants.extra_full_wallet); toast.maketext(this,mfullwallet.getproxycard().getpan().tostring(),toast.length_long).show(); wallet.payments.notifytransactionstatus(mgoogleapiclient, generatenotifytransactionstatusrequest(mfullwallet.getgoogletransactionid(), notifytransactionstatusrequest.status.success)); break; default: toast.maketext(this,"an error occured",toast.length_long).show(); break; } break; case walletconstants.result_error: toast.maketext(this,"an error occured",toast.length_long).show(); break; } } public static notifytransactionstatusrequest generatenotifytransactionstatusrequest( string googletransactionid,int status ){ homecoming notifytransactionstatusrequest.newbuilder() .setgoogletransactionid(googletransactionid) .setstatus(status) .build(); } private maskedwalletrequest generatemaskedwalletrequest(){ maskedwalletrequest maskwalletrequest=maskedwalletrequest.newbuilder() .setmerchantname("google i/o coadelab") .setphonenumberrequired(true) .setshippingaddressrequired(true) .setcurrencycode("inr") .setestimatedtotalprice("10.00") .setcart(cart.newbuilder() .setcurrencycode("inr") .settotalprice("10.00") .addlineitem(lineitem.newbuilder().setcurrencycode("inr") .setquantity("1") .setunitprice("10.00") .settotalprice("10.00") .build() ) .build()) .build(); homecoming maskwalletrequest; } private fullwalletrequest generatefullwalletrequest(string googletransactionid){ fullwalletrequest fullwalletrequest=fullwalletrequest.newbuilder() .setcart(cart.newbuilder() .setcurrencycode("inr") .settotalprice("10.10") .addlineitem(lineitem.newbuilder() .setcurrencycode("inr") .setquantity("1") .setunitprice("10.00") .settotalprice("10.00") .build()) .addlineitem(lineitem.newbuilder() .setcurrencycode("inr") .setdescription("tax") .setrole(lineitem.role.tax) .settotalprice(".10") .build()) .build()) .build(); homecoming fullwalletrequest; } public void requestfullwallet(view view){ if(mgoogleapiclient.isconnected()){ wallet.payments.loadfullwallet(mgoogleapiclient, generatefullwalletrequest(mmaskedwallet.getgoogletransactionid()), full_wallet_request_code); } } @override public void onconnected(bundle bundle) { } @override public void onconnectionsuspended(int i) { } @override public void onconnectionfailed(connectionresult connectionresult) { } }
hope utilize total you.
android android-pay
Comments
Post a Comment