@delopay/sdk 0.229.0 → 0.232.0

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.cjs CHANGED
@@ -134,6 +134,11 @@ __export(index_exports, {
134
134
  UNKNOWN_SECTION_ORDER: () => UNKNOWN_SECTION_ORDER,
135
135
  WCAG_AA_TEXT: () => WCAG_AA_TEXT,
136
136
  WCAG_AA_UI: () => WCAG_AA_UI,
137
+ WHOP_ACCENT_COLORS: () => WHOP_ACCENT_COLORS,
138
+ WHOP_BILLING_DETAILS: () => WHOP_BILLING_DETAILS,
139
+ WHOP_CARD_PRESETS: () => WHOP_CARD_PRESETS,
140
+ WHOP_EMAIL_LABELS: () => WHOP_EMAIL_LABELS,
141
+ WHOP_GRAY_COLORS: () => WHOP_GRAY_COLORS,
137
142
  Webhooks: () => Webhooks,
138
143
  WhopResolutionCases: () => WhopResolutionCases,
139
144
  airwallexCardLayout: () => airwallexCardLayout,
@@ -207,6 +212,7 @@ __export(index_exports, {
207
212
  leaf: () => leaf,
208
213
  logoDimensions: () => logoDimensions,
209
214
  nativePaneMethodInfo: () => nativePaneMethodInfo,
215
+ nearestWhopAccent: () => nearestWhopAccent,
210
216
  noticeText: () => noticeText,
211
217
  noticesIn: () => noticesIn,
212
218
  offerablePaneMethods: () => offerablePaneMethods,
@@ -227,6 +233,7 @@ __export(index_exports, {
227
233
  resolveGooglePayButtonColor: () => resolveGooglePayButtonColor,
228
234
  resolveNoticesAndBadges: () => resolveNoticesAndBadges,
229
235
  resolveStripeTheme: () => resolveStripeTheme,
236
+ resolveWhopAccent: () => resolveWhopAccent,
230
237
  ruleMatchToTree: () => ruleMatchToTree,
231
238
  sanitizeCustomCss: () => sanitizeCustomCss,
232
239
  sectionLabel: () => sectionLabel,
@@ -241,8 +248,11 @@ __export(index_exports, {
241
248
  surfacePadValue: () => surfacePadValue,
242
249
  validSectionOrder: () => validSectionOrder,
243
250
  validatePanes: () => validatePanes,
251
+ vaultFormAppearance: () => vaultFormAppearance,
244
252
  verticalGapValue: () => verticalGapValue,
245
- visibleCustomFields: () => visibleCustomFields
253
+ visibleCustomFields: () => visibleCustomFields,
254
+ whopAccentSwatch: () => whopAccentSwatch,
255
+ whopCardElement: () => whopCardElement
246
256
  });
247
257
  module.exports = __toCommonJS(index_exports);
248
258
 
@@ -2091,6 +2101,20 @@ var PaymentLinks = class {
2091
2101
  async retrieve(linkId) {
2092
2102
  return this.request("GET", `/payment-link/${encodeURIComponent(linkId)}`);
2093
2103
  }
2104
+ /**
2105
+ * The merchant and payment an opaque checkout link opens.
2106
+ *
2107
+ * A link the API issues today is `/pay/{payment_link_id}`, so it names
2108
+ * neither the merchant nor the payment. This answers which ones it means.
2109
+ * Unauthenticated, like the checkout render it precedes: no credential is
2110
+ * needed or sent beyond what the client already carries. An unknown id is a
2111
+ * 404.
2112
+ *
2113
+ * `GET /payment-link/resolve/{payment_link_id}`
2114
+ */
2115
+ async resolve(paymentLinkId) {
2116
+ return this.request("GET", `/payment-link/resolve/${encodeURIComponent(paymentLinkId)}`);
2117
+ }
2094
2118
  /**
2095
2119
  * List payment links, optionally filtered by status or date range.
2096
2120
  *
@@ -8774,6 +8798,133 @@ var GOOGLE_PAY_BUTTON_TYPES = [
8774
8798
  "subscribe",
8775
8799
  "donate"
8776
8800
  ];
8801
+ var WHOP_CARD_PRESETS = ["accordion", "tiles", "card_stacked", "card_compact"];
8802
+ function whopCardElement(preset) {
8803
+ switch (preset) {
8804
+ case "tiles":
8805
+ return { element: "payment", layout: "horizontal" };
8806
+ case "card_stacked":
8807
+ return { element: "card", layout: "stacked" };
8808
+ case "card_compact":
8809
+ return { element: "card", layout: "compact" };
8810
+ default:
8811
+ return { element: "payment", layout: "accordion" };
8812
+ }
8813
+ }
8814
+ var WHOP_ACCENT_COLORS = [
8815
+ "auto",
8816
+ "gray",
8817
+ "blue",
8818
+ "indigo",
8819
+ "iris",
8820
+ "violet",
8821
+ "purple",
8822
+ "plum",
8823
+ "pink",
8824
+ "crimson",
8825
+ "ruby",
8826
+ "red",
8827
+ "tomato",
8828
+ "orange",
8829
+ "amber",
8830
+ "yellow",
8831
+ "lime",
8832
+ "grass",
8833
+ "green",
8834
+ "jade",
8835
+ "teal",
8836
+ "cyan",
8837
+ "sky",
8838
+ "mint",
8839
+ "brown",
8840
+ "bronze",
8841
+ "gold"
8842
+ ];
8843
+ var WHOP_ACCENT_SWATCHES = {
8844
+ blue: "#0090ff",
8845
+ indigo: "#3e63dd",
8846
+ iris: "#5b5bd6",
8847
+ violet: "#6e56cf",
8848
+ purple: "#8e4ec6",
8849
+ plum: "#ab4aba",
8850
+ pink: "#d6409f",
8851
+ crimson: "#e93d82",
8852
+ ruby: "#e54666",
8853
+ red: "#e5484d",
8854
+ tomato: "#e54d2e",
8855
+ orange: "#f76b15",
8856
+ amber: "#ffc53d",
8857
+ yellow: "#ffe629",
8858
+ lime: "#bdee63",
8859
+ grass: "#46a758",
8860
+ green: "#30a46c",
8861
+ jade: "#29a383",
8862
+ teal: "#12a594",
8863
+ cyan: "#00a2c7",
8864
+ sky: "#7ce2fe",
8865
+ mint: "#86ead4",
8866
+ brown: "#ad7f58",
8867
+ bronze: "#a18072",
8868
+ gold: "#978365"
8869
+ };
8870
+ function whopAccentSwatch(accent) {
8871
+ return accent === "gray" ? "#8d8d8d" : WHOP_ACCENT_SWATCHES[accent];
8872
+ }
8873
+ function hexRgb(hex) {
8874
+ const raw = hex.trim().replace(/^#/, "");
8875
+ const full = raw.length === 3 ? raw.replace(/./g, (c) => c + c) : raw;
8876
+ if (!/^[0-9a-f]{6}$/i.test(full)) return null;
8877
+ const n = Number.parseInt(full, 16);
8878
+ return [n >> 16 & 255, n >> 8 & 255, n & 255];
8879
+ }
8880
+ function oklab([r, g, b]) {
8881
+ const lin = (c) => {
8882
+ const v = c / 255;
8883
+ return v <= 0.04045 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4;
8884
+ };
8885
+ const [lr, lg, lb] = [lin(r), lin(g), lin(b)];
8886
+ const l = Math.cbrt(0.4122214708 * lr + 0.5363325363 * lg + 0.0514459929 * lb);
8887
+ const m = Math.cbrt(0.2119034982 * lr + 0.6806995451 * lg + 0.1073969566 * lb);
8888
+ const s2 = Math.cbrt(0.0883024619 * lr + 0.2817188376 * lg + 0.6299787005 * lb);
8889
+ return [
8890
+ 0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s2,
8891
+ 1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s2,
8892
+ 0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s2
8893
+ ];
8894
+ }
8895
+ function nearestWhopAccent(hex) {
8896
+ const rgb = hexRgb(hex);
8897
+ if (!rgb) return "blue";
8898
+ const [L, a, b] = oklab(rgb);
8899
+ if (Math.hypot(a, b) < 0.04) return "gray";
8900
+ let best = "blue";
8901
+ let bestDistance = Number.POSITIVE_INFINITY;
8902
+ for (const [name, swatch] of Object.entries(WHOP_ACCENT_SWATCHES)) {
8903
+ const swatchRgb = hexRgb(swatch);
8904
+ if (!swatchRgb) continue;
8905
+ const [sL, sa, sb] = oklab(swatchRgb);
8906
+ const distance = Math.hypot((L - sL) * 0.5, a - sa, b - sb);
8907
+ if (distance < bestDistance) {
8908
+ bestDistance = distance;
8909
+ best = name;
8910
+ }
8911
+ }
8912
+ return best;
8913
+ }
8914
+ function resolveWhopAccent(accent, primaryHex) {
8915
+ return accent === "auto" ? nearestWhopAccent(primaryHex) : accent;
8916
+ }
8917
+ var WHOP_EMAIL_LABELS = ["above", "floating"];
8918
+ var WHOP_GRAY_COLORS = [
8919
+ "auto",
8920
+ "gray",
8921
+ "mauve",
8922
+ "slate",
8923
+ "sage",
8924
+ "olive",
8925
+ "sand"
8926
+ ];
8927
+ var WHOP_BILLING_DETAILS = ["minimal", "full"];
8777
8928
 
8778
8929
  // src/branding.ts
8779
8930
  function surchargeShowsLabel(labelMode, style, position) {
@@ -9048,6 +9199,19 @@ function inputPadValue(size) {
9048
9199
  function buttonPadValue(size) {
9049
9200
  return BUTTON_PAD[size] ?? BUTTON_PAD.md;
9050
9201
  }
9202
+ function vaultFormAppearance(b, danger) {
9203
+ return {
9204
+ surface: b.surface,
9205
+ text: b.text,
9206
+ border: b.border,
9207
+ accent: b.primary,
9208
+ ...danger ? { danger } : {},
9209
+ font: b.fontFamily,
9210
+ radius: b.radiusInput,
9211
+ size: b.inputSize,
9212
+ labels: b.labelStyle
9213
+ };
9214
+ }
9051
9215
  function logoDimensions(size) {
9052
9216
  switch (size) {
9053
9217
  case "sm":
@@ -9527,6 +9691,16 @@ var DEFAULT_BRANDING_BASE = {
9527
9691
  micropaymentFieldFontSize: "md",
9528
9692
  micropaymentFieldWeight: "regular",
9529
9693
  micropaymentFocusRing: "strong",
9694
+ whopCardPreset: "accordion",
9695
+ whopAccentColor: "auto",
9696
+ whopGrayColor: "auto",
9697
+ whopBillingDetails: "minimal",
9698
+ whopSeparated: false,
9699
+ whopEmailLabel: "above",
9700
+ whopFieldChrome: "outlined",
9701
+ whopFieldFontSize: "md",
9702
+ whopFieldWeight: "regular",
9703
+ whopFocusRing: "strong",
9530
9704
  customCss: ""
9531
9705
  };
9532
9706
  var DEFAULT_BRANDING = {
@@ -10469,6 +10643,52 @@ function decodeBranding(source) {
10469
10643
  CARD_FOCUS_RINGS,
10470
10644
  DEFAULT_BRANDING.micropaymentFocusRing
10471
10645
  ),
10646
+ whopCardPreset: pickEnum(
10647
+ extras["whopCardPreset"],
10648
+ WHOP_CARD_PRESETS,
10649
+ DEFAULT_BRANDING.whopCardPreset
10650
+ ),
10651
+ whopAccentColor: pickEnum(
10652
+ extras["whopAccentColor"],
10653
+ WHOP_ACCENT_COLORS,
10654
+ DEFAULT_BRANDING.whopAccentColor
10655
+ ),
10656
+ whopGrayColor: pickEnum(
10657
+ extras["whopGrayColor"],
10658
+ WHOP_GRAY_COLORS,
10659
+ DEFAULT_BRANDING.whopGrayColor
10660
+ ),
10661
+ whopBillingDetails: pickEnum(
10662
+ extras["whopBillingDetails"],
10663
+ WHOP_BILLING_DETAILS,
10664
+ DEFAULT_BRANDING.whopBillingDetails
10665
+ ),
10666
+ whopSeparated: parseBool(extras["whopSeparated"], DEFAULT_BRANDING.whopSeparated),
10667
+ whopEmailLabel: pickEnum(
10668
+ extras["whopEmailLabel"],
10669
+ WHOP_EMAIL_LABELS,
10670
+ DEFAULT_BRANDING.whopEmailLabel
10671
+ ),
10672
+ whopFieldChrome: pickEnum(
10673
+ extras["whopFieldChrome"],
10674
+ CARD_FIELD_CHROMES,
10675
+ DEFAULT_BRANDING.whopFieldChrome
10676
+ ),
10677
+ whopFieldFontSize: pickEnum(
10678
+ extras["whopFieldFontSize"],
10679
+ CARD_FIELD_FONT_SIZES,
10680
+ DEFAULT_BRANDING.whopFieldFontSize
10681
+ ),
10682
+ whopFieldWeight: pickEnum(
10683
+ extras["whopFieldWeight"],
10684
+ CARD_FIELD_WEIGHTS,
10685
+ DEFAULT_BRANDING.whopFieldWeight
10686
+ ),
10687
+ whopFocusRing: pickEnum(
10688
+ extras["whopFocusRing"],
10689
+ CARD_FOCUS_RINGS,
10690
+ DEFAULT_BRANDING.whopFocusRing
10691
+ ),
10472
10692
  paypalValidTint: parseBool(extras["paypalValidTint"], DEFAULT_BRANDING.paypalValidTint),
10473
10693
  nomupayFormStyle: pickEnum(
10474
10694
  extras["nomupayFormStyle"],
@@ -10616,6 +10836,16 @@ function encodeBranding(branding, base) {
10616
10836
  micropaymentFieldFontSize: branding.micropaymentFieldFontSize,
10617
10837
  micropaymentFieldWeight: branding.micropaymentFieldWeight,
10618
10838
  micropaymentFocusRing: branding.micropaymentFocusRing,
10839
+ whopCardPreset: branding.whopCardPreset,
10840
+ whopAccentColor: branding.whopAccentColor,
10841
+ whopGrayColor: branding.whopGrayColor,
10842
+ whopBillingDetails: branding.whopBillingDetails,
10843
+ whopSeparated: String(branding.whopSeparated),
10844
+ whopEmailLabel: branding.whopEmailLabel,
10845
+ whopFieldChrome: branding.whopFieldChrome,
10846
+ whopFieldFontSize: branding.whopFieldFontSize,
10847
+ whopFieldWeight: branding.whopFieldWeight,
10848
+ whopFocusRing: branding.whopFocusRing,
10619
10849
  paypalValidTint: String(branding.paypalValidTint),
10620
10850
  nomupayFormStyle: branding.nomupayFormStyle,
10621
10851
  nomupayShowLabels: String(branding.nomupayShowLabels),
@@ -11023,6 +11253,52 @@ function parseImportedBranding(raw) {
11023
11253
  CARD_FOCUS_RINGS,
11024
11254
  dflt.micropaymentFocusRing
11025
11255
  ),
11256
+ whopCardPreset: pickEnum(
11257
+ root["whopCardPreset"],
11258
+ WHOP_CARD_PRESETS,
11259
+ dflt.whopCardPreset
11260
+ ),
11261
+ whopAccentColor: pickEnum(
11262
+ root["whopAccentColor"],
11263
+ WHOP_ACCENT_COLORS,
11264
+ dflt.whopAccentColor
11265
+ ),
11266
+ whopGrayColor: pickEnum(
11267
+ root["whopGrayColor"],
11268
+ WHOP_GRAY_COLORS,
11269
+ dflt.whopGrayColor
11270
+ ),
11271
+ whopBillingDetails: pickEnum(
11272
+ root["whopBillingDetails"],
11273
+ WHOP_BILLING_DETAILS,
11274
+ dflt.whopBillingDetails
11275
+ ),
11276
+ whopSeparated: parseBool(root["whopSeparated"], dflt.whopSeparated),
11277
+ whopEmailLabel: pickEnum(
11278
+ root["whopEmailLabel"],
11279
+ WHOP_EMAIL_LABELS,
11280
+ dflt.whopEmailLabel
11281
+ ),
11282
+ whopFieldChrome: pickEnum(
11283
+ root["whopFieldChrome"],
11284
+ CARD_FIELD_CHROMES,
11285
+ dflt.whopFieldChrome
11286
+ ),
11287
+ whopFieldFontSize: pickEnum(
11288
+ root["whopFieldFontSize"],
11289
+ CARD_FIELD_FONT_SIZES,
11290
+ dflt.whopFieldFontSize
11291
+ ),
11292
+ whopFieldWeight: pickEnum(
11293
+ root["whopFieldWeight"],
11294
+ CARD_FIELD_WEIGHTS,
11295
+ dflt.whopFieldWeight
11296
+ ),
11297
+ whopFocusRing: pickEnum(
11298
+ root["whopFocusRing"],
11299
+ CARD_FOCUS_RINGS,
11300
+ dflt.whopFocusRing
11301
+ ),
11026
11302
  paypalValidTint: parseBool(root["paypalValidTint"], dflt.paypalValidTint),
11027
11303
  nomupayFormStyle: pickEnum(
11028
11304
  root["nomupayFormStyle"],
@@ -11562,11 +11838,29 @@ var CheckoutSession = class {
11562
11838
  * reports the vault as enabled and still expects its cards cloaked. The same
11563
11839
  * status also covers a payment that does not exist.
11564
11840
  *
11841
+ * `params.appearance` asks for a form styled to match the page (Enigma
11842
+ * Vault). The answer then carries `height`, the frame height to use. If the
11843
+ * vault refuses the styled form the answer is the plain one, without
11844
+ * `height`. `params.locale` is the buyer's locale.
11845
+ *
11565
11846
  * `GET /payment-link/{merchantId}/{paymentId}/vault/collect-session`
11566
11847
  */
11567
- async vaultCollectSession(options) {
11848
+ async vaultCollectSession(options, params) {
11849
+ const look = params?.appearance;
11568
11850
  return this.client.request("GET", `${this.linkBase}/vault/collect-session`, {
11569
11851
  ...options,
11852
+ query: {
11853
+ locale: params?.locale,
11854
+ form_surface: look?.surface,
11855
+ form_text: look?.text,
11856
+ form_border: look?.border,
11857
+ form_accent: look?.accent,
11858
+ form_danger: look?.danger,
11859
+ form_font: look?.font,
11860
+ form_radius: look?.radius,
11861
+ form_size: look?.size,
11862
+ form_labels: look?.labels
11863
+ },
11570
11864
  headers: this.bearerHeaders(options?.headers)
11571
11865
  });
11572
11866
  }
@@ -12155,9 +12449,10 @@ function encodePanes(panes) {
12155
12449
  };
12156
12450
  });
12157
12451
  }
12452
+ var OPAQUE_PAYMENT_LINK_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
12158
12453
  function focusedCheckoutUrl(params) {
12159
12454
  const base = params.checkoutBaseUrl.replace(/\/+$/, "");
12160
- const path = `${base}/pay/${encodeURIComponent(params.merchantId)}/${encodeURIComponent(
12455
+ const path = params.paymentLinkId && OPAQUE_PAYMENT_LINK_ID.test(params.paymentLinkId) ? `${base}/pay/${params.paymentLinkId}` : `${base}/pay/${encodeURIComponent(params.merchantId)}/${encodeURIComponent(
12161
12456
  params.paymentId
12162
12457
  )}`;
12163
12458
  const query = new URLSearchParams({ pane: params.method });
@@ -12311,6 +12606,11 @@ var encodeNativePanes = encodePanes;
12311
12606
  UNKNOWN_SECTION_ORDER,
12312
12607
  WCAG_AA_TEXT,
12313
12608
  WCAG_AA_UI,
12609
+ WHOP_ACCENT_COLORS,
12610
+ WHOP_BILLING_DETAILS,
12611
+ WHOP_CARD_PRESETS,
12612
+ WHOP_EMAIL_LABELS,
12613
+ WHOP_GRAY_COLORS,
12314
12614
  Webhooks,
12315
12615
  WhopResolutionCases,
12316
12616
  airwallexCardLayout,
@@ -12384,6 +12684,7 @@ var encodeNativePanes = encodePanes;
12384
12684
  leaf,
12385
12685
  logoDimensions,
12386
12686
  nativePaneMethodInfo,
12687
+ nearestWhopAccent,
12387
12688
  noticeText,
12388
12689
  noticesIn,
12389
12690
  offerablePaneMethods,
@@ -12404,6 +12705,7 @@ var encodeNativePanes = encodePanes;
12404
12705
  resolveGooglePayButtonColor,
12405
12706
  resolveNoticesAndBadges,
12406
12707
  resolveStripeTheme,
12708
+ resolveWhopAccent,
12407
12709
  ruleMatchToTree,
12408
12710
  sanitizeCustomCss,
12409
12711
  sectionLabel,
@@ -12418,7 +12720,10 @@ var encodeNativePanes = encodePanes;
12418
12720
  surfacePadValue,
12419
12721
  validSectionOrder,
12420
12722
  validatePanes,
12723
+ vaultFormAppearance,
12421
12724
  verticalGapValue,
12422
- visibleCustomFields
12725
+ visibleCustomFields,
12726
+ whopAccentSwatch,
12727
+ whopCardElement
12423
12728
  });
12424
12729
  //# sourceMappingURL=index.cjs.map