コード例 #1
0
        public ActionResult SpecialistRegisterStep3(SpecialistPaymentViewModel paymentModel, Guid id)
        {
            var user = Services.Users.GetUserById(id);

            if (paymentModel.CreditCard == null)
            {
                @ViewBag.Error = NotificationMessage.MissingPaymentMethod;
                return View("SpecialistRegisterStep3");
            }

            try
            {
                Services.Payment.SetCurrentUser(user.FirstName, user.LastName, user.Email, user.MobilePhone);

                var expiry = paymentModel.CreditCard.ExpDate.MonthExp + paymentModel.CreditCard.ExpDate.YearExp.ToString();

                PaymentCard card = new PaymentCard(paymentModel.CreditCard.NameCard, paymentModel.CreditCard.CardNumber, Convert.ToDateTime(expiry), paymentModel.CreditCard.SecurityCode);

                // Check the existing of current user
                bool isExist = Services.Payment.IsCustomerExists(user.Id.ToString());
                StoreCustomerResult storeResult;
                if (isExist)
                    storeResult = Services.Payment.UpdateCustomerWithCreditCard(card, user.Id);
                else
                    storeResult = Services.Payment.StoreCustomerWithCreditCard(card, user.Id);

                if (string.IsNullOrWhiteSpace(storeResult.ErrorMessage))
                {
                    user.Profile.BSB = paymentModel.Bank.BSB;
                    user.Profile.AccountName = paymentModel.Bank.AccountName;
                    user.Profile.AccountNumber = paymentModel.Bank.AccountNumber;
                    user.CompletedStep = Step.Step3;
                    user.PaymentMethod = PaymentMethod.CreditCard;
                    Services.Users.UpdateUserInfo(user);

                    return RedirectToAction("SpecialistRegisterStep4", new { id = id });
                }
                else
                {
                    @ViewBag.Error = storeResult.ErrorMessage;
                    return View("SpecialistRegisterStep3");
                }
            }
            catch
            {
                @ViewBag.Error = UiHints.WarningMessageTemplates.UnableConnectToPaymentGateway;
                return View("SpecialistRegisterStep3");
            }
        }
コード例 #2
0
        public StoreCustomerResult UpdateCustomerWithCreditCard(PaymentCard card, Guid userId)
        {
            var request = new CustomerRequest
            {
                Id = userId.ToString(),
                FirstName = currentUser.FirstName,
                LastName = currentUser.LastName,
                Email = currentUser.Email,
                Phone = currentUser.MobilePhone,

                CreditCard = new CreditCardRequest
                {
                    CardholderName = card.Name,
                    Number = card.Number,
                    CVV = card.CVV,
                    ExpirationDate = card.ExpiryDate.ToString("MM/yyyy"),
                    Options = new CreditCardOptionsRequest
                    {
                        MakeDefault = true,
                        VerifyCard = true
                    }
                }
            };

            Result<Customer> result = Gateway.Customer.Update(userId.ToString(), request);

            if (result.IsSuccess())
            {
                Customer customer = result.Target;
                return new StoreCustomerResult { CustomerId = customer.Id, FirstName = customer.FirstName, LastName = customer.LastName };
            }
            else
            {
                foreach (ValidationError error in result.Errors.DeepAll())
                {
                    if (error.Code == ValidationErrorCode.CREDIT_CARD_NUMBER_IS_INVALID ||
                        error.Code == ValidationErrorCode.CREDIT_CARD_CREDIT_CARD_TYPE_IS_NOT_ACCEPTED)
                    {
                        return new StoreCustomerResult { ErrorMessage = ErrorMessage.CreditCardNumberInvalid };
                    }
                }
                return new StoreCustomerResult { ErrorMessage = result.Message };
            }
        }
コード例 #3
0
        public PaymentResult Transaction(PaymentCard card, decimal amount)
        {
            TransactionRequest request = new TransactionRequest
            {
                Amount = amount,
                CreditCard = new TransactionCreditCardRequest
                {
                    CardholderName = card.Name,
                    Number = card.Number,
                    CVV = card.CVV,
                    ExpirationDate = card.ExpiryDate.ToString("MM/yyyy"),
                },
                Options = new TransactionOptionsRequest
                {
                    SubmitForSettlement = true,
                    StoreInVault = false
                }
            };

            Result<Transaction> result = Gateway.Transaction.Sale(request);

            if (result.IsSuccess())
            {
                return new PaymentResult { Success = true, Transaction = result.Target };
            }
            else
            {
                foreach (ValidationError error in result.Errors.DeepAll())
                {
                    if (error.Code == ValidationErrorCode.CREDIT_CARD_NUMBER_IS_INVALID ||
                        error.Code == ValidationErrorCode.CREDIT_CARD_CREDIT_CARD_TYPE_IS_NOT_ACCEPTED)
                    {
                        return new PaymentResult { Success = false, ErrorMessage = ErrorMessage.CreditCardNumberInvalid };
                    }
                }
                return new PaymentResult { Success = false, ErrorMessage = result.Message };
            }
        }
コード例 #4
0
 public PaymentResult StoreCard(PaymentCard card)
 {
     var request = new CreditCardRequest
     {
         CardholderName = card.Name,
         Number = card.Number,
         CVV = card.CVV,
         ExpirationDate = card.ExpiryDate.ToString("MM/yyyy"),
         Options = new CreditCardOptionsRequest
         {
             MakeDefault = true,
             VerifyCard = true
         }
     };
     var response = Gateway.CreditCard.Create(request);
     if (response.IsSuccess())
     {
         return new PaymentResult { Success = true };
     }
     else
     {
         return new PaymentResult { Success = true, ErrorMessage = response.Message };
     }
     throw new ApplicationException("Cannot add card to vault.");
 }
コード例 #5
0
        public StoreCustomerResult CreateMerchantAccounts(PaymentAddress addr, BankAccountDetail bank, PaymentCard card)
        {
            MerchantAccountRequest request = new MerchantAccountRequest
            {
                Individual = new IndividualRequest
                {
                    FirstName = currentUser.FirstName,
                    LastName = currentUser.LastName,
                    Email = currentUser.Email,
                    Phone = currentUser.MobilePhone,
                    Address = new AddressRequest
                    {
                        StreetAddress = addr.StreetAddress,
                        Locality = addr.Locality,
                        Region = addr.Region,
                    }
                },
                Funding = new FundingRequest
                {
                    Destination = FundingDestination.BANK,
                    MobilePhone = currentUser.MobilePhone,
                    AccountNumber = bank.AccountNumber,
                    RoutingNumber = bank.BSB
                },
                TosAccepted = true,
            };

            Result<MerchantAccount> result = Gateway.MerchantAccount.Create(request);
            if (result.IsSuccess())
            {
                MerchantAccount merchant = result.Target;

                return new StoreCustomerResult
                {
                    CustomerId = merchant.Id,
                    FirstName = merchant.IndividualDetails.FirstName,
                    LastName = merchant.IndividualDetails.LastName
                };
            }
            else
            {
                return new StoreCustomerResult { ErrorMessage = result.Message };
            }
        }
コード例 #6
0
        public async Task<ActionResult> CreateStep2(PaymentViewModel model, string btnNext)
        {
            if (btnNext != null)
            {
                if (ModelState.IsValid)
                {
                    UserDto user = Services.Users.GetByUserName(model.UserName);
                    if (user != null)
                    {
                        // -------Payment----------
                        if (model.CreditCard != null && !string.IsNullOrWhiteSpace(model.CreditCard.CardNumber))
                        {
                            try
                            {
                                Services.Payment.SetCurrentUser(user.FirstName, user.LastName, user.Email, user.MobilePhone);

                                var expiry = model.CreditCard.ExpDate.MonthExp + model.CreditCard.ExpDate.YearExp.ToString();

                                PaymentCard card = new PaymentCard(model.CreditCard.NameCard, model.CreditCard.CardNumber, Convert.ToDateTime(expiry), model.CreditCard.SecurityCode);

                                // Check the existing of current user
                                bool isExist = Services.Payment.IsCustomerExists(user.Id.ToString());
                                StoreCustomerResult storeResult;
                                if (isExist)
                                    storeResult = Services.Payment.UpdateCustomerWithCreditCard(card, user.Id);
                                else
                                    storeResult = Services.Payment.StoreCustomerWithCreditCard(card, user.Id);

                                if (string.IsNullOrWhiteSpace(storeResult.ErrorMessage))
                                {
                                    user.PaymentMethod = PaymentMethod.CreditCard;
                                }
                                else
                                {
                                    ViewBag.Error = storeResult.ErrorMessage;
                                }
                            }
                            catch (Exception e)
                            {
                                ViewBag.Error = e.Message;
                            }
                        }
                        else if (model.Prepayment != null)
                        {
                            try
                            {
                                var expiry = model.Prepayment.ExpDate.MonthExp + model.Prepayment.ExpDate.YearExp.ToString();
                                try
                                {
                                    var amount = Convert.ToDecimal(model.Prepayment.Amount);
                                    if (amount > 0)
                                    {
                                        PaymentResult prepayResult = Services.Payment.Transaction(new PaymentCard(model.Prepayment.NameCard, model.Prepayment.CardNumber, Convert.ToDateTime(expiry), model.Prepayment.SecurityCode), amount);

                                        if (prepayResult.Success)
                                        {
                                            user.PrePaymentAmount = amount;
                                            user.PaymentMethod = PaymentMethod.PrePayment;

                                            var invoice = Services.Invoices.CreatePrepaymentInvoice(amount, user);
                                        }
                                        else
                                        {
                                            ViewBag.Error = prepayResult.ErrorMessage;
                                        }
                                    }
                                    else
                                    {
                                        ViewBag.Error = NotificationMessage.AmountError;
                                    }
                                }
                                catch (Exception e)
                                {
                                    ViewBag.Error = e.Message;
                                }
                            }
                            catch
                            {
                                ViewBag.Error = NotificationMessage.PrepaymentError;
                            }
                        }

                        if (ViewBag.Error == null)
                        {
                            // Save account
                            user.CompletedStep = Step.Step2;
                            user.Status = Status.InActive;

                            if (user.IsPhoneConfirmed && user.IsEmailConfirmed)
                            {
                                user.Status = Status.Active;
                            }

                            if (Services.Users.UpdateUserInfo(user))
                            {
                                return RedirectToAction("ListBooking", "Booking");
                            }
                            else
                            {
                                Log.Error("Update account failed at cus-registration step 2. UserId: " + user.Id);
                                ViewBag.Error = "Update account failed";
                            }
                        }
                        else
                        {
                            return View(model);
                        }
                    }
                    else
                    {
                        ViewBag.Error = "Account does not exists";
                    }
                }
            }
            return View(model);
        }