Adds balance to a subscription or installment order, which is billed with the next payments.
POST https://www.digistore24.com/api/call/addBalanceToPurchase
Constructor arguments of AddBalanceToPurchaseRequest:
purchaseId(string, required) — The Digistore24 order ID.amount(float, required) — The balance to add. Negative values reduce the balance, but the total cannot go below 0.
use GoSuccess\Digistore24\Api\Digistore24;
use GoSuccess\Digistore24\Api\Client\Configuration;
use GoSuccess\Digistore24\Api\Request\Purchase\AddBalanceToPurchaseRequest;
$ds24 = new Digistore24(new Configuration('YOUR-API-KEY'));
$request = new AddBalanceToPurchaseRequest(
purchaseId: '12345678',
amount: 25.0,
);
$response = $ds24->purchases->addBalance($request);
echo $response->oldBalance; // e.g. 0.0
echo $response->newBalance; // e.g. 25.0
echo $response->getBalanceChange(); // e.g. 25.0To reduce the balance, pass a negative amount:
$request = new AddBalanceToPurchaseRequest(
purchaseId: '12345678',
amount: -10.0,
);AddBalanceToPurchaseResponse exposes typed public properties:
result(string) — Result status returned by the API.oldBalance(float) — Balance before the change.newBalance(float) — Balance after the change.
It also provides a helper method:
getBalanceChange(): float— ReturnsnewBalance - oldBalance.
try {
$response = $ds24->purchases->addBalance($request);
} catch (ValidationException $e) {
// request failed local validation; $e->getErrors() lists the problems
} catch (ApiException $e) {
// API returned an error or the HTTP call failed
}