javascript - Scala Play Issue 中的 PayPal 客户端实现

标签 javascript scala paypal playframework-2.3 webjars

我正在尝试使用 Webjars 在 Play Scala 模板中实现 PayPal 结帐按钮。 这是 sbt 中的定义:

   "org.webjars" %% "webjars-play"% "2.6.1",
   "org.webjars"% "bootstrap"% "4.2.1" exclude ("org.webjars", "jquery"),
   "org.webjars"% "jquery"% "3.2.1",

这是模板中的导入:

@import org.webjars.play.WebJarsUtil

我还包括 jQuery、Popper.js 和 bootstrap javaScript 插件脚本。

以下 html 在浏览器中运行良好:

<!DOCTYPE html>
<html>
<!DOCTYPE html>
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <script
   src="https://www.paypal.com/sdk/js?client-id=sb">
  </script>
</head>
<body>
  <div id="paypal-button-container"></div>
  <script>
    paypal.Buttons().render('#paypal-button-container');
  </script>
</body>
</html>

但它不会在播放模板中呈现 感谢您帮助解决这个问题

Krzysztof,通过对播放配置进行以下修改解决了问题:

# Security Filter Configuration - Content Security Policy
play.filters.headers {
  contentSecurityPolicy = "default-src 'self' * .paypal.com;"
  contentSecurityPolicy = $ {play.filters.headers.contentSecurityPolicy} "img-src 'self' data: * .fbcdn.net * .twimg.com * .googleusercontent.com * .xingassets.com vk.com * .yimg.com secure .gravatar.com; "
  contentSecurityPolicy = $ {play.filters.headers.contentSecurityPolicy} "style-src 'self' 'unsafe-inline' cdnjs.cloudflare.com maxcdn.bootstrapcdn.com cdn.jsdelivr.net fonts.googleapis.com;"
  contentSecurityPolicy = $ {play.filters.headers.contentSecurityPolicy} "font-src 'self' fonts.gstatic.com fonts.googleapis.com cdnjs.cloudflare.com;"
  contentSecurityPolicy = $ {play.filters.headers.contentSecurityPolicy} "script-src 'self' 'unsafe-inline' 'unsafe-eval' cdnjs.cloudflare.com * .paypal.com;"
  contentSecurityPolicy = $ {play.filters.headers.contentSecurityPolicy} "connect-src 'self' twitter.com * .xing.com * .paypal.com;"

谢谢你¡

我还想从 Play 2.6.11 迁移到 Play 2.7.0。但是,在包含插件和 Requirejs 的依赖项之后,我在执行中遇到以下错误:

ProvisionException: Unable to provision, see the following errors: 1) Error injecting constructor, java.lang.AbstractMethodError: Method org / webjars / play / RequireJS.play $ api $ mvc $ Results $ _setter_ $ PreconditionRequired_ $ eq (Lplay / api / mvc / Results $ Status;) V is abstract at org.webjars.play.RequireJS. <init> (RequireJS.scala: 9) at org.webjars.play.RequireJS.class (RequireJS.scala: 9) while locating org. webjars.play.RequireJS for the 2nd parameter of webjars.Routes. <init> (Routes.scala: .........

我想知道有什么困难 非常感谢

最佳答案

您的问题是由播放应用程序中的 CspFilter 引起的。如果您使用的是 2.7 或更高版本,则可以将 csp 随机数添加到要添加到页面的每个脚本中。假设这是您的模板:

@* At the beggining import CSPNonce *@
@import views.html.helper.CSPNonce

@* It's important that you pass implicit request to your view, without script won't compile *@
@(title: String)(content: Html)(implicit request: RequestHeader)

<!DOCTYPE html>
<html lang="en">
    <head>
        @* Adding  @{CSPNonce.attr} would generate nonce for external script *@
        <script @{CSPNonce.attr} src="https://www.paypal.com/sdk/js?client-id=sb"></script>
    </head>
    <body>
      <div id="paypal-button-container"></div>
        @* Adding  @{CSPNonce.attr} would generate nonce for inline script *@
      <script @{CSPNonce.attr}>
        paypal.Buttons().render('#paypal-button-container');
      </script>
    </body>
</html>

在 play 2.6 和之前的 nonces 没有实现,所以你必须自己实现它或者允许在没有 nonces 的情况下评估内联脚本。

play.filters.headers.contentSecurityPolicy = "default-src 'self'; script-src 'self' 'unsafe-inline' https://www.paypal.com"

关于javascript - Scala Play Issue 中的 PayPal 客户端实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55170319/

相关文章:

scala - 旋转 View 引擎外观相似

scala - 为什么延迟工厂方法在F的上下文中有返回值

c# - ASP.Net 核心 : PayPal checkout endpoint

javascript - 在位于单独文件中的 $routeProvider 路由中定义 Controller

javascript - Firebase - 获取没有键名的 child 的 child

Scala 的案例类及其传递给父类(super class)的构造函数参数

php - 我的 PayPal 脚本突然停止验证 SSL 证书

android - 错误 : INTERNAL_SERVICE_ERROR in Paypal Android SDK

javascript - 使用 addEventListener 加载 DOMContent

javascript - 迭代 JSON 对象,并在下一次迭代之前暂停