/ Published in: C#
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.
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.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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; } }