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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ const icpay = new Icpay({
});

// Server-side operations
const transactions = await icpay.getTransactionHistory();
const accountBalances = await icpay.getAccountWalletBalances();
const transactions = await icpay.protected.getTransactionHistory();
const accountBalances = await icpay.protected.getAccountWalletBalances();
```

## Authentication Modes
Expand Down
2 changes: 1 addition & 1 deletion examples/balance-check-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ async function testEnhancedBalanceFeatures() {
// 5. Test getting account wallet balances (from API)
console.log('\n5. Testing getAccountWalletBalances...');
try {
const accountBalances = await icpay.getAccountWalletBalances();
const accountBalances = await icpay.protected.getAccountWalletBalances();
console.log('Account Wallet Balances:', {
totalBalancesUSD: accountBalances.totalBalancesUSD,
lastUpdated: accountBalances.lastUpdated,
Expand Down
2 changes: 1 addition & 1 deletion examples/basic-usage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ async function example() {

// 8. Check transaction status
console.log('\nChecking transaction status...');
const status = await icpay.getTransactionStatus(transaction.transactionId);
const status = await icpay.protected.getTransactionStatus(transaction.transactionId);
console.log('Transaction Status:', status);

// 9. Get account information
Expand Down
4 changes: 2 additions & 2 deletions examples/enhanced-usage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ async function privateExample() {

// 9. Get account wallet balances (from API, private method)
console.log('\n9. Fetching account wallet balances from API...');
const accountWalletBalances = await icpay.getAccountWalletBalances();
const accountWalletBalances = await icpay.protected.getAccountWalletBalances();
console.log('Account Wallet Balances:', {
totalBalancesUSD: accountWalletBalances.totalBalancesUSD,
lastUpdated: accountWalletBalances.lastUpdated,
Expand Down Expand Up @@ -197,7 +197,7 @@ async function privateExample() {

// 13. Get transaction status (private method)
console.log('\n13. Checking transaction status...');
const transactionStatus = await icpay.getTransactionStatus(transaction.transactionId);
const transactionStatus = await icpay.protected.getTransactionStatus(transaction.transactionId);
console.log('Transaction Status:', {
transactionId: transactionStatus.transactionId,
status: transactionStatus.status,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@icpay/sdk",
"version": "1.3.51",
"version": "1.3.52",
"description": "Official icpay SDK for Internet Computer payments",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
58 changes: 5 additions & 53 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,11 @@ import {
IcpayConfig,
CreateTransactionRequest,
TransactionResponse,
TransactionStatus,
AccountInfo,
PublicAccountInfo,
VerifiedLedger,
WalletConnectionResult,
AllLedgerBalances,
LedgerBalance,
PriceCalculationRequest,
PriceCalculationResult,
PaymentHistoryRequest,
PaymentHistoryResponse,
GetPaymentsByPrincipalRequest,
LedgerInfo,
SendFundsUsdRequest,
AccountPublic,
LedgerPublic,
Expand All @@ -28,8 +20,8 @@ import { HttpAgent, Actor } from '@dfinity/agent';
import { idlFactory as icpayIdl } from './declarations/icpay_canister_backend/icpay_canister_backend.did.js';
import { idlFactory as ledgerIdl } from './declarations/icrc-ledger/ledger.did.js';
import { Principal } from '@dfinity/principal';
import { toAccountIdentifier, debugLog } from './utils';
import { IcpayProtected } from './protected';
import { debugLog } from './utils';
import { createProtectedApi, ProtectedApi } from './protected';

export class Icpay {
private config: IcpayConfig;
Expand All @@ -43,7 +35,7 @@ export class Icpay {
private accountInfoCache: any = null;
private verifiedLedgersCache: { data: LedgerPublic[] | null; timestamp: number } = { data: null, timestamp: 0 };
private events: IcpayEventCenter;
public protected: IcpayProtected;
public protected: ProtectedApi;

constructor(config: IcpayConfig) {
this.config = {
Expand Down Expand Up @@ -101,9 +93,8 @@ export class Icpay {

debugLog(this.config.debug || false, 'privateApiClient created', this.privateApiClient);

// Initialize protected wrapper
this.protected = new IcpayProtected({
publicApiClient: this.publicApiClient,
// Initialize protected API
this.protected = createProtectedApi({
privateApiClient: this.privateApiClient,
emitStart: (name, args) => this.emitMethodStart(name, args),
emitSuccess: (name, result) => this.emitMethodSuccess(name, result),
Expand Down Expand Up @@ -219,13 +210,6 @@ export class Icpay {
}
}

/**
* Get detailed account information (private method - full data)
*/
async getDetailedAccountInfo(): Promise<AccountInfo> {
return this.protected.getDetailedAccountInfo();
}

/**
* Get verified ledgers (public method)
*/
Expand Down Expand Up @@ -300,17 +284,6 @@ export class Icpay {
return result;
}

/**
* Get transaction status by canister transaction ID (private method)
*
* This method returns transaction status from the ICPay API database.
* Note: Canister transactions may take up to 1 minute to sync to the API database.
* If a transaction is not found, a sync notification will be automatically triggered.
*/
async getTransactionStatus(canisterTransactionId: number): Promise<TransactionStatus> {
return this.protected.getTransactionStatus(canisterTransactionId);
}

/**
* Trigger transaction sync from canister (public method)
*
Expand Down Expand Up @@ -1224,20 +1197,6 @@ export class Icpay {
}
}

/**
* Get payment history for account (requires secret key)
*/
async getPaymentHistory(request: PaymentHistoryRequest = {}): Promise<PaymentHistoryResponse> {
return this.protected.getPaymentHistory(request);
}

/**
* Get payments by principal ID (for connected wallet) - checks both sender_principal_id and expected_sender_principal
*/
async getPaymentsByPrincipal(request: GetPaymentsByPrincipalRequest): Promise<PaymentHistoryResponse> {
return this.protected.getPaymentsByPrincipal(request);
}

/**
* Get detailed ledger information including price data (public method)
*/
Expand Down Expand Up @@ -1360,13 +1319,6 @@ export class Icpay {
}
}

/**
* Get account wallet balances (from API, not connected wallet) (private method)
*/
async getAccountWalletBalances(): Promise<AllLedgerBalances> {
return this.protected.getAccountWalletBalances();
}

/**
* Utility function to format balance from smallest unit to human readable
*/
Expand Down
Loading