use subscriptions::{
accounts::{Plan, SubscriptionAuthority},
generated::{instructions::*, types::*},
};
const SYSTEM_PROGRAM_ID: Address = address!("11111111111111111111111111111111");
let (event_authority, _) =
Address::find_program_address(&[b"event_authority"], &SUBSCRIPTIONS_ID);
let subscriber: Address = address!("SUBSCRIBER_WALLET_ADDRESS_HERE");
let subscriber_ata: Address = address!("SUBSCRIBER_TOKEN_ACCOUNT_ADDRESS_HERE");
let (subscription_authority, _) = Address::find_program_address(
&[b"SubscriptionAuthority", subscriber.as_ref(), token_mint.as_ref()],
&SUBSCRIPTIONS_ID,
);
let (subscription_pda, _) = Address::find_program_address(
&[b"subscription", plan_pda.as_ref(), subscriber.as_ref()],
&SUBSCRIPTIONS_ID,
);
let (_, plan_bump) = Address::find_program_address(
&[b"plan", merchant.as_ref(), &plan_id.to_le_bytes()],
&SUBSCRIPTIONS_ID,
);
let init_ix = InitSubscriptionAuthorityBuilder::new()
.owner(subscriber)
.subscription_authority(subscription_authority)
.token_mint(token_mint)
.user_ata(subscriber_ata)
.system_program(SYSTEM_PROGRAM_ID)
.token_program(TOKEN_PROGRAM_ID)
.instruction();
// Fetch and decode the plan account before building SubscribeData.
let fetched_plan: Plan = fetched_plan;
// Read `init_id` from the Subscription Authority account: fetch it once the
// init instruction above has landed and decode it.
let authority_account: SubscriptionAuthority = authority_account;
let subscribe_ix = SubscribeBuilder::new()
.subscriber(subscriber)
.merchant(merchant)
.plan_pda(plan_pda)
.subscription_pda(subscription_pda)
.subscription_authority_pda(subscription_authority)
.event_authority(event_authority)
.subscribe_data(SubscribeData {
plan_id,
plan_bump,
expected_mint: fetched_plan.data.mint,
expected_amount: fetched_plan.data.terms.amount,
expected_period_hours: fetched_plan.data.terms.period_hours,
expected_created_at: fetched_plan.data.terms.created_at,
expected_subscription_authority_init_id: authority_account.init_id,
})
.instruction();