@crediblemark/buayar 0.8.2 → 0.8.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/cli/index.js CHANGED
@@ -484,7 +484,7 @@ function printScaffoldSummary(result) {
484
484
  }
485
485
 
486
486
  // src/cli/index.ts
487
- var VERSION = "0.8.2";
487
+ var VERSION = "0.8.3";
488
488
  function parseArgs(argv) {
489
489
  const flags = [];
490
490
  const rest = [];
package/dist/index.d.mts CHANGED
@@ -1523,6 +1523,29 @@ declare function generateIpaymuSignature(method: "GET" | "POST", va: string, api
1523
1523
  signature: string;
1524
1524
  timestamp: string;
1525
1525
  };
1526
+ /**
1527
+ * Normalisasi payload callback iPaymu agar identik dengan apa yang
1528
+ * ditandatangani iPaymu (merujuk dokumentasi resmi callback):
1529
+ * - trx_id / status_code / transaction_status_code / paid_off → Integer
1530
+ * - is_escrow → Boolean
1531
+ * - additional_info "[]" (string) → [] (array); tambah [] saat field tidak ada
1532
+ * - field lain → String
1533
+ * - field "signature" (bila ikut terkirim di body) dibuang dari perhitungan
1534
+ */
1535
+ declare function normalizeIpaymuCallback(payload: any): Record<string, any>;
1536
+ /**
1537
+ * Bangun string JSON yang ditandatangani iPaymu untuk verifikasi callback:
1538
+ * - key diurutkan ascending (A-Z) dengan sort case-sensitif
1539
+ * - forward slash di-escape menjadi "\/" sesuai standar PHP json_encode
1540
+ */
1541
+ declare function buildIpaymuCallbackString(payload: any): string;
1542
+ /**
1543
+ * Verifikasi signature callback iPaymu.
1544
+ * Secret key = Nomor VA (Merchant VA) akun iPaymu; dibandingkan dengan
1545
+ * nilai header X-Signature menggunakan perbandingan timing-safe.
1546
+ * Tanpa header signature atau secret → INVALID.
1547
+ */
1548
+ declare function verifyIpaymuCallbackSignature(payload: any, secretKey: string, xSignature?: string): boolean;
1526
1549
  /**
1527
1550
  * Verifikasi callback webhook dari iPaymu
1528
1551
  */
@@ -1870,4 +1893,4 @@ declare function safeCompare(a: string, b: string): boolean;
1870
1893
  */
1871
1894
  declare function getPaymentMethodCategory(code: string, name?: string): "Virtual Account" | "QRIS" | "E-Wallet" | "Retail / Gerai" | "Kartu Kredit" | "Paylater / Cicilan" | "Lainnya";
1872
1895
 
1873
- export { AdyenClient, AdyenProvider, BasePaymentProvider, BraintreeClient, BraintreeProvider, Buayar, type BuayarConfig, CANONICAL_TO_DOKU, CANONICAL_TO_DUITKU, CANONICAL_TO_FASPAY, CANONICAL_TO_FINPAY, CANONICAL_TO_IPAYMU, CANONICAL_TO_MIDTRANS, CANONICAL_TO_NICEPAY, CANONICAL_TO_OY, CANONICAL_TO_PRISMALINK, CANONICAL_TO_STRIPE, CANONICAL_TO_XENDIT, CORE_API_METHODS, type CanonicalPaymentMethod, type CheckBalanceResult, type CheckTransactionParams, type CheckTransactionResult, CheckoutComClient, CheckoutComProvider, type CreateInvoiceParams, type CustomerDetails, DUITKU_TO_CANONICAL, type DisburseParams, type DisburseResult, DokuClient, DokuProvider, DuitkuClient, type DuitkuDisbursementParams, DuitkuProvider, type EWalletResponse, FaspayClient, FaspayProvider, FinpayClient, FinpayProvider, type GetPaymentMethodsParams, type GetPaymentMethodsResult, type InvoiceResponse, IpaymuClient, IpaymuProvider, MIDTRANS_PROBE_PAYLOADS, MIDTRANS_STATIC_METHODS, type MandiriBillInfo, MidtransClient, MidtransProvider, NicepayClient, NicepayProvider, OyClient, OyProvider, PaymentManager, type PaymentMethod, type PaymentMethodItem, type PaymentMode, PaypalClient, PaypalProvider, PayuClient, PayuProvider, PrismalinkClient, PrismalinkProvider, type ProviderCapability, type ProviderConfig, type ProviderDescriptor, ProviderRegistry, type QrisResponse, RazorpayClient, RazorpayProvider, type RefundParams, type RefundResult, SnapApiError, SnapClient, type SnapClientOptions, SquareClient, SquareProvider, StripeClient, StripeProvider, TwoCheckoutClient, TwoCheckoutProvider, type VerifyCallbackResult, type VirtualAccountResponse, XenditClient, type XenditDisbursementParams, XenditProvider, buayar, buildBraintreeBasicAuth, buildCoreChargePayload, buildDefaultDescriptors, buildPaypalBasicAuth, buildPayuBasicAuth, buildRazorpayBasicAuth, buildTwoCheckoutAuth, formatNicepayTimestamp, generateDokuHeaders, generateFaspaySignature, generateFinpaySignature, generateIpaymuSignature, generateNicepayToken, generateOyHeaders, generatePrismalinkSignature, generateSnapAsymmetricSignature, generateSnapSymmetricSignature, getDuitkuInquirySignatures, getDuitkuPaymentMethodsSignature, getDuitkuStatusSignatures, getPaymentMethodCategory, getXenditAuthHeader, hmacSha256, md5, minifyJson, parseCoreChargeResponse, paymentManager, providerRegistry, resolveConfigFromEnv, safeCompare, serializePaypalParams, serializeStripeParams, sha256, sha256Hex, sha512, snapErrorHint, snapExternalId, snapTimestamp, snapUtcTimestamp, toCanonicalPaymentMethod, toDokuPaymentMethod, toDuitkuPaymentMethod, toFaspayPaymentMethod, toFinpayPaymentMethod, toIpaymuPaymentMethod, toNicepayPaymentMethod, toOyPaymentMethod, toPrismalinkPaymentMethod, toStripePaymentMethod, toXenditPaymentMethod, verifyAdyenWebhook, verifyBraintreeWebhook, verifyCheckoutComWebhook, verifyDokuWebhookSignature, verifyDuitkuCallbackSignature, verifyFaspaySignature, verifyFinpaySignature, verifyIpaymuCallback, verifyNicepayWebhook, verifyOyWebhook, verifyPaypalWebhookSimple, verifyPayuWebhook, verifyPrismalinkSignature, verifyRazorpayWebhook, verifySnapWebhookSignature, verifySquareWebhook, verifyStripeWebhook, verifyTwoCheckoutWebhook, verifyXenditWebhookToken };
1896
+ export { AdyenClient, AdyenProvider, BasePaymentProvider, BraintreeClient, BraintreeProvider, Buayar, type BuayarConfig, CANONICAL_TO_DOKU, CANONICAL_TO_DUITKU, CANONICAL_TO_FASPAY, CANONICAL_TO_FINPAY, CANONICAL_TO_IPAYMU, CANONICAL_TO_MIDTRANS, CANONICAL_TO_NICEPAY, CANONICAL_TO_OY, CANONICAL_TO_PRISMALINK, CANONICAL_TO_STRIPE, CANONICAL_TO_XENDIT, CORE_API_METHODS, type CanonicalPaymentMethod, type CheckBalanceResult, type CheckTransactionParams, type CheckTransactionResult, CheckoutComClient, CheckoutComProvider, type CreateInvoiceParams, type CustomerDetails, DUITKU_TO_CANONICAL, type DisburseParams, type DisburseResult, DokuClient, DokuProvider, DuitkuClient, type DuitkuDisbursementParams, DuitkuProvider, type EWalletResponse, FaspayClient, FaspayProvider, FinpayClient, FinpayProvider, type GetPaymentMethodsParams, type GetPaymentMethodsResult, type InvoiceResponse, IpaymuClient, IpaymuProvider, MIDTRANS_PROBE_PAYLOADS, MIDTRANS_STATIC_METHODS, type MandiriBillInfo, MidtransClient, MidtransProvider, NicepayClient, NicepayProvider, OyClient, OyProvider, PaymentManager, type PaymentMethod, type PaymentMethodItem, type PaymentMode, PaypalClient, PaypalProvider, PayuClient, PayuProvider, PrismalinkClient, PrismalinkProvider, type ProviderCapability, type ProviderConfig, type ProviderDescriptor, ProviderRegistry, type QrisResponse, RazorpayClient, RazorpayProvider, type RefundParams, type RefundResult, SnapApiError, SnapClient, type SnapClientOptions, SquareClient, SquareProvider, StripeClient, StripeProvider, TwoCheckoutClient, TwoCheckoutProvider, type VerifyCallbackResult, type VirtualAccountResponse, XenditClient, type XenditDisbursementParams, XenditProvider, buayar, buildBraintreeBasicAuth, buildCoreChargePayload, buildDefaultDescriptors, buildIpaymuCallbackString, buildPaypalBasicAuth, buildPayuBasicAuth, buildRazorpayBasicAuth, buildTwoCheckoutAuth, formatNicepayTimestamp, generateDokuHeaders, generateFaspaySignature, generateFinpaySignature, generateIpaymuSignature, generateNicepayToken, generateOyHeaders, generatePrismalinkSignature, generateSnapAsymmetricSignature, generateSnapSymmetricSignature, getDuitkuInquirySignatures, getDuitkuPaymentMethodsSignature, getDuitkuStatusSignatures, getPaymentMethodCategory, getXenditAuthHeader, hmacSha256, md5, minifyJson, normalizeIpaymuCallback, parseCoreChargeResponse, paymentManager, providerRegistry, resolveConfigFromEnv, safeCompare, serializePaypalParams, serializeStripeParams, sha256, sha256Hex, sha512, snapErrorHint, snapExternalId, snapTimestamp, snapUtcTimestamp, toCanonicalPaymentMethod, toDokuPaymentMethod, toDuitkuPaymentMethod, toFaspayPaymentMethod, toFinpayPaymentMethod, toIpaymuPaymentMethod, toNicepayPaymentMethod, toOyPaymentMethod, toPrismalinkPaymentMethod, toStripePaymentMethod, toXenditPaymentMethod, verifyAdyenWebhook, verifyBraintreeWebhook, verifyCheckoutComWebhook, verifyDokuWebhookSignature, verifyDuitkuCallbackSignature, verifyFaspaySignature, verifyFinpaySignature, verifyIpaymuCallback, verifyIpaymuCallbackSignature, verifyNicepayWebhook, verifyOyWebhook, verifyPaypalWebhookSimple, verifyPayuWebhook, verifyPrismalinkSignature, verifyRazorpayWebhook, verifySnapWebhookSignature, verifySquareWebhook, verifyStripeWebhook, verifyTwoCheckoutWebhook, verifyXenditWebhookToken };
package/dist/index.d.ts CHANGED
@@ -1523,6 +1523,29 @@ declare function generateIpaymuSignature(method: "GET" | "POST", va: string, api
1523
1523
  signature: string;
1524
1524
  timestamp: string;
1525
1525
  };
1526
+ /**
1527
+ * Normalisasi payload callback iPaymu agar identik dengan apa yang
1528
+ * ditandatangani iPaymu (merujuk dokumentasi resmi callback):
1529
+ * - trx_id / status_code / transaction_status_code / paid_off → Integer
1530
+ * - is_escrow → Boolean
1531
+ * - additional_info "[]" (string) → [] (array); tambah [] saat field tidak ada
1532
+ * - field lain → String
1533
+ * - field "signature" (bila ikut terkirim di body) dibuang dari perhitungan
1534
+ */
1535
+ declare function normalizeIpaymuCallback(payload: any): Record<string, any>;
1536
+ /**
1537
+ * Bangun string JSON yang ditandatangani iPaymu untuk verifikasi callback:
1538
+ * - key diurutkan ascending (A-Z) dengan sort case-sensitif
1539
+ * - forward slash di-escape menjadi "\/" sesuai standar PHP json_encode
1540
+ */
1541
+ declare function buildIpaymuCallbackString(payload: any): string;
1542
+ /**
1543
+ * Verifikasi signature callback iPaymu.
1544
+ * Secret key = Nomor VA (Merchant VA) akun iPaymu; dibandingkan dengan
1545
+ * nilai header X-Signature menggunakan perbandingan timing-safe.
1546
+ * Tanpa header signature atau secret → INVALID.
1547
+ */
1548
+ declare function verifyIpaymuCallbackSignature(payload: any, secretKey: string, xSignature?: string): boolean;
1526
1549
  /**
1527
1550
  * Verifikasi callback webhook dari iPaymu
1528
1551
  */
@@ -1870,4 +1893,4 @@ declare function safeCompare(a: string, b: string): boolean;
1870
1893
  */
1871
1894
  declare function getPaymentMethodCategory(code: string, name?: string): "Virtual Account" | "QRIS" | "E-Wallet" | "Retail / Gerai" | "Kartu Kredit" | "Paylater / Cicilan" | "Lainnya";
1872
1895
 
1873
- export { AdyenClient, AdyenProvider, BasePaymentProvider, BraintreeClient, BraintreeProvider, Buayar, type BuayarConfig, CANONICAL_TO_DOKU, CANONICAL_TO_DUITKU, CANONICAL_TO_FASPAY, CANONICAL_TO_FINPAY, CANONICAL_TO_IPAYMU, CANONICAL_TO_MIDTRANS, CANONICAL_TO_NICEPAY, CANONICAL_TO_OY, CANONICAL_TO_PRISMALINK, CANONICAL_TO_STRIPE, CANONICAL_TO_XENDIT, CORE_API_METHODS, type CanonicalPaymentMethod, type CheckBalanceResult, type CheckTransactionParams, type CheckTransactionResult, CheckoutComClient, CheckoutComProvider, type CreateInvoiceParams, type CustomerDetails, DUITKU_TO_CANONICAL, type DisburseParams, type DisburseResult, DokuClient, DokuProvider, DuitkuClient, type DuitkuDisbursementParams, DuitkuProvider, type EWalletResponse, FaspayClient, FaspayProvider, FinpayClient, FinpayProvider, type GetPaymentMethodsParams, type GetPaymentMethodsResult, type InvoiceResponse, IpaymuClient, IpaymuProvider, MIDTRANS_PROBE_PAYLOADS, MIDTRANS_STATIC_METHODS, type MandiriBillInfo, MidtransClient, MidtransProvider, NicepayClient, NicepayProvider, OyClient, OyProvider, PaymentManager, type PaymentMethod, type PaymentMethodItem, type PaymentMode, PaypalClient, PaypalProvider, PayuClient, PayuProvider, PrismalinkClient, PrismalinkProvider, type ProviderCapability, type ProviderConfig, type ProviderDescriptor, ProviderRegistry, type QrisResponse, RazorpayClient, RazorpayProvider, type RefundParams, type RefundResult, SnapApiError, SnapClient, type SnapClientOptions, SquareClient, SquareProvider, StripeClient, StripeProvider, TwoCheckoutClient, TwoCheckoutProvider, type VerifyCallbackResult, type VirtualAccountResponse, XenditClient, type XenditDisbursementParams, XenditProvider, buayar, buildBraintreeBasicAuth, buildCoreChargePayload, buildDefaultDescriptors, buildPaypalBasicAuth, buildPayuBasicAuth, buildRazorpayBasicAuth, buildTwoCheckoutAuth, formatNicepayTimestamp, generateDokuHeaders, generateFaspaySignature, generateFinpaySignature, generateIpaymuSignature, generateNicepayToken, generateOyHeaders, generatePrismalinkSignature, generateSnapAsymmetricSignature, generateSnapSymmetricSignature, getDuitkuInquirySignatures, getDuitkuPaymentMethodsSignature, getDuitkuStatusSignatures, getPaymentMethodCategory, getXenditAuthHeader, hmacSha256, md5, minifyJson, parseCoreChargeResponse, paymentManager, providerRegistry, resolveConfigFromEnv, safeCompare, serializePaypalParams, serializeStripeParams, sha256, sha256Hex, sha512, snapErrorHint, snapExternalId, snapTimestamp, snapUtcTimestamp, toCanonicalPaymentMethod, toDokuPaymentMethod, toDuitkuPaymentMethod, toFaspayPaymentMethod, toFinpayPaymentMethod, toIpaymuPaymentMethod, toNicepayPaymentMethod, toOyPaymentMethod, toPrismalinkPaymentMethod, toStripePaymentMethod, toXenditPaymentMethod, verifyAdyenWebhook, verifyBraintreeWebhook, verifyCheckoutComWebhook, verifyDokuWebhookSignature, verifyDuitkuCallbackSignature, verifyFaspaySignature, verifyFinpaySignature, verifyIpaymuCallback, verifyNicepayWebhook, verifyOyWebhook, verifyPaypalWebhookSimple, verifyPayuWebhook, verifyPrismalinkSignature, verifyRazorpayWebhook, verifySnapWebhookSignature, verifySquareWebhook, verifyStripeWebhook, verifyTwoCheckoutWebhook, verifyXenditWebhookToken };
1896
+ export { AdyenClient, AdyenProvider, BasePaymentProvider, BraintreeClient, BraintreeProvider, Buayar, type BuayarConfig, CANONICAL_TO_DOKU, CANONICAL_TO_DUITKU, CANONICAL_TO_FASPAY, CANONICAL_TO_FINPAY, CANONICAL_TO_IPAYMU, CANONICAL_TO_MIDTRANS, CANONICAL_TO_NICEPAY, CANONICAL_TO_OY, CANONICAL_TO_PRISMALINK, CANONICAL_TO_STRIPE, CANONICAL_TO_XENDIT, CORE_API_METHODS, type CanonicalPaymentMethod, type CheckBalanceResult, type CheckTransactionParams, type CheckTransactionResult, CheckoutComClient, CheckoutComProvider, type CreateInvoiceParams, type CustomerDetails, DUITKU_TO_CANONICAL, type DisburseParams, type DisburseResult, DokuClient, DokuProvider, DuitkuClient, type DuitkuDisbursementParams, DuitkuProvider, type EWalletResponse, FaspayClient, FaspayProvider, FinpayClient, FinpayProvider, type GetPaymentMethodsParams, type GetPaymentMethodsResult, type InvoiceResponse, IpaymuClient, IpaymuProvider, MIDTRANS_PROBE_PAYLOADS, MIDTRANS_STATIC_METHODS, type MandiriBillInfo, MidtransClient, MidtransProvider, NicepayClient, NicepayProvider, OyClient, OyProvider, PaymentManager, type PaymentMethod, type PaymentMethodItem, type PaymentMode, PaypalClient, PaypalProvider, PayuClient, PayuProvider, PrismalinkClient, PrismalinkProvider, type ProviderCapability, type ProviderConfig, type ProviderDescriptor, ProviderRegistry, type QrisResponse, RazorpayClient, RazorpayProvider, type RefundParams, type RefundResult, SnapApiError, SnapClient, type SnapClientOptions, SquareClient, SquareProvider, StripeClient, StripeProvider, TwoCheckoutClient, TwoCheckoutProvider, type VerifyCallbackResult, type VirtualAccountResponse, XenditClient, type XenditDisbursementParams, XenditProvider, buayar, buildBraintreeBasicAuth, buildCoreChargePayload, buildDefaultDescriptors, buildIpaymuCallbackString, buildPaypalBasicAuth, buildPayuBasicAuth, buildRazorpayBasicAuth, buildTwoCheckoutAuth, formatNicepayTimestamp, generateDokuHeaders, generateFaspaySignature, generateFinpaySignature, generateIpaymuSignature, generateNicepayToken, generateOyHeaders, generatePrismalinkSignature, generateSnapAsymmetricSignature, generateSnapSymmetricSignature, getDuitkuInquirySignatures, getDuitkuPaymentMethodsSignature, getDuitkuStatusSignatures, getPaymentMethodCategory, getXenditAuthHeader, hmacSha256, md5, minifyJson, normalizeIpaymuCallback, parseCoreChargeResponse, paymentManager, providerRegistry, resolveConfigFromEnv, safeCompare, serializePaypalParams, serializeStripeParams, sha256, sha256Hex, sha512, snapErrorHint, snapExternalId, snapTimestamp, snapUtcTimestamp, toCanonicalPaymentMethod, toDokuPaymentMethod, toDuitkuPaymentMethod, toFaspayPaymentMethod, toFinpayPaymentMethod, toIpaymuPaymentMethod, toNicepayPaymentMethod, toOyPaymentMethod, toPrismalinkPaymentMethod, toStripePaymentMethod, toXenditPaymentMethod, verifyAdyenWebhook, verifyBraintreeWebhook, verifyCheckoutComWebhook, verifyDokuWebhookSignature, verifyDuitkuCallbackSignature, verifyFaspaySignature, verifyFinpaySignature, verifyIpaymuCallback, verifyIpaymuCallbackSignature, verifyNicepayWebhook, verifyOyWebhook, verifyPaypalWebhookSimple, verifyPayuWebhook, verifyPrismalinkSignature, verifyRazorpayWebhook, verifySnapWebhookSignature, verifySquareWebhook, verifyStripeWebhook, verifyTwoCheckoutWebhook, verifyXenditWebhookToken };
package/dist/index.js CHANGED
@@ -93,6 +93,7 @@ __export(index_exports, {
93
93
  buildBraintreeBasicAuth: () => buildBraintreeBasicAuth,
94
94
  buildCoreChargePayload: () => buildCoreChargePayload,
95
95
  buildDefaultDescriptors: () => buildDefaultDescriptors,
96
+ buildIpaymuCallbackString: () => buildIpaymuCallbackString,
96
97
  buildPaypalBasicAuth: () => buildPaypalBasicAuth,
97
98
  buildPayuBasicAuth: () => buildPayuBasicAuth,
98
99
  buildRazorpayBasicAuth: () => buildRazorpayBasicAuth,
@@ -115,6 +116,7 @@ __export(index_exports, {
115
116
  hmacSha256: () => hmacSha256,
116
117
  md5: () => md5,
117
118
  minifyJson: () => minifyJson,
119
+ normalizeIpaymuCallback: () => normalizeIpaymuCallback,
118
120
  parseCoreChargeResponse: () => parseCoreChargeResponse,
119
121
  paymentManager: () => paymentManager,
120
122
  providerRegistry: () => providerRegistry,
@@ -148,6 +150,7 @@ __export(index_exports, {
148
150
  verifyFaspaySignature: () => verifyFaspaySignature,
149
151
  verifyFinpaySignature: () => verifyFinpaySignature,
150
152
  verifyIpaymuCallback: () => verifyIpaymuCallback,
153
+ verifyIpaymuCallbackSignature: () => verifyIpaymuCallbackSignature,
151
154
  verifyNicepayWebhook: () => verifyNicepayWebhook,
152
155
  verifyOyWebhook: () => verifyOyWebhook,
153
156
  verifyPaypalWebhookSimple: () => verifyPaypalWebhookSimple,
@@ -1728,6 +1731,44 @@ function generateIpaymuSignature(method, va, apiKey, body) {
1728
1731
  const signature = hmacSha256(stringToSign, apiKey);
1729
1732
  return { signature, timestamp };
1730
1733
  }
1734
+ function normalizeIpaymuCallback(payload) {
1735
+ const result = {};
1736
+ for (const key of Object.keys(payload || {})) {
1737
+ const val = payload[key];
1738
+ if (key === "is_escrow") {
1739
+ result[key] = val === "true" || val === "1" || val === 1 || val === true;
1740
+ } else if (["trx_id", "status_code", "transaction_status_code", "paid_off"].includes(key)) {
1741
+ const intVal = parseInt(String(val), 10);
1742
+ result[key] = Number.isNaN(intVal) ? 0 : intVal;
1743
+ } else if (key === "additional_info") {
1744
+ result[key] = val === "[]" || val === "null" ? [] : val;
1745
+ } else if (key === "signature") {
1746
+ continue;
1747
+ } else {
1748
+ result[key] = String(val);
1749
+ }
1750
+ }
1751
+ if (!Object.prototype.hasOwnProperty.call(result, "additional_info")) {
1752
+ result.additional_info = [];
1753
+ }
1754
+ return result;
1755
+ }
1756
+ function buildIpaymuCallbackString(payload) {
1757
+ const normalized = normalizeIpaymuCallback(payload);
1758
+ const sorted = {};
1759
+ for (const key of Object.keys(normalized).sort((a, b) => a.localeCompare(b))) {
1760
+ sorted[key] = normalized[key];
1761
+ }
1762
+ let json = JSON.stringify(sorted);
1763
+ json = json.replace(/\//g, "\\/");
1764
+ return json;
1765
+ }
1766
+ function verifyIpaymuCallbackSignature(payload, secretKey, xSignature) {
1767
+ if (!secretKey || !xSignature) return false;
1768
+ const stringToSign = buildIpaymuCallbackString(payload);
1769
+ const computed = hmacSha256(stringToSign, secretKey);
1770
+ return safeCompare(String(xSignature).toLowerCase(), computed.toLowerCase());
1771
+ }
1731
1772
  function verifyIpaymuCallback(payload) {
1732
1773
  const status = (payload.status || "").toLowerCase();
1733
1774
  const statusCode = payload.status_code !== void 0 ? String(payload.status_code) : "";
@@ -1893,15 +1934,20 @@ var IpaymuProvider = class extends BasePaymentProvider {
1893
1934
  const { isPaid, isPending, isFailed } = verifyIpaymuCallback(body);
1894
1935
  const orderId = body.reference_id || body.referenceId || body.trx_id || "";
1895
1936
  const amount = body.amount || body.total || 0;
1937
+ const secretKey = config.merchantCode || config.merchantId || "";
1938
+ const headers = config.extra?.headers || {};
1939
+ const rawSig = headers["x-signature"] ?? headers["X-Signature"] ?? "";
1940
+ const xSignature = Array.isArray(rawSig) ? rawSig[0] : rawSig;
1941
+ const isValid = verifyIpaymuCallbackSignature(body, secretKey, xSignature);
1896
1942
  return {
1897
- isValid: true,
1943
+ isValid,
1898
1944
  provider: "ipaymu",
1899
1945
  orderId: String(orderId),
1900
1946
  amount: Number(amount) || 0,
1901
1947
  status: isPaid ? "paid" : isPending ? "pending" : "failed",
1902
- isPaid,
1903
- isPending,
1904
- isFailed,
1948
+ isPaid: isValid && isPaid,
1949
+ isPending: isValid && isPending,
1950
+ isFailed: !isValid || isFailed,
1905
1951
  isExpired: (body.status || "").toLowerCase() === "expired",
1906
1952
  statusCode: String(body.status_code || body.status || ""),
1907
1953
  rawPayload: body
@@ -10478,6 +10524,7 @@ var buayar = new Buayar();
10478
10524
  buildBraintreeBasicAuth,
10479
10525
  buildCoreChargePayload,
10480
10526
  buildDefaultDescriptors,
10527
+ buildIpaymuCallbackString,
10481
10528
  buildPaypalBasicAuth,
10482
10529
  buildPayuBasicAuth,
10483
10530
  buildRazorpayBasicAuth,
@@ -10500,6 +10547,7 @@ var buayar = new Buayar();
10500
10547
  hmacSha256,
10501
10548
  md5,
10502
10549
  minifyJson,
10550
+ normalizeIpaymuCallback,
10503
10551
  parseCoreChargeResponse,
10504
10552
  paymentManager,
10505
10553
  providerRegistry,
@@ -10533,6 +10581,7 @@ var buayar = new Buayar();
10533
10581
  verifyFaspaySignature,
10534
10582
  verifyFinpaySignature,
10535
10583
  verifyIpaymuCallback,
10584
+ verifyIpaymuCallbackSignature,
10536
10585
  verifyNicepayWebhook,
10537
10586
  verifyOyWebhook,
10538
10587
  verifyPaypalWebhookSimple,
package/dist/index.mjs CHANGED
@@ -1564,6 +1564,44 @@ function generateIpaymuSignature(method, va, apiKey, body) {
1564
1564
  const signature = hmacSha256(stringToSign, apiKey);
1565
1565
  return { signature, timestamp };
1566
1566
  }
1567
+ function normalizeIpaymuCallback(payload) {
1568
+ const result = {};
1569
+ for (const key of Object.keys(payload || {})) {
1570
+ const val = payload[key];
1571
+ if (key === "is_escrow") {
1572
+ result[key] = val === "true" || val === "1" || val === 1 || val === true;
1573
+ } else if (["trx_id", "status_code", "transaction_status_code", "paid_off"].includes(key)) {
1574
+ const intVal = parseInt(String(val), 10);
1575
+ result[key] = Number.isNaN(intVal) ? 0 : intVal;
1576
+ } else if (key === "additional_info") {
1577
+ result[key] = val === "[]" || val === "null" ? [] : val;
1578
+ } else if (key === "signature") {
1579
+ continue;
1580
+ } else {
1581
+ result[key] = String(val);
1582
+ }
1583
+ }
1584
+ if (!Object.prototype.hasOwnProperty.call(result, "additional_info")) {
1585
+ result.additional_info = [];
1586
+ }
1587
+ return result;
1588
+ }
1589
+ function buildIpaymuCallbackString(payload) {
1590
+ const normalized = normalizeIpaymuCallback(payload);
1591
+ const sorted = {};
1592
+ for (const key of Object.keys(normalized).sort((a, b) => a.localeCompare(b))) {
1593
+ sorted[key] = normalized[key];
1594
+ }
1595
+ let json = JSON.stringify(sorted);
1596
+ json = json.replace(/\//g, "\\/");
1597
+ return json;
1598
+ }
1599
+ function verifyIpaymuCallbackSignature(payload, secretKey, xSignature) {
1600
+ if (!secretKey || !xSignature) return false;
1601
+ const stringToSign = buildIpaymuCallbackString(payload);
1602
+ const computed = hmacSha256(stringToSign, secretKey);
1603
+ return safeCompare(String(xSignature).toLowerCase(), computed.toLowerCase());
1604
+ }
1567
1605
  function verifyIpaymuCallback(payload) {
1568
1606
  const status = (payload.status || "").toLowerCase();
1569
1607
  const statusCode = payload.status_code !== void 0 ? String(payload.status_code) : "";
@@ -1729,15 +1767,20 @@ var IpaymuProvider = class extends BasePaymentProvider {
1729
1767
  const { isPaid, isPending, isFailed } = verifyIpaymuCallback(body);
1730
1768
  const orderId = body.reference_id || body.referenceId || body.trx_id || "";
1731
1769
  const amount = body.amount || body.total || 0;
1770
+ const secretKey = config.merchantCode || config.merchantId || "";
1771
+ const headers = config.extra?.headers || {};
1772
+ const rawSig = headers["x-signature"] ?? headers["X-Signature"] ?? "";
1773
+ const xSignature = Array.isArray(rawSig) ? rawSig[0] : rawSig;
1774
+ const isValid = verifyIpaymuCallbackSignature(body, secretKey, xSignature);
1732
1775
  return {
1733
- isValid: true,
1776
+ isValid,
1734
1777
  provider: "ipaymu",
1735
1778
  orderId: String(orderId),
1736
1779
  amount: Number(amount) || 0,
1737
1780
  status: isPaid ? "paid" : isPending ? "pending" : "failed",
1738
- isPaid,
1739
- isPending,
1740
- isFailed,
1781
+ isPaid: isValid && isPaid,
1782
+ isPending: isValid && isPending,
1783
+ isFailed: !isValid || isFailed,
1741
1784
  isExpired: (body.status || "").toLowerCase() === "expired",
1742
1785
  statusCode: String(body.status_code || body.status || ""),
1743
1786
  rawPayload: body
@@ -10313,6 +10356,7 @@ export {
10313
10356
  buildBraintreeBasicAuth,
10314
10357
  buildCoreChargePayload,
10315
10358
  buildDefaultDescriptors,
10359
+ buildIpaymuCallbackString,
10316
10360
  buildPaypalBasicAuth,
10317
10361
  buildPayuBasicAuth,
10318
10362
  buildRazorpayBasicAuth,
@@ -10335,6 +10379,7 @@ export {
10335
10379
  hmacSha256,
10336
10380
  md5,
10337
10381
  minifyJson,
10382
+ normalizeIpaymuCallback,
10338
10383
  parseCoreChargeResponse,
10339
10384
  paymentManager,
10340
10385
  providerRegistry,
@@ -10368,6 +10413,7 @@ export {
10368
10413
  verifyFaspaySignature,
10369
10414
  verifyFinpaySignature,
10370
10415
  verifyIpaymuCallback,
10416
+ verifyIpaymuCallbackSignature,
10371
10417
  verifyNicepayWebhook,
10372
10418
  verifyOyWebhook,
10373
10419
  verifyPaypalWebhookSimple,
package/docs/ipaymu.md CHANGED
@@ -249,12 +249,17 @@ const banks = await client.getBankList();
249
249
 
250
250
  ## 9. Webhook & Verifikasi Notifikasi Callback
251
251
 
252
- Saat pembeli menyelesaikan pembayaran, iPaymu mengirimkan HTTP POST request ke `notifyUrl`:
252
+ Saat pembeli menyelesaikan pembayaran, iPaymu mengirimkan HTTP POST request ke `notifyUrl`.
253
+ Callback **harus** membawa header `X-Signature`; Buayar memverifikasinya dengan
254
+ **HMAC-SHA256** atas payload callback yang dinormalisasi (sort kunci A–Z + escape slash)
255
+ menggunakan **Merchant VA** sebagai secret key. Callback tanpa `X-Signature` yang sah
256
+ akan selalu ditolak (`isValid === false`).
253
257
 
254
258
  ```typescript
255
- // Di handler Express.js / Next.js API route:
259
+ // Di handler Express.js / Next.js API route + REST framework apapun (Elysia/Hono/...):
256
260
  app.post("/api/payment/webhook", (req, res) => {
257
- const result = buayar.verifyCallback(req.body);
261
+ // Header request (termasuk `x-signature`) WAJIB diferuskan:
262
+ const result = buayar.verifyWebhook(req.body, req.headers);
258
263
 
259
264
  if (result.isValid && result.isPaid) {
260
265
  console.log("Pembayaran Berhasil untuk Order ID:", result.orderId);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crediblemark/buayar",
3
- "version": "0.8.2",
3
+ "version": "0.8.3",
4
4
  "description": "Unified Payment Gateway SDK for Node.js & TypeScript — 19 providers (Midtrans, Xendit, Duitku, Stripe, PayPal, Adyen, Razorpay, Square, Checkout.com, PayU, Braintree, 2Checkout, DOKU, iPaymu, PrismaLink, Faspay, Finpay, Nicepay, OY!) with zero-code switching via .env",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",