I'm having trouble getting Stripe checkout to function properly with Angular 1.x

Utilizing the Stripe payment system for processing payments, I referenced a project on GitHub and a helpful blog.

Incorporating nested views and routers in my project, the structure appears as follows:

src
  app
    views
    controllers
    directives
    index.html
    app.js

The critical "app.js" file loads the Angular module manually along with the necessary routers.

app.js

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

The inclusion of Angular and Stripe scripts happens in the "index.html" file.

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>

Within the "formData" directive lies the integration of Stripe payment functionality.

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){
            //Callback for handling Stripe payment is implemented here
            $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 success "+result.id);
                    window.alert('success! token: ' + result.id);
                }
            };

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

The "formData.tpl.html" also includes another ui router.

formData.tpl.html

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

One of the HTML pages handled by the ui router is the payment page containing the following code:

<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> 

While validations are functioning correctly, hitting submit does not print anything to the console. It seems that the JavaScript is not executing properly. Additional information can be provided upon request.

Answer №1

When nested forms are used, it creates invalid html which may not display correctly in all browsers. However, most browsers will still render the page properly by treating the inner form as a regular element rather than a form. To fix this issue, try moving the checkoutForm outside of the signup-form to ensure proper rendering.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Prevent a form from loading depending on the response received from an ajax callback

I am currently working on implementing an ajax post function. The process involves sending data and receiving a callback from PHP with some data in return. Depending on the returned data, I need to make a decision whether to proceed or allow the user to re ...

Switching from using infinite scroll for pagination to using a traditional page by page approach

My current setup involves infinite scroll pagination using Elasticsearch and AngularJS for a search application. I want to switch to a more traditional pagination style like Google or Bing search engines. I have been attempting to implement the AngularJS U ...

Guide on how to retrieve a list of objects from a controller and showcase them utilizing JQuery in a Spring MVC application with ajax functionality

Here is the controller code snippet: @Controller public class MainController { @Autowired SqlSession sqlSession; @Autowired Message messageVO; @RequestMapping(value="getMessages", method=RequestMethod.GET) public @ResponseBody List<Messag ...

Utilizing the power of AngularJS with ng-class for dynamic styling and

I recently started learning AngularJs and I have a question about how angular handles the ng-class attribute. While working with external libraries for visualization, charts, etc., I often need to trigger the resize event: window.dispatchEvent(new Event( ...

Emphasizes the P tag by incorporating forward and backward navigation options

My goal is to enable users to navigate up and down a list by pressing the up and down arrow keys. For example, if "roma" is currently highlighted, I want it to change to "milan" when the user presses the down arrow key. Here is the HTML code I am working w ...

Difficulty in using window.scrollTo within useEffect in reactJS

I'm facing an issue where I am trying to use window.scrollTo on the initial render using the useEffect function. I have stored the vertical offset as an integer in localStorage, but the scrolling is not working and remains at position 0. Problem with ...

Transmitting information from the front-end Fetch to the back-end server

In my stack, I am using Nodejs, Express, MySQL, body-parser, and EJS. My goal is to trigger a PUT request that will update the counter by 1 when a button is pressed. The idea is to pass the ID of the clicked button to increment it by 1. app.put("/too ...

Convert the JSON data into the specified format using JavaScript

Is there a way to transform JSON data like this in JavaScript? data = [{acquired: "2018-03-09T22:49:52.935Z", mean_ndvi: -0.0483685} {acquired: "2018-02-13T22:49:16.568Z", mean_ndvi: 0.00595065} {acquired: "2018-04-01T22:50:30.912Z", mean_ndvi: -0.033455} ...

Issue with Ajax request not redirecting to correct URL

I have been successfully using ajax requests in my document without any issues. I am looking to retrieve the user's coordinates as they load the document and then pass this data on to other methods for distance calculations. On the loading of the ind ...

Encountering TypeError while attempting to assign an axios response to a data variable within a Vue component

Encountering the error message TypeError: Cannot set property 'randomWord' of undefined specifically at the line: this.randomWord = response.data.word; Confirming that console.log(response.data.word) does display a string. Vue Component Structu ...

What methods do developers employ to establish connections between pages in AngularJs?

As a new AngularJS developer, I have a good grasp on concepts like SPA and Components. However, one area that still confuses me is how to efficiently redirect users to different pages within an Angular app. I am seeking advice on the best approach for seam ...

A beginner's guide to using Jasmine to test $http requests in AngularJS

I'm struggling with testing the data received from an $http request in my controller as I don't have much experience with Angular. Whenever I try to access $scope, it always comes back as undefined. Additionally, fetching the data from the test ...

Tips for stopping PHP echo from cutting off a JS string?

I encountered an issue with my code: <!DOCTYPE html> <html> <head> <title>Sign up page</title> <meta charset="UTF-8"/> </head> <body> <h1>Sign up page</h ...

Ways to make JavaScript cycle through a set of images

I'm having trouble trying to set up a code that will rotate multiple images in a cycle for an image gallery I'm working on. So far, I've only been able to get one image to cycle through successfully. Any help or suggestions would be greatly ...

JavaScript forEach functionality is not compatible with Dynamics CRM 2016

I'm currently working on writing some JavaScript code for a ribbon button in Dynamics CRM 2016 that will extract phone numbers from a list of Leads displayed in the Active Leads window. However, I've encountered an error message when attempting ...

What is the best way to wrap a call to XMLHttp Request within a $q promise?

I am trying to figure out how to wrap the following code in an AngularJS ui-router resolve section with a $q promise. The goal is to return success or fail based on whether the http request works. Should I encapsulate all of this inside a promise or just ...

What purpose do controller.$viewValue and controller.$modelValue serve in the Angular framework?

I'm confused about the connection between scope.ngModel and controller.$viewValue/controller.$modelValue/controller.$setViewValue(). I'm specifically unsure of the purpose of the latter three. Take a look at this jsfiddle: <input type="text" ...

Tips for boosting ViteJs development mode performance

One issue I am facing is the slow server performance during development mode. After starting the server and opening the page in my browser, I have to wait 3–6 minutes for it to load! Initially, ViteJs downloads a small amount of resources, but then the ...

What is the best way to retrieve the document DOM object within an EJS template?

I am attempting to display a list of participants when the user clicks on the button. However, every time I try, I encounter an error stating "document is not defined". (Please refrain from suggesting the use of jQuery!). <% var btn = document.getEle ...

Having trouble importing Tone.js in your Next.js project?

Having trouble importing Tone in my Next.js project. Despite having Tone as a dependency, I face an issue when trying to run import * as Tone from 'tone'. Next.js shows an error stating it can't locate the module node_modules/tone/build/esm/ ...