2017-07-31 93 views
0

我正在使用條紋付款處理付款。我跟着這個GITHUB項目和這個blog條紋結算不能在角度1.x中工作

我的項目具有嵌套的視圖並使用路由器。

我的項目結構看起來像

src 
    app 
    views 
    controllers 
    directives 
    index.html 
    app.js 

的app.js是其中角模塊被手動加載並具有路由器。

app.js

var myApp = angular.module('myApp', ['ui.router', 'formData']); 
myApp.config(function($stateProvider, $urlRouterProvider, $httpProvider) { 
    // routers 
} 

中的index.html是其中角和條紋腳本被包括

的index.html

<head lang="en"> 
    <script type="text/javascript" src="https://js.stripe.com/v2/"></script> 
    <Script src="resources/angular.min.js"></Script> 
    <Script src="resources/angular-ui-router.min.js"></Script> 
    <script src="app.js"></script> 
    <script src="directives/formData/formData.js"></script> 
    <script type="text/javascript" 
     src="resources/angular-payments.js"> 
    </script> 
    <script> 
     Stripe.setPublishableKey('key') 
    </script> 
</head> 
<div> 
    <div ui-view> 
    </div> 
</div> 

Ñ流的FORMDATA指令是在那裏我想包括條支付

formData.js

var formData = angular.module('formData',['angularPayments']); 
formData.directive('formData',function(){ 
    return { 
     restrict: 'EA', 
     scope: {}, 
     replace: true, 
     link: function($scope, element, attributes){ 

     }, 
     controller: function($scope,$attrs,$http, $state){ 
      //This is the callback for strip from the links above as followed 
      $scope.stripeCallback = function (code, result) { 
       console.log("inside cc callbakc"); 
       if (result.error) { 
        console.log("credit card error"); 
        window.alert('it failed! error: ' + result.error.message); 
       } else { 
        console.log(result); 
        console.log("credit card succes "+result.id); 
        window.alert('success! token: ' + result.id); 
       } 
      }; 

     }, 
     templateUrl: 'directives/formData/formData.tpl.html' 
    } 
}); 

formData.tpl.html有另一個UI路由器

formData.tpl .html

<form id="signup-form" ng-submit="processForm()"> 
    <!-- our nested state views will be injected here --> 
    <div ui-view></div 
</form> 

和UI路由器html頁面的一個是付款頁面,此代碼

<form stripe-form="stripeCallback" name="checkoutForm">> 
    <input ng-model="number" placeholder="Card Number" 
      payments-format="card" payments-validate="card" name="card" /> 
    <input ng-model="expiry" placeholder="Expiration" 
      payments-format="expiry" payments-validate="expiry"     
      name="expiry" /> 
    <input ng-model="cvc" placeholder="CVC" payments-format="cvc" payments-validate="cvc" name="cvc" /> 
    <button type="submit">Submit</button> 
</form> 

我在控制檯中工作的驗證,但不執行打印作業時,我打提交。我猜js沒有被解僱。如果您需要更多信息,請與我們聯繫。

回答

1

這將渲染爲嵌套窗體,這是無效的html。大多數瀏覽器通過將內部表單視爲非表單元素來默默「寬恕」這一點。 如果您將checkoutForm從註冊表單中移出,這應該使您走上正確的軌道。

+0

是的,如果我在註冊表單之外有這個工作。但我真的需要這裏面 – ksernow