示例#1
0
        /// <summary>
        /// </summary>
        /// <param name="attachmentId">The reference to the uploaded file to attach to this note.</param>
        /// <param name="description">Optional description of the attachment.</param>
        public static BunqResponse <int> Create(int bunqmeFundraiserResultId, int?attachmentId,
                                                int?monetaryAccountId = null, string description = null, IDictionary <string, string> customHeaders = null)
        {
            if (customHeaders == null)
            {
                customHeaders = new Dictionary <string, string>();
            }

            var apiClient = new ApiClient(GetApiContext());

            var requestMap = new Dictionary <string, object>
            {
                { FIELD_DESCRIPTION, description },
                { FIELD_ATTACHMENT_ID, attachmentId },
            };

            var requestBytes = Encoding.UTF8.GetBytes(BunqJsonConvert.SerializeObject(requestMap));
            var responseRaw  =
                apiClient.Post(
                    string.Format(ENDPOINT_URL_CREATE, DetermineUserId(), DetermineMonetaryAccountId(monetaryAccountId),
                                  bunqmeFundraiserResultId), requestBytes, customHeaders);

            return(ProcessForId(responseRaw));
        }
示例#2
0
        /// <summary>
        /// </summary>
        /// <param name="bunqmeTabEntry">The bunq.me entry containing the payment information.</param>
        /// <param name="status">The status of the bunq.me. Ignored in POST requests but can be used for cancelling the bunq.me by setting status as CANCELLED with a PUT request.</param>
        public static BunqResponse <int> Create(BunqMeTabEntry bunqmeTabEntry, int?monetaryAccountId = null,
                                                string status = null, IDictionary <string, string> customHeaders = null)
        {
            if (customHeaders == null)
            {
                customHeaders = new Dictionary <string, string>();
            }

            var apiClient = new ApiClient(GetApiContext());

            var requestMap = new Dictionary <string, object>
            {
                { FIELD_BUNQME_TAB_ENTRY, bunqmeTabEntry },
                { FIELD_STATUS, status },
            };

            var requestBytes = Encoding.UTF8.GetBytes(BunqJsonConvert.SerializeObject(requestMap));
            var responseRaw  =
                apiClient.Post(
                    string.Format(ENDPOINT_URL_CREATE, DetermineUserId(),
                                  DetermineMonetaryAccountId(monetaryAccountId)), requestBytes, customHeaders);

            return(ProcessForId(responseRaw));
        }
示例#3
0
        /// <summary>
        /// </summary>
        /// <param name="type">The type of generated cvc2. Can be STATIC or GENERATED.</param>
        public static BunqResponse <int> Update(int cardId, int cardGeneratedCvc2Id, string type = null,
                                                IDictionary <string, string> customHeaders       = null)
        {
            if (customHeaders == null)
            {
                customHeaders = new Dictionary <string, string>();
            }

            var apiClient = new ApiClient(GetApiContext());

            var requestMap = new Dictionary <string, object>
            {
                { FIELD_TYPE, type },
            };

            var requestBytes = Encoding.UTF8.GetBytes(BunqJsonConvert.SerializeObject(requestMap));

            requestBytes = SecurityUtils.Encrypt(GetApiContext(), requestBytes, customHeaders);
            var responseRaw =
                apiClient.Put(string.Format(ENDPOINT_URL_UPDATE, DetermineUserId(), cardId, cardGeneratedCvc2Id),
                              requestBytes, customHeaders);

            return(ProcessForId(responseRaw));
        }
        /// <summary>
        /// </summary>
        /// <param name="currency">The currency of the MonetaryAccountJoint as an ISO 4217 formatted currency code.</param>
        /// <param name="allCoOwner">The users the account will be joint with.</param>
        /// <param name="description">The description of the MonetaryAccountJoint. Defaults to 'bunq account'.</param>
        /// <param name="dailyLimit">The daily spending limit Amount of the MonetaryAccountJoint. Defaults to 1000 EUR. Currency must match the MonetaryAccountJoint's currency. Limited to 10000 EUR.</param>
        /// <param name="overdraftLimit">The maximum Amount the MonetaryAccountJoint can be 'in the red'. Must be 0 EUR or omitted.</param>
        /// <param name="alias">The Aliases to add to MonetaryAccountJoint. Must all be confirmed first. Can mostly be ignored.</param>
        /// <param name="avatarUuid">The UUID of the Avatar of the MonetaryAccountJoint.</param>
        /// <param name="status">The status of the MonetaryAccountJoint. Ignored in POST requests (always set to ACTIVE) can be CANCELLED or PENDING_REOPEN in PUT requests to cancel (close) or reopen the MonetaryAccountJoint. When updating the status and/or sub_status no other fields can be updated in the same request (and vice versa).</param>
        /// <param name="subStatus">The sub-status of the MonetaryAccountJoint providing extra information regarding the status. Should be ignored for POST requests. In case of PUT requests with status CANCELLED it can only be REDEMPTION_VOLUNTARY, while with status PENDING_REOPEN it can only be NONE. When updating the status and/or sub_status no other fields can be updated in the same request (and vice versa).</param>
        /// <param name="reason">The reason for voluntarily cancelling (closing) the MonetaryAccountJoint, can only be OTHER. Should only be specified if updating the status to CANCELLED.</param>
        /// <param name="reasonDescription">The optional free-form reason for voluntarily cancelling (closing) the MonetaryAccountJoint. Can be any user provided message. Should only be specified if updating the status to CANCELLED.</param>
        /// <param name="notificationFilters">The types of notifications that will result in a push notification or URL callback for this MonetaryAccountJoint.</param>
        /// <param name="setting">The settings of the MonetaryAccountJoint.</param>
        public static BunqResponse <int> Create(string currency, List <CoOwner> allCoOwner, string description = null,
                                                Amount dailyLimit              = null, Amount overdraftLimit = null, List <Pointer> alias = null,
                                                string avatarUuid              = null, string status         = null, string subStatus     = null, string reason = null,
                                                string reasonDescription       = null, List <NotificationFilter> notificationFilters = null,
                                                MonetaryAccountSetting setting = null, IDictionary <string, string> customHeaders    = null)
        {
            if (customHeaders == null)
            {
                customHeaders = new Dictionary <string, string>();
            }

            var apiClient = new ApiClient(GetApiContext());

            var requestMap = new Dictionary <string, object>
            {
                { FIELD_CURRENCY, currency },
                { FIELD_DESCRIPTION, description },
                { FIELD_DAILY_LIMIT, dailyLimit },
                { FIELD_OVERDRAFT_LIMIT, overdraftLimit },
                { FIELD_ALIAS, alias },
                { FIELD_AVATAR_UUID, avatarUuid },
                { FIELD_STATUS, status },
                { FIELD_SUB_STATUS, subStatus },
                { FIELD_REASON, reason },
                { FIELD_REASON_DESCRIPTION, reasonDescription },
                { FIELD_ALL_CO_OWNER, allCoOwner },
                { FIELD_NOTIFICATION_FILTERS, notificationFilters },
                { FIELD_SETTING, setting },
            };

            var requestBytes = Encoding.UTF8.GetBytes(BunqJsonConvert.SerializeObject(requestMap));
            var responseRaw  = apiClient.Post(string.Format(ENDPOINT_URL_CREATE, DetermineUserId()), requestBytes,
                                              customHeaders);

            return(ProcessForId(responseRaw));
        }
示例#5
0
        /// <summary>
        /// </summary>
        /// <param name="description">Optional description of the attachment.</param>
        public static BunqResponse <int> Update(int whitelistId, int whitelistResultId,
                                                int noteAttachmentWhitelistResultId, int?monetaryAccountId = null, string description = null,
                                                IDictionary <string, string> customHeaders = null)
        {
            if (customHeaders == null)
            {
                customHeaders = new Dictionary <string, string>();
            }

            var apiClient = new ApiClient(GetApiContext());

            var requestMap = new Dictionary <string, object>
            {
                { FIELD_DESCRIPTION, description },
            };

            var requestBytes = Encoding.UTF8.GetBytes(BunqJsonConvert.SerializeObject(requestMap));
            var responseRaw  =
                apiClient.Put(
                    string.Format(ENDPOINT_URL_UPDATE, DetermineUserId(), DetermineMonetaryAccountId(monetaryAccountId),
                                  whitelistId, whitelistResultId, noteAttachmentWhitelistResultId), requestBytes, customHeaders);

            return(ProcessForId(responseRaw));
        }
        /// <summary>
        /// </summary>
        /// <param name="currencySource">The source currency.</param>
        /// <param name="currencyTarget">The target currency.</param>
        /// <param name="amountSource">The source amount. Required if target amount is left empty.</param>
        /// <param name="amountTarget">The target amount. Required if source amount is left empty.</param>
        public static BunqResponse <int> Create(string currencySource, string currencyTarget, Amount amountSource = null,
                                                Amount amountTarget = null, IDictionary <string, string> customHeaders = null)
        {
            if (customHeaders == null)
            {
                customHeaders = new Dictionary <string, string>();
            }

            var apiClient = new ApiClient(GetApiContext());

            var requestMap = new Dictionary <string, object>
            {
                { FIELD_CURRENCY_SOURCE, currencySource },
                { FIELD_CURRENCY_TARGET, currencyTarget },
                { FIELD_AMOUNT_SOURCE, amountSource },
                { FIELD_AMOUNT_TARGET, amountTarget },
            };

            var requestBytes = Encoding.UTF8.GetBytes(BunqJsonConvert.SerializeObject(requestMap));
            var responseRaw  = apiClient.Post(string.Format(ENDPOINT_URL_CREATE, DetermineUserId()), requestBytes,
                                              customHeaders);

            return(ProcessForId(responseRaw));
        }
示例#7
0
        /// <summary>
        /// Update a draft share invite. When sending status CANCELLED it is possible to cancel the draft share invite.
        /// </summary>
        /// <param name="status">The status of the draft share invite. Can be CANCELLED (the user cancels the draft share before it's used).</param>
        /// <param name="subStatus">The sub-status of the draft share invite. Can be NONE, ACCEPTED or REJECTED.</param>
        /// <param name="expiration">The moment when this draft share invite expires.</param>
        public static BunqResponse <DraftShareInviteApiKey> Update(int draftShareInviteApiKeyId, string status = null,
                                                                   string subStatus = null, string expiration = null, IDictionary <string, string> customHeaders = null)
        {
            if (customHeaders == null)
            {
                customHeaders = new Dictionary <string, string>();
            }

            var apiClient = new ApiClient(GetApiContext());

            var requestMap = new Dictionary <string, object>
            {
                { FIELD_STATUS, status },
                { FIELD_SUB_STATUS, subStatus },
                { FIELD_EXPIRATION, expiration },
            };

            var requestBytes = Encoding.UTF8.GetBytes(BunqJsonConvert.SerializeObject(requestMap));
            var responseRaw  =
                apiClient.Put(string.Format(ENDPOINT_URL_UPDATE, DetermineUserId(), draftShareInviteApiKeyId),
                              requestBytes, customHeaders);

            return(FromJson <DraftShareInviteApiKey>(responseRaw, OBJECT_TYPE_PUT));
        }
示例#8
0
        public async Task <BunqResponse> BunqSendAsync(HttpRequestMessage request)
        {
            //TODO check if session ready
            if (NeedsSession(request.RequestUri))
            {
            }

            SetDefaultHeaders(request);
            //SetHeaders(request, customHeaders);
            var needSigning = NeedsSigning(request.RequestUri);

            if (needSigning)
            {
                SetSessionHeaders(request);
            }

            //var responseMessage = client.SendAsync(requestMessage).Result;
            var response = await SendAsync(request);

            AssertResponseSuccess(response);
            if (needSigning)
            {
                ValidateResponse(response);
            }

            var json = await response.Content.ReadAsStringAsync();

            //var json = Encoding.UTF8.GetString(responseRaw.BodyBytes);

            var jObject       = BunqJsonConvert.DeserializeObject <JObject>(json);
            var responseArray = (JArray)jObject.GetValue(FIELD_RESPONSE);

            //TODO: response.Headers;

            return(new BunqResponse(responseArray));
        }
示例#9
0
 /// <summary>
 /// De-serializes a context from JSON.
 /// </summary>
 public static ApiContext FromJson(string json)
 {
     return(BunqJsonConvert.DeserializeObject <ApiContext>(json));
 }
示例#10
0
 /// <summary>
 /// Serialize the API Context to JSON.
 /// </summary>
 public string ToJson()
 {
     return(BunqJsonConvert.SerializeObject(this));
 }
示例#11
0
 public override string ToString()
 {
     return(BunqJsonConvert.SerializeObject(this));
 }
示例#12
0
        private static JObject DeserializeResponseObject(BunqResponseRaw responseRaw)
        {
            var json = Encoding.UTF8.GetString(responseRaw.BodyBytes);

            return(BunqJsonConvert.DeserializeObject <JObject>(json));
        }
示例#13
0
        private static Pagination DeserializePagination(JObject responseObject)
        {
            var paginationBody = responseObject.GetValue(FIELD_PAGINATION).ToString();

            return(BunqJsonConvert.DeserializeObject <Pagination>(paginationBody));
        }
示例#14
0
        public static T CreateFromJsonString <T>(string json)
        {
            var modelValue = BunqJsonConvert.DeserializeObject <T>(json);

            return(modelValue);
        }
示例#15
0
        public Task Save()
        {
            var data = BunqJsonConvert.SerializeObject(this, Formatting.Indented);

            return(File.WriteAllTextAsync(FILENAME, data));
        }