<commit_before>(function() {
"use strict";

var shopStripeModule = angular.module('django.shop.stripe', ['ng.django.urls', 'angular-stripe', 'django.shop.dialogs']);

// Directive <ANY stripe-card-form>
// Must be added to the form containing the CC input fields
shopStripeModule.directive('stripeCardForm', ['$http', 'djangoUrl', 'stripe', 'djangoShop',
                           function($http, djangoUrl, stripe, djangoShop) {
	// iterate over sibling scopes to find the scope object holding the customer's data
	function findCustomerScope(scope) {
		while (scope && scope.hasOwnProperty('data')) {
			if (scope.data.hasOwnProperty('customer'))
				return scope.data.customer;
			scope = scope.$$prevSibling;
		}
		return null;
	}

	return {
		restrict: 'A',
		require: 'form',
		scope: false,
		controller: ['$scope', function($scope) {
			var customer = findCustomerScope($scope);
			if (customer) {
				$scope.payment = {
					card: {name: [
					    customer.first_name ? customer.first_name : '',
					    customer.last_name ? customer.last_name : ''].join(' ')
					}
				};
			}
			if (!angular.isObject($scope.data.payment_method)) {
				$scope.data.payment_method = {};
			}

			// pass data from Stripe Card Form to PSP and fetch the token
			function createToken(deferred) {
				$scope.dismiss();
				stripe.card.createToken($scope.payment.card).then(function(token) {
					console.log('token created for card ending in ', token.card.last4);
					deferred.resolve(token);
				}, function(error) {
					console.error(error.message);
					$scope.stripe_error_message = error.message;
					deferred.reject(error.code);
				});
				return deferred.promise;
			}

			$scope.prepare = function(deferred) {
				if (angular.isString($scope.data.payment_method.payment_data.token_id)) {
					deferred.resolve();<commit_msg>ups, don't create a token if not asked for<commit_after>(function() {
"use strict";

var shopStripeModule = angular.module('django.shop.stripe', ['ng.django.urls', 'angular-stripe', 'django.shop.dialogs']);

// Directive <ANY stripe-card-form>
// Must be added to the form containing the CC input fields
shopStripeModule.directive('stripeCardForm', ['$http', 'djangoUrl', 'stripe', 'djangoShop',
                           function($http, djangoUrl, stripe, djangoShop) {
	// iterate over sibling scopes to find the scope object holding the customer's data
	function findCustomerScope(scope) {
		while (scope && scope.hasOwnProperty('data')) {
			if (scope.data.hasOwnProperty('customer'))
				return scope.data.customer;
			scope = scope.$$prevSibling;
		}
		return null;
	}

	return {
		restrict: 'A',
		require: 'form',
		scope: false,
		controller: ['$scope', function($scope) {
			var customer = findCustomerScope($scope);
			if (customer) {
				$scope.payment = {
					card: {name: [
					    customer.first_name ? customer.first_name : '',
					    customer.last_name ? customer.last_name : ''].join(' ')
					}
				};
			}
			if (!angular.isObject($scope.data.payment_method)) {
				$scope.data.payment_method = {};
			}

			// pass data from Stripe Card Form to PSP and fetch the token
			function createToken(deferred) {
				$scope.dismiss();
				stripe.card.createToken($scope.payment.card).then(function(token) {
					console.log('token created for card ending in ', token.card.last4);
					deferred.resolve(token);
				}, function(error) {
					console.error(error.message);
					$scope.stripe_error_message = error.message;
					deferred.reject(error.code);
				});
				return deferred.promise;
			}

			$scope.prepare = function(deferred) {
				if ($scope.data.payment_method.payment_modifier !== 'stripe-payment'
				  || angular.isString($scope.data.payment_method.payment_data.token_id)) {
					deferred.resolve();
{'fraction_non_alphanumeric': 0.14411060888061686, 'fraction_numerical': 0.0005317734645041213, 'mean_word_length': 3.527075812274368, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1992818', 'n_tokens_mistral': 1372, 'n_tokens_neox': 1148, 'n_words': 249}