我試圖實現付款方式Paypal的按鈕。所以我想按照網站上的guide。我正在使用Java和Play框架2.6。在Play框架Java 2.6中添加Paypal按鈕
他們給下面的代碼在網站上自己的代碼添加:
<!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("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和內容文件中。
它看起來很簡單,但由於某種原因,我無法弄清楚。