> ## Documentation Index
> Fetch the complete documentation index at: https://vowena-dependabot-github-actions-actions-checkout-7.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# reactivate

> Reactivates a paused subscription by re-approving the token allowance and attempting an immediate charge. Returns the subscription to active billing on success.

```rust theme={null}
fn reactivate(
    env: Env,
    subscriber: Address,
    sub_id: u64,
    expiration_ledger: u32,
    allowance_periods: u32,
) -> Result<bool>
```

Reactivates a subscription that was paused due to failed charges. The function re-approves the token allowance and immediately attempts to charge the overdue period. If the charge succeeds, the subscription returns to `Active` status.

***

## Parameters

| Name                | Type      | Description                                                                               |
| ------------------- | --------- | ----------------------------------------------------------------------------------------- |
| `subscriber`        | `Address` | The subscriber's Stellar address. Must sign the transaction.                              |
| `sub_id`            | `u64`     | The subscription ID to reactivate.                                                        |
| `expiration_ledger` | `u32`     | Absolute ledger at which the refreshed SAC allowance expires.                             |
| `allowance_periods` | `u32`     | Number of periods the new allowance should cover. Clamped to the remaining `max_periods`. |

***

## Authorization

```rust theme={null}
subscriber.require_auth();
```

Only the subscriber can reactivate their own subscription. The subscriber's signature covers both the `reactivate()` call and the nested `token.approve()` to refresh the allowance.

***

## Return value

`Result<bool>` - `true` if the immediate charge succeeded, `false` if it did not (e.g., still insufficient balance). The subscription is reactivated regardless - the charge attempt is best-effort.

***

## Events emitted

| Event       | Topics                 | Data                 |
| ----------- | ---------------------- | -------------------- |
| `sub_react` | `subscriber`, `sub_id` | Reactivation details |

Additional events may be emitted from the implicit charge attempt (`charge_ok` or `charge_fail`).

***

## Error cases

| Code | Name           | Description                                                                               |
| ---- | -------------- | ----------------------------------------------------------------------------------------- |
| 8    | `SubNotFound`  | No subscription exists with the given `sub_id`.                                           |
| 9    | `Unauthorized` | Caller is not the subscriber on this subscription.                                        |
| 13   | `NotPaused`    | The subscription is not in `Paused` status. Only paused subscriptions can be reactivated. |

***

## Examples

<Tabs>
  <Tab title="SDK">
    ```typescript theme={null}
    import { VowenaClient, NETWORKS } from "@vowena/sdk";

    const client = new VowenaClient({
      contractId: NETWORKS.testnet.contractId,
      rpcUrl: NETWORKS.testnet.rpcUrl,
      networkPassphrase: NETWORKS.testnet.networkPassphrase,
    });

    // Subscriber reactivates a paused subscription
    const tx = await client.buildReactivate(
      "GSUBSCRIBER...ADDR",   // Subscriber's address
      subscriptionId,          // Subscription ID
      { allowancePeriods: 24 } // Optional: SDK picks a safe default otherwise
    );

    const signedXdr = await signTransaction(tx);
    const result = await client.submitTransaction(signedXdr);
    console.log("Charged on reactivation:", result.charged); // true or false
    ```
  </Tab>

  <Tab title="Soroban CLI">
    ```bash theme={null}
    soroban contract invoke \
      --id CONTRACT_ID \
      --network testnet \
      --source SUBSCRIBER_SECRET \
      -- \
      reactivate \
      --subscriber GSUBSCRIBER...ADDR \
      --sub_id 1 \
      --expiration_ledger 3100000 \
      --allowance_periods 24
    ```
  </Tab>
</Tabs>

<Info>
  Before reactivating, make sure the subscriber's wallet has sufficient USDC
  balance. The reactivation will re-approve the token allowance and immediately
  attempt to charge the overdue period. If the balance is still insufficient,
  the subscription returns to `Active` status but the charge will fail again on
  the next `charge()` call.
</Info>
