Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions contracts/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![no_std]

use soroban_sdk::{contract, contractimpl, contracttype, Address, Env, String, Vec};
use soroban_sdk::{contract, contractimpl, contracttype, token, Address, Env, String, Vec};

/// Billing interval in seconds
#[contracttype]
Expand Down Expand Up @@ -355,6 +355,13 @@ impl SubTrackrContract {
.get(&DataKey::Plan(sub.plan_id))
.expect("Plan not found");

// Execute actual token transfer from subscriber to merchant
token::Client::new(&env, &plan.token).transfer(
&sub.subscriber,
&plan.merchant,
&plan.price,
);

sub.last_charged_at = now;
sub.next_charge_at = now + plan.interval.seconds();
sub.total_paid += plan.price;
Expand Down Expand Up @@ -528,6 +535,14 @@ mod test {
use soroban_sdk::testutils::{Address as _, Ledger};
use soroban_sdk::Env;

#[contract]
pub struct MockToken;

#[contractimpl]
impl MockToken {
pub fn transfer(_env: Env, _from: Address, _to: Address, _amount: i128) {}
}

fn setup(
env: &Env,
) -> (
Expand All @@ -543,7 +558,7 @@ mod test {
let admin = Address::generate(env);
let merchant = Address::generate(env);
let subscriber = Address::generate(env);
let token = Address::generate(env);
let token = env.register_contract(None, MockToken);

env.mock_all_auths();
client.initialize(&admin);
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "expo/tsconfig.base",
"compilerOptions": {
"strict": true
"strict": true,
"lib": ["es2017", "dom"]
}
}
Loading