|
| 1 | +using Bunq.Sdk.Context; |
| 2 | +using Bunq.Sdk.Http; |
| 3 | +using Bunq.Sdk.Json; |
| 4 | +using Bunq.Sdk.Model.Core; |
| 5 | +using Bunq.Sdk.Security; |
| 6 | +using Newtonsoft.Json; |
| 7 | +using System.Collections.Generic; |
| 8 | +using System.Text; |
| 9 | +using System; |
| 10 | + |
| 11 | +namespace Bunq.Sdk.Model.Generated.Endpoint |
| 12 | +{ |
| 13 | + /// <summary> |
| 14 | + /// Endpoint for generating and retrieving a new CVC2 code. |
| 15 | + /// </summary> |
| 16 | + public class CardGeneratedCvc2 : BunqModel |
| 17 | + { |
| 18 | + /// <summary> |
| 19 | + /// Endpoint constants. |
| 20 | + /// </summary> |
| 21 | + private const string ENDPOINT_URL_CREATE = "user/{0}/card/{1}/generated-cvc2"; |
| 22 | + private const string ENDPOINT_URL_READ = "user/{0}/card/{1}/generated-cvc2/{2}"; |
| 23 | + private const string ENDPOINT_URL_LISTING = "user/{0}/card/{1}/generated-cvc2"; |
| 24 | + |
| 25 | + /// <summary> |
| 26 | + /// Object type. |
| 27 | + /// </summary> |
| 28 | + private const string OBJECT_TYPE = "CardGeneratedCvc2"; |
| 29 | + |
| 30 | + /// <summary> |
| 31 | + /// The id of the cvc code. |
| 32 | + /// </summary> |
| 33 | + [JsonProperty(PropertyName = "id")] |
| 34 | + public int? Id { get; private set; } |
| 35 | + |
| 36 | + /// <summary> |
| 37 | + /// The timestamp of the cvc code's creation. |
| 38 | + /// </summary> |
| 39 | + [JsonProperty(PropertyName = "created")] |
| 40 | + public string Created { get; private set; } |
| 41 | + |
| 42 | + /// <summary> |
| 43 | + /// The timestamp of the cvc code's last update. |
| 44 | + /// </summary> |
| 45 | + [JsonProperty(PropertyName = "updated")] |
| 46 | + public string Updated { get; private set; } |
| 47 | + |
| 48 | + /// <summary> |
| 49 | + /// The cvc2 code. |
| 50 | + /// </summary> |
| 51 | + [JsonProperty(PropertyName = "cvc2")] |
| 52 | + public string Cvc2 { get; private set; } |
| 53 | + |
| 54 | + /// <summary> |
| 55 | + /// The status of the cvc2. Can be AVAILABLE, USED, EXPIRED, BLOCKED. |
| 56 | + /// </summary> |
| 57 | + [JsonProperty(PropertyName = "status")] |
| 58 | + public string Status { get; private set; } |
| 59 | + |
| 60 | + /// <summary> |
| 61 | + /// Expiry time of the cvc2. |
| 62 | + /// </summary> |
| 63 | + [JsonProperty(PropertyName = "expiry_time")] |
| 64 | + public string ExpiryTime { get; private set; } |
| 65 | + |
| 66 | + /// <summary> |
| 67 | + /// Generate a new CVC2 code for a card. |
| 68 | + /// </summary> |
| 69 | + public static BunqResponse<CardGeneratedCvc2> Create(ApiContext apiContext, IDictionary<string, object> requestMap, int userId, int cardId, IDictionary<string, string> customHeaders = null) |
| 70 | + { |
| 71 | + if (customHeaders == null) customHeaders = new Dictionary<string, string>(); |
| 72 | + |
| 73 | + var apiClient = new ApiClient(apiContext); |
| 74 | + var requestBytes = Encoding.UTF8.GetBytes(BunqJsonConvert.SerializeObject(requestMap)); |
| 75 | + requestBytes = SecurityUtils.Encrypt(apiContext, requestBytes, customHeaders); |
| 76 | + var responseRaw = apiClient.Post(string.Format(ENDPOINT_URL_CREATE, userId, cardId), requestBytes, customHeaders); |
| 77 | + |
| 78 | + return FromJson<CardGeneratedCvc2>(responseRaw, OBJECT_TYPE); |
| 79 | + } |
| 80 | + |
| 81 | + /// <summary> |
| 82 | + /// Get the details for a specific generated CVC2 code. |
| 83 | + /// </summary> |
| 84 | + public static BunqResponse<CardGeneratedCvc2> Get(ApiContext apiContext, int userId, int cardId, int cardGeneratedCvc2Id, IDictionary<string, string> customHeaders = null) |
| 85 | + { |
| 86 | + if (customHeaders == null) customHeaders = new Dictionary<string, string>(); |
| 87 | + |
| 88 | + var apiClient = new ApiClient(apiContext); |
| 89 | + var responseRaw = apiClient.Get(string.Format(ENDPOINT_URL_READ, userId, cardId, cardGeneratedCvc2Id), new Dictionary<string, string>(), customHeaders); |
| 90 | + |
| 91 | + return FromJson<CardGeneratedCvc2>(responseRaw, OBJECT_TYPE); |
| 92 | + } |
| 93 | + |
| 94 | + /// <summary> |
| 95 | + /// Get all generated CVC2 codes for a card. |
| 96 | + /// </summary> |
| 97 | + public static BunqResponse<List<CardGeneratedCvc2>> List(ApiContext apiContext, int userId, int cardId, IDictionary<string, string> urlParams = null, IDictionary<string, string> customHeaders = null) |
| 98 | + { |
| 99 | + if (urlParams == null) urlParams = new Dictionary<string, string>(); |
| 100 | + if (customHeaders == null) customHeaders = new Dictionary<string, string>(); |
| 101 | + |
| 102 | + var apiClient = new ApiClient(apiContext); |
| 103 | + var responseRaw = apiClient.Get(string.Format(ENDPOINT_URL_LISTING, userId, cardId), urlParams, customHeaders); |
| 104 | + |
| 105 | + return FromJsonList<CardGeneratedCvc2>(responseRaw, OBJECT_TYPE); |
| 106 | + } |
| 107 | + } |
| 108 | +} |
0 commit comments