I am using Flex Microform and was able to successfully render the Credit Card Iframe from Cybersource.
Now, the question is to Add/Send CVN/CVV details along with above request.
In the document, we can pass only three parameters in the createToken Method - CardType, CardExpirationYear, and CardExpirationMonth.
I couldn't find anything about sending/Adding CVN.
Please guide if anyone has done similar implementation where we can send CVN details from the Flex Form.
Html
---
<label id="cardNumber-label">Card Number</label>
<div id="number-container" class="form-control"></div>
<label for="securityCode-container">Security Code</label>
<div id="securityCode-container" class="form-control"></div>
--
</div>
<div class="form-row">
----
</form>
Js
var flex = new Flex(captureContext);
var microform = flex.microform({ styles: myStyles });
var number = microform.createField('number', { placeholder: 'Enter card number' });
var securityCode = microform.createField('securityCode', { placeholder: '•••' });
number.load('#number-container');
securityCode.load('#securityCode-container');
Ref: developer-guides
I think this is what you're looking for
https://developer.cybersource.com/docs/cybs/en-us/digital-accept-flex/developer/all/rest/digital-accept-flex/microform-integ/api_reference/class_Microform.html
Example:
<div class="container card">
<div class="card-body">
<h1>Checkout</h1>
<div id="errors-output" role="alert"></div>
<div class="form-group">
<label for="cardholderName">Name</label>
<input id="cardholderName" class="form-control" name="cardholderName" placeholder="Name on the card">
<label id="cardNumber-label">Card Number</label>
<div id="number-container" class="form-control"></div>
<label for="securityCode-container">Security Code</label>
<div id="securityCode-container" class="form-control"></div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label for="expMonth">Expiry month</label>
<select id="expMonth" class="form-control">
<option>01</option>
<option>02</option>
<option>03</option>
<option>04</option>
<option>05</option>
<option>06</option>
<option>07</option>
<option>08</option>
<option>09</option>
<option>10</option>
<option>11</option>
<option>12</option>
</select>
</div>
<div class="form-group col-md-6">
<label for="expYear">Expiry year</label>
<select id="expYear" class="form-control">
<option>2022</option>
<option>2023</option>
</select>
</div>
</div>
</div>
</div>
<script src="https://flex.cybersource.com/cybersource/assets/microform/0.11/flex-microform.min.js"></script>
<script>
$(document).ready(function() {
$('#submission-form').submit(function(e) {
e.preventDefault();
});
var form = document.querySelector('#submission-form');
var payButton = document.querySelector('#btnPay');
var flexResponse = document.querySelector('#SecureToken');
var expMonth = document.querySelector('#expMonth');
var expYear = document.querySelector('#expYear');
var errorsOutput = document.querySelector('#errors-output');
// the capture context that was requested server-side for this transaction
var captureContext = /*caputre context loaded here*/ ;
// setup
var flex = new Flex(captureContext);
var number = microform.createField('number', {
placeholder: 'Enter card number'
});
var securityCode = microform.createField('securityCode', {
placeholder: '•••'
});
number.load('#number-container');
securityCode.load('#securityCode-container');
payButton.addEventListener('click', function() {
var options = {
expirationMonth: expMonth.value,
expirationYear: expYear.value
};
microform.createToken(options, function(err, token) {
if (err) {
// handle error
} else {
flexResponse.value = JSON.stringify(token);
form.submit();
}
});
});
});
</script>
Related
I have a progress bar I want to show after I click a button.
I set my variable to true on click, yet it's not working.
The ng-show in question is on the bottom of the html, and the button i click is on a different html page but i didn't include because it uses the successOnClick function in this same controller. I console logged the isEmailing variable inside the onclick and it is assigned true. Doesn't work for ng-if either
What gives?
module.exports = app => {
app.controller('ContactController', ($scope, $http) => {
$scope.isEmailing = false;
$scope.email = (e) => {
$scope.isEmailing = true;
const requestBody = {};
const id = e.target.id;
requestBody.name = document.getElementById(`${id}-name`).value;
requestBody.email = document.getElementById(`${id}-email`).value;
requestBody.subject = document.getElementById(`${id}-subject`).value;
requestBody.body = document.getElementById(`${id}-body`).value;
$http.post('/email', JSON.stringify(requestBody), {
'Content-Type': 'application/json'
})
.then(res => {
console.log('Success!');
document.getElementById(`${id}-name`).value = '';
document.getElementById(`${id}-email`).value = '';
document.getElementById(`${id}-subject`).value = '';
document.getElementById(`${id}-body`).value = '';
$scope.isEmailing = false;
})
.catch(err => {
console.log('Error!');
$scope.isEmailing = false;
})
}
$scope.successOnClick = () => {
$scope.isEmailing = true;
}
})
}
<footer class="footer" ng-controller="ContactController">
<div class="footer__block social-media-container">
<div class="social-media">
<img src="http://i.imgur.com/bVqv5Kk.png" alt="fb-icon">
<img src="http://i.imgur.com/sJWiCHV.png" alt="twitter-icon">
<img src="http://i.imgur.com/o7yTVyL.png" alt="insta-icon">
</div>
</div>
<div class="footer__block">
<form class="footer__form" ng-submit="email($event)" id="footer">
<textarea placeholder="Message" id="footer-body" required></textarea>
<input type="text" placeholder="Name" id="footer-name" required>
<input type="email" placeholder="Email" id="footer-email" required>
<input type="text" placeholder="Subject" id="footer-subject" required>
<input type="submit" placeholder="Email">
</form>
</div>
<div class="footer__block mailing-list">
<span>Join our Mailing List!</span>
<form>
<input type="email" placeholder="Email" required>
<input type="submit">
</form>
</div>
<!-- <div class="grey-screen">
<div class="success">
<h1>Success!</h1>
</div>
</div> -->
<div class="progress-bar" ng-show="isEmailing">
</div>
</footer>
If you have several controller of same type it is not mean, that they all are same the instance. AngularJS creates controllers not via singleton pattern. You should synchronize them by yourself by means of events:
angular.module('app', [])
.controller('MyController', ['$scope', '$rootScope', function($scope, $rootScope) {
$rootScope.$on('Changed', function(event, data){
$scope.isEmailing = data;
})
$scope.successOnClick = function(){
$scope.$emit('Changed', !$scope.isEmailing);
}
}]);
<script src="//code.angularjs.org/snapshot/angular.min.js"></script>
<div ng-app="app">
<div ng-controller="MyController">
<h3 ng-style="{'background-color' : isEmailing ? 'red' : 'white'}">First controller</h3>
<input type='button' ng-click='successOnClick()' value='Change color'/>
</div>
<div ng-controller="MyController">
<h3 ng-style="{'background-color' : isEmailing ? 'red' : 'white'}">Second controller</h3>
<input type='button' ng-click='successOnClick()' value='Change color'/>
</div>
</div>
If one controller located inside another you can try to use $scope.$parent.isEmailing(where .$parent can be typed several times, depending on nesting level), but it is very uncomfortable. If your controllers located at different routes, you should pass data from one controler to another via route parameters or custom AngularJS service or $rootScope.
I have two drop downs with add resource button, when I click add resource button I need to pass selected option values from drop downs into insertResource method.How to get selected option value??I know we can easily do it using option:selected in jquery But I want do it in angular.Any help?
<body ng-app="intranet_App" ng-controller="myCtrl" ng-init="init()">
<div class="container">
<div class="row">
<div>
<label class="displayBlock margin">Project Name</label>
<input type="text" name="name" class="currentProjectName">
</div>
<div>
<label class="displayBlock margin">Resource Name</label>
<select name="ResourceInsert" id="allocateResource"><option data-ng-repeat="data in resourceList" value="{{data.EmpId}}">{{data.ResourceName}}</option></select>
</div>
<div>
<label class="displayBlock margin">Role Name</label>
<select name="ResourceInsert" id="allocateRole"><option data-ng-repeat="data in roleList" value="{{data.RoleId}}">{{data.RoleName}}</option></select>
</div>
</div>
<div class="row">
<button class="btn btn-primary addResource" ng-click="insertResource()">Add Resource</button>
</div>
</div>
</body>
<script>
var app = angular
.module('intranet_App', [])
.controller('myCtrl', function ($scope,$http) {
$scope.init = function () {
$scope.getProjId();
$scope.ResourceJson();
$scope.RoleJson();
}
$scope.getProjId = function () {
var url = document.URL;
var id = decodeURI(/id=([^&]+)/.exec(url)[1]);
var projectName = decodeURI(/val=([^&]+)/.exec(url)[1]);
$('.currentProjectName').val(projectName)
}
$scope.ResourceJson = function () {
$http.post('/Project/empList').then(function (response) {
$scope.resourceList = response.data;
console.log($scope.resourceList)
})
}
$scope.RoleJson = function () {
$http.post('/Project/roleList').then(function (response) {
$scope.roleList = response.data;
console.log($scope.roleList)
})
}
$scope.insertResource = function () {
}
});
</script>
If your questions is getting data of selected item of select. It is done as follows using ng-model directive:
<select name="ResourceInsert" id="allocateResource" ng-model="selectedValue">
<option data-ng-repeat="data in resourceList" value="{{data.EmpId}}">{{data.ResourceName}}</option>
</select>
In Controller:
console.log($scope.selectedValue, "selected Value"); //Your selected value which is EmpId.
I am having issue with ng-repeat , its replacing all values with latest one.
E.g. I am adding a value to textbox then adding that value in ng-repeat div but its replacing all values with last value entered.
Here is Jsfiddle
https://jsfiddle.net/mahajan344/9bz4Lwxa/656/
This is happening because you have only one statusObj and you are modifying it every time someone clicks the Add New Status button. Delete the statusObj you have now, and have the AddNewStatus method create a new one each time:
var xyzApi = xyzApi || {
sayHello: function() {
return "hey there\n";
}
};
angular.module('demoApp', [])
.controller('MainController', MainController)
.provider('xyzApi', function XyzApiProvider() {
this.$get = function() {
var xyzApiFactory = {
otherFunction: function() {
//$log.log('other function called');
return 'other function \n';
}
};
//console.log(xyzApiFactory, xyzApi);
angular.merge(xyzApiFactory, xyzApi);
return xyzApiFactory;
};
});
function MainController(xyzApi) {
var vm = this;
vm.test = '';
vm.listOfStatus = [];
vm.showStatusError = false;
vm.statusText = "";
vm.sayHello = function() {
vm.test += xyzApi.sayHello() + xyzApi.otherFunction();
}
vm.AddNewStatus = function(statusText) {
if (statusText.length < 1) {
vm.showStatusError = true;
return;
} else {
vm.showStatusError = false;
}
var statusObj = {
StatusComment: statusText,
scId: 0,
scTimeStamp: new Date(),
JobNum: 0,
IsNew: 0,
};
vm.listOfStatus.push(statusObj);
vm.statusText = "";
};
vm.RemoveStatus = function(index) {
vm.listOfStatus.splice(index, 1);
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.0-rc.0/angular.js"></script>
<div ng-app="demoApp" ng-controller="MainController as mainCtrl">
<pre>{{mainCtrl.test}}</pre>
<button ng-click="mainCtrl.sayHello()">
say hello!!
</button>
<div id="DivStatus">
<div class="form-group">
Status
<div class="col-md-3 col-sm-3 col-xs-12">
<input type="text" ng-model="mainCtrl.statusText" id="txtStatus" class="form-control col-md-7 col-xs-12">
<div class="text-danger error-message" id="txtStatusError" ng-show="showStatusError">Please enter new status</div>
</div>
<div class="col-md-3 col-md-3x col-sm-3 col-xs-12">
<input type="button" class="btn" ng-click="mainCtrl.AddNewStatus(mainCtrl.statusText)" value="Add New Status" />
</div>
</div>
<div class="form-group" ng-repeat="statusObj in mainCtrl.listOfStatus track by $index">
<div class="col-md-3 col-sm-3 col-xs-12">
<input type="text" value="{{statusObj.StatusComment}}" ng-disabled="true" class="form-control col-md-7 col-xs-12">
</div>
<span class="remove-record" ng-click="mainCtrl.RemoveStatus($index)" style="cursor:pointer"><i class="fa fa-times"></i></span>
</div>
</div>
</div>
So, i have this problem where a property in my array collection changes. Here is the code snippet for my controller:
$http({
method: 'GET',
headers: globalData.httpHeader,
params: {
orderkey:$scope.transaction.orderData.orderkey,
category:'ViewOrderDetail'},
url: globalData.APIARN+ globalData.StageVariable + globalData.OrderRes
}).then(function successCallback(response) {
$ionicLoading.hide();
if (response.data.errorMessage) {
swal({
title: "Ooops!",
text: "Problem Encountered in the Server. Please Contact Support."
});
} else {
$scope.itemDetails =response.data.order.orderdetail;
$scope.items = $scope.itemDetails;
angular.forEach($scope.itemDetails, function(value, key) {
$scope.itemKeys.push(value.productKey);
$scope.itemKey = $scope.itemKeys[$scope.itemKeys.length - 1];
$scope.itemKey++
$scope.itemAmountValues.push(value.quantity * value.unitPrice)
});
}
$scope.calcTotalAndProductAmt();
$scope.showItem = function(selectedKey){
$scope.selectedKeyItems = [];
angular.forEach($scope.itemDetails, function(value, key) {
if(value.itemKey == selectedKey){
$scope.selectedKeyItems.push(value)
}
});
}
console.log("before " + JSON.stringify($scope.items));
$timeout(function(){
console.log("after " + JSON.stringify($scope.items));
})
}, function errorCallback(response) {
// called asynchronously if an error occurs
// or server returns response with an error status.
$ionicLoading.hide();
$scope.messageText = globalData.ProblemLoad;
swal({
title: "Ooops!",
text: $scope.messageText
});
}); // $http call
Now, the console log result shows the following:
before [{"id":95,"productKey":"19","productName":"Roast Chicken","quantity":2,"unitPrice":175,"itemStatus":"OPEN"},{"id":96,"productKey":"14","productName":"Bolognese","quantity":3,"unitPrice":225,"itemStatus":"OPEN"},{"id":97,"productKey":"16","productName":"Coke","quantity":4,"unitPrice":50,"itemStatus":"CLOSE"},{"id":98,"productKey":"22","productName":"Rice","quantity":2,"unitPrice":45,"itemStatus":"OPEN"}]
transaction.js:1149
after [{"id":95,"productKey":"19","productName":"Roast Chicken","quantity":2,"unitPrice":175,"itemStatus":"OPEN","$$hashKey":"object:103"},{"id":96,"productKey":"14","productName":"Bolognese","quantity":3,"unitPrice":225,"itemStatus":"OPEN","$$hashKey":"object:104"},{"id":97,"productKey":"16","productName":"Coke","quantity":4,"unitPrice":50,"itemStatus":"OPEN","$$hashKey":"object:105"},{"id":98,"productKey":"22","productName":"Rice","quantity":2,"unitPrice":45,"itemStatus":"OPEN","$$hashKey":"object:106"}]
As you can see, the itemStatus for Coke changes from "CLOSED" to "OPEN". However, i don't know how the value changes since my controller does not have a code that changes this. My html looks like this:
<div class="row" ng-repeat="item in items">
<div class="col col-60" ng-show="item.itemStatus='OPEN'" >
{{item}}
<label class="item item-input">
<select ng-model="item.productKey" ng-change="addPriceEdit(item)" ng-required="true">
<option ng-repeat="item in productskey" value="{{item.productkey}}" >{{item.productname}}</option>
</select>
</label>
</div>
<div class="col col-15">
<label class="item item-input">
<input type="number" ng-model="item.quantity" min="1" step="1" max="9999999999" ng-required="true" ng-change="calcTotalAndProductAmt()">
</label>
</div>
<div class="col col-15">
<label class="item ">
{{item.unitPrice}}
</label>
</div>
<div class="col col-10">
<button class="button button-assertive"
ng-disabled="item.itemStatus!='OPEN'"
ng-click="removeItem($index)">-</button>
</div>
</div>
Anyone has an idea on what's wrong?
Replace your code with -
<div class="col col-60" ng-show="item.itemStatus=='OPEN'" >
Because , with single = , you are assigning value to the variable(so for each object it will change itemstatus to open) . For comparing , you should use ==.
I have a weird issue with the {{json_req}} expression, the {{pseudo}} and {{password}} expression are working well, I can see the changes I make in live.
But nothing happened for the {{json_req}} expression, no matter what I write on the Login and Password input.
I guess It's a basic mistake by me but I'm a little lost with this one right now :/.
Thanks for the help :)
Login.html
<div class="row">
Pseudo : {{pseudo}}
</div>
<div class="row">
Password : {{password}}
</div>
<div class="row">
json : {{json_req}}
</div>
<div class="row">
<label class="float-center">
Pseudo
<input ng-model="pseudo" type="text" required>
<span class="form-error">
Pseudo Missing.
</span>
</label>
</div>
<div class="row">
<label class="float-center">
Password
<input ng-model="password" type="password" required>
<span class="form-error">
Password Missing.
</span>
</label>
</div>
LoginCtrl.js
mCtrl.controller('LoginCtrl', ['$scope', 'User', function ($scope, User) {
$scope.json_req = {
pseudo: $scope.pseudo,
password: $scope.password
};
$scope.LoginUser = function () {
if ($scope.json_req.pseudo != undefined && $scope.json_req.password != undefined) {
User.login($scope.json_req).then(function (data) {
$scope.response = data;
$scope.json_req = {};
});
} else
console.log("UNDEFINED");
};
}]);
This is expected behaviour. When you write:
$scope.json_req = {
pseudo: $scope.pseudo,
password: $scope.password
};
you create a "snapshot" of the values for $scope.pseudo and $scope.password. They will not update when you change model later.
You could setup a $scope.$watch and update json_req when either of pseudo or password changes (not really recommended). Or what I would recommend, write a getter function on the scope:
Object.defineProperty($scope, 'json_req', {
get: function() {
return {
pseudo: $scope.pseudo,
password: $scope.password
}
}
});
Try this:
angular.module("asdfapp",[]).service("User",function(){}).controller('LoginCtrl', ['$scope', 'User',
function ($scope, User) {
$scope.json_req = {
pseudo: "",
password: ""
};
$scope.LoginUser = function () {
if ($scope.json_req.pseudo != undefined
&& $scope.json_req.password != undefined) {
User.login($scope.json_req).then(function (data) {
$scope.response = data;
$scope.json_req = {};
});
} else
console.log("UNDEFINED");
};
}]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="asdfapp" ng-controller="LoginCtrl">
<div class="row">
Pseudo : {{json_req.pseudo}}
</div>
<div class="row">
Password : {{json_req.password}}
</div>
<div class="row">
json : {{json_req}}
</div>
<div class="row">
<label class="float-center">
Pseudo
<input ng-model="json_req.pseudo" type="text" required>
<span class="form-error">
Pseudo Missing.
</span>
</label>
</div>
<div class="row">
<label class="float-center">
Password
<input ng-model="json_req.password" type="password" required>
<span class="form-error">
Password Missing.
</span>
</label>
</div>
</div>
Ok I find the solution. And is expected It was a stupid mistake from me xD
I should write ng-model="json_req.pseudo" and not ng-model="pseudo" to fill the json_req object :/
Sorry to have bothered you guys !
Thanks