'use strict';

angular.module('scratchApp')
    .controller('ContractCtrl', function ($scope, $http, $location) {
        var serversPublicKey,
            wallet,
            paymentTx,
            refundTx,
            signedTx;

        $scope.generate = function () {
            getServersPublicKey($scope.walet_publicKey);

            signTransactionAtServer();
        }

        function getServersPublicKey(clientsPublicKey) {
            $http.post("http://0.0.0.0:3000/wallet/create", {clientsPublicKey:"026477115981fe981a6918a6297d9803c4dc04f328f22041bedff886bbc2962e01"}).success(function (data, status, headers, config) {
                console.log("Server responded with key: " + data);
                serversPublicKey = data;
                createTransactions($scope.wallet_amount, $scope.wallet_duration);
            }).
                error(function (data, status, headers, config) {
                    alert("Server returned an error: " + status + " " + data);
                    $location.path('/');
                });
            serversPublicKey = "ServersPublicKey";
        }

        function createTransactions(amount, duration) {
            // generate wallet

            // create payment transaction

            // create refund transaction
        }

        function signTransactionAtServer() {
            signedTx = "signed transaction";
        }
    });

@@ -446,64 +446,257 @@
     
-$http.post(%22http://0.0.0.0:3000/wallet/create%22, %7Bclients
+var req = %7B%0A                method: 'POST',%0A                url: 'http://0.0.0.0:3000/wallet/create',%0A                headers: %7B%0A                  'Content-Type': 'application/json'%0A                %7D,%0A                data: %7B%0A                    user
 Publ
@@ -769,17 +769,72 @@
 2962e01%22
-%7D
+%0A                %7D%0A            %7D;%0A%0A            $http(req
 ).succes
@@ -870,32 +870,33 @@
 ders, config) %7B%0A
+%0A
                 
@@ -1085,28 +1085,15 @@
     
-%7D).%0A            
     
+%7D).
 erro
@@ -1141,87 +1141,8 @@
 ) %7B%0A
-                    alert(%22Server returned an error: %22 + status + %22 %22 + data);%0A
     

Modify request to add necessary header