gpt4 book ai didi

java - 在 Paypal Express 结帐中添加多个项目

转载 作者:太空宇宙 更新时间:2023-11-03 16:00:17 25 4
gpt4 key购买 nike

我想将第二个项目添加到我用于快速结账的 Java 代码中:

public void initPayPal() 
{
PaymentDetailsType paymentDetails = new PaymentDetailsType();
paymentDetails.setPaymentAction(PaymentActionCodeType.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);
}

如何将第二个项目添加到项目列表中:

enter image description here

这个问题有什么解决办法吗?

我找不到任何可以用来解决问题的好例子?

附言

我测试了这段代码:

public void initPayPal()
{
PaymentDetailsType paymentDetails = new PaymentDetailsType();
paymentDetails.setPaymentAction(PaymentActionCodeType.SALE);
PaymentDetailsItemType item = new PaymentDetailsItemType();
BasicAmountType amt = new BasicAmountType();
amt.setCurrencyID(CurrencyCodeType.fromValue("USD"));
amt.setValue(String.valueOf(totalPrice));
int itemQuantity = 1;
item.setQuantity(itemQuantity);
item.setName("item 1");
item.setAmount(amt);

//this is now "item2"
PaymentDetailsItemType item2 = new PaymentDetailsItemType();
BasicAmountType amt2 = new BasicAmountType();
amt2.setCurrencyID(CurrencyCodeType.fromValue("USD"));
double itemAmount2 = 1.00;
amt2.setValue(String.valueOf(itemAmount2));
int itemQuantity2 = 1;
item2.setQuantity(itemQuantity2);
item2.setName("item 2");
item2.setAmount(amt2);

//add item2 to your lineItems List
List<PaymentDetailsItemType> lineItems = new ArrayList<PaymentDetailsItemType>();
lineItems.add(item);
lineItems.add(item2);

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

SetExpressCheckoutRequestDetailsType setExpressCheckoutRequestDetails = new SetExpressCheckoutRequestDetailsType();
setExpressCheckoutRequestDetails.setReturnURL("http://52.25.168.28:8080/Web_site/summary_payment.xhtml");
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);
}

获取错误 此交易无效。请返回收款人的网站,使用他们的常规结账流程完成您的交易。

最佳答案

不是 Java 开发人员,但快速的答案是添加另一个 PaymentDetailsItemType item到您的列表 List<PaymentDetailsItemType> lineItems

因此取自您上面的代码:

//this is now "item2"
PaymentDetailsItemType item2 = new PaymentDetailsItemType();
BasicAmountType amt2 = new BasicAmountType();
amt2.setCurrencyID(CurrencyCodeType.fromValue("USD"));
double itemAmount2 = 1.00;
amt2.setValue(String.valueOf(itemAmount2));
int itemQuantity2 = 1;
item2.setQuantity(itemQuantity2);
item2.setName("item 2");
item2.setAmount(amt2);

//add item2 to your lineItems List
lineItems.add(item2);

嗯..

关于java - 在 Paypal Express 结帐中添加多个项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31763262/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com