public void ToHashtableTests() { var subscription = new SubscriptionRequest("merchant123", 2m, 1, "month") { User = new UserRequest { FirstName = "Tim", Email = "*****@*****.**" } }; var subscriptionHash = subscription.ToHashParams(); Assert.AreEqual(2m, subscriptionHash["amount"].Single()); Assert.AreEqual("merchant123", subscriptionHash["merchant_id"].Single()); Assert.AreEqual("Tim", subscriptionHash["user[first_name]"].Single()); Assert.AreEqual("*****@*****.**", subscriptionHash["user[email]"].Single()); var manageMerchant = new ManageMerchantRequest { Merchant = new Merchant { Name = "Mike the Merchant", BillingAddress1 = "Flat 1", BillingAddress2 = "200 High St", BillingTown = "Townville", BillingCounty = "Countyshire", BillingPostcode = "N1 1AB", User = new User { FirstName = "Mike", LastName = "Merchant", Email = "*****@*****.**", } } }; var manageMerchantHash = manageMerchant.ToHashParams(); Assert.AreEqual("Mike the Merchant", manageMerchantHash["merchant[name]"].Single()); Assert.AreEqual("Flat 1", manageMerchantHash["merchant[billing_address1]"].Single()); Assert.AreEqual("200 High St", manageMerchantHash["merchant[billing_address2]"].Single()); Assert.AreEqual("Townville", manageMerchantHash["merchant[billing_town]"].Single()); Assert.AreEqual("Countyshire", manageMerchantHash["merchant[billing_county]"].Single()); Assert.AreEqual("N1 1AB", manageMerchantHash["merchant[billing_postcode]"].Single()); Assert.AreEqual("Mike", manageMerchantHash["merchant[user][first_name]"].Single()); Assert.AreEqual("Merchant", manageMerchantHash["merchant[user][last_name]"].Single()); Assert.AreEqual("*****@*****.**", manageMerchantHash["merchant[user][email]"].Single()); }
/// <summary> /// Generate the URL for creating a new subscription. /// </summary> /// <remarks> /// The parameters passed in define various attributes of the subscription. /// Redirecting a user to the resulting URL will show them a page where they /// can approve or reject the subscription described by the parameters. /// Note that this method automatically includes the nonce, timestamp and signature. /// </remarks> /// <param name="requestResource">the request values</param> /// <param name="redirectUri">optional override URI on success</param> /// <param name="cancelUri">optional override URI on cancel</param> /// <param name="state">optional state, gets passed back with the successful payload</param> /// <returns>the generated URL</returns> public string NewSubscriptionUrl(SubscriptionRequest requestResource, string redirectUri = null, string cancelUri = null, string state = null) { return GenerateNewLimitUrl("subscription", requestResource, redirectUri, cancelUri, state); }
public void NewSubscriptionUrl_IncOptionalParams_GeneratesCorrectUrl() { var request = new SubscriptionRequest("0190G74E3J", 15m, 1, "month") { StartAt = new DateTimeOffset(new DateTime(2012, 03, 24, 19, 32, 22)), ExpiresAt = new DateTimeOffset(new DateTime(2013, 03, 24, 19, 32, 22)), Name = "Premium Account", Description = "test subscription", IntervalCount = 12, User = new UserRequest { Name = "John Smith", FirstName = "John", LastName = "Smith", Email = "*****@*****.**", BillingAddress1 = "Flat 1", BillingAddress2 = "100 Main Street", BillingTown = "Townville", BillingCounty = "Countyshire", BillingPostcode = "N1 1AB", } }; GoCardless.Environment = GoCardless.Environments.Sandbox; GoCardless.AccountDetails.AppId = "test_id"; GoCardless.AccountDetails.AppSecret = "test_secret"; GoCardless.GenerateNonce = () => "Q9gMPVBZixfRiQ9VnRdDyrrMiskqT0ox8IT+HO3ReWMxavlco0Fw8rva+ZcI"; GoCardless.GetUtcNow = () => new DateTimeOffset(new DateTime(2012, 03, 21, 08, 55, 56)); var url = GoCardless.Connect.NewSubscriptionUrl(request); var expected = "https://sandbox.gocardless.com/connect/subscriptions/new?client_id=test_id&nonce=Q9gMPVBZixfRiQ9VnRdDyrrMiskqT0ox8IT%2BHO3ReWMxavlco0Fw8rva%2BZcI&signature=7b5a1fe9abc37a21c9cd8b22cd09dfbca9ec3d8d9cd1083796c6a4cbef666984&subscription%5Bamount%5D=15.00&subscription%5Bdescription%5D=test%20subscription&subscription%5Bexpires_at%5D=2013-03-24T19%3A32%3A22Z&subscription%5Binterval_count%5D=12&subscription%5Binterval_length%5D=1&subscription%5Binterval_unit%5D=month&subscription%5Bmerchant_id%5D=0190G74E3J&subscription%5Bname%5D=Premium%20Account&subscription%5Bstart_at%5D=2012-03-24T19%3A32%3A22Z&subscription%5Buser%5D%5Bbilling_address1%5D=Flat%201&subscription%5Buser%5D%5Bbilling_address2%5D=100%20Main%20Street&subscription%5Buser%5D%5Bbilling_county%5D=Countyshire&subscription%5Buser%5D%5Bbilling_postcode%5D=N1%201AB&subscription%5Buser%5D%5Bbilling_town%5D=Townville&subscription%5Buser%5D%5Bemail%5D=john.smith%40example.com&subscription%5Buser%5D%5Bfirst_name%5D=John&subscription%5Buser%5D%5Blast_name%5D=Smith&subscription%5Buser%5D%5Bname%5D=John%20Smith×tamp=2012-03-21T08%3A55%3A56Z"; Assert.AreEqual(expected, url); }
public void NewSubscriptionUrl_ExcOptionalParams_GeneratesCorrectUrl() { var request = new SubscriptionRequest("0190G74E3J", 15m, 1, "month"); GoCardless.Environment = GoCardless.Environments.Sandbox; GoCardless.AccountDetails.AppId = "test_id"; GoCardless.AccountDetails.AppSecret = "test_secret"; GoCardless.GenerateNonce = () => "Q9gMPVBZixfRiQ9VnRdDyrrMiskqT0ox8IT+HO3ReWMxavlco0Fw8rva+ZcI"; GoCardless.GetUtcNow = () => new DateTimeOffset(new DateTime(2012, 03, 21, 08, 55, 56)); var url = GoCardless.Connect.NewSubscriptionUrl(request); var expected = "https://sandbox.gocardless.com/connect/subscriptions/new?client_id=test_id&nonce=Q9gMPVBZixfRiQ9VnRdDyrrMiskqT0ox8IT%2BHO3ReWMxavlco0Fw8rva%2BZcI&signature=5e17c04a0f7f211f55bba6ba633cb06121eb79c3284a5a1d9ac0ba5d0bce0c80&subscription%5Bamount%5D=15.00&subscription%5Binterval_length%5D=1&subscription%5Binterval_unit%5D=month&subscription%5Bmerchant_id%5D=0190G74E3J×tamp=2012-03-21T08%3A55%3A56Z"; Assert.AreEqual(expected, url); }
/// <summary> /// Generate the URL for creating a new subscription. /// </summary> /// <remarks> /// The parameters passed in define various attributes of the subscription. /// Redirecting a user to the resulting URL will show them a page where they /// can approve or reject the subscription described by the parameters. /// Note that this method automatically includes the nonce, timestamp and signature. /// </remarks> /// <param name="requestResource">the request values</param> /// <param name="redirectUri">optional override URI on success</param> /// <param name="cancelUri">optional override URI on cancel</param> /// <param name="state">optional state, gets passed back with the successful payload</param> /// <returns>the generated URL</returns> public string NewSubscriptionUrl(SubscriptionRequest requestResource, string redirectUri = null, string cancelUri = null, string state = null) { return(GenerateNewLimitUrl("subscription", requestResource, redirectUri, cancelUri, state)); }
public void ToQueryStringTests() { Assert.AreEqual("name=Bob", new UserRequest {Name = "Bob"}.ToQueryString()); var subscription = new SubscriptionRequest("merchant123", 2m, 1, "month") { StartAt = new DateTimeOffset(new DateTime(2011, 01, 01, 12, 00, 00)), User = new UserRequest { Name = "John Smith", FirstName = "John", } }; Assert.AreEqual( "amount=2.00&interval_length=1&interval_unit=month&merchant_id=merchant123&start_at=2011-01-01T12%3A00%3A00Z&user%5Bfirst_name%5D=John&user%5Bname%5D=John%20Smith", subscription.ToQueryString()); }