Java PayPal支付接口,疑问~求解答

问题描述

需求如下: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之后的那部分莫名其妙被注释了。。大家应该看得懂吧~
解决方案十二:
主要是你的注释太坑爹了,,,不要两种都用,用其中一种不是好看些吗??可读性高很多

时间: 2024-08-02 22:47:57

Java PayPal支付接口,疑问~求解答的相关文章

多线程-php单例问题 疑问求解答

问题描述 php单例问题 疑问求解答 A.php <?php class Singleton { private static $instance; private function __construct() { echo "This is ok!rn"; } public static function GetInstance() { if (!(self::$instance instanceof self)) { self::$instance = new self();

解析PayPal支付接口的PHP开发方式

申请PayPal注册网址:https://www.paypal.com/ paypal接口与其它接口有些不同,稍微复杂一点. 其实银行接口也算是一个站点的插件. 所谓paypal ipn(Instant Payment Notification),就是Paypal开发的一种能主动通知第三方卖家系统交易状态的一种机制.IPN的原理很简单,就是当产生了一个交易之后, 交易状态发生变化时,如用户已经付款.或者退款.撤销时,Paypal利用常用的HTTP POST方式,将交易的一些变量提交给网站的某个页

c++-C++ 弦截法 有些疑问求解答

问题描述 C++ 弦截法 有些疑问求解答 弦截法中,函数各种嵌套调用,例题中所给的一元三次方程是给定的,系数定好的,那么假如我希望一元三次方程的系数是由自己输入的,但调用的函数不是不能存的么,写在主函数里,那后面的 f 函数好像也用不到了,假如 f 函数再调用一个"定系数的函数",总不能每次计算都输入一次吧... #include <iostream> #include <iomanip> #include <cmath> using namespa

测试-关于windows多语言的疑问 求解答

问题描述 关于windows多语言的疑问 求解答 我干测试也有两年了,近日来一直被windows多语言的测试所困扰,公司有一款C/S软件,需要测试多语言,测试系统兼容性,大家都知道windows是可以装语言包的. 那么在不同版本的系统上也需要测多语言么,比如在win8上测了一遍,win10上还需要测试么?windows更新从win7起提出了多语言系统的概念,到后面每次升级都没有再提了,那么是不是可以认为从win7 到win8 win8.1 乃至现在的win10.在多语言上实现是一样的. 一直找不

解析PayPal支付接口的PHP开发方式_php技巧

申请PayPal注册网址:https://www.paypal.com/ paypal接口与其它接口有些不同,稍微复杂一点. 其实银行接口也算是一个站点的插件. 所谓paypal ipn(Instant Payment Notification),就是Paypal开发的一种能主动通知第三方卖家系统交易状态的一种机制.IPN的原理很简单,就是当产生了一个交易之后, 交易状态发生变化时,如用户已经付款.或者退款.撤销时,Paypal利用常用的HTTP POST方式,将交易的一些变量提交给网站的某个页

XMPP + openfire 疑问求解答 ******

问题描述 我用agsXMPP去连接,给这个XmppClientConnection类实例也加了相应的事件处理函数,但是始终不触发式什么情况privateXmppClientConnectionXmppCon;...XmppCon.Open(); 而且就是服务器地址,账号密码随意传值,Open执行后,查看XmppCon的XmppConnectionState总是Connected 解决方案 本帖最后由 n284716246 于 2015-03-19 10:36:45 编辑解决方案二:没人...求解

httpclient的疑问求解答!

问题描述 我使用httpclient来爬去固定一些网站的数据信息,由于使用了线程池因此在抓取的时候经常碰到有异常!Exception in thread "pool-226-thread-200" java.lang.IllegalStateException: Invalid use of SingleClientConnManager: connection still allocated.Make sure to release the connection before all

JAVA中的问题,求解答

问题描述 Exceptioninthread"main"org.ejml.alg.dense.mult.MatrixDimensionException:The'a'and'b'matricesdonothavecompatibledimensionsatorg.ejml.alg.dense.mult.MatrixMatrixMult.mult_small(UnknownSource)atorg.ejml.ops.CommonOps.mult(UnknownSource)atorg.e

java-Java程序员成长疑问,求指点,求指教

问题描述 Java程序员成长疑问,求指点,求指教 大家好: 小弟做Java开发近2年,在学习成长过程中出现了迷茫,不知道该如何走下去... 目前从事电信项目的开发,主要是业务方面的开发,技术性不是很强,不知道该往哪个方面走,该学习什么,还是该如何规划下面的发展,希望各位前辈给予指点,谢谢!! 解决方案 你既然选择了这行,我建议一定要走下去,因为其它行业也不是好混的. 既然你已经做好2年开发了现在不想做是不是对行业不敢兴趣?就像我当年一样,换了行业(电商)后兴趣增加不少.仅供参考! 建议:千万不要