Change account settings
What you will build
You read the settings of an environment, change some of them, and read what Black records for the change. You learn what each setting holds and does, which client may change each one, and what Black answers when a client changes a setting that it may not.
Before you start
You need an access token. See Authentication. Each environment holds its own settings, so a test environment can try grace while the live environment has it off. The data-processing agreement is the exception: the account holds one, and both environments show it.
Two kinds of client change settings. The API client of an account changes the settings of its own environment. A vendor's client changes the settings of a sub-account's environment when the request names the sub-account in the Black-Account header. See Create and act for sub-accounts.
Steps
-
Read the settings. Send a
GETrequest to/v1/settings. The response holds every setting of the environment, theidof the environment andlivemode. Any client of the account, and its vendor, reads every setting. -
Change the settings you want to change. Send a
PATCHrequest to/v1/settingswith only the settings that change. Send a switch astrueorfalse, a number as a whole number, and the time zone and the payment mode as strings. The response holds all the settings as they are after the change. -
Read the refusal when a value is wrong. A field that does not exist, a value of the wrong kind and a value out of bounds are refused with
422and the codeparameter_invalid, andparamnames the field. For one country ofvat_ratesit namesvat_rates.SA, and for a part of the agreementdata_processing_agreement.signed_on. Black changes nothing when it refuses any part of the request, so send the whole change again with the value corrected. -
Read the event the change records. When a change alters a value, Black records
settings.updated. Itsdata.objectholds the settings after the change. Itsdata.previous_attributesholds each changed setting as it was, and forvat_ratesthe whole object. Itsdata.affected_customersis how many customers, not deleted, hold a live subscription the change reaches, which is every one of them. Itsactoris the client that made the change. A request that alters nothing records nothing, and a change to the agreement alone records no event.
Read each setting
Each setting has a default and the values it takes. A setting that changes billing changes it for the subscriptions that read it afterwards.
| Setting | Default | Allowed | What it holds and does |
|---|---|---|---|
grace_enabled | true | true or false | Whether a subscription with an unpaid renewal enters grace (past_due) or ends at the invoice's due date. |
grace_length_days | 15 | 1 to 60 | How many days after the due date grace lasts. Black keeps the value while grace is off and does not use it. |
grace_retries | 3 | 1 to 10 | The retries in grace. Black retries nothing where your account collects the money. Black keeps the value while grace is off. |
cancellation_reason_required | false | true or false | Whether a cancel must carry a reason. See Cancel a subscription. |
price_change_notice_days | 7 | 1 to 30 | The notice period of a price change, in days. |
renewals_stopped | false | true or false | Whether renewals are stopped. While it is true, sales are closed, renews is false in the lookup, and the renewal of an active or past_due subscription ends it at its period end. |
keeps_entitlements_in_grace | true | true or false | Whether a past_due subscription keeps giving the features of its product. Black reads it at each request. |
unpaid_subscription_expiry_hours | 23 | 1 to 720 | How long a new subscription waits for its first payment before it expires. |
revival_days | 7 | 0 to 90 | How long after a subscription ends for an unpaid invoice a late report can still bring it back. 0 means it is never brought back. |
time_zone | Asia/Riyadh | An IANA time zone name in its exact case, such as Europe/London. A fixed offset, an abbreviation and an old alias are refused. | The time zone of the environment. A change applies to subscriptions created afterwards. |
days_until_due | 1 | 0 to 365 | How many days after an invoice is finalized it is due. 1 makes it due one day after it is finalized, so a renewal that you report paid within the day never reads past_due. 0 makes it due when it is finalized, so a renewal is past_due, in grace, from its first second until you report it paid. A new subscription takes the value at its creation and keeps it. An account created before the default became 1 keeps the value it had. |
invoice_prefix | INV | 1 to 12 letters, digits or hyphens | The letters at the start of each invoice's number. Black numbers the invoices of an environment in one unbroken sequence, such as INV-000001, and writes the number on each invoice when it is created. A change of the prefix applies to the invoices created after it; an invoice keeps the number it has. |
reminder_lead_days | 7 | 1 to 30 | How many days before a renewal Black records the renewal's notice, customer.subscription.renewal_upcoming. |
payment_mode | account_collects | account_collects | Who collects the money. With account_collects you take each payment yourself and report it, and a subscription's collection_method defaults to send_invoice. |
service_off | false | true or false | Whether the service is off. While it is true, sales are closed and the lookup of what a customer holds answers an empty list. It changes no billing and nothing stored, so switching it off gives back what was there. |
vat_rates | {} | One entry for each country: a country code in upper case and a rate from 0 to 100 with at most two decimals | The VAT rate of each customer's country. Send null for a country to remove its rate, and the other countries keep theirs. Black answers each rate as a string with two decimals. |
tax_mode | none | none or rules | How Black taxes invoices. With rules, Black applies the rates of vat_rates and vat_default_rate. |
prices_include_tax | true | true or false | Whether a price already includes the tax. |
vat_default_rate | null | A rate from 0 to 100 with at most two decimals, or null | The rate of a customer whose country has no rate in vat_rates. Black answers it as a string with two decimals. |
tax_registration_number | null | Up to 64 letters, digits, spaces and hyphens | Your tax registration number, which Black copies onto each taxed invoice. |
tax_seller_country | null | A country code in upper case, or null | The country you sell from. |
presentment_currencies | [] | Up to 20 currencies that Black knows, each once, in upper case | The currencies the environment shows and charges in, besides the currency of each price. Black answers the list in code order. |
exchange_rate_margin_percent | 0.00 | A percentage from 0 to 10 with at most two decimals | A margin that Black adds to the exchange rate before it converts a price. Black answers it as a string with two decimals. |
exchange_rate_hold_minutes | 60 | 0 to 1440 | How long a price that you showed stays good for a new subscription after a newer set of exchange rates arrives. |
data_processing_agreement | null | An object with a reference of at most 255 characters and a signed_on date that is not in the future | The reference and the signature date of your data-processing agreement, held by the account. Send both together. A new agreement replaces the one held, and Black never clears it. |
For the tax settings in use, see Charge tax with your own rules. For the currency settings in use, see Show and charge in your customer's currency.
A value of payment_mode of black_charges needs an active gateway connection, as Connect a payment gateway shows. Without one, the change is refused with 409 and the code gateway_not_connected.
For the grace settings in use, see "Handle an unpaid renewal" in Create a subscription and report its payments. For service_off and renewals_stopped and what they close, see "Read what you can sell" in Check what a customer holds.
Know which client may change which setting
The client decides which settings a request may change:
| Setting | Who may change it |
|---|---|
The grace settings, cancellation_reason_required, price_change_notice_days, keeps_entitlements_in_grace, unpaid_subscription_expiry_hours, revival_days, time_zone, days_until_due, reminder_lead_days, vat_rates, vat_default_rate, tax_registration_number, tax_seller_country, presentment_currencies, exchange_rate_margin_percent and exchange_rate_hold_minutes | The account's own client, or the account's vendor with Black-Account. |
payment_mode, service_off, renewals_stopped, tax_mode and prices_include_tax | Only the vendor, with Black-Account. |
data_processing_agreement | Only the vendor's live client, with Black-Account. A test request never changes what the live environment holds. |
An account that has no vendor has the vendor-only settings changed by Black's operators.
Handle a refusal
setting_set_by_vendor(403). Your client sentpayment_mode,service_off,renewals_stopped,tax_mode,prices_include_taxordata_processing_agreement, and only the vendor changes it. For the agreement the cause can also be that the vendor used a test client.paramnames the field. Black checks this before it checks any value, so the answer is403whatever the value is, and it changes nothing in the request, including the other settings you sent. Leave the field out of your request and ask your vendor to change it, or, as the vendor, send the request withBlack-Accountand, for the agreement, with your live client.parameter_invalid(422). A value is out of bounds, of the wrong kind or not a setting. Readparamandmessage, correct the value and send the change again.gateway_not_connected(409). You sentpayment_modeblack_chargesand the environment has no active gateway connection. Connect a gateway, then send the change again, or sendaccount_collects.account_required(403). A vendor's client sent the request withoutBlack-Account. Add the header with the sub-account's ID.
The request below comes from the client of an account that has no vendor. It tries to switch the service off, and Black refuses it with 403 and the code setting_set_by_vendor, naming service_off. The sample writes PLACEHOLDER_ACCESS_TOKEN where the access token of the account's own client goes:
curl --silent --request PATCH https://api.black.example/v1/settings \
--header "Authorization: Bearer PLACEHOLDER_ACCESS_TOKEN" \
--header "Content-Type: application/json" \
--data '{"service_off":true}'
A client that may not change a setting still reads it in GET /v1/settings, including service_off. See Errors for every code.
A runnable sample
The sample is a vendor's. It creates a sub-account, reads its settings, changes the grace length, the grace retries and the reminder lead time, switches the service off, reads that sales are closed, switches the service on again, restores the settings it changed, and reads the events of the changes. It writes PLACEHOLDER_VENDOR_ACCESS_TOKEN where your access token goes, reads the sub-account's ID from the response, and needs sed. A test environment takes five writes a second, so the sample waits a second after each write.
TOKEN=PLACEHOLDER_VENDOR_ACCESS_TOKEN
ACCOUNT=$(curl --silent --request POST https://api.black.example/v1/vendor/accounts \
--header "Authorization: Bearer $TOKEN" \
--data name="Settings Demo" \
--data contact_email=owner@settings-demo.example \
--data external_reference=settings-demo-3310 \
| sed -n 's/.*"id":"\(acct_[0-9a-z]*\)".*/\1/p')
curl --silent https://api.black.example/v1/settings \
--header "Authorization: Bearer $TOKEN" \
--header "Black-Account: $ACCOUNT"
curl --silent --request PATCH https://api.black.example/v1/settings \
--header "Authorization: Bearer $TOKEN" \
--header "Black-Account: $ACCOUNT" \
--header "Content-Type: application/json" \
--data '{"grace_length_days":30,"grace_retries":5,"reminder_lead_days":10}'
curl --silent --request PATCH https://api.black.example/v1/settings \
--header "Authorization: Bearer $TOKEN" \
--header "Black-Account: $ACCOUNT" \
--header "Content-Type: application/json" \
--data '{"service_off":true}'
curl --silent https://api.black.example/v1/plans \
--header "Authorization: Bearer $TOKEN" \
--header "Black-Account: $ACCOUNT"
curl --silent --request PATCH https://api.black.example/v1/settings \
--header "Authorization: Bearer $TOKEN" \
--header "Black-Account: $ACCOUNT" \
--header "Content-Type: application/json" \
--data '{"service_off":false}'
curl --silent --request PATCH https://api.black.example/v1/settings \
--header "Authorization: Bearer $TOKEN" \
--header "Black-Account: $ACCOUNT" \
--header "Content-Type: application/json" \
--data '{"grace_length_days":15,"grace_retries":3,"reminder_lead_days":7}'
curl --silent "https://api.black.example/v1/events?type=settings.updated" \
--header "Authorization: Bearer $TOKEN" \
--header "Black-Account: $ACCOUNT"
The first request answers 201, and the others 200. The settings first read as the defaults in the table. After the first change, grace_length_days is 30, grace_retries is 5 and reminder_lead_days is 10. The plans read answers sales_open false, and sales_closed_reasons holds service_off while the service is off. The last read lists the settings.updated events of the sub-account, newest first. The restore comes first, and its previous_attributes hold the three values you set. The first change comes after the two switches of service_off, and its previous_attributes hold the three defaults. If you run the sample again, the sub-account that its external_reference names answers 200 instead of 201, and the rest runs as before.
What to do next
- Read what an unpaid renewal does with the grace settings in Create a subscription and report its payments.
- Read what a cancel does with
cancellation_reason_requiredin Cancel a subscription. - Read how a vendor acts for a sub-account in Create and act for sub-accounts.
- Read every event, including
settings.updated, in Events. - Read every error code in Errors.