Paypal:查看哪个用户付款



我正在开发一个基于Spring的Java应用程序,在这个应用程序中我能够成功地集成paypal。我们有一个基于课程注册的网站,用户在那里注册。现在我稍微修改了一下支付方式,所以从前端我也会收到哪个学生在尝试支付哪个课程。检查数据库中的课程费用,我可以设置费用,并执行付款。

问题是,哪个用户付钱了,这是我还不知道的。是否有任何方法,在请求中添加一个自定义整数字段,贝宝的响应,这样我就可以提取这些信息,并做下一步,以确保学生也标记为"支付"在我的后端。请告诉我……

Paypal代码:
public Payment createPayment(HttpServletRequest req, HttpServletResponse resp, String abc) {
        System.out.println("String abc is "+abc);
        InputStream is = TestPayment.class
                .getResourceAsStream("/sdk_config.properties");
        try {
            PayPalResource.initConfig(is);
        } catch (PayPalRESTException e) {
            LOGGER.fatal(e.getMessage());
        }
        Payment createdPayment = null;
        APIContext apiContext = null;
        String accessToken = null;
        try {
            accessToken = GenerateAccessToken.getAccessToken();
            apiContext = new APIContext(accessToken);
        } catch (PayPalRESTException e) {
            req.setAttribute("error", e.getMessage());
        }
        if (req.getParameter("PayerID") != null) {
            Payment payment = new Payment();
            if (req.getParameter("guid") != null) {
                payment.setId(map.get(req.getParameter("guid")));
            }
            PaymentExecution paymentExecution = new PaymentExecution();
            paymentExecution.setPayerId(req.getParameter("PayerID"));
            try {
                createdPayment = payment.execute(apiContext, paymentExecution);
                //ResultPrinter.addResult(req, resp, "Executed The Payment", Payment.getLastRequest(), Payment.getLastResponse(), null);
            } catch (PayPalRESTException e) {
              //  ResultPrinter.addResult(req, resp, "Executed The Payment", Payment.getLastRequest(), null, e.getMessage());
            }
        } else {
            Details details = new Details();
            details.setShipping("1");
            details.setSubtotal("5");
            details.setTax("1");

            Amount amount = new Amount();
            amount.setCurrency("EUR");
            // Total must be equal to sum of shipping, tax and subtotal.
            amount.setTotal("7");
            amount.setDetails(details);
            // ###Transaction
            // A transaction defines the contract of a
            // payment - what is the payment for and who
            // is fulfilling it. Transaction is created with
            // a `Payee` and `Amount` types
            Transaction transaction = new Transaction();
            transaction.setAmount(amount);
            transaction
                    .setDescription("This is the payment transaction description.");
            // ### Items
            Item item = new Item();
            item.setName("Online Market").setQuantity("1").setCurrency("EUR").setPrice("5");
            ItemList itemList = new ItemList();
            List<Item> items = new ArrayList<Item>();
            items.add(item);
            itemList.setItems(items);
            transaction.setItemList(itemList);
            // The Payment creation API requires a list of
            // Transaction; add the created `Transaction`
            // to a List
            List<Transaction> transactions = new ArrayList<Transaction>();
            transactions.add(transaction);
            // ###Payer
            // A resource representing a Payer that funds a payment
            // Payment Method
            // as 'paypal'
            Payer payer = new Payer();
            payer.setPaymentMethod("paypal");
            // ###Payment
            // A Payment Resource; create one using
            // the above types and intent as 'sale'
            Payment payment = new Payment();
            payment.setIntent("sale");
            payment.setPayer(payer);
            payment.setTransactions(transactions);
            // ###Redirect URLs
            RedirectUrls redirectUrls = new RedirectUrls();
            String guid = UUID.randomUUID().toString().replaceAll("-", "");
            redirectUrls.setCancelUrl(req.getScheme() + "://"
                    + req.getServerName() + ":" + req.getServerPort()
                    + req.getContextPath() + "/paymentcancelled");
            redirectUrls.setReturnUrl(req.getScheme() + "://"
                    + req.getServerName() + ":" + req.getServerPort()
                    + req.getContextPath() + "/successpayment");
            payment.setRedirectUrls(redirectUrls);
            // Create a payment by posting to the APIService
            // using a valid AccessToken
            // The return object contains the status;
            try {
                createdPayment = payment.create(apiContext);
               /* LOGGER.info("Created payment with id = "
                        + createdPayment.getId() + " and status = "
                        + createdPayment.getState());*/
                // ###Payment Approval Url
                Iterator<Links> links = createdPayment.getLinks().iterator();
                while (links.hasNext()) {
                    Links link = links.next();
                    if (link.getRel().equalsIgnoreCase("approval_url")) {
                        req.setAttribute("redirectURL", link.getHref());
                    }
                }
             //   ResultPrinter.addResult(req, resp, "Payment with PayPal", Payment.getLastRequest(), Payment.getLastResponse(), null);
                map.put(guid, createdPayment.getId());
            } catch (PayPalRESTException e) {
               // ResultPrinter.addResult(req, resp, "Payment with PayPal", Payment.getLastRequest(), null, e.getMessage());
            }
        }
        return createdPayment;
    } 

请告诉我。非常感谢。

在Transaction对象中设置"custom"字段

https://developer.paypal.com/webapps/developer/docs/release-notes/更新- - - - - - - 5 - 8月- 2014年

最新更新