I have encountered an issue while trying to call a service method in AngularJS. The service method is being called successfully, but it is not returning any value to the controller function that invoked it.
If anyone can offer assistance, I would greatly appreciate it. Below is my code:
logosStreams.factory("processPaypal", ['$http', '$timeout', '$q', '$state',function($http, $timeout, $q, $state){
var transCall = {};
var transcallPromise2 = $q.defer();
return {
onSuccesfulPayment: function(payment) {
console.log("payment success: " + JSON.stringify(payment, null, 4));
transcallPromise2.resolve(payment);
},
onAuthorizationCallback: function(authorization) {
console.log("authorization: " + JSON.stringify(authorization, null, 4));
//return authorization;
},
createPayment: function(data) {
// for simplicity use predefined amount
var paymentDetails = new PayPalPaymentDetails("0", "0", "0");
var payment = new PayPalPayment(data.amt, "USD", data.name, "Sale",
paymentDetails);
return payment;
},
buyInFutureBtn : function(e) {
// future payment
PayPalMobile.renderFuturePaymentUI(this.onAuthorizationCallback, this.onUserCanceled);
},
profileSharingBtn : function(e) {
// profile sharing
PayPalMobile.renderProfileSharingUI(["profile", "email", "phone","address", "futurepayments", "paypalattributes"],
this.onAuthorizationCallback, this.onUserCanceled);
},
buyNowBtn : function(data) {
// single payment
PayPalMobile.renderSinglePaymentUI(this.createPayment(data), this.onSuccesfulPayment, this.onUserCanceled);
return transcallPromise2.promise;
},
onPrepareRender: function() {
},
onUserCanceled: function(result) {
console.log(result);
transcallPromise2.reject(result);
}
}
}])
To invoke the `buyNowBtn` method within the controller:
processPaypal.buyNowBtn($scope.MMParams).then(function(response){
console.log(response);
})