@delopay/sdk 0.77.0 → 0.79.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
@@ -30,6 +30,7 @@ __export(index_exports, {
30
30
  BRANDING_EXPORT_VERSION: () => BRANDING_EXPORT_VERSION,
31
31
  CHECKBOX_CHECKED: () => CHECKBOX_CHECKED,
32
32
  CHECKBOX_UNCHECKED: () => CHECKBOX_UNCHECKED,
33
+ CHECKOUT_EVENT_KINDS: () => CHECKOUT_EVENT_KINDS,
33
34
  CUSTOM_CSS_MAX_LENGTH: () => CUSTOM_CSS_MAX_LENGTH,
34
35
  CUSTOM_FIELDS_MAX: () => CUSTOM_FIELDS_MAX,
35
36
  CUSTOM_FIELD_CONDITIONS_MAX: () => CUSTOM_FIELD_CONDITIONS_MAX,
@@ -49,7 +50,11 @@ __export(index_exports, {
49
50
  FeeProgramBuilder: () => FeeProgramBuilder,
50
51
  Files: () => Files,
51
52
  Forex: () => Forex,
53
+ NATIVE_PANES_MAX: () => NATIVE_PANES_MAX,
54
+ NATIVE_PANE_CATEGORY_KEYS: () => NATIVE_PANE_CATEGORY_KEYS,
55
+ NATIVE_PANE_ICON_KEYS: () => NATIVE_PANE_ICON_KEYS,
52
56
  Regions: () => Regions,
57
+ STRIPE_NATIVE_PANE_METHODS: () => STRIPE_NATIVE_PANE_METHODS,
53
58
  Search: () => Search,
54
59
  Subscriptions: () => Subscriptions,
55
60
  Webhooks: () => Webhooks,
@@ -60,6 +65,7 @@ __export(index_exports, {
60
65
  buttonPadValue: () => buttonPadValue,
61
66
  cloneBranding: () => cloneBranding,
62
67
  cloneCustomField: () => cloneCustomField,
68
+ cloneNativePane: () => cloneNativePane,
63
69
  customFieldContextFromMetadata: () => customFieldContextFromMetadata,
64
70
  customFieldIsTextLike: () => customFieldIsTextLike,
65
71
  customFieldOperatorTakesValue: () => customFieldOperatorTakesValue,
@@ -68,15 +74,19 @@ __export(index_exports, {
68
74
  decodeBadges: () => decodeBadges,
69
75
  decodeBranding: () => decodeBranding,
70
76
  decodeCustomFields: () => decodeCustomFields,
77
+ decodeNativePanes: () => decodeNativePanes,
71
78
  defaultBranding: () => defaultBranding,
72
79
  defaultCustomFieldVisibility: () => defaultCustomFieldVisibility,
80
+ defaultNativePane: () => defaultNativePane,
73
81
  defaultOperatorForSource: () => defaultOperatorForSource,
74
82
  encodeBadges: () => encodeBadges,
75
83
  encodeBranding: () => encodeBranding,
76
84
  encodeCustomFields: () => encodeCustomFields,
85
+ encodeNativePanes: () => encodeNativePanes,
77
86
  evaluateCustomFieldCondition: () => evaluateCustomFieldCondition,
78
87
  evaluateCustomFieldVisibility: () => evaluateCustomFieldVisibility,
79
88
  feeProgram: () => feeProgram,
89
+ focusedCheckoutUrl: () => focusedCheckoutUrl,
80
90
  fontStack: () => fontStack,
81
91
  fontWeightValue: () => fontWeightValue,
82
92
  inputPadValue: () => inputPadValue,
@@ -85,6 +95,7 @@ __export(index_exports, {
85
95
  isHexColor: () => isHexColor,
86
96
  leaf: () => leaf,
87
97
  logoDimensions: () => logoDimensions,
98
+ nativePaneMethodInfo: () => nativePaneMethodInfo,
88
99
  parseCustomFieldsLoose: () => parseCustomFieldsLoose,
89
100
  parseImportedBranding: () => parseImportedBranding,
90
101
  programToTree: () => programToTree,
@@ -1153,10 +1164,45 @@ var PaymentMethods = class {
1153
1164
  return this.request("DELETE", `/payment-methods/${encodeURIComponent(methodId)}`);
1154
1165
  }
1155
1166
  /**
1156
- * List payment methods using a client secret.
1167
+ * List the payment methods available for a payment — the discovery endpoint a
1168
+ * custom checkout renders its tiles from.
1157
1169
  *
1158
- * @param params - Filter by `client_secret`.
1159
- * @returns Array of payment methods.
1170
+ * Callable with a publishable key plus the payment's `client_secret`, so it
1171
+ * runs from the browser. The returned set is already filtered by country,
1172
+ * order value and the merchant's availability rules, and each entry carries
1173
+ * `display` (name + icon slug) and `amount_limits` (the order values it stays
1174
+ * available for) so you do not have to maintain either alongside.
1175
+ *
1176
+ * This is *not* the customer's saved methods — see {@link listForCustomer}.
1177
+ *
1178
+ * @param params - `client_secret`, plus optional `country`, `amount` and filters.
1179
+ * @returns The methods available for the payment, grouped by payment method.
1180
+ *
1181
+ * @example
1182
+ * ```typescript
1183
+ * const { payment_methods } = await delopay.paymentMethods.list({
1184
+ * client_secret: 'pay_abc_secret_xyz',
1185
+ * country: 'DE',
1186
+ * amount: 25000,
1187
+ * });
1188
+ *
1189
+ * for (const group of payment_methods) {
1190
+ * for (const method of group.payment_method_types) {
1191
+ * // Re-check availability yourself as the cart total changes, instead of
1192
+ * // re-listing on every keystroke.
1193
+ * const limits = method.amount_limits;
1194
+ * const available =
1195
+ * !limits ||
1196
+ * ((limits.min_amount == null || cartTotal >= limits.min_amount) &&
1197
+ * (limits.max_amount == null || cartTotal <= limits.max_amount) &&
1198
+ * !limits.excluded_ranges.some(
1199
+ * (band) => cartTotal >= band.min_amount && cartTotal <= band.max_amount,
1200
+ * ));
1201
+ *
1202
+ * if (available) render(method.display?.display_name, method.display?.icon_slug);
1203
+ * }
1204
+ * }
1205
+ * ```
1160
1206
  */
1161
1207
  async list(params) {
1162
1208
  return this.request("GET", "/payment-methods", {
@@ -4782,6 +4828,230 @@ function shadowFor(style) {
4782
4828
  return "none";
4783
4829
  }
4784
4830
  }
4831
+
4832
+ // src/nativePanes.ts
4833
+ var STRIPE_NATIVE_PANE_METHODS = [
4834
+ {
4835
+ key: "apple_pay",
4836
+ rail: "wallet",
4837
+ defaultLabel: "Apple Pay",
4838
+ defaultSublabel: "Pay with Apple Pay",
4839
+ defaultCategory: "wallet",
4840
+ defaultIcon: "apple"
4841
+ },
4842
+ {
4843
+ key: "google_pay",
4844
+ rail: "wallet",
4845
+ defaultLabel: "Google Pay",
4846
+ defaultSublabel: "Pay with Google Pay",
4847
+ defaultCategory: "wallet",
4848
+ defaultIcon: "google"
4849
+ },
4850
+ {
4851
+ key: "link",
4852
+ rail: "wallet",
4853
+ defaultLabel: "Link",
4854
+ defaultSublabel: "Pay with saved details",
4855
+ defaultCategory: "wallet",
4856
+ defaultIcon: "wallet"
4857
+ },
4858
+ {
4859
+ key: "klarna",
4860
+ rail: "redirect",
4861
+ defaultLabel: "Klarna",
4862
+ defaultSublabel: "Pay later or in instalments",
4863
+ defaultCategory: "bnpl",
4864
+ defaultIcon: "bnpl"
4865
+ },
4866
+ {
4867
+ key: "affirm",
4868
+ rail: "redirect",
4869
+ defaultLabel: "Affirm",
4870
+ defaultSublabel: "Pay over time",
4871
+ defaultCategory: "bnpl",
4872
+ defaultIcon: "bnpl"
4873
+ },
4874
+ {
4875
+ key: "ideal",
4876
+ rail: "redirect",
4877
+ defaultLabel: "iDEAL",
4878
+ defaultSublabel: "Pay from your bank",
4879
+ defaultCategory: "bank_redirect",
4880
+ defaultIcon: "bank"
4881
+ },
4882
+ // eps / p24 / bancontact were removed from the router catalog: Stripe
4883
+ // hard-requires billing fields the focused checkout never collects (full
4884
+ // name for EPS/Bancontact, email for Przelewy24), so their tiles could
4885
+ // never succeed. They may return behind billing-aware gating.
4886
+ {
4887
+ key: "alipay",
4888
+ rail: "redirect",
4889
+ defaultLabel: "Alipay",
4890
+ defaultSublabel: "Pay with Alipay",
4891
+ defaultCategory: "wallet",
4892
+ defaultIcon: "wallet"
4893
+ },
4894
+ {
4895
+ key: "revolut_pay",
4896
+ rail: "redirect",
4897
+ defaultLabel: "Revolut Pay",
4898
+ defaultSublabel: "Pay with Revolut",
4899
+ defaultCategory: "wallet",
4900
+ defaultIcon: "wallet"
4901
+ },
4902
+ {
4903
+ key: "amazon_pay",
4904
+ rail: "redirect",
4905
+ defaultLabel: "Amazon Pay",
4906
+ defaultSublabel: "Pay with Amazon",
4907
+ defaultCategory: "wallet",
4908
+ defaultIcon: "wallet"
4909
+ }
4910
+ ];
4911
+ var NATIVE_PANE_ICON_KEYS = [
4912
+ "wallet",
4913
+ "card",
4914
+ "bank",
4915
+ "apple",
4916
+ "google",
4917
+ "bnpl",
4918
+ "cash"
4919
+ ];
4920
+ var NATIVE_PANE_CATEGORY_KEYS = [
4921
+ "wallet",
4922
+ "card",
4923
+ "bnpl",
4924
+ "bank_redirect",
4925
+ "bank_transfer",
4926
+ "cash"
4927
+ ];
4928
+ var NATIVE_PANES_MAX = 12;
4929
+ function nativePaneMethodInfo(method) {
4930
+ return STRIPE_NATIVE_PANE_METHODS.find((m) => m.key === method);
4931
+ }
4932
+ function defaultNativePane(method) {
4933
+ const info = nativePaneMethodInfo(method);
4934
+ return {
4935
+ method,
4936
+ enabled: true,
4937
+ label: "",
4938
+ labelTranslations: {},
4939
+ sublabel: null,
4940
+ sublabelTranslations: {},
4941
+ category: "",
4942
+ icon: info?.defaultIcon ?? "",
4943
+ iconSvg: "",
4944
+ displayOrder: 0,
4945
+ visibility: "always"
4946
+ };
4947
+ }
4948
+ function cloneNativePane(pane) {
4949
+ return {
4950
+ ...pane,
4951
+ labelTranslations: { ...pane.labelTranslations },
4952
+ sublabelTranslations: { ...pane.sublabelTranslations }
4953
+ };
4954
+ }
4955
+ function isObject2(value) {
4956
+ return typeof value === "object" && value !== null && !Array.isArray(value);
4957
+ }
4958
+ function parseTranslations2(raw) {
4959
+ if (!isObject2(raw)) return {};
4960
+ const out = {};
4961
+ for (const [locale, value] of Object.entries(raw)) {
4962
+ if (typeof value === "string" && value.length > 0) out[locale] = value;
4963
+ }
4964
+ return out;
4965
+ }
4966
+ function str(raw) {
4967
+ return typeof raw === "string" ? raw : "";
4968
+ }
4969
+ var DISPLAY_ORDER_MIN = -2147483648;
4970
+ var DISPLAY_ORDER_MAX = 2147483647;
4971
+ function clampDisplayOrder(raw) {
4972
+ if (!Number.isFinite(raw)) return 0;
4973
+ return Math.min(DISPLAY_ORDER_MAX, Math.max(DISPLAY_ORDER_MIN, Math.trunc(raw)));
4974
+ }
4975
+ function decodeNativePanes(raw) {
4976
+ if (!Array.isArray(raw)) return null;
4977
+ const decodeRow = (entry, method) => ({
4978
+ method,
4979
+ enabled: entry["enabled"] !== false,
4980
+ label: str(entry["label"]),
4981
+ labelTranslations: parseTranslations2(entry["label_translations"]),
4982
+ sublabel: typeof entry["sublabel"] === "string" ? entry["sublabel"] : null,
4983
+ sublabelTranslations: parseTranslations2(entry["sublabel_translations"]),
4984
+ category: str(entry["category"]),
4985
+ icon: str(entry["icon"]),
4986
+ iconSvg: str(entry["icon_svg"]),
4987
+ displayOrder: clampDisplayOrder(Number(entry["display_order"])),
4988
+ // Anything unrecognised degrades to `always` rather than dropping the row.
4989
+ visibility: entry["visibility"] === "embedded_only" ? "embedded_only" : "always"
4990
+ });
4991
+ const indexByMethod = /* @__PURE__ */ new Map();
4992
+ const out = [];
4993
+ for (const entry of raw) {
4994
+ if (out.length >= NATIVE_PANES_MAX) break;
4995
+ if (!isObject2(entry)) continue;
4996
+ const method = str(entry["method"]).trim();
4997
+ if (!method) continue;
4998
+ const kept = indexByMethod.get(method);
4999
+ if (kept !== void 0) {
5000
+ const enabled = entry["enabled"] !== false;
5001
+ const existing = out[kept];
5002
+ if (enabled && existing && !existing.enabled) out[kept] = decodeRow(entry, method);
5003
+ continue;
5004
+ }
5005
+ indexByMethod.set(method, out.length);
5006
+ out.push(decodeRow(entry, method));
5007
+ }
5008
+ return out;
5009
+ }
5010
+ function encodeNativePanes(panes) {
5011
+ const nonEmpty = (map) => {
5012
+ const entries = Object.entries(map).filter(([, v]) => v.trim().length > 0);
5013
+ return entries.length > 0 ? Object.fromEntries(entries) : void 0;
5014
+ };
5015
+ return panes.slice(0, NATIVE_PANES_MAX).map((pane) => {
5016
+ const labelTranslations = nonEmpty(pane.labelTranslations);
5017
+ const sublabelTranslations = nonEmpty(pane.sublabelTranslations);
5018
+ return {
5019
+ method: pane.method,
5020
+ enabled: pane.enabled,
5021
+ ...pane.label.trim() ? { label: pane.label.trim() } : {},
5022
+ ...labelTranslations ? { label_translations: labelTranslations } : {},
5023
+ // `null` omits the key entirely (catalog default wins); `''` is sent
5024
+ // as-is because that is how the merchant hides the second line.
5025
+ ...pane.sublabel !== null ? { sublabel: pane.sublabel } : {},
5026
+ ...sublabelTranslations ? { sublabel_translations: sublabelTranslations } : {},
5027
+ ...pane.category.trim() ? { category: pane.category.trim() } : {},
5028
+ ...pane.icon.trim() ? { icon: pane.icon.trim() } : {},
5029
+ ...pane.iconSvg.trim() ? { icon_svg: pane.iconSvg.trim() } : {},
5030
+ // Clamped on encode too, not only decode: the router's strict i32 row
5031
+ // decode drops a row whole for a fractional or out-of-range value, so
5032
+ // writing e.g. 3.5 or Date.now() verbatim would silently delete the
5033
+ // pane at render while every read surface shows it healthy.
5034
+ display_order: clampDisplayOrder(pane.displayOrder),
5035
+ visibility: pane.visibility
5036
+ };
5037
+ });
5038
+ }
5039
+ function focusedCheckoutUrl(params) {
5040
+ const base = params.checkoutBaseUrl.replace(/\/+$/, "");
5041
+ const path = `${base}/pay/${encodeURIComponent(params.merchantId)}/${encodeURIComponent(
5042
+ params.paymentId
5043
+ )}`;
5044
+ const query = new URLSearchParams({ pane: params.method });
5045
+ if (params.locale) query.set("locale", params.locale);
5046
+ if (params.customFieldsCollected) query.set("cf", "1");
5047
+ return `${path}?${query.toString()}`;
5048
+ }
5049
+ var CHECKOUT_EVENT_KINDS = [
5050
+ "native_pane_selected",
5051
+ "native_pane_tab_opened",
5052
+ "native_pane_tab_blocked",
5053
+ "native_pane_abandoned"
5054
+ ];
4785
5055
  // Annotate the CommonJS export names for ESM import in node:
4786
5056
  0 && (module.exports = {
4787
5057
  ALL_CUSTOM_FIELD_CONDITION_SOURCES,
@@ -4794,6 +5064,7 @@ function shadowFor(style) {
4794
5064
  BRANDING_EXPORT_VERSION,
4795
5065
  CHECKBOX_CHECKED,
4796
5066
  CHECKBOX_UNCHECKED,
5067
+ CHECKOUT_EVENT_KINDS,
4797
5068
  CUSTOM_CSS_MAX_LENGTH,
4798
5069
  CUSTOM_FIELDS_MAX,
4799
5070
  CUSTOM_FIELD_CONDITIONS_MAX,
@@ -4813,7 +5084,11 @@ function shadowFor(style) {
4813
5084
  FeeProgramBuilder,
4814
5085
  Files,
4815
5086
  Forex,
5087
+ NATIVE_PANES_MAX,
5088
+ NATIVE_PANE_CATEGORY_KEYS,
5089
+ NATIVE_PANE_ICON_KEYS,
4816
5090
  Regions,
5091
+ STRIPE_NATIVE_PANE_METHODS,
4817
5092
  Search,
4818
5093
  Subscriptions,
4819
5094
  Webhooks,
@@ -4824,6 +5099,7 @@ function shadowFor(style) {
4824
5099
  buttonPadValue,
4825
5100
  cloneBranding,
4826
5101
  cloneCustomField,
5102
+ cloneNativePane,
4827
5103
  customFieldContextFromMetadata,
4828
5104
  customFieldIsTextLike,
4829
5105
  customFieldOperatorTakesValue,
@@ -4832,15 +5108,19 @@ function shadowFor(style) {
4832
5108
  decodeBadges,
4833
5109
  decodeBranding,
4834
5110
  decodeCustomFields,
5111
+ decodeNativePanes,
4835
5112
  defaultBranding,
4836
5113
  defaultCustomFieldVisibility,
5114
+ defaultNativePane,
4837
5115
  defaultOperatorForSource,
4838
5116
  encodeBadges,
4839
5117
  encodeBranding,
4840
5118
  encodeCustomFields,
5119
+ encodeNativePanes,
4841
5120
  evaluateCustomFieldCondition,
4842
5121
  evaluateCustomFieldVisibility,
4843
5122
  feeProgram,
5123
+ focusedCheckoutUrl,
4844
5124
  fontStack,
4845
5125
  fontWeightValue,
4846
5126
  inputPadValue,
@@ -4849,6 +5129,7 @@ function shadowFor(style) {
4849
5129
  isHexColor,
4850
5130
  leaf,
4851
5131
  logoDimensions,
5132
+ nativePaneMethodInfo,
4852
5133
  parseCustomFieldsLoose,
4853
5134
  parseImportedBranding,
4854
5135
  programToTree,