Ejemplo n.º 1
0
        public async Task <IActionResult> Post([FromBody] PaymentMethodPayload payload)
        {
            var errors = ValidateAssociationPayload(payload);

            if (errors.Count > 0)
            {
                return(BadRequest(errors));
            }
            var provider            = Context.Providers.Single(x => x.Code.Equals(payload.ProviderCode));
            var endpoint            = provider.LinkEndpoint;
            var confirmationPayload = CreateConfirmationPayload(payload);
            var api = ProviderApiFactory.Create(endpoint);
            await api.AssociateAccount(confirmationPayload);

            var userId        = GetIdFromToken();
            var user          = Context.Users.Find(userId);
            var paymentMethod = new PaymentMethod {
                CreationTimestamp = DateTime.Now,
                Provider          = provider,
                User  = user,
                Token = confirmationPayload.AssociationToken
            };

            Context.PaymentMethods.Add(paymentMethod);
            Context.SaveChanges();
            return(Ok("OK"));
        }
Ejemplo n.º 2
0
        public void test_04_payment_method_payload_without_operation_token_from_provider_is_not_valid()
        {
            var dto = new PaymentMethodPayload {
                ProviderCode = Provider.Code
            };
            var errors = dto.Validate(Context);

            errors.Should().NotBeEmpty();
            errors.Count.Should().Be(1);
        }
Ejemplo n.º 3
0
        public void test_02_payment_method_payload_without_provider_code_is_not_valid()
        {
            var dto = new PaymentMethodPayload {
                OperationTokenFromProvider = "tokenFromProvider"
            };
            var errors = dto.Validate(Context);

            errors.Should().NotBeEmpty();
            errors.Count.Should().Be(1);
        }
Ejemplo n.º 4
0
        public void test_01_payment_method_payload_is_valid()
        {
            var dto = new PaymentMethodPayload
            {
                ProviderCode = Provider.Code, OperationTokenFromProvider = "tokenFromProvider"
            };
            var noErrors = dto.Validate(Context);

            noErrors.Should().BeEmpty();
        }
Ejemplo n.º 5
0
        public async void test_02_provider_token_is_bogus()
        {
            var paymentMethodPayload = new PaymentMethodPayload {
                ProviderCode = "A Bogus Code",
                OperationTokenFromProvider = VisaProviderToken
            };
            var linkingResult = await Controller.Post(paymentMethodPayload) as ObjectResult;

            linkingResult.Should().NotBeNull();
            linkingResult.StatusCode.Should().Be(400);
        }
Ejemplo n.º 6
0
        private PaymentMethodConfirmation CreateConfirmationPayload(PaymentMethodPayload payload)
        {
            var tokenStore         = new JwtTokenStore();
            var keyBuilder         = new SimpleKeyBuilder(Guid.NewGuid().ToString());
            var permanentTokenLife = DateTime.Now.AddHours(1);
            var token = tokenStore.GiveToken(permanentTokenLife, keyBuilder, new List <Claim>());

            return(new PaymentMethodConfirmation {
                AssociationToken = token,
                OperationTokenFromProvider = payload.OperationTokenFromProvider
            });
        }
Ejemplo n.º 7
0
        private List <string> ValidateAssociationPayload(PaymentMethodPayload payload)
        {
            var errors = new List <string>();
            var userId = GetIdFromToken();

            if (!Context.Users.Any(x => x.Id.Equals(userId)))
            {
                errors.Add($"User with id {userId} doesnt exist");
            }
            errors.AddRange(payload.Validate(Context));
            return(errors);
        }
Ejemplo n.º 8
0
        public async void test_01_visa_method_is_linked_succesfully()
        {
            var paymentMethodPayload = new PaymentMethodPayload {
                ProviderCode = VisaProvider.Code,
                OperationTokenFromProvider = VisaProviderToken
            };
            var linkingResult = await Controller.Post(paymentMethodPayload) as ObjectResult;

            linkingResult.Should().NotBeNull();
            linkingResult.StatusCode.Should().Be(200);
            Context.PaymentMethods.Count().Should().Be(1);
        }
Ejemplo n.º 9
0
        public void test_03_payment_method_payload_with_nonmatching_provider_is_not_valid()
        {
            var dto = new PaymentMethodPayload {
                OperationTokenFromProvider = "tokenFromProvider"
            };

            dto.ProviderCode = "NON_MATCHING_CODE";
            var errors = dto.Validate(Context);

            errors.Should().NotBeEmpty();
            errors.Count.Should().Be(1);
        }
Ejemplo n.º 10
0
 public static PaymentMethod CreatePaymentMethod(PaymentMethodPayload payload = null)
 {
     PaymentMethodPayload dummy = new PaymentMethodPayload()
     {
         FirstName = "FirstName",
         LastName = "LastName",
         Address1 = "123 Main St.",
         Address2 = "Apt #3",
         City = "Chicago",
         State = "IL",
         Zip = "10101",
         CardNumber = "4111-1111-1111-1111",
         Cvv = "123",
         ExpiryMonth = 3,
         ExpiryYear = 2015,
         Custom = "custom",
         Sandbox = true
     };
     dummy.Merge(payload);
     return PaymentMethod.Create(dummy);
 }
        public void TestInitialize()
        {
            Samurai.Options = new SamuraiOptions()
            {
                MerchantKey = "a1ebafb6da5238fb8a3ac9f6",
                MerchantPassword = "******",
                ProcessorToken = "5a0e1ca1e5a11a2997bbf912",
                Debug = true
            };

            defaultPayload = new PaymentMethodPayload()
            {
                FirstName = "FirstName",
                LastName = "LastName",
                Address1 = "123 Main St.",
                Address2 = "Apt #3",
                City = "Chicago",
                State = "IL",
                Zip = "10101",
                CardNumber = "4111-1111-1111-1111",
                Cvv = "123",
                ExpiryMonth = 3,
                ExpiryYear = 2015,
                Custom = "custom",
                Sandbox = true
            };
            defaultPaymentMethod = PaymentMethod.Create(defaultPayload);

            rand = new Random().Next().ToString();
        }
        public void S2SUpdateShouldBeSuccessfulPreservingSensitiveData()
        {
            var pm = TestHelper.CreatePaymentMethod(defaultPayload);
            defaultUpdatePayload = defaultUpdatePayload.Merge(new PaymentMethodPayload(){
                CardNumber = "****************",
                Cvv = "***"
            });
            pm.UpdateAttributes(defaultUpdatePayload);

            Assert.IsTrue(pm.IsSensitiveDataValid);
            Assert.IsTrue(pm.IsExpirationValid);
            Assert.AreEqual(defaultUpdatePayload.FirstName, pm.FirstName);
            Assert.AreEqual(defaultUpdatePayload.LastName, pm.LastName);
            Assert.AreEqual(defaultUpdatePayload.Address1, pm.Address1);
            Assert.AreEqual(defaultUpdatePayload.Address2, pm.Address2);
            Assert.AreEqual(defaultUpdatePayload.City, pm.City);
            Assert.AreEqual(defaultUpdatePayload.State, pm.State);
            Assert.AreEqual(defaultUpdatePayload.Zip, pm.Zip);
            Assert.AreEqual(defaultPayload.CardNumber.Substring(defaultPayload.CardNumber.Length - 4), pm.LastFourDigits);
            Assert.AreEqual(defaultUpdatePayload.ExpiryMonth, pm.ExpiryMonth);
            Assert.AreEqual(defaultUpdatePayload.ExpiryYear, pm.ExpiryYear);
        }