@delopay/sdk 0.35.1 → 0.36.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
@@ -35,6 +35,7 @@ __export(index_exports, {
35
35
  DelopayError: () => DelopayError,
36
36
  Export: () => Export,
37
37
  FeatureMatrix: () => FeatureMatrix,
38
+ FeeProgramBuilder: () => FeeProgramBuilder,
38
39
  Files: () => Files,
39
40
  Forex: () => Forex,
40
41
  Regions: () => Regions,
@@ -50,6 +51,7 @@ __export(index_exports, {
50
51
  defaultBranding: () => defaultBranding,
51
52
  encodeBadges: () => encodeBadges,
52
53
  encodeBranding: () => encodeBranding,
54
+ feeProgram: () => feeProgram,
53
55
  fontStack: () => fontStack,
54
56
  fontWeightValue: () => fontWeightValue,
55
57
  inputPadValue: () => inputPadValue,
@@ -692,6 +694,7 @@ var Events = class {
692
694
  var Fees = class {
693
695
  constructor(request) {
694
696
  this.request = request;
697
+ this.rules = new FeeRulesManager(request);
695
698
  }
696
699
  /**
697
700
  * Create a merchant-scoped fee schedule (optionally per-shop).
@@ -733,6 +736,46 @@ var Fees = class {
733
736
  return this.request("DELETE", `/merchant-fees/${encodeURIComponent(feeId)}`);
734
737
  }
735
738
  };
739
+ var FeeRulesManager = class {
740
+ constructor(request) {
741
+ this.request = request;
742
+ }
743
+ /**
744
+ * Create or replace the merchant's fee-rule program (a new active version;
745
+ * the previous version is deactivated server-side).
746
+ *
747
+ * @param params - The program plus optional name / shop scope / validity window.
748
+ * @param merchantId - The merchant account ID.
749
+ */
750
+ async upsert(params, merchantId) {
751
+ const body = { ...params, fee_owner: "merchant" };
752
+ return this.request("PUT", "/merchant-fees/rules", {
753
+ body,
754
+ query: { merchant_id: merchantId }
755
+ });
756
+ }
757
+ /**
758
+ * Retrieve the merchant's active fee-rule program, or `null` if none.
759
+ *
760
+ * @param merchantId - The merchant account ID.
761
+ */
762
+ async retrieve(merchantId) {
763
+ return this.request("GET", "/merchant-fees/rules", {
764
+ query: { merchant_id: merchantId }
765
+ });
766
+ }
767
+ /**
768
+ * Deactivate the merchant's active fee-rule program (falls back to the flat
769
+ * fee schedules / volume tier). Idempotent.
770
+ *
771
+ * @param merchantId - The merchant account ID.
772
+ */
773
+ async delete(merchantId) {
774
+ await this.request("DELETE", "/merchant-fees/rules", {
775
+ query: { merchant_id: merchantId }
776
+ });
777
+ }
778
+ };
736
779
 
737
780
  // src/resources/mandates.ts
738
781
  var Mandates = class {
@@ -3084,6 +3127,74 @@ var Delopay = class {
3084
3127
  /** Utility for verifying incoming webhook signatures (static, no instance needed). */
3085
3128
  Delopay.webhooks = Webhooks;
3086
3129
 
3130
+ // src/feeProgram.ts
3131
+ function toFeeOutput(spec) {
3132
+ const hasPct = spec.percentage != null;
3133
+ const hasFlat = spec.flat != null;
3134
+ const feeType = hasPct && hasFlat ? "combined" : hasFlat ? "flat" : "percentage";
3135
+ return {
3136
+ fee_type: feeType,
3137
+ percentage_fee: spec.percentage ?? null,
3138
+ flat_fee_amount: spec.flat ?? null,
3139
+ flat_fee_currency: spec.flatCurrency ?? null,
3140
+ min_fee_amount: spec.min ?? null,
3141
+ max_fee_amount: spec.max ?? null
3142
+ };
3143
+ }
3144
+ function enumCondition(lhs, value) {
3145
+ return { lhs, comparison: "equal", value: { type: "enum_variant", value }, metadata: {} };
3146
+ }
3147
+ function numberCondition(lhs, comparison, value) {
3148
+ return { lhs, comparison, value: { type: "number", value }, metadata: {} };
3149
+ }
3150
+ function buildConditions(when = {}, raw = []) {
3151
+ const out = [];
3152
+ if (when.paymentMethod != null) out.push(enumCondition("payment_method", when.paymentMethod));
3153
+ if (when.connector != null) out.push(enumCondition("connector", when.connector));
3154
+ if (when.currency != null) out.push(enumCondition("currency", when.currency));
3155
+ if (when.cardNetwork != null) out.push(enumCondition("card_network", when.cardNetwork));
3156
+ if (when.amountEquals != null) out.push(numberCondition("amount", "equal", when.amountEquals));
3157
+ if (when.amountGreaterThan != null) {
3158
+ out.push(numberCondition("amount", "greater_than", when.amountGreaterThan));
3159
+ }
3160
+ if (when.amountLessThan != null) {
3161
+ out.push(numberCondition("amount", "less_than", when.amountLessThan));
3162
+ }
3163
+ out.push(...raw);
3164
+ return out;
3165
+ }
3166
+ var FeeProgramBuilder = class {
3167
+ constructor() {
3168
+ this.rules = [];
3169
+ this.defaultFee = null;
3170
+ }
3171
+ /** Append a rule. Provided `when`/`rawConditions` are ANDed. */
3172
+ rule(input) {
3173
+ this.rules.push({
3174
+ name: input.name,
3175
+ connectorSelection: { fee: toFeeOutput(input.fee) },
3176
+ statements: [{ condition: buildConditions(input.when, input.rawConditions) }]
3177
+ });
3178
+ return this;
3179
+ }
3180
+ /** Set the default selection (applied when no rule matches). */
3181
+ otherwise(fee) {
3182
+ this.defaultFee = toFeeOutput(fee);
3183
+ return this;
3184
+ }
3185
+ /** Produce the wire-ready program. */
3186
+ build() {
3187
+ return {
3188
+ defaultSelection: { fee: this.defaultFee },
3189
+ rules: this.rules,
3190
+ metadata: {}
3191
+ };
3192
+ }
3193
+ };
3194
+ function feeProgram() {
3195
+ return new FeeProgramBuilder();
3196
+ }
3197
+
3087
3198
  // src/branding.ts
3088
3199
  var FONT_STACKS = {
3089
3200
  inter: "'Inter Variable', 'Inter', system-ui, -apple-system, sans-serif",
@@ -3731,6 +3842,7 @@ function shadowFor(style) {
3731
3842
  DelopayError,
3732
3843
  Export,
3733
3844
  FeatureMatrix,
3845
+ FeeProgramBuilder,
3734
3846
  Files,
3735
3847
  Forex,
3736
3848
  Regions,
@@ -3746,6 +3858,7 @@ function shadowFor(style) {
3746
3858
  defaultBranding,
3747
3859
  encodeBadges,
3748
3860
  encodeBranding,
3861
+ feeProgram,
3749
3862
  fontStack,
3750
3863
  fontWeightValue,
3751
3864
  inputPadValue,