【发布时间】:2018-04-01 19:13:46
【问题描述】:
我正在尝试实现支付方式 Paypal 的按钮。所以我想在网站上关注guide。我正在使用 Java 和 Play 框架 2.6。
他们在网站上提供以下代码以添加您自己的代码:
<!DOCTYPE html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://www.paypalobjects.com/api/checkout.js"></script>
</head>
<body>
<div id="paypal-button"></div>
<script>
paypal.Button.render({
env: 'production', // Or 'sandbox',
commit: true, // Show a 'Pay Now' button
payment: function() {
// Set up the payment here
},
onAuthorize: function(data, actions) {
// Execute the payment here
}
}, '#paypal-button');
</script>
</body>
我的代码有点不同,因为我的头部有一个不同的文件(称为 main.scala.html)。所以主要看起来是这样的:
@*
* This template is called from the `index` template. This template
* handles the rendering of the page header and body tags. It takes
* two arguments, a `String` for the title of the page and an `Html`
* object to insert into the body of the page.
*@
@(title: String)(content: Html)
<!DOCTYPE html>
<html lang="en">
<head>
<!-- These are the meta and scripts for paypal-->
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://www.paypalobjects.com/api/checkout.js" data-version-4></script>
@* Here's where we render the page title `String`. *@
<title>@title</title>
<!-- Loading third party fonts -->
<link href="@routes.Assets.versioned("fonts/another_font.css")" rel="stylesheet" type="text/css">
<!-- Loading weather css file -->
<link rel="stylesheet" href="@routes.Assets.versioned("stylesheets/bootstrap.css")">
<link rel="stylesheet" href="@routes.Assets.versioned("stylesheets/weather.css")">
<link rel="shortcut icon" type="image/png" href="@routes.Assets.versioned("images/favicon.png")">
<script src="@routes.Assets.versioned("javascripts/jquery-3.2.1.min.js")" type="text/javascript"></script>
<script src="@routes.Assets.versioned("javascripts/bootstrap.js")" type="text/javascript"></script>
</head>
<body>
@* And here's where we render the `Html` object containing
* the page content. *@
@content
</body>
</html>
在 Main 中为 body 调用的内容如下所示:
@main("ReStart") {
<body>
<!-- Payment Methods -->
@*TODO*@
<div class="col-md-9">
<h2>payment methodes</h2>
<div id="paypal-button"></div>
<script>
paypal.button.render({
env: 'production', // Or 'sandbox',
commit: true, // Show a 'Pay Now' button
payment: function() {
// Set up the payment here
},
onAuthorize: function(data, actions) {
// Execute the payment here
}
}, '#paypal-button');
</script>
</div>
<!-- Required for the banner -->
<script src="@routes.Assets.versioned("javascripts/jquery-1.11.1.min.js")"></script>
<script src="@routes.Assets.versioned("javascripts/plugins.js")"></script>
<script src="@routes.Assets.versioned("javascripts/app.js")"></script>
</body>
}
在主文件中,我添加了元和脚本链接。在内容文件中有渲染按钮的调用,但由于某种原因我无法渲染它。
我尝试过的事情:
-
下载 checkout.js 并使用以下脚本标签
<script src="@route.Assets.Versioned("javascript/checkout.js")"></script> 我在两个文件中都尝试了脚本标签(带有链接和下载的 js 文件)。在 Main 和内容文件中。
它看起来很简单,但由于某种原因我无法弄清楚。
【问题讨论】:
标签: javascript java html paypal playframework