Skip to main content

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​

  1. Read the settings. Send a GET request to /v1/settings. The response holds every setting of the environment, the id of the environment and livemode. Any client of the account, and its vendor, reads every setting.

  2. Change the settings you want to change. Send a PATCH request to /v1/settings with only the settings that change. Send a switch as true or false, 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.

  3. 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 422 and the code parameter_invalid, and param names the field. For one country of vat_rates it names vat_rates.SA, and for a part of the agreement data_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.

  4. Read the event the change records. When a change alters a value, Black records settings.updated. Its data.object holds the settings after the change. Its data.previous_attributes holds each changed setting as it was, and for vat_rates the whole object. Its data.affected_customers is how many customers, not deleted, hold a live subscription the change reaches, which is every one of them. Its actor is 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.

SettingDefaultAllowedWhat it holds and does
grace_enabledtruetrue or falseWhether a subscription with an unpaid renewal enters grace (past_due) or ends at the invoice's due date.
grace_length_days151 to 60How many days after the due date grace lasts. Black keeps the value while grace is off and does not use it.
grace_retries31 to 10The retries in grace. Black retries nothing where your account collects the money. Black keeps the value while grace is off.
cancellation_reason_requiredfalsetrue or falseWhether a cancel must carry a reason. See Cancel a subscription.
price_change_notice_days71 to 30The notice period of a price change, in days.
renewals_stoppedfalsetrue or falseWhether 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_gracetruetrue or falseWhether a past_due subscription keeps giving the features of its product. Black reads it at each request.
unpaid_subscription_expiry_hours231 to 720How long a new subscription waits for its first payment before it expires.
revival_days70 to 90How 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_zoneAsia/RiyadhAn 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_due10 to 365How 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_prefixINV1 to 12 letters, digits or hyphensThe 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_days71 to 30How many days before a renewal Black records the renewal's notice, customer.subscription.renewal_upcoming.
payment_modeaccount_collectsaccount_collectsWho 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_offfalsetrue or falseWhether 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 decimalsThe 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_modenonenone or rulesHow Black taxes invoices. With rules, Black applies the rates of vat_rates and vat_default_rate.
prices_include_taxtruetrue or falseWhether a price already includes the tax.
vat_default_ratenullA rate from 0 to 100 with at most two decimals, or nullThe rate of a customer whose country has no rate in vat_rates. Black answers it as a string with two decimals.
tax_registration_numbernullUp to 64 letters, digits, spaces and hyphensYour tax registration number, which Black copies onto each taxed invoice.
tax_seller_countrynullA country code in upper case, or nullThe country you sell from.
presentment_currencies[]Up to 20 currencies that Black knows, each once, in upper caseThe currencies the environment shows and charges in, besides the currency of each price. Black answers the list in code order.
exchange_rate_margin_percent0.00A percentage from 0 to 10 with at most two decimalsA 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_minutes600 to 1440How long a price that you showed stays good for a new subscription after a newer set of exchange rates arrives.
data_processing_agreementnullAn object with a reference of at most 255 characters and a signed_on date that is not in the futureThe 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:

SettingWho 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_minutesThe account's own client, or the account's vendor with Black-Account.
payment_mode, service_off, renewals_stopped, tax_mode and prices_include_taxOnly the vendor, with Black-Account.
data_processing_agreementOnly 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 sent payment_mode, service_off, renewals_stopped, tax_mode, prices_include_tax or data_processing_agreement, and only the vendor changes it. For the agreement the cause can also be that the vendor used a test client. param names the field. Black checks this before it checks any value, so the answer is 403 whatever 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 with Black-Account and, for the agreement, with your live client.
  • parameter_invalid (422). A value is out of bounds, of the wrong kind or not a setting. Read param and message, correct the value and send the change again.
  • gateway_not_connected (409). You sent payment_mode black_charges and the environment has no active gateway connection. Connect a gateway, then send the change again, or send account_collects.
  • account_required (403). A vendor's client sent the request without Black-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​