public void setting_additional_funding_sources_requires_allow_funding_sources_to_be_true()
        {
            var cr = new DwollaCheckoutRequest()
            {
                AllowFundingSources      = false,
                AdditionalFundingSources = FundingSource.Banks | FundingSource.Credit
            };

            validator.ShouldHaveValidationErrorFor(x => x.AllowFundingSources, cr);
            cr.AllowFundingSources = true;
            validator.ShouldNotHaveValidationErrorFor(x => x.AllowFundingSources, cr);
        }
Пример #2
0
        public void example_checkout_request()
        {
            var api = new DwollaServerCheckoutApi(appKey: "...", appSecret: "...");

            //Create a checkout request
            var checkoutRequest = new DwollaCheckoutRequest
            {
                OrderId       = "MyOrderTest",
                PurchaseOrder = new DwollaPurchaseOrder
                {
                    OrderItems =
                    {
                        new DwollaOrderItem
                            (name: "Candy Bar",
                            price: 25.00m,
                            quantity: 1)
                        {
                            Description = "Expensive Candy Bar",
                        }
                    },
                    DestinationId = "812-111-1111",
                },

                Callback = new Uri("http://www.example.com/order-callback")
            };

            //Optional: Validate your checkout request before
            //          sending the request to Dwolla.
            var preflightCheck = api.ValidatorFactory.GetValidator <DwollaCheckoutRequest>()
                                 .Validate(checkoutRequest);

            if (!preflightCheck.IsValid)
            {
                //Check preflightCheck.Errors for a list of validation errors.
            }

            //Send the request to Dwolla.
            var checkoutResponse = api.SendCheckoutRequest(checkoutRequest);

            if (!checkoutResponse.Success)
            {
                //Handle Error
            }
            else if (checkoutResponse.Success)
            {
                var redirectUrl = checkoutResponse.GetRedirectUrl();
                //Send HTTP Redirect to browser so the
                //customer can finish the checkout process
                Console.WriteLine(redirectUrl);
            }
        }
Пример #3
0
        public void example_checkout_request()
        {
            var api = new DwollaServerCheckoutApi( appKey:"...", appSecret: "..." );

            //Create a checkout request
            var checkoutRequest = new DwollaCheckoutRequest
                                      {
                                          OrderId = "MyOrderTest",
                                          PurchaseOrder = new DwollaPurchaseOrder
                                                              {
                                                                  OrderItems =
                                                                      {
                                                                          new DwollaOrderItem
                                                                              ( name: "Candy Bar",
                                                                                price: 25.00m,
                                                                                quantity: 1 )
                                                                              {
                                                                                  Description = "Expensive Candy Bar",
                                                                              }
                                                                      },
                                                                  DestinationId = "812-111-1111",
                                                              },

                                          Callback = new Uri( "http://www.example.com/order-callback" )

                                      };

            //Optional: Validate your checkout request before
            //          sending the request to Dwolla.
            var preflightCheck = api.ValidatorFactory.GetValidator<DwollaCheckoutRequest>()
                .Validate( checkoutRequest );
            if( !preflightCheck.IsValid )
            {
                //Check preflightCheck.Errors for a list of validation errors.
            }

            //Send the request to Dwolla.
            var checkoutResponse = api.SendCheckoutRequest( checkoutRequest );

            if( checkoutResponse.Result == DwollaCheckoutResponseResult.Failure )
            {
                //Handle Error
            }
            else if( checkoutResponse.Result == DwollaCheckoutResponseResult.Success)
            {
                var redirectUrl = api.GetCheckoutRedirectUrl( checkoutResponse );
                //Send HTTP Redirect to browser so the
                //customer can finish the checkout process
            }
        }
        public void allow_guest_checkout_validation()
        {
            var cr = new DwollaCheckoutRequest()
            {
                AllowGuestCheckout  = true,
                AllowFundingSources = false
            };

            validator.ShouldHaveValidationErrorFor(x => x.AllowFundingSources, cr);

            cr.AllowGuestCheckout  = true;
            cr.AllowFundingSources = true;
            validator.ShouldNotHaveValidationErrorFor(x => x.AllowFundingSources, cr);

            cr.AllowGuestCheckout  = false;
            cr.AllowFundingSources = false;
            validator.ShouldNotHaveValidationErrorFor(x => x.AllowFundingSources, cr);
        }
        public void allow_guest_checkout_validation()
        {
            var cr = new DwollaCheckoutRequest()
                {
                    AllowGuestCheckout = true,
                    AllowFundingSources = false
                };

            validator.ShouldHaveValidationErrorFor( x => x.AllowFundingSources, cr );

            cr.AllowGuestCheckout = true;
            cr.AllowFundingSources = true;
            validator.ShouldNotHaveValidationErrorFor( x => x.AllowFundingSources, cr );

            cr.AllowGuestCheckout = false;
            cr.AllowFundingSources = false;
            validator.ShouldNotHaveValidationErrorFor( x => x.AllowFundingSources, cr );
        }
        public void invalid_order_item_should_cause_checkout_request_to_fail_validation()
        {
            var badRequest = new DwollaCheckoutRequest
            {
                ClientId      = "abcdefg",
                ClientSecret  = "abcdefg",
                OrderId       = "MyOrderId1",
                PurchaseOrder = new DwollaPurchaseOrder
                {
                    OrderItems =
                    {
                        new DwollaOrderItem("Candy Bar", -25.00m, 0)
                        {
                            Description = "Expensive Candy Bar",
                        }
                    },
                    DestinationId = "",
                },
            };

            var results = new AttributedValidatorFactory().GetValidator <DwollaCheckoutRequest>()
                          .Validate(badRequest);

            results.IsValid.Should().BeFalse();

            //check customized error message descriptions too.
            results.Errors.Select(x =>
            {
                Console.WriteLine((object)x);
                return(x.ErrorMessage);
            }
                                  ).SequenceEqual(new[]
            {
                "'PurchaseOrder.DestinationId' should not be empty.",
                "The 'OrderItem.Price' for 'Candy Bar' must be greater than or equal to $0.00.",
                "The 'OrderItem.Quantity' for 'Candy Bar' must be greater than or equal to 1.",
                "'PurchaseOrder.Total' must be greater than or equal to '1.00'."
            })
            .Should().BeTrue();
        }
        public void invalid_order_item_should_cause_checkout_request_to_fail_validation()
        {
            var badRequest = new DwollaCheckoutRequest
                                 {
                                     ClientId = "abcdefg",
                                     ClientSecret = "abcdefg",
                                     OrderId = "MyOrderId1",
                                     PurchaseOrder = new DwollaPurchaseOrder
                                                         {
                                                             OrderItems =
                                                                 {
                                                                     new DwollaOrderItem("Candy Bar",-25.00m, 0)
                                                                         {
                                                                             Description = "Expensive Candy Bar",
                                                                         }
                                                                 },
                                                             DestinationId = "",
                                                         },
                                 };

            var results = new AttributedValidatorFactory().GetValidator<DwollaCheckoutRequest>()
                .Validate( badRequest );

            results.IsValid.Should().BeFalse();

            //check customized error message descriptions too.
            results.Errors.Select( x =>
                                       {
                                           Console.WriteLine( (object)x );
                                           return x.ErrorMessage;
                                       }
                ).SequenceEqual( new[]
                                     {
                                         "'PurchaseOrder.DestinationId' should not be empty.",
                                         "The 'OrderItem.Price' for 'Candy Bar' must be greater than or equal to $0.00.",
                                         "The 'OrderItem.Quantity' for 'Candy Bar' must be greater than or equal to 1.",
                                         "'PurchaseOrder.Total' must be greater than or equal to '1.00'."
                                     } )
                .Should().BeTrue();
        }
Пример #8
0
        public void can_seralize_valid_checkout_request()
        {
            var expected = @"{
              ""Key"": null,
              ""Secret"": null,
              ""Callback"": ""http://www.example.com/order-callback"",
              ""Redirect"": null,
              ""AllowGuestCheckout"": false,
              ""AllowFundingSources"": false,
              ""OrderId"": ""MyOrderTest"",
              ""Test"": false,
              ""PurchaseOrder"": {
            ""CustomerInfo"": null,
            ""DestinationId"": ""812-111-1111"",
            ""Discount"": 0.0,
            ""Shipping"": 0.0,
            ""Tax"": 0.0,
            ""Total"": 25.00,
            ""FacilitatorAmount"": null,
            ""OrderItems"": [
              {
            ""Description"": ""Expensive Candy Bar"",
            ""Name"": ""Candy Bar"",
            ""Price"": 25.00,
            ""Quantity"": 1
              }
            ],
            ""Notes"": null
              }
            }";

            var checkoutRequest = new DwollaCheckoutRequest
                                      {
                                          OrderId = "MyOrderTest",
                                          PurchaseOrder = new DwollaPurchaseOrder
                                                              {
                                                                  OrderItems =
                                                                      {
                                                                          new DwollaOrderItem
                                                                              ( name: "Candy Bar",
                                                                                price: 25.00m,
                                                                                quantity: 1 )
                                                                              {
                                                                                  Description = "Expensive Candy Bar",
                                                                              }
                                                                      },
                                                                  DestinationId = "812-111-1111",
                                                              },

                                          Callback = new Uri( "http://www.example.com/order-callback" )

                                      };

            var json = JsonConvert.SerializeObject( checkoutRequest, Formatting.Indented );
            Console.WriteLine( json );

            //Help with debugging serialization issues
            //File.WriteAllText( "_output.txt", json );
            //File.WriteAllText( "_expected.txt", expected );

            json.Should().Be( expected );
        }
Пример #9
0
        public void can_seralize_valid_checkout_request()
        {
            var expected = @"{
  ""client_id"": null,
  ""client_secret"": null,
  ""AssumeCosts"": false,
  ""CheckoutWithApi"": false,
  ""Callback"": ""http://www.example.com/order-callback"",
  ""Redirect"": null,
  ""AllowGuestCheckout"": false,
  ""AllowFundingSources"": false,
  ""OrderId"": ""MyOrderTest"",
  ""Test"": false,
  ""PurchaseOrder"": {
    ""CustomerInfo"": null,
    ""DestinationId"": ""812-111-1111"",
    ""Discount"": 0.0,
    ""Shipping"": 0.0,
    ""Tax"": 0.0,
    ""Total"": 25.00,
    ""FacilitatorAmount"": null,
    ""OrderItems"": [
      {
        ""Description"": ""Expensive Candy Bar"",
        ""Name"": ""Candy Bar"",
        ""Price"": 25.00,
        ""Quantity"": 1
      }
    ],
    ""Notes"": null,
    ""Metadata"": {}
  },
  ""ProfileId"": null,
  ""AdditionalFundingSources"": null
}";

            var checkoutRequest = new DwollaCheckoutRequest
            {
                OrderId       = "MyOrderTest",
                PurchaseOrder = new DwollaPurchaseOrder
                {
                    OrderItems =
                    {
                        new DwollaOrderItem
                            (name: "Candy Bar",
                            price: 25.00m,
                            quantity: 1)
                        {
                            Description = "Expensive Candy Bar",
                        }
                    },
                    DestinationId = "812-111-1111",
                },

                Callback = new Uri("http://www.example.com/order-callback")
            };

            var json = JsonConvert.SerializeObject(checkoutRequest, Formatting.Indented);

            Console.WriteLine(json);

            //Help with debugging serialization issues
            //File.WriteAllText( "_output.txt", json );
            //File.WriteAllText( "_expected.txt", expected );

            json.Should().Be(expected);
        }
 public void setting_additional_funding_sources_requires_allow_funding_sources_to_be_true()
 {
     var cr = new DwollaCheckoutRequest()
         {
             AllowFundingSources = false,
             AdditionalFundingSources = FundingSource.Banks | FundingSource.Credit
         };
     validator.ShouldHaveValidationErrorFor(x => x.AllowFundingSources, cr);
     cr.AllowFundingSources = true;
     validator.ShouldNotHaveValidationErrorFor(x => x.AllowFundingSources, cr);
 }