@zendfi/sdk 0.7.1 → 0.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +1 -4
- package/dist/index.d.ts +1 -4
- package/dist/index.js +11 -30
- package/dist/index.mjs +11 -30
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1838,6 +1838,7 @@ declare class ZendFiEmbeddedCheckout {
|
|
|
1838
1838
|
private checkoutData;
|
|
1839
1839
|
private pollInterval;
|
|
1840
1840
|
private mounted;
|
|
1841
|
+
private paymentProcessed;
|
|
1841
1842
|
constructor(config: EmbeddedCheckoutConfig);
|
|
1842
1843
|
private getDefaultApiUrl;
|
|
1843
1844
|
/**
|
|
@@ -1856,10 +1857,6 @@ declare class ZendFiEmbeddedCheckout {
|
|
|
1856
1857
|
* Poll for payment confirmation
|
|
1857
1858
|
*/
|
|
1858
1859
|
private startPaymentPolling;
|
|
1859
|
-
/**
|
|
1860
|
-
* Fetch full payment details and handle success
|
|
1861
|
-
*/
|
|
1862
|
-
private fetchAndHandlePaymentSuccess;
|
|
1863
1860
|
/**
|
|
1864
1861
|
* Handle successful payment
|
|
1865
1862
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -1838,6 +1838,7 @@ declare class ZendFiEmbeddedCheckout {
|
|
|
1838
1838
|
private checkoutData;
|
|
1839
1839
|
private pollInterval;
|
|
1840
1840
|
private mounted;
|
|
1841
|
+
private paymentProcessed;
|
|
1841
1842
|
constructor(config: EmbeddedCheckoutConfig);
|
|
1842
1843
|
private getDefaultApiUrl;
|
|
1843
1844
|
/**
|
|
@@ -1856,10 +1857,6 @@ declare class ZendFiEmbeddedCheckout {
|
|
|
1856
1857
|
* Poll for payment confirmation
|
|
1857
1858
|
*/
|
|
1858
1859
|
private startPaymentPolling;
|
|
1859
|
-
/**
|
|
1860
|
-
* Fetch full payment details and handle success
|
|
1861
|
-
*/
|
|
1862
|
-
private fetchAndHandlePaymentSuccess;
|
|
1863
1860
|
/**
|
|
1864
1861
|
* Handle successful payment
|
|
1865
1862
|
*/
|
package/dist/index.js
CHANGED
|
@@ -3498,6 +3498,8 @@ var ZendFiEmbeddedCheckout = class {
|
|
|
3498
3498
|
checkoutData = null;
|
|
3499
3499
|
pollInterval = null;
|
|
3500
3500
|
mounted = false;
|
|
3501
|
+
paymentProcessed = false;
|
|
3502
|
+
// Prevent duplicate success callbacks
|
|
3501
3503
|
constructor(config) {
|
|
3502
3504
|
this.config = {
|
|
3503
3505
|
linkCode: config.linkCode || "",
|
|
@@ -3601,7 +3603,7 @@ var ZendFiEmbeddedCheckout = class {
|
|
|
3601
3603
|
*/
|
|
3602
3604
|
startPaymentPolling() {
|
|
3603
3605
|
this.pollInterval = setInterval(async () => {
|
|
3604
|
-
if (!this.checkoutData) return;
|
|
3606
|
+
if (!this.checkoutData || this.paymentProcessed) return;
|
|
3605
3607
|
try {
|
|
3606
3608
|
const response = await fetch(
|
|
3607
3609
|
`${this.config.apiUrl}/api/v1/payments/${this.checkoutData.payment_id}/status`,
|
|
@@ -3614,8 +3616,8 @@ var ZendFiEmbeddedCheckout = class {
|
|
|
3614
3616
|
);
|
|
3615
3617
|
if (response.ok) {
|
|
3616
3618
|
const data = await response.json();
|
|
3617
|
-
if (data.status === "confirmed") {
|
|
3618
|
-
|
|
3619
|
+
if (data.status === "confirmed" && !this.paymentProcessed) {
|
|
3620
|
+
this.handlePaymentSuccess(data);
|
|
3619
3621
|
} else if (data.status === "failed") {
|
|
3620
3622
|
this.handlePaymentFailure(data);
|
|
3621
3623
|
} else if (data.status === "expired") {
|
|
@@ -3627,41 +3629,20 @@ var ZendFiEmbeddedCheckout = class {
|
|
|
3627
3629
|
}
|
|
3628
3630
|
}, 3e3);
|
|
3629
3631
|
}
|
|
3630
|
-
/**
|
|
3631
|
-
* Fetch full payment details and handle success
|
|
3632
|
-
*/
|
|
3633
|
-
async fetchAndHandlePaymentSuccess() {
|
|
3634
|
-
if (!this.checkoutData) return;
|
|
3635
|
-
try {
|
|
3636
|
-
const response = await fetch(
|
|
3637
|
-
`${this.config.apiUrl}/api/v1/payments/${this.checkoutData.payment_id}`,
|
|
3638
|
-
{
|
|
3639
|
-
method: "GET",
|
|
3640
|
-
headers: {
|
|
3641
|
-
"Content-Type": "application/json"
|
|
3642
|
-
}
|
|
3643
|
-
}
|
|
3644
|
-
);
|
|
3645
|
-
if (response.ok) {
|
|
3646
|
-
const payment = await response.json();
|
|
3647
|
-
this.handlePaymentSuccess(payment);
|
|
3648
|
-
}
|
|
3649
|
-
} catch (error) {
|
|
3650
|
-
console.error("Failed to fetch payment details:", error);
|
|
3651
|
-
}
|
|
3652
|
-
}
|
|
3653
3632
|
/**
|
|
3654
3633
|
* Handle successful payment
|
|
3655
3634
|
*/
|
|
3656
|
-
handlePaymentSuccess(
|
|
3635
|
+
handlePaymentSuccess(statusData) {
|
|
3636
|
+
if (this.paymentProcessed) return;
|
|
3637
|
+
this.paymentProcessed = true;
|
|
3657
3638
|
if (this.pollInterval) {
|
|
3658
3639
|
clearInterval(this.pollInterval);
|
|
3659
3640
|
this.pollInterval = null;
|
|
3660
3641
|
}
|
|
3661
3642
|
this.config.onSuccess({
|
|
3662
|
-
paymentId:
|
|
3663
|
-
transactionSignature:
|
|
3664
|
-
amount:
|
|
3643
|
+
paymentId: this.checkoutData?.payment_id || statusData.payment_id,
|
|
3644
|
+
transactionSignature: statusData.transaction_signature || "Processing...",
|
|
3645
|
+
amount: this.checkoutData?.amount_usd || 0,
|
|
3665
3646
|
token: this.checkoutData?.token || "USDC",
|
|
3666
3647
|
merchantName: this.checkoutData?.merchant_name || "Merchant"
|
|
3667
3648
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -2442,6 +2442,8 @@ var ZendFiEmbeddedCheckout = class {
|
|
|
2442
2442
|
checkoutData = null;
|
|
2443
2443
|
pollInterval = null;
|
|
2444
2444
|
mounted = false;
|
|
2445
|
+
paymentProcessed = false;
|
|
2446
|
+
// Prevent duplicate success callbacks
|
|
2445
2447
|
constructor(config) {
|
|
2446
2448
|
this.config = {
|
|
2447
2449
|
linkCode: config.linkCode || "",
|
|
@@ -2545,7 +2547,7 @@ var ZendFiEmbeddedCheckout = class {
|
|
|
2545
2547
|
*/
|
|
2546
2548
|
startPaymentPolling() {
|
|
2547
2549
|
this.pollInterval = setInterval(async () => {
|
|
2548
|
-
if (!this.checkoutData) return;
|
|
2550
|
+
if (!this.checkoutData || this.paymentProcessed) return;
|
|
2549
2551
|
try {
|
|
2550
2552
|
const response = await fetch(
|
|
2551
2553
|
`${this.config.apiUrl}/api/v1/payments/${this.checkoutData.payment_id}/status`,
|
|
@@ -2558,8 +2560,8 @@ var ZendFiEmbeddedCheckout = class {
|
|
|
2558
2560
|
);
|
|
2559
2561
|
if (response.ok) {
|
|
2560
2562
|
const data = await response.json();
|
|
2561
|
-
if (data.status === "confirmed") {
|
|
2562
|
-
|
|
2563
|
+
if (data.status === "confirmed" && !this.paymentProcessed) {
|
|
2564
|
+
this.handlePaymentSuccess(data);
|
|
2563
2565
|
} else if (data.status === "failed") {
|
|
2564
2566
|
this.handlePaymentFailure(data);
|
|
2565
2567
|
} else if (data.status === "expired") {
|
|
@@ -2571,41 +2573,20 @@ var ZendFiEmbeddedCheckout = class {
|
|
|
2571
2573
|
}
|
|
2572
2574
|
}, 3e3);
|
|
2573
2575
|
}
|
|
2574
|
-
/**
|
|
2575
|
-
* Fetch full payment details and handle success
|
|
2576
|
-
*/
|
|
2577
|
-
async fetchAndHandlePaymentSuccess() {
|
|
2578
|
-
if (!this.checkoutData) return;
|
|
2579
|
-
try {
|
|
2580
|
-
const response = await fetch(
|
|
2581
|
-
`${this.config.apiUrl}/api/v1/payments/${this.checkoutData.payment_id}`,
|
|
2582
|
-
{
|
|
2583
|
-
method: "GET",
|
|
2584
|
-
headers: {
|
|
2585
|
-
"Content-Type": "application/json"
|
|
2586
|
-
}
|
|
2587
|
-
}
|
|
2588
|
-
);
|
|
2589
|
-
if (response.ok) {
|
|
2590
|
-
const payment = await response.json();
|
|
2591
|
-
this.handlePaymentSuccess(payment);
|
|
2592
|
-
}
|
|
2593
|
-
} catch (error) {
|
|
2594
|
-
console.error("Failed to fetch payment details:", error);
|
|
2595
|
-
}
|
|
2596
|
-
}
|
|
2597
2576
|
/**
|
|
2598
2577
|
* Handle successful payment
|
|
2599
2578
|
*/
|
|
2600
|
-
handlePaymentSuccess(
|
|
2579
|
+
handlePaymentSuccess(statusData) {
|
|
2580
|
+
if (this.paymentProcessed) return;
|
|
2581
|
+
this.paymentProcessed = true;
|
|
2601
2582
|
if (this.pollInterval) {
|
|
2602
2583
|
clearInterval(this.pollInterval);
|
|
2603
2584
|
this.pollInterval = null;
|
|
2604
2585
|
}
|
|
2605
2586
|
this.config.onSuccess({
|
|
2606
|
-
paymentId:
|
|
2607
|
-
transactionSignature:
|
|
2608
|
-
amount:
|
|
2587
|
+
paymentId: this.checkoutData?.payment_id || statusData.payment_id,
|
|
2588
|
+
transactionSignature: statusData.transaction_signature || "Processing...",
|
|
2589
|
+
amount: this.checkoutData?.amount_usd || 0,
|
|
2609
2590
|
token: this.checkoutData?.token || "USDC",
|
|
2610
2591
|
merchantName: this.checkoutData?.merchant_name || "Merchant"
|
|
2611
2592
|
});
|