gpt4 book ai didi

java - 玩!框架支付处理(电子商务/ Paypal )

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:42:14 28 4
gpt4 key购买 nike

我希望构建一个用户能够从我的站点购买产品的应用程序。购买将包括他们购买的实物、运输、税收(如果适用)等。我知道 PayPal 有许多付款选项,其中一个是 Web 服务,另一个只是重定向到他们的网站。我希望用户体验尽可能无缝,但我不想涉足存储信用卡等业务。

如果我确实在我的服务器上处理交易(使用安全连接/SSL),我是否会承担将信用卡信息传递给他们的服务进行处理的风险?

最佳答案

玩吧! Framework v1.2 对WebServices 有很好的支持。 Play 没有paypal 模块,但是代码写起来并不复杂。我为我们的招聘网站 (www.express-board.fr) 实现了 Web 服务解决方案,用了 3 天时间。

首先:用户总是被重定向到 Paypal 网站。没有面向 paypal 客户端的解决方案。如果您选择 Web 服务解决方案 (developer.paypal.com),您可以使用您的 Logo 自定义 paypal 网页。不是最好的解决方案,但它有效。

在 Play 方面,这是使用 Paypal Web 服务的结帐方法的示例代码:

 public static void checkout() {
Double amount = Double.parseDouble(session.get("amount"));
Long userId = Long.parseLong(session.get("user-id"));
User user = User.findById(userId);
if (user != null) {
renderArgs.put("user", user);
}

// we calculate the net and gross amount with French V.A.T (19.6%)
BigDecimal amountBD = new BigDecimal(amount * 1.196);
BigDecimal netAmountBD = new BigDecimal(amount);
BigDecimal taxAmountBD = amountBD.subtract(netAmountBD);

String netAmount = netAmountBD.setScale(2, BigDecimal.ROUND_HALF_EVEN).toString();
String totalAmount = amountBD.setScale(2, BigDecimal.ROUND_HALF_EVEN).toString();
String taxAmount = taxAmountBD.setScale(2, BigDecimal.ROUND_HALF_EVEN).toString();

String subject="Publication d'une offre d'emploi";


// Paypal Web service callback executed by Play!
// I have a paypal.api.server configuration property with prod and sandbox server

WS.HttpResponse res = WS.url(Play.configuration.get("paypal.api.server").toString() +
"&USER=%s" +
"&PWD=%s" +
"&SIGNATURE=%s" +
"&VERSION=%s" +
"&METHOD=%s" +
"&PAYMENTREQUEST_0_PAYMENTACTION=%s" +
"&LANDINGPAGE=%s" +
"&SOLUTIONTYPE=%s" +
"&EMAIL=%s" +
"&FIRSTNAME=%s" +
"&LASTNAME=%s" +
"&STREET=%s" +
"&STREET2=%s" +
"&CITY=%s" +
"&ZIP=%s" +
"&STATE=%s" +
"&PAYMENTREQUEST_0_CURRENCYCODE=%s" +
"&MAXAMT=%s" +
"&PAYMENTREQUEST_0_AMT=%s" +
"&PAYMENTREQUEST_0_ITEMAMT=%s" +
"&PAYMENTREQUEST_0_TAXAMT=%s" +
"&PAYMENTREQUEST_0_DESC=%s" +
"&L_PAYMENTREQUEST_0_NAME0=%s" +
"&L_PAYMENTREQUEST_0_NUMER0=%s" +
"&L_PAYMENTREQUEST_0_DESC0=%s" +
"&L_PAYMENTREQUEST_0_AMT0=%s" +
"&L_PAYMENTREQUEST_0_QTY0=%s" +

"&NOSHIPPING=%s" +
"&LOCALECODE=%s" +
"&RETURNURL=%s" +
"&CANCELURL=%s" +
"&ADDROVERRIDE=%s" +
"&BRANDNAME=%s"
,
//-------
Play.configuration.get("paypal.api.username").toString(),
Play.configuration.get("paypal.api.password").toString(),
Play.configuration.get("paypal.api.signature").toString(),
"69.0", // API Version
"SetExpressCheckout", //Method
"Sale",
"Billing",
"Sole",
user.email,
"" + user.fullname,
"" + user.fullname,
"" + user.postalAddress,
"" + user.postalAddress2,
"" + user.city,
"" + user.zip,
"None",
"EUR",
totalAmount, //MaxAMT
totalAmount, //amount.toString()
netAmount, //PAYMENTREQUEST_n_ITEMAMT
taxAmount,
subject,
//---------
"Item name",
"1",
subject,
netAmount,
"1",
//---------
"1",
"FR",
Play.configuration.get("paypal.returnUrl").toString(),
Play.configuration.get("paypal.cancelPay").toString(),
"1", //ADDROVERRIDE
"eXpress-Board pour Innoteria"
).get();


String message = res.getString();
PaypalResponse paypalResponse = new PaypalResponse(message);
if (paypalResponse.isSuccess()) {
Payment payment = new Payment();
payment.userId = user.id;
payment.totalAmount = totalAmount;
payment.netAmount = netAmount;
payment.taxAmount = taxAmount;
payment.token = paypalResponse.getToken();
payment.correlationID = paypalResponse.getCorrelationID();
payment.save();

redirect(Play.configuration.get("paypal.api.http").toString() + "/cgi-bin/webscr?cmd=_express-checkout&token=" + paypalResponse.getToken());
}

Logger.error("Error on SetExpressCheckout with: ");
for (String tokens : message.split("&")) {
try {
Logger.error(URLDecoder.decode(tokens, "UTF-8"));
} catch (UnsupportedEncodingException e) {
}
}

error("Error from Paypal");

}

希望对你有帮助

关于java - 玩!框架支付处理(电子商务/ Paypal ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9982894/

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