Using GCheckout.dll
Join("") is an IEnumerable extension I wrote (to concatenate strings with a separator) Base64Decode() is a string extension I wrote (decode base64)
Configuration.Google[Test]Merchant{Id|Key} are just some static variables holding my info.
- private GCheckout.EnvironmentType CheckAuthorization(string authHeader)
- {
- if (string.IsNullOrEmpty(authHeader))
- {
- Logger.Debug("No Authorization Header");
- return GCheckout.EnvironmentType.Unknown;
- }
- if (authHeader.Contains("Basic"))
- authHeader = authHeader.Substring(authHeader.IndexOf("Basic") + 5);
- var base64Auth = authHeader.Trim().Base64Decode();
- var userPass = base64Auth.Split(':');
- if (userPass.Length < 2)
- {
- Logger.Debug("Authorization Header was malformed. Raw: " + authHeader + ", Base64Decoded: " + base64Auth);
- return GCheckout.EnvironmentType.Unknown;
- }
- if (userPass.Length > 2)
- userPass[1] = userPass.Skip(1).Join("");
- if (userPass[0] == Configuration.GoogleMerchantId &&
- userPass[1] == Configuration.GoogleMerchantKey)
- {
- return GCheckout.EnvironmentType.Production;
- }
- else if (userPass[0] == Configuration.GoogleTestMerchantId &&
- userPass[1] == Configuration.GoogleTestMerchantKey)
- {
- return GCheckout.EnvironmentType.Sandbox;
- }
- else
- {
- return GCheckout.EnvironmentType.Unknown;
- }
- }
No comments:
Post a Comment