/// <summary>
        /// Modify a specific TabUsageMultiple. You can change the amount_total, status and visibility. Once you change
        /// the status to PAYABLE the TabUsageMultiple will expire after a year (default). If you've created any
        /// TabItems for a Tab the sum of the amounts of these items must be equal to the total_amount of the Tab when
        /// you change its status to PAYABLE.
        /// </summary>
        /// <param name="status">The status of the TabUsageMultiple. On creation the status must be set to OPEN. You can change the status from OPEN to PAYABLE. If the TabUsageMultiple gets paid the status will remain PAYABLE.</param>
        /// <param name="amountTotal">The total amount of the Tab. Must be a positive amount. As long as the tab has the status OPEN you can change the total amount. This amount is not affected by the amounts of the TabItems. However, if you've created any TabItems for a Tab the sum of the amounts of these items must be equal to the total_amount of the Tab when you change its status to PAYABLE</param>
        /// <param name="visibility">The visibility of a Tab. A Tab can be visible trough NearPay, the QR code of the CashRegister and its own QR code.</param>
        /// <param name="expiration">The moment when this Tab expires. Can be at most 365 days into the future.</param>
        /// <param name="tabAttachment">An array of attachments that describe the tab. Uploaded through the POST /user/{userid}/attachment-tab endpoint.</param>
        public static BunqResponse <string> Update(int cashRegisterId, string tabUsageMultipleUuid,
                                                   int?monetaryAccountId    = null, string status     = null, Amount amountTotal = null,
                                                   TabVisibility visibility = null, string expiration = null, List <BunqId> tabAttachment = 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_AMOUNT_TOTAL, amountTotal },
                { FIELD_VISIBILITY, visibility },
                { FIELD_EXPIRATION, expiration },
                { FIELD_TAB_ATTACHMENT, tabAttachment },
            };

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

            return(ProcessForUuid(responseRaw));
        }
        /// <summary>
        /// Create a TabUsageMultiple. On creation the status must be set to OPEN
        /// </summary>
        /// <param name="description">The description of the TabUsageMultiple. Maximum 9000 characters. Field is required but can be an empty string.</param>
        /// <param name="status">The status of the TabUsageMultiple. On creation the status must be set to OPEN. You can change the status from OPEN to PAYABLE. If the TabUsageMultiple gets paid the status will remain PAYABLE.</param>
        /// <param name="amountTotal">The total amount of the Tab. Must be a positive amount. As long as the tab has the status OPEN you can change the total amount. This amount is not affected by the amounts of the TabItems. However, if you've created any TabItems for a Tab the sum of the amounts of these items must be equal to the total_amount of the Tab when you change its status to PAYABLE</param>
        /// <param name="allowAmountHigher">[DEPRECATED] Whether or not a higher amount can be paid.</param>
        /// <param name="allowAmountLower">[DEPRECATED] Whether or not a lower amount can be paid.</param>
        /// <param name="wantTip">[DEPRECATED] Whether or not the user paying the Tab should be asked if he wants to give a tip. When want_tip is set to true, allow_amount_higher must also be set to true and allow_amount_lower must be false.</param>
        /// <param name="minimumAge">The minimum age of the user paying the Tab.</param>
        /// <param name="requireAddress">Whether a billing and shipping address must be provided when paying the Tab. Possible values are: BILLING, SHIPPING, BILLING_SHIPPING, NONE, OPTIONAL. Default is NONE.</param>
        /// <param name="redirectUrl">The URL which the user is sent to after paying the Tab.</param>
        /// <param name="visibility">The visibility of a Tab. A Tab can be visible trough NearPay, the QR code of the CashRegister and its own QR code.</param>
        /// <param name="expiration">The moment when this Tab expires. Can be at most 365 days into the future.</param>
        /// <param name="tabAttachment">An array of attachments that describe the tab. Uploaded through the POST /user/{userid}/attachment-tab endpoint.</param>
        public static BunqResponse <string> Create(int cashRegisterId, string description, string status,
                                                   Amount amountTotal, int?monetaryAccountId = null, bool?allowAmountHigher = null,
                                                   bool?allowAmountLower       = null, bool?wantTip             = null, int?minimumAge    = null, string requireAddress = null,
                                                   string redirectUrl          = null, TabVisibility visibility = null, string expiration = null,
                                                   List <BunqId> tabAttachment = 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_STATUS, status },
                { FIELD_AMOUNT_TOTAL, amountTotal },
                { FIELD_ALLOW_AMOUNT_HIGHER, allowAmountHigher },
                { FIELD_ALLOW_AMOUNT_LOWER, allowAmountLower },
                { FIELD_WANT_TIP, wantTip },
                { FIELD_MINIMUM_AGE, minimumAge },
                { FIELD_REQUIRE_ADDRESS, requireAddress },
                { FIELD_REDIRECT_URL, redirectUrl },
                { FIELD_VISIBILITY, visibility },
                { FIELD_EXPIRATION, expiration },
                { FIELD_TAB_ATTACHMENT, tabAttachment },
            };

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

            return(ProcessForUuid(responseRaw));
        }
示例#3
0
        /// <summary>
        /// Update the visibility of a tab for a given profile.
        /// </summary>
        /// <param name="serverUrl">URL to SF server</param>
        /// <param name="username">Login username</param>
        /// <param name="password">Login password</param>
        /// <param name="orgId">Organization ID found at settings/company settings/company information/salesforce.com organization id</param>
        /// <param name="profileName">API name of profile to update</param>
        /// <param name="tabName">SF name of the tab whose visiblity status to update.  Note this is not the same as the label given in the SF CRM.  For instance,
        /// the standard objects such as 'Account' will have the name 'standard-Account'.</param>
        /// <param name="tabVisibility">The visibility status to be assigned for the given tab for the given profile.</param>
        static void setTabVisibility(String serverUrl, String username, String password, String orgId, String profileName, String tabName, TabVisibility tabVisibility)
        {
            // establish session
            SoapClient  client = new SoapClient();
            LoginResult res    = client.login(new PartnerServiceReference.LoginScopeHeader {
                organizationId = orgId
            }, null, username, password);
            var sessionId = res.sessionId;

            // Console.WriteLine("Session ID: " + sessionId);

            try
            {
                // get the profile and the tabs
                MetadataPortTypeClient mclient  = new MetadataPortTypeClient(MetadataPortTypeClient.EndpointConfiguration.Metadata, res.metadataServerUrl);
                Metadata[]             profiles = mclient.readMetadata(new MetadataServiceReference.SessionHeader {
                    sessionId = sessionId
                }, null, "Profile", new String[] { profileName });
                if (profiles.Length != 1)
                {
                    throw new Exception("Failed to locate profile");
                }

                // set the visiblity for the tab
                Profile profile        = (Profile)profiles[0];
                Profile updatedProfile = null;
                foreach (ProfileTabVisibility tabVisibilityField in profile.tabVisibilities)
                {
                    // Console.WriteLine(tabVisibilityField.tab);
                    if (tabVisibilityField.tab == tabName)
                    {
                        updatedProfile = new Profile()
                        {
                            fullName = profile.fullName
                        };
                        updatedProfile.tabVisibilities = new ProfileTabVisibility[] {
                            new ProfileTabVisibility()
                            {
                                tab        = tabName,
                                visibility = tabVisibility
                            }
                        };
                        break;
                    }
                }
                if (null == updatedProfile)
                {
                    throw new Exception("Failed to locate tab");
                }

                // update the profile
                MetadataServiceReference.SaveResult[] response = mclient.updateMetadata(new MetadataServiceReference.SessionHeader {
                    sessionId = sessionId
                }, null, null, new Metadata[] { updatedProfile });
                if (response.Length != 1 || !response[0].success)
                {
                    throw new Exception("Failed to update profile");
                }
            }
            finally
            {
                // close session
                client = new SoapClient(SoapClient.EndpointConfiguration.Soap, res.serverUrl);
                client.logout(new PartnerServiceReference.SessionHeader {
                    sessionId = sessionId
                }, null);
            }
        }