/// <summary> /// Generate the URL for creating a limit, including the /// provided params, nonce, timestamp and signature /// </summary> /// <param name="type">the limit type (subscription, etc)</param> /// <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> private static string GenerateNewLimitUrl(string type, object requestResource, string redirectUri = null, string cancelUri = null, string state = null) { var hash = new Utils.HashParams { { "client_id", GoCardless.AccountDetails.AppId }, { "nonce", GoCardless.GenerateNonce() }, { "timestamp", GoCardless.GetUtcNow().IsoFormatTime() }, }; hash = requestResource.ToHashParams(hash, type); if (redirectUri != null) { hash.Add("redirect_uri", redirectUri); } if (cancelUri != null) { hash.Add("cancel_uri", cancelUri); } if (state != null) { hash.Add("state", state); } hash = SignParams(hash); var url = GoCardless.BaseUrl + "/connect/" + type + "s/new?" + hash.ToQueryString(); return(url); }
/// <summary> /// Add a signature to a Hash of parameters. The signature will be generated /// from the app secret and the provided parameters, and should be used /// whenever signed data needs to be sent to GoCardless (e.g. when creating /// a new subscription). The signature will be added to the hash under the /// key signature. /// </summary> /// <param name="params">the parameters to sign</param> /// <returns>the parameters with the new signature key</returns> private static Utils.HashParams SignParams(Utils.HashParams @params) { var signature = Utils.GetSignatureForParams(@params, GoCardless.AccountDetails.AppSecret); @params.Add("signature", signature); return(@params); }
/// <summary> /// Generate the URL for creating a limit, including the /// provided params, nonce, timestamp and signature /// </summary> /// <param name="type">the limit type (subscription, etc)</param> /// <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> private static string GenerateNewLimitUrl(string type, object requestResource, string redirectUri = null, string cancelUri = null, string state = null) { var hash = new Utils.HashParams { {"client_id", GoCardless.AccountDetails.AppId}, {"nonce", GoCardless.GenerateNonce()}, {"timestamp", GoCardless.GetUtcNow().IsoFormatTime()}, }; hash = requestResource.ToHashParams(hash, type); if (redirectUri != null) { hash.Add("redirect_uri", redirectUri); } if (cancelUri != null) { hash.Add("cancel_uri", cancelUri); } if (state != null) { hash.Add("state", state); } hash = SignParams(hash); var url = GoCardless.BaseUrl + "/connect/" + type + "s/new?" + hash.ToQueryString(); return url; }