-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSDK.cs
162 lines (140 loc) · 4.41 KB
/
SDK.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
// Decompiled with JetBrains decompiler
// Type: MercadoPago.SDK
// Assembly: MercadoPago, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 0C24A3BA-51C0-4EAB-8180-D4EA12994FDF
// Assembly location: C:\Users\Laucha\source\repos\WindowsFormsApp1\WindowsFormsApp1\bin\Debug\MercadoPago.dll
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Configuration;
namespace MercadoPago
{
public class SDK
{
private string UserToken = (string) null;
public string RefreshToken = (string) null;
private string _clientSecret = (string) null;
private string _clientId = (string) null;
private string _accessToken = (string) null;
private string _appId = (string) null;
private string _baseUrl = "https://api.mercadopago.com";
private const string DEFAULT_BASE_URL = "https://api.mercadopago.com";
public string ClientSecret
{
get
{
return this._clientSecret;
}
set
{
this._clientSecret = value;
}
}
public string ClientId
{
get
{
return this._clientId;
}
set
{
this._clientId = value;
}
}
public string AccessToken
{
get
{
return this._accessToken;
}
set
{
this._accessToken = value;
}
}
public string AppId
{
get
{
return this._appId;
}
set
{
this._appId = value;
}
}
public string BaseUrl
{
get
{
return this._baseUrl;
}
}
public void SetConfiguration(IDictionary<string, string> configurationParams)
{
if (configurationParams == null)
throw new ArgumentException("Invalid configurationParams parameter");
configurationParams.TryGetValue("clientSecret", out this._clientSecret);
configurationParams.TryGetValue("clientId", out this._clientId);
configurationParams.TryGetValue("accessToken", out this._accessToken);
configurationParams.TryGetValue("appId", out this._appId);
}
//public static void SetConfiguration(System.Configuration.Configuration config)
//{
// if (config == null)
// throw new ArgumentException("config parameter cannot be null");
// SDK._clientSecret = SDK.GetConfigValue(config, "ClientSecret");
// SDK._clientId = SDK.GetConfigValue(config, "ClientId");
// SDK._accessToken = SDK.GetConfigValue(config, "AccessToken");
// SDK._appId = SDK.GetConfigValue(config, "AppId");
//}
public void CleanConfiguration()
{
this._clientSecret = (string) null;
this._clientId = (string) null;
this._accessToken = (string) null;
this._appId = (string) null;
this._baseUrl = "https://api.mercadopago.com";
}
public void SetBaseUrl(string baseUrl)
{
this._baseUrl = baseUrl;
}
//private static string GetConfigValue(System.Configuration.Configuration config, string key)
//{
// string str = (string) null;
// KeyValueConfigurationElement setting = config.AppSettings.Settings[key];
// if (setting != null)
// str = setting.Value;
// return str;
//}
public string GetAccessToken()
{
if (string.IsNullOrEmpty(this.AccessToken))
this.AccessToken = MPCredentials.GetAccessToken(this);
return this.AccessToken;
}
public void SetAccessToken(string accessToken)
{
if (!string.IsNullOrEmpty(this.AccessToken))
throw new MPException("Access_Token setting cannot be changed.");
this.AccessToken = accessToken;
}
public string GetUserToken()
{
return this.UserToken;
}
public JToken Get(string uri)
{
return new MPRESTClient().ExecuteGenericRequest(HttpMethod.GET, uri, PayloadType.JSON, (JObject) null, this);
}
public JToken Post(string uri, JObject payload)
{
return new MPRESTClient().ExecuteGenericRequest(HttpMethod.POST, uri, PayloadType.JSON, payload, this);
}
public JToken Put(string uri, JObject payload)
{
return new MPRESTClient().ExecuteGenericRequest(HttpMethod.PUT, uri, PayloadType.JSON, payload, this);
}
}
}