【问题标题】:Paypal cordova plugin not getting firedPaypal cordova 插件没有被解雇
【发布时间】:2016-03-03 05:42:06
【问题描述】:

我正在尝试将 Paypal 付款方式添加到我的应用中。这是我的 JS 代码。

 app.controller('PaypalController',function($scope){
 var output = function() {
    var menuorder = '';
    angular.forEach($scope.filtereditem, function(item) {
      var size = " ";
      var size2 = " ";
      var size3 = " ";
      var size4 = " ";
      var size5 = " ";
      angular.forEach(item.sizes, function(option) {
        if (option && option.active) {
          size += option.name + " in #1<br>";
        }
        if (option && option.active2) {
          size2 += option.name + " in #2<br>";
        }
        if (option && option.active3) {
          size3 += option.name + " in #3<br>";
        }
        if (option && option.active4) {
          size4 += option.name + " in #4<br>";
        }
        if (option && option.active5) {
          size5 += option.name + " in #5<br>";
        }
      });
      menuorder += item.name + "<br/>Side: " + item.type + ", Qty: " + item.qty + ", Modifiers: " + item.modifier + "<br/><br/>Add-Ons:<br/>" + size + size2 + size3 + size4 + size5 + "<br/><br/>";
    });
    return menuorder;
  }
  $scope.filteredmenu = output();
 var init_defer;
    /**
     * Service object
     * @type object
     */
    var service = {
        initPaymentUI: initPaymentUI,
        createPayment: createPayment,
        configuration: configuration,
        onPayPalMobileInit: onPayPalMobileInit,
    };
    function initPaymentUI(){
         var clientIDs = {
       "PayPalEnvironmentProduction": "XXXXXXXXXXXXXXXX",
       "PayPalEnvironmentSandbox": "XXXXXXXXXXXXXXXX"
         };
         PayPalMobile.init(clientIDs, onPayPalMobileInit);
     }

   function createPayment() {
     var paymentDetails = new PayPalPaymentDetails(scope.pricetotal, "0.00", "0.00");
     var payment = new PayPalPayment(scope.pricetotal, "CAD", scope.filteredmenu, "Sale", paymentDetails);
     return payment;
   }
   function configuration() {
     var config = new PayPalConfiguration({merchantName: "SIGNS Store", merchantPrivacyPolicyURL: "https://mytestshop.com/policy", merchantUserAgreementURL: "https://mytestshop.com/agreement"});
     return config;
   }
   function onPayPalMobileInit() {
     PayPalMobile.prepareToRender("PayPalEnvironmentSandbox", configuration());
   }
   function onUserCanceled(result) {
     console.log(result);
   }

    return {
        initPaymentUI : initPaymentUI, 
        createPayment : createPayment,
        configuration : configuration,
        onPayPalMobileInit: onPayPalMobileInit,
    }
    $scope.pay = function(){
                    PayPalMobile.renderSinglePaymentUI(createPayment(), onSuccesfulPayment, onUserCanceled);
}
if(typeof PayPalMobile != 'undefined')
    initPaymentUI();
page_load();

我的 HTML 代码如下:

        <label>Payment Method:&nbsp;&nbsp;</label>
        <md-select placeholder="Select a Payment Method" ng-model="item.payment" ng-change="selectChanged()">
      <md-option aria-label="side set" class="md-accent" value="1">Pay at SIGNS</md-option>
      <md-option aria-label="side set" class="md-accent" value="2">Pay Now</md-option>
    </md-select>
<md-button class="md-raised md-primary" ng-controller="PaypalController" ng-show="item.payment==2" ng-click="pay()">
  Pay with PayPal
</md-button>

所以基本上,我已将 $scope.pricetotal 定义为别处的总价,并已定义 $scope.filteredmenu(我已显示代码)。这些是基于 html 选择的 JSON 变化元素,但最终分别作为数值和字符串,我试图将它们作为 paypal 价格和项目描述推送。

我已添加到我的索引并添加了 paypal 插件以及在我的 config.xml 中使用(我正在使用 phonegap 构建)。我还添加了我的贝宝沙箱和生产 ID。然而,出于某种原因,贝宝似乎根本没有启动。对此的任何帮助将不胜感激。

我的 config.xml 按要求:

 <?xml version="1.0" encoding="UTF-8"?>
<widget xmlns = "http://www.w3.org/ns/widgets"
    xmlns:gap = "http://phonegap.com/ns/1.0"
    id        = "com.signsrestaurant.app"
    versionCode="1.00"
    version   = "1.00">
    <name>Signs Restaurant</name>
    <description>
    Where Noise Meets Silence       </description>
    <author href="http://signsrestaurant.ca" email="gmanikumar@umhs-sk.net">
    Signs Restaurant
    </author>
    <preference name="phonegap-version" value="cli-5.2.0" />
    <preference name="orientation" value="default" />
    <preference name="fullscreen" value="false" />
    <preference name="target-device" value="universal" />
    <preference name="webviewbounce" value="true" />
    <preference name="prerendered-icon" value="true" />
    <preference name="stay-in-webview" value="true" />
    <preference name="ios-statusbarstyle" value="black-opaque" />
    <preference name="detect-data-types" value="true" />
    <preference name="exit-on-suspend" value="true" />
    <preference name="show-splash-screen-spinner" value="true" />
    <preference name="auto-hide-splash-screen" value="true" />
    <preference name="EnableViewportScale" value="true" />
    <preference name="MediaPlaybackRequiresUserAction" value="true" />
    <preference name="AllowInlineMediaPlayback" value="true" />
    <preference name="BackupWebStorage" value="cloud" />
    <preference name="TopActivityIndicator" value="gray" />
    <preference name="KeyboardDisplayRequiresUserAction" value="true" />
    <preference name="HideKeyboardFormAccessoryBar" value="true" />
    <preference name="SuppressesIncrementalRendering" value="true" />
    <preference name="android-minSdkVersion" value="7" />
    <preference name="android-installLocation" value="internalOnly" />
    <preference name="SplashScreenDelay" value="5000" />
    <preference name="ErrorUrl" value=""/>
    <preference name="BackgroundColor" value="0x000000"/>
    <preference name="KeepRunning" value="true"/>
    <preference name="DisallowOverscroll" value="true"/>
    <preference name="LoadingDialog" value=","/> 
    <preference name="LoadUrlTimeoutValue" value="20000" />
    <preference name="disable-cursor" value="true" />
    <gap:platform name="ios" />
    <gap:platform name="android" />
    <gap:platform name="winphone" />
    <feature name="http://api.phonegap.com/1.0/battery"/>
    <feature name="http://api.phonegap.com/1.0/camera"/>
    <feature name="http://api.phonegap.com/1.0/contacts"/>
    <feature name="http://api.phonegap.com/1.0/file"/>
    <feature name="http://api.phonegap.com/1.0/geolocation"/>
    <feature name="http://api.phonegap.com/1.0/media"/>
    <feature name="http://api.phonegap.com/1.0/network"/>
    <feature name="http://api.phonegap.com/1.0/notification"/>
    <feature name="http://api.phonegap.com/1.0/contacts"/>
    <feature name="http://api.phonegap.com/1.0/device"/>
    <gap:plugin name="org.apache.cordova.file" spec="1.3.3" source="pgb" />
    <gap:plugin name="org.apache.cordova.file-transfer" spec="0.5.0" source="pgb" />
    <gap:plugin name="org.apache.cordova.geolocation" source="npm" />
    <gap:plugin name="org.apache.cordova.inappbrowser" source="npm" />
    <gap:plugin name="org.apache.cordova.network-information" source="npm" />
    <gap:plugin name="cordova-plugin-whitelist" source="npm" />
    <gap:plugin name="com.paypal.cordova.mobilesdk" version="3.1.9" source="npm"/>
    <gap:plugin name="nl.x-services.plugins.socialsharing" />
    <gap:plugin name="com.plugin.datepicker" />
    <gap:plugin name="de.appplant.cordova.plugin.email-composer" version="0.8.2" />
    <icon src="images/icon-57.png" gap:platform="ios" width="57" height="57" />
    <icon src="images/icon-72.png" gap:platform="ios" width="72" height="72" />
    <icon src="images/icon-114.png" gap:platform="ios" width="114" height="114" />
    <icon src="images/icon-144.png" gap:platform="ios" width="144" height="144" />
    <icon src="images/icon-76.png" gap:platform="ios" width="76" height="76" />
    <icon src="images/icon-120.png" gap:platform="ios" width="120" height="120" />
    <icon src="images/icon-152.png" gap:platform="ios" width="152" height="152" />
    <icon src="images/icon-36.png" gap:platform="android" gap:density="ldpi" />
    <icon src="images/icon-48.png" gap:platform="android" gap:density="mdpi" />
    <icon src="images/icon-72.png" gap:platform="android" gap:density="hdpi" />
    <icon src="images/icon-96.png" gap:platform="android" gap:density="xhdpi" />
    <icon src="images/icon-144.png" gap:platform="android" gap:density="xxhdpi" />
    <icon src="images/icon-192.png" gap:platform="android" gap:density="xxxhdpi" />
    <icon src="images/icon-62.png" gap:platform="winphone" />
    <icon src="images/icon-173.png" gap:platform="winphone" gap:role="background" />
    <icon src="icon.png" />
    <gap:splash src="images/splash-480-320.png" gap:platform="ios" width="320" height="480" />
    <gap:splash src="images/splash-320-480.png" gap:platform="ios" width="480" height="320" />
    <gap:splash src="images/splash-960-640.png" gap:platform="ios" width="640" height="960" />
    <gap:splash src="images/splash-640-960.png" gap:platform="ios" width="960" height="640" />
    <gap:splash src="images/splash-1136-640.png" gap:platform="ios" width="640" height="1136" />
    <gap:splash src="images/splash-640-1136.png" gap:platform="ios" width="1136" height="640" />
    <gap:splash src="images/splash-1024-768.png" gap:platform="ios" width="768" height="1024 " />
    <gap:splash src="images/splash-768-1024.png" gap:platform="ios" width="1024" height="768" />
    <gap:splash src="images/splash-400-240.png" gap:platform="android" gap:density="ldpi" />
    <gap:splash src="images/splash-480-320.png" gap:platform="android" gap:density="mdpi" />
    <gap:splash src="images/splash-800-480.png" gap:platform="android" gap:density="hdpi" />
    <gap:splash src="images/splash-960-720.png" gap:platform="android" gap:density="xhdpi" />
    <gap:splash src="images/splash-1920-1080.png" gap:platform="android" gap:density="xxhdpi" />
    <gap:splash src="images/splash-800-480.png" gap:platform="winphone" />
    <gap:splash src="splash.png" />
    <access origin="*" />
</widget>

我的标题:

<head>
<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://maps.google.com https://maps.googleapis.com https://s.ytimg.com">
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-capable" content="yes">
<title>Signs Restaurant and Bar</title>  

<!-- All our CSS -->
<!-- onsen-css-components.css is the skin of your app, you can generate one custom skin with this generator: http://components.onsen.io/ -->
<link rel="stylesheet" href="lib/onsen/css/onsenui.css">    
<link rel="stylesheet" href="css/onsen-css-components.css"> 
<link rel="stylesheet" href="css/plugins.css"/>
<link rel="stylesheet" href="css/roots.css"/>
<link rel="stylesheet" href="css/app.css"/>
<link rel="stylesheet" href="css/style.css">

<!-- These are our JS libraries that make all the magic in our App -->
<script src="js/maps.js"></script>
<script src="js/youtube.js"></script>
<script src="js/angular.min.js"></script>
<script src="js/angular-animate.min.js"></script>
<script src="js/angular-aria.min.js"></script>
<script src="js/angular-messages.min.js"></script>
<script src="js/angular-material.min.js"></script>
<script src="js/angular-ui-router.min.js"></script>
<script src="js/angular-sanitize.min.js"></script>    
<script src="lib/onsen/js/angular/angular-touch.js"></script>   
<script src="lib/onsen/js/onsenui.js"></script>    
<script src="js/plugins.js"></script>
<script src="js/app.js"></script>
<script src="cordova.js"></script>
<script type="text/javascript" src="js/paypal-mobile-js-helper.js"></script>  
</head>

【问题讨论】:

  • 两 (2) 件事。 1)你想做什么?你的最终目标是什么? 2) 请发布您的config.xml。 -- 你可能没有whitelist 设置。
  • 您好,感谢您的回复。对于任何含糊之处,我深表歉意,并将尝试澄清我的尝试: 1) 基本上,我创建了一个可以工作的餐厅外卖应用程序,它当前会生成一个订单名称和价格,并将其作为电子邮件发送。我的最终目标是通过贝宝添加付款并使用插件发送定义的订单名称订单价格(目前在沙箱环境中测试)。 2)发布!如果您正在考虑白名单插件,我想我已经加入了,并且也在 index.html 中定义了元数据。我在 chrome 检查中收到 0 个控制台错误。有小费吗?谢谢!
  • whitelist 几乎没有错误。对不起,我忘了说,将该信息添加到您的原始帖子中。请添加标题(元部分)。您的CSP 中可能有一些错误。另外,我会看看你的config.xml。你有些东西不见了。
  • 哦,感谢您的调查!我已经在那里添加了我的标题部分。

标签: angularjs cordova paypal phonegap-plugins phonegap-build


【解决方案1】:

好的,这就是你需要做的。

  1. &lt;feature (...)&gt; 已被 Phonegap Build 弃用。
  2. 您需要更新“核心”插件
  3. 您的第 3 方插件可能需要更换。
  4. 你需要实现whitelist系统

1。 &lt;feature (...)&gt; 已被 Phonegap Build 弃用。

不要再使用它了。 SEE

移除

<feature name="http://api.phonegap.com/1.0/battery"/>
<feature name="http://api.phonegap.com/1.0/camera"/>
<feature name="http://api.phonegap.com/1.0/contacts"/>
<feature name="http://api.phonegap.com/1.0/file"/>
<feature name="http://api.phonegap.com/1.0/geolocation"/>
<feature name="http://api.phonegap.com/1.0/media"/>
<feature name="http://api.phonegap.com/1.0/network"/>
<feature name="http://api.phonegap.com/1.0/notification"/>
<feature name="http://api.phonegap.com/1.0/contacts"/>
<feature name="http://api.phonegap.com/1.0/device"/>

2。你需要更新你的“核心”插件

所有核心插件现在都在NPM。 但是,目前,您应该使用的列表(“核心”插件)是:http://cordova.apache.org/docs/en/latest/cordova/plugins/pluginapis.html 此外,Phonegap Build 现在被认为是“最佳实践”,始终使用您想要的版本。

此外,一个多星期前还有some big changes to config.xml。它们不会影响您所做的事情,但我已经为您提供了一个先机,通过为您进行更改 - 有意义的地方。

替换

<!--
<gap:plugin name="org.apache.cordova.file" spec="1.3.3" source="pgb" />
<gap:plugin name="org.apache.cordova.file-transfer" spec="0.5.0" source="pgb" />
<gap:plugin name="org.apache.cordova.geolocation" source="npm" />
<gap:plugin name="org.apache.cordova.inappbrowser" source="npm" />
<gap:plugin name="org.apache.cordova.network-information" source="npm" />
<gap:plugin name="cordova-plugin-whitelist" source="npm" />
-->

有了这个

<plugin name="cordova-plugin-file"           source="npm" spec="2.1.0" />
<plugin name="cordova-plugin-file-transfer"  source="npm" spec="1.2.0" />
<plugin name="cordova-plugin-geolocation"    source="npm" spec="1.0.1" />
<plugin name="cordova-plugin-inappbrowser"   source="npm" spec="1.0.1" />
<plugin name="cordova-plugin-network-information" source="npm" spec="1.0.1" />
<plugin name="cordova-plugin-whitelist"      source="npm" spec="1.1.0" />

3。您的第 3 方插件可能需要更换。

我已经更新了你所有的 3rd-party 插件。 如果它们无法构建或不起作用,请返回原始设置。 解释很长,为什么它们可能不起作用。

第三方插件

<!-- https://www.npmjs.com/package/com.paypal.cordova.mobilesdk -->
<plugin name="com.paypal.cordova.mobilesdk"  source="npm" spec="3.1.9" />
<!-- https://www.npmjs.com/package/cordova-plugin-x-socialsharing -->
<plugin name="cordova-plugin-x-socialsharing" source="npm" spec="5.0.7" />
<!-- https://www.npmjs.com/package/cordova-plugin-datepicker -->
<gap:plugin name="cordova-plugin-datepicker"  source="npm" spec="0.9.3" />
<!-- https://www.npmjs.com/package/cordova-plugin-email-composer -->
<gap:plugin name="cordova-plugin-email-composer" source="npm" version="0.8.2" />

4。你需要实现whitelist系统

您需要实施白名单系统。 这个 whitelist 工作表应该会有所帮助。
HOW TO apply the Cordova/Phonegap the whitelist system

与此同时,要让事情正常进行,请执行以下操作。
请注意,您的应用现在不安全。保护您的应用由您决定。

将以下内容添加到您的config.xml

改变

<allow-navigation href="*" />
<allow-intent href="*" />
<access origin="*" /> <!-- Required for iOS9 -->

将以下内容添加到您的index.html

更新:2015-12-01 以前,我忘记在 CSP 元标记中添加通配符 (*)。我现在包括这个。此元标记应添加到正在播放音频的index.html 文件的标题中。

请注意,您的应用现在不安全。保护您的应用由您决定。

<meta http-equiv="Content-Security-Policy" 
         content="default-src *; 
                  style-src * 'self' 'unsafe-inline' 'unsafe-eval'; 
                  script-src * 'self' 'unsafe-inline' 'unsafe-eval';">

【讨论】:

  • 非常感谢您的回答。我已按照建议删除了 1 。然后,我继续更新我所有的核心插件和 3rd 方插件,并假设我会遇到一些错误,但没有;就这样顺利进行。在4中,我确实已经有了,但是没有其他参数并且也添加了这些参数。我使用了发布的相同元标记,但为 youtube 和 google maps api 脚本添加了例外。完成所有操作后,我希望这能解决问题,但插件仍然没有启动。我不知道还有什么可以研究的。非常感谢,不过!我知道这些很重要。
  • 我还没有放弃。让我继续找。我会在一小时内回复你。
  • 好的,最后一个想法。首先,我不做 Angular,所以我对此的评论有限。但是,控制器中有很多开销。您能否尝试在没有控制器开销的情况下进行事务,只是为了检查网络连接?
  • 刚刚试过了,不行。奇怪的是我没有收到控制台错误,所以不知道出了什么问题。我使用了这个 git 并在此处跟随它到一个 T:gist.github.com/Urbiwanus/c1e456f889f53e940a11 并创建了一个工厂以及在控制器中调用该函数。再次感谢所有建议。
  • Hmmmm.. 刚刚有了另一个想法。有时,该插件适用于 Phonegap Build 还没有的编译器版本!例如,PGB cli-5.2.0 固定到 (iOS/Android/Windows) (3.9.1 / 4.1.1 / 3.8.1)。但是Cordova CLI 5.4.0 的最新版本将(iOS/Android/Windows)放在 (3.9.2/4.1.1/3.8.1) 和 leading edge 是 (3.9.2/5.0.0/4.2.0)。我在Nitobi 上看到的一个修复是使用一个插件一 (1) 或两 (2) 个版本
猜你喜欢
  • 2016-07-15
  • 2020-03-28
  • 2015-10-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-16
相关资源
最近更新 更多