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
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.40",
"version": "1.3.41",
"description": "Official icpay SDK for Internet Computer payments",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
18 changes: 17 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,14 +486,28 @@ export class Icpay {
let paymentIntentCode: number | null = null;
try {
debugLog(this.config.debug || false, 'creating payment intent');

// Get the expected sender principal from connected wallet
const expectedSenderPrincipal = this.connectedWallet?.owner || this.connectedWallet?.principal?.toString();
if (!expectedSenderPrincipal) {
throw new IcpayError({
code: ICPAY_ERROR_CODES.WALLET_NOT_CONNECTED,
message: 'Wallet must be connected to create payment intent',
details: { connectedWallet: this.connectedWallet },
retryable: false,
userAction: 'Connect your wallet first'
});
}

const intentResp = await this.publicApiClient.post('/sdk/public/payments/intents', {
amount: request.amount,
ledgerCanisterId,
expectedSenderPrincipal,
metadata: request.metadata || {},
});
paymentIntentId = intentResp.data?.paymentIntent?.id || null;
paymentIntentCode = intentResp.data?.paymentIntent?.intentCode ?? null;
debugLog(this.config.debug || false, 'payment intent created', { paymentIntentId, paymentIntentCode });
debugLog(this.config.debug || false, 'payment intent created', { paymentIntentId, paymentIntentCode, expectedSenderPrincipal });
} catch (e) {
// Do not proceed without a payment intent
// Throw a standardized error so integrators can handle it consistently
Expand Down Expand Up @@ -1074,6 +1088,8 @@ export class Icpay {
fee: tx.fee,
decimals: tx.decimals,
tokenPrice: tx.tokenPrice,
expectedSenderPrincipal: tx.expectedSenderPrincipal,
metadata: tx.metadata,
createdAt: new Date(tx.createdAt),
updatedAt: new Date(tx.updatedAt)
})),
Expand Down
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ export interface TransactionHistoryItem {
fee?: string;
decimals?: number;
tokenPrice?: string;
expectedSenderPrincipal?: string;
metadata?: any;
createdAt: Date;
updatedAt: Date;
Expand Down