Skip to content

Conversation

@spencerstock
Copy link
Collaborator

@spencerstock spencerstock commented Sep 5, 2025

What changed? Why?

Added a new getSubscriptionStatus method to the payment interface that allows checking the status of a subscription created via the subscribe method.

added prepareCharge which wraps existing utils after doing some validations

How was this tested?

manually + unit

How can reviewers manually test these changes?

  1. Create a subscription using the subscribe method
  2. Call getSubscriptionStatus with the returned subscription ID
  3. Verify the status information reflects the subscription state correctly
  4. Test with both new subscriptions (no on-chain state) and existing subscriptions
  5. Verify period calculations are accurate for various subscription configurations

Demo/screenshots

@cb-heimdall
Copy link
Collaborator

cb-heimdall commented Sep 5, 2025

✅ Heimdall Review Status

Requirement Status More Info
Reviews 2/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
2 if repo is sensitive 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 0
Sum 1

@spencerstock spencerstock marked this pull request as ready for review September 8, 2025 05:15
Copy link
Collaborator

@fan-zhang-sv fan-zhang-sv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Comment on lines +76 to +100
if (permission.chainId !== expectedChainId) {
// Determine if the subscription is on mainnet or testnet
const isSubscriptionOnMainnet = permission.chainId === CHAIN_IDS.base;
const isSubscriptionOnTestnet = permission.chainId === CHAIN_IDS.baseSepolia;

let errorMessage: string;
if (testnet && isSubscriptionOnMainnet) {
errorMessage =
'The subscription was requested on testnet but is actually a mainnet subscription';
} else if (!testnet && isSubscriptionOnTestnet) {
errorMessage =
'The subscription was requested on mainnet but is actually a testnet subscription';
} else {
// Fallback for unexpected chain IDs
errorMessage = `Subscription is on chain ${permission.chainId}, expected ${expectedChainId} (${testnet ? 'Base Sepolia' : 'Base'})`;
}

throw new Error(errorMessage);
}

if (permission.permission.token.toLowerCase() !== expectedTokenAddress) {
throw new Error(
`Subscription is not for USDC token. Got ${permission.permission.token}, expected ${expectedTokenAddress}`
);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could abstract these to some internal subscription helper for reuseability

* console.log(`Recurring amount: $${status.recurringAmount}`);
* ```
*/
export async function getSubscriptionStatus(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed there's no tests for this, are there plans to add any?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will add!

* @param currentTimestamp - Optional timestamp to use as "now" (defaults to current time)
* @returns The current period with start, end, and spend (0 for inferred periods)
*/
export function calculateCurrentPeriod(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also should have a test

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will add!

@spencerstock spencerstock merged commit 2afb92c into master Sep 8, 2025
8 checks passed
@spencerstock spencerstock deleted the spencer/getsubstatus branch September 8, 2025 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants