【问题标题】:Print invoice and redirect back to page in JSF page打印发票并重定向回 JSF 页面中的页面
【发布时间】:2015-10-23 05:31:25
【问题描述】:

我使用 JSF 创建了这个简单的 PayPal 快速结账示例:

xhtml:

<h:form target="_blank">
    <h:commandButton value="paypal" action="#{pricingCalculator.initPayPal}" image="https://www.sandbox.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif"/>
</h:form>

Java 代码:

public void initPayPal() throws SSLConfigurationException, InvalidCredentialException, IOException, HttpErrorException, InvalidResponseDataException, ClientActionRequiredException, MissingCredentialException, InterruptedException, OAuthException, ParserConfigurationException, com.paypal.exception.SSLConfigurationException, com.paypal.exception.InvalidCredentialException, com.paypal.exception.HttpErrorException, com.paypal.exception.InvalidResponseDataException, com.paypal.exception.ClientActionRequiredException, com.paypal.exception.MissingCredentialException, com.paypal.sdk.exceptions.OAuthException, org.xml.sax.SAXException
    {
        PaymentDetailsType paymentDetails = new PaymentDetailsType();
        paymentDetails.setPaymentAction(PaymentActionCodeType.fromValue("Sale"));
        PaymentDetailsItemType item = new PaymentDetailsItemType();
        BasicAmountType amt = new BasicAmountType();
        amt.setCurrencyID(CurrencyCodeType.fromValue("USD"));
        double itemAmount = 1.00;
        amt.setValue(String.valueOf(itemAmount));
        int itemQuantity = 1;
        item.setQuantity(itemQuantity);
        item.setName("item");
        item.setAmount(amt);

        List<PaymentDetailsItemType> lineItems = new ArrayList<PaymentDetailsItemType>();
        lineItems.add(item);
        paymentDetails.setPaymentDetailsItem(lineItems);
        BasicAmountType orderTotal = new BasicAmountType();
        orderTotal.setCurrencyID(CurrencyCodeType.fromValue("USD"));
        orderTotal.setValue(String.valueOf(itemAmount * itemQuantity));
        paymentDetails.setOrderTotal(orderTotal);
        List<PaymentDetailsType> paymentDetailsList = new ArrayList<PaymentDetailsType>();
        paymentDetailsList.add(paymentDetails);

        SetExpressCheckoutRequestDetailsType setExpressCheckoutRequestDetails = new SetExpressCheckoutRequestDetailsType();
        setExpressCheckoutRequestDetails.setReturnURL("http://devtools-paypal.com/guide/expresscheckout/java?success=true");
        setExpressCheckoutRequestDetails.setCancelURL("http://devtools-paypal.com/guide/expresscheckout/java?cancel=true");

        setExpressCheckoutRequestDetails.setPaymentDetails(paymentDetailsList);

        SetExpressCheckoutRequestType setExpressCheckoutRequest = new SetExpressCheckoutRequestType(setExpressCheckoutRequestDetails);
        setExpressCheckoutRequest.setVersion("104.0");

        SetExpressCheckoutReq setExpressCheckoutReq = new SetExpressCheckoutReq();
        setExpressCheckoutReq.setSetExpressCheckoutRequest(setExpressCheckoutRequest);

        Map<String, String> sdkConfig = new HashMap<String, String>();
        sdkConfig.put("mode", "sandbox");
        sdkConfig.put("acct1.UserName", "peter.penzov_api1.gmail.com");
        sdkConfig.put("acct1.Password", "5LQB5QHQJVKP9QKN");
        sdkConfig.put("acct1.Signature", "AFcWxV21C7fd0v3bYYYRCpSSRl31A6JqBNQNOE3.Jwxfs7nIV1jR7qcl");
        PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService(sdkConfig);
        SetExpressCheckoutResponseType setExpressCheckoutResponse = service.setExpressCheckout(setExpressCheckoutReq);

        String token = setExpressCheckoutResponse.getToken();

        String link = "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=" + token;

        ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
        externalContext.redirect(link);
    }

我可以成功付款,但是当我点击付款按钮时,我被重定向到http://devtools-paypal.com/guide/expresscheckout/java?success=true 我想打印 Paypal 发票?我需要添加什么 Java 代码?

在我成功付款后,我想被重定向回 JSF 页面,但使用旧数据。如何保存旧数据?也许我必须使用会话范围 bean?

【问题讨论】:

  • 是的,使用会话 bean 或 viewescoped。都是基本的 jsf 东西,与贝宝无关。就像贝宝问题部分与 jsf 无关。请集中你的问题(= 除了知道它是什么,关于,每个问题还有一个问题)

标签: jsf paypal paypal-sandbox jsf-2.2 paypal-rest-sdk


【解决方案1】:

在 SetExpressCheckout 中,只需将返回 URL 更改为您自己的返回 URL 即可。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多