Esempio n. 1
0
        /// <summary>
        /// The add transaction.
        /// </summary>
        /// <param name="request">
        /// The request.
        /// </param>
        /// <returns>
        /// The <see cref="AddTransactionResponse"/>.
        /// </returns>
        public AddTransactionResponse AddTransaction(AddTransactionRequest request)
        {
            var response = new AddTransactionResponse { MessageType = Messaging.MessageType.Success };
            try
            {
                var transaction = request.ConvertToTransaction();
                transaction.WalletId = request.WalletId;
                transaction.OperationType = OperationType.PayPalBalanceLoad;
                var result = this.transactionsRepository.AddTransaction(transaction);
                response = result.ConvertToAddTransactionResponse();
            }
            catch (Exception e)
            {
                response.MessageType = Messaging.MessageType.Error;
                response.Message = e.Message;
            }

            return response;
        }
Esempio n. 2
0
 public ActionResult AddTransaction(string amount)
 {
     var localAmount = decimal.Parse(amount, CultureInfo.InvariantCulture);
     try
     {
         // get token from paypal
         var token = PayPalHelper.GetTokenFromPayPalApi(
             localAmount,
             ResolveServerUrl(this.HttpContext, VirtualPathUtility.ToAbsolute(Url.Action("PaymentSucceded", "Member")), false),
             ResolveServerUrl(this.HttpContext, VirtualPathUtility.ToAbsolute(Url.Action("PaymentCanceled", "Member")), false),
             "SAW sandbox test deposit", // TODO add description
             "SAW");
         
         var profile = this.membershipService.GetProfile(new Services.Messaging.Membership.GetProfileRequest
                                          {
                                              IdentityToken = this.FormsAuthentication.GetAuthenticationToken()
                                          });
         var request = new AddTransactionRequest
         {
             Date = DateTime.Now,
             IdentityToken = this.FormsAuthentication.GetAuthenticationToken(),
             OperationAmount = localAmount,
             OperationDescription = "PayPal transaction",
             TransactionStatus = TransactionStatus.InProgress,
             Token = token,
             WalletId = profile.WalletId
         };
         var response = this.transactionService.AddTransaction(request);
         var jsonNetResult = new JsonNetResult
         {
             Formatting = (Formatting)Newtonsoft.Json.Formatting.Indented,
             Data = new AddTransactionViewModel { Message = response.Message, MessageType = response.MessageType.ToString(), RedirectUrl = PayPalHelper.GetRedirectUrl(token) }
         };
         return jsonNetResult;
     }
     catch (PayPalException ex)
     {
         var jsonNetResult = new JsonNetResult
         {
             Formatting = (Formatting)Newtonsoft.Json.Formatting.Indented,
             Data = new AddTransactionViewModel { Message = ex.Message, MessageType = "Error" }
         };
         return jsonNetResult;
     }
 }