问题描述
需求如下:1)选择PayPal支付提交订单后跳转到PayPal登陆支付,返回的参数做保存判断.1)根据保存的交易号或者事务号做退款操作已经找到了PayPal给的接口实例,但是他喵的我真的没找到哪里给我跳转弹窗出PayPal页面的代码。文档读的一阵阵蛋疼,贴出部分实例代码如下://##Create//SampleshowingtocreateaPaymentusingPayPal//付款实例@OverrideprotectedvoiddoPost(HttpServletRequestreq,HttpServletResponseresp)throwsServletException,IOException{//
解决方案二:
AccessToken//Retrievetheaccesstokenfrom//OAuthTokenCredentialbypassingin//ClientIDandClientSecret//获取访问令牌APIContextapiContext=null;StringaccessToken=null;try{//根据clientIDclientSecret获取令牌accessToken=GenerateAccessToken.getAccessToken();//
解决方案三:
ApiContext//Passina`ApiContext`objecttoauthenticate//thecallandtosendauniquerequestid//(thatensuresidempotency).TheSDKgenerates//arequestidifyoudonotpassoneexplicitly.//根据accessToken获取API上下文apiContext=newAPIContext(accessToken);//Usethisvariantifyouwanttopassinarequestid//thatismeaningfulinyourapplication,ideally//aorderid./**StringrequestId=Long.toString(System.nanoTime();APIContext*apiContext=newAPIContext(accessToken,requestId));*/}catch(PayPalRESTExceptione){req.setAttribute("error",e.getMessage());}//如果PayerID不为null,是从PayPal跳转回来的,执行支付if(req.getParameter("PayerID")!=null){Paymentpayment=newPayment();if(req.getParameter("guid")!=null){payment.setId(map.get(req.getParameter("guid")));}PaymentExecutionpaymentExecution=newPaymentExecution();paymentExecution.setPayerId(req.getParameter("PayerID"));try{payment.execute(apiContext,paymentExecution);req.setAttribute("response",Payment.getLastResponse());}catch(PayPalRESTExceptione){req.setAttribute("error",e.getMessage());}}else{//
解决方案四:
Payer//AresourcerepresentingaPayerthatfundsapayment//PaymentMethod//as'paypal'Payerpayer=newPayer();payer.setPaymentMethod("paypal");/*Randomrndm=newRandom();//第一种int转String非常规方法,int为低阶数据类型,String为高阶,低到高自动转换,高到低需牵制转换StringintTostr=rndm.nextInt(10000)+"";StringintTostr1=String.valueOf(rndm.nextInt(10000));StringintTostr2=Integer.toString(rndm.nextInt(10000));*///
解决方案五:
Details//Let'syouspecifydetailsofapaymentamount.Detailsdetails=newDetails();details.setShipping("1");//运费details.setSubtotal("5");//小计,商品总价details.setTax("1");//税//
解决方案六:
Amount//Let'syouspecifyapaymentamount.//总金额Amountamount=newAmount();amount.setCurrency("USD");//货币//Totalmustbeequaltosumofshipping,taxandsubtotal.amount.setTotal("7");//订单总计amount.setDetails(details);//
解决方案七:
Transaction//Atransactiondefinesthecontractofa//payment-whatisthepaymentforandwho//isfulfillingit.Transactioniscreatedwith//a`Payee`and`Amount`types//事物Transactiontransaction=newTransaction();transaction.setAmount(amount);transaction.setDescription("Thisisthepaymenttransactiondescription.");//ThePaymentcreationAPIrequiresalistof//Transaction;addthecreated`Transaction`//toaListList<Transaction>transactions=newArrayList<Transaction>();transactions.add(transaction);//
解决方案八:
Payment//APaymentResource;createoneusing//theabovetypesandintentas'sale'Paymentpayment=newPayment();payment.setIntent("sale");payment.setPayer(payer);payment.setTransactions(transactions);//
解决方案九:
RedirectURLs//跳转地址RedirectUrlsredirectUrls=newRedirectUrls();Stringguid=UUID.randomUUID().toString().replaceAll("-","");//getScheme()返回协议名称例如http//getContextPath()解决相对路径的问题,可返回站点根目录redirectUrls.setCancelUrl(req.getScheme()+"://"+req.getServerName()+":"+req.getServerPort()+req.getContextPath()+"/paymentwithpaypal?guid="+guid);redirectUrls.setReturnUrl(req.getScheme()+"://"+req.getServerName()+":"+req.getServerPort()+req.getContextPath()+"/paymentwithpaypal?guid="+guid);payment.setRedirectUrls(redirectUrls);//CreateapaymentbypostingtotheAPIService//usingavalidAccessToken//Thereturnobjectcontainsthestatus;try{HttpSessionsession=req.getSession();PaymentcreatedPayment=payment.create(apiContext);LOGGER.info("Createdpaymentwithid="+createdPayment.getId()+"andstatus="+createdPayment.getState());//
解决方案十:
PaymentApprovalUrlIterator<Links>links=createdPayment.getLinks().iterator();while(links.hasNext()){Linkslink=links.next();if(link.getRel().equalsIgnoreCase("approval_url")){req.setAttribute("redirectURL",link.getHref());System.out.println(link.getHref());session.setAttribute("guid",createdPayment.getId());//returnredirectUrls.setReturnUrl(link.getHref());}}System.out.println(Payment.getLastResponse());req.setAttribute("response",Payment.getLastResponse());map.put(guid,createdPayment.getId());}catch(PayPalRESTExceptione){req.setAttribute("error",e.getMessage());}}req.setAttribute("request",Payment.getLastRequest());req.getRequestDispatcher("response.jsp").forward(req,resp);}
解决方案
解决方案十一:
catch之后的那部分莫名其妙被注释了。。大家应该看得懂吧~
解决方案十二:
主要是你的注释太坑爹了,,,不要两种都用,用其中一种不是好看些吗??可读性高很多