moyasar-payment-form 2.0.15 → 2.0.16

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.
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * name: moyasar-payment-form
3
- * version: v2.0.15
3
+ * version: v2.0.16
4
4
  * description: Moyasar payment form utilities
5
5
  * author: Jan Jagieła - Railwaymen Team
6
6
  * homepage: https://docs.moyasar.com
package/dist/moyasar.css CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * name: moyasar-payment-form
3
- * version: v2.0.15
3
+ * version: v2.0.16
4
4
  * description: Moyasar payment form utilities
5
5
  * author: Jan Jagieła - Railwaymen Team
6
6
  * homepage: https://docs.moyasar.com
package/dist/moyasar.d.ts CHANGED
@@ -1,31 +1,7 @@
1
- import { Dispatch } from 'preact/hooks';
2
- import { StateUpdater } from 'preact/hooks';
3
-
4
- declare interface AppCtxProps extends MoyasarJS.PaymentFormConfig {
5
- formattedAmount: string;
6
- decimalAmount: string;
7
- isRtl: boolean;
8
- version: string;
9
- setFormSettings?: SetFormSettings;
10
- isProcessing: boolean;
11
- apiError?: string;
12
- showForm: boolean;
13
- isTestMode?: boolean;
14
- scriptsLoaded?: {
15
- samsung: boolean;
16
- google: boolean;
17
- apple: boolean;
18
- };
19
- }
20
-
21
1
  declare class Moyasar {
22
2
  static init(config: MoyasarJS.PaymentFormConfig): void;
23
3
  static setAmount(newAmount: number): void;
24
4
  }
25
5
  export default Moyasar;
26
6
 
27
- export declare function registerAmountSetter(setter: SetFormSettings): void;
28
-
29
- declare type SetFormSettings = Dispatch<StateUpdater<AppCtxProps>>;
30
-
31
7
  export { }
package/dist/moyasar.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * name: moyasar-payment-form
3
- * version: v2.0.15
3
+ * version: v2.0.16
4
4
  * description: Moyasar payment form utilities
5
5
  * author: Jan Jagieła - Railwaymen Team
6
6
  * homepage: https://docs.moyasar.com
@@ -319,7 +319,7 @@ function p(A, t, e, r, n, a) {
319
319
  if (typeof A == "function" && (o = A.defaultProps)) for (l in o) i[l] === void 0 && (i[l] = o[l]);
320
320
  return k.vnode && k.vnode(s), s;
321
321
  }
322
- const ee = "2.0.15", W = lt({});
322
+ const ee = "2.0.16", W = lt({});
323
323
  var cA, N, WA, ht, hA = 0, re = [], U = k, yt = U.__b, wt = U.__r, bt = U.diffed, Ct = U.__c, Dt = U.unmount, kt = U.__;
324
324
  function zA(A, t) {
325
325
  U.__h && U.__h(N, A, hA || t), hA = 0;
@@ -3235,13 +3235,17 @@ var on = /* @__PURE__ */ function() {
3235
3235
  action: ""
3236
3236
  }, t;
3237
3237
  }(F);
3238
- const sn = () => /* @__PURE__ */ p("div", { class: "mx-auto w-fit rounded-lg border-red-800 bg-red-500/20 p-4 font-mono text-sm leading-6", children: /* @__PURE__ */ p("h2", { class: "mb-4 text-center text-xl font-medium", children: "Something went wrong" }) });
3239
- function tt(A, t) {
3238
+ let tt = null;
3239
+ function sn(A) {
3240
+ tt = A;
3241
+ }
3242
+ const cn = () => /* @__PURE__ */ p("div", { class: "mx-auto w-fit rounded-lg border-red-800 bg-red-500/20 p-4 font-mono text-sm leading-6", children: /* @__PURE__ */ p("h2", { class: "mb-4 text-center text-xl font-medium", children: "Something went wrong" }) });
3243
+ function et(A, t) {
3240
3244
  const e = uA[t] || uA.default;
3241
3245
  return e === 0 ? A : parseFloat((A / ft(10, e)).toFixed(e));
3242
3246
  }
3243
3247
  function Wt(A, t) {
3244
- const e = uA[t] || uA.default, r = tt(A, t);
3248
+ const e = uA[t] || uA.default, r = et(A, t);
3245
3249
  let n = new Intl.NumberFormat("en", {
3246
3250
  style: "currency",
3247
3251
  currency: t,
@@ -3250,8 +3254,8 @@ function Wt(A, t) {
3250
3254
  }).format(r);
3251
3255
  return ["SAR", "AED"].includes(t) && (n = n.replace(t, "").trim()), n;
3252
3256
  }
3253
- function cn({ config: A }) {
3254
- const { amount: t, currency: e, language: r, translations: n, publishable_api_key: a } = A, o = document.documentElement.dir === "rtl" || r === "ar", l = uA[e] || uA.default, i = tt(t, e), s = Wt(t, e), [u, c] = T(X(M({
3257
+ function un({ config: A }) {
3258
+ const { amount: t, currency: e, language: r, translations: n, publishable_api_key: a } = A, o = document.documentElement.dir === "rtl" || r === "ar", l = uA[e] || uA.default, i = et(t, e), s = Wt(t, e), [u, c] = T(X(M({
3255
3259
  version: ee
3256
3260
  }, A), {
3257
3261
  translations: Je(n),
@@ -3262,11 +3266,11 @@ function cn({ config: A }) {
3262
3266
  showForm: !1,
3263
3267
  isTestMode: (a == null ? void 0 : a.startsWith("pk_test")) || location.protocol === "http:"
3264
3268
  }));
3265
- wn(c), Y(() => {
3269
+ sn(c), Y(() => {
3266
3270
  c((b) => X(M({}, b), {
3267
3271
  amount: u.amount,
3268
3272
  formattedAmount: Wt(u.amount, u.currency),
3269
- decimalAmount: tt(u.amount, u.currency).toFixed(l).toString()
3273
+ decimalAmount: et(u.amount, u.currency).toFixed(l).toString()
3270
3274
  }));
3271
3275
  }, [u.amount]);
3272
3276
  const [m, f] = T({
@@ -3306,7 +3310,7 @@ function cn({ config: A }) {
3306
3310
  {
3307
3311
  instance: an,
3308
3312
  tags: { tag: "moyasar-payment-form" },
3309
- fallback: () => /* @__PURE__ */ p(sn, {}),
3313
+ fallback: () => /* @__PURE__ */ p(cn, {}),
3310
3314
  children: /* @__PURE__ */ p("div", { id: "mysr", children: /* @__PURE__ */ p(
3311
3315
  "div",
3312
3316
  {
@@ -3328,7 +3332,7 @@ function cn({ config: A }) {
3328
3332
  }
3329
3333
  );
3330
3334
  }
3331
- const un = (A) => {
3335
+ const pn = (A) => {
3332
3336
  function t(e) {
3333
3337
  if (typeof e != "function") return !1;
3334
3338
  const r = (e == null ? void 0 : e.constructor.prototype.constructor.name) === "AsyncFunction", n = e.toString().startsWith("async");
@@ -3343,14 +3347,14 @@ const un = (A) => {
3343
3347
  ), A.on_redirect && !t(A.on_redirect) && C(
3344
3348
  "On redirect must be a promise based callback, check documentation for implementation details"
3345
3349
  ), !0;
3346
- }, pn = (A) => {
3350
+ }, fn = (A) => {
3347
3351
  var t, e;
3348
3352
  return A.payment_button_type && typeof A.payment_button_type != "string" && aA("Payment button type"), A.given_id && (/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(A.given_id) || C("`given_id` must be a valid UUID v4")), A.payment_button_type && !Sr.includes(A.payment_button_type) && C("Unsupported button type, check documentation for list of supported types"), A.language && typeof A.language != "string" && aA("Language"), A.translations && typeof A.translations != "object" && aA("Translations"), A.metadata && typeof A.metadata != "object" && C("Metadata must be and object"), A.metadata && Object.entries(A.metadata).length > 50 && C("Only 50 Key/Value pairs are allowed in metadata"), A.invoice_id && typeof A.invoice_id != "string" && C("Invoice ID must be a string"), A.invoice_id && (/^[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89aAbB][a-f0-9]{3}-[a-f0-9]{12}$/.test(
3349
3353
  (t = A.invoice_id) != null ? t : ""
3350
3354
  ) || C("Invalid invoice ID format")), A.statement_descriptor && typeof A.statement_descriptor != "string" && C("Statement descriptor must be a string"), A.statement_descriptor && (/^[\w\s\d\-~]{1,64}$/.test((e = A.statement_descriptor) != null ? e : "") || C(
3351
3355
  'Invalid format for the statement descriptor [length between 1 and 64 characters, allowed alphanumeric characters, white-spaces, "/", "-" and "~" symbols] '
3352
3356
  )), A.fixed_width && typeof A.fixed_width != "boolean" && C("Fixed width expects boolean value"), !0;
3353
- }, qt = (A, t) => A.every((e) => t.includes(e)), fn = (A) => {
3357
+ }, qt = (A, t) => A.every((e) => t.includes(e)), dn = (A) => {
3354
3358
  var t, e, r, n, a, o, l, i, s, u, c, m, f, b, w, g;
3355
3359
  if (A.methods && !Array.isArray(A.methods) && C("Methods must be an array"), A.methods.includes("creditcard") && ((t = A.credit_card) != null && t.manual && typeof A.credit_card.manual != "boolean" && C("Credit Card manual option must be a boolean"), (e = A.credit_card) != null && e.save_card && typeof A.credit_card.save_card != "boolean" && C("Credit Card save card option must be a boolean")), A.methods.includes("applepay") && (A.apple_pay || q("Apple Pay configuration"), A.apple_pay)) {
3356
3360
  const d = A.apple_pay.country || ((r = A.payment_options) == null ? void 0 : r.country), v = A.apple_pay.label || ((n = A.payment_options) == null ? void 0 : n.label), h = /^[\x20-\x7E]+$/;
@@ -3371,13 +3375,13 @@ const un = (A) => {
3371
3375
  D && !Array.isArray(D) && C("Google Pay auth_methods must be an array"), D && !D.every((B) => B === "PAN_ONLY" || B === "CRYPTOGRAM_3DS") && C("Google Pay auth_methods must contain 'CRYPTOGRAM_3DS' and/or 'PAN_ONLY'");
3372
3376
  }
3373
3377
  return A.supported_networks && (qt(A.supported_networks, HA) || C(`Moyasar form supports only ${HA.join(", ")} networks`)), !0;
3374
- }, dn = (A) => (A.element || q("element"), typeof A.element != "string" && !(A.element instanceof Element) && aA("Element"), typeof A.element == "string" && !document.querySelector(A.element) && C(`Selector ${A.element} does't exist id DOM`), A.publishable_api_key.trim() || q("publishable_api_key"), A.publishable_api_key && (/^pk_(test|live)_/.test(A.publishable_api_key) || aA("Publishable API Key"), location.protocol.toLowerCase() === "http:" && A.publishable_api_key.startsWith("pk_live") && C(
3378
+ }, mn = (A) => (A.element || q("element"), typeof A.element != "string" && !(A.element instanceof Element) && aA("Element"), typeof A.element == "string" && !document.querySelector(A.element) && C(`Selector ${A.element} does't exist id DOM`), A.publishable_api_key.trim() || q("publishable_api_key"), A.publishable_api_key && (/^pk_(test|live)_/.test(A.publishable_api_key) || aA("Publishable API Key"), location.protocol.toLowerCase() === "http:" && A.publishable_api_key.startsWith("pk_live") && C(
3375
3379
  "Production key (pk_live) require secure connection, for development use key starting with pk_test"
3376
3380
  )), A.amount || q("amount"), A.amount && ((typeof A.amount != "number" || A.amount < 100) && C("Amount must be a non-negative integer. Minimal supported value is 100."), Number.isInteger(A.amount) || C(
3377
3381
  "Amount must be in minor unit of selected currency, e.g. for $19.99 set amount to 1999."
3378
3382
  )), A.currency || q("currency"), A.currency && A.currency.trim().length !== 3 && C("Currency must be in ISO 3166-1 alpha-3 country code format"), A.description || q("description"), A.description && A.description.trim().length === 0 && C("Description can't be empty"), A.callback_url || q("callback_url"), ke(A.callback_url) || aA("Callback URL"), !0), C = (A) => {
3379
3383
  throw window.silentError && console.error(A), new Error(A);
3380
- }, q = (A) => C(`Missing entry: ${A} is required`), aA = (A) => C(`${A} is invalid`), ke = (A) => typeof A == "string" && /^https?:\/\/.+/.test(A), mn = (A, t = !1) => (t && (window.silentError = t), dn(A), fn(A), pn(A), un(A), !0), vn = (A) => {
3384
+ }, q = (A) => C(`Missing entry: ${A} is required`), aA = (A) => C(`${A} is invalid`), ke = (A) => typeof A == "string" && /^https?:\/\/.+/.test(A), vn = (A, t = !1) => (t && (window.silentError = t), mn(A), dn(A), fn(A), pn(A), !0), gn = (A) => {
3381
3385
  const t = A.publishable_api_key.startsWith("pk_test") || location.protocol === "http:", e = A.element;
3382
3386
  let r;
3383
3387
  if (typeof e == "string" && (r = document.querySelector(e)), e instanceof Element && (r = e), !r) {
@@ -3387,7 +3391,7 @@ const un = (A) => {
3387
3391
  return;
3388
3392
  }
3389
3393
  try {
3390
- mn(A, t);
3394
+ vn(A, t);
3391
3395
  } catch (n) {
3392
3396
  console.error(n), gt(/* @__PURE__ */ p(() => /* @__PURE__ */ p("div", { class: "mx-auto w-fit rounded-lg border-red-800 bg-red-500/20 p-4 font-mono text-sm leading-6", children: [
3393
3397
  /* @__PURE__ */ p("h2", { class: "mb-4 text-center text-xl font-medium", children: "Form configuration issue!" }),
@@ -3396,34 +3400,29 @@ const un = (A) => {
3396
3400
  ] }), {}), r);
3397
3401
  return;
3398
3402
  }
3399
- r.setAttribute("lang", A.language), gt(/* @__PURE__ */ p(cn, { config: A }), r);
3400
- }, gn = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
3401
- let hn = (A = 21) => {
3403
+ r.setAttribute("lang", A.language), gt(/* @__PURE__ */ p(un, { config: A }), r);
3404
+ }, hn = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
3405
+ let yn = (A = 21) => {
3402
3406
  let t = "", e = crypto.getRandomValues(new Uint8Array(A |= 0));
3403
3407
  for (; A--; )
3404
- t += gn[e[A] & 63];
3408
+ t += hn[e[A] & 63];
3405
3409
  return t;
3406
3410
  };
3407
- const yn = (A) => {
3411
+ const wn = (A) => {
3408
3412
  const t = M({}, A);
3409
3413
  return A.base_url || (t.base_url = "https://api.moyasar.com"), A.payment_button_type || (t.payment_button_type = "pay"), A.language || (t.language = document.documentElement.lang || "en"), A.methods || (t.methods = Br), A.supported_networks || (t.supported_networks = HA.filter((e) => e !== "amex")), !A.fixed_width && A.fixed_width !== !1 && (t.fixed_width = !0), A.apple_pay && (A.apple_pay.version || (t.apple_pay.version = 6), A.apple_pay.merchant_capabilities || (t.apple_pay.merchant_capabilities = jA.filter(
3410
3414
  (e) => e !== "supportsEMV"
3411
- )), A.apple_pay.supported_countries || (t.apple_pay.supported_countries = ["SA"])), A.samsung_pay && (A.samsung_pay.version || (t.samsung_pay.version = 2), A.samsung_pay.environment || (t.samsung_pay.environment = "PRODUCTION")), A.google_pay && (A.google_pay.environment || (t.google_pay.environment = "PRODUCTION"), A.google_pay.auth_methods || (t.google_pay.auth_methods = ["PAN_ONLY", "CRYPTOGRAM_3DS"]), A.google_pay.gateway_merchant_id || (t.google_pay.gateway_merchant_id = hn(36))), t;
3415
+ )), A.apple_pay.supported_countries || (t.apple_pay.supported_countries = ["SA"])), A.samsung_pay && (A.samsung_pay.version || (t.samsung_pay.version = 2), A.samsung_pay.environment || (t.samsung_pay.environment = "PRODUCTION")), A.google_pay && (A.google_pay.environment || (t.google_pay.environment = "PRODUCTION"), A.google_pay.auth_methods || (t.google_pay.auth_methods = ["PAN_ONLY", "CRYPTOGRAM_3DS"]), A.google_pay.gateway_merchant_id || (t.google_pay.gateway_merchant_id = yn(36))), t;
3412
3416
  };
3413
- let et = null;
3414
- function wn(A) {
3415
- et = A;
3416
- }
3417
3417
  class Cn {
3418
3418
  static init(t) {
3419
- const e = yn(t);
3420
- vn(e);
3419
+ const e = wn(t);
3420
+ gn(e);
3421
3421
  }
3422
3422
  static setAmount(t) {
3423
- et ? et((e) => X(M({}, e), { amount: t })) : console.warn("Form not yet initialized.");
3423
+ tt ? tt((e) => X(M({}, e), { amount: t })) : console.warn("Form not yet initialized.");
3424
3424
  }
3425
3425
  }
3426
3426
  export {
3427
- Cn as default,
3428
- wn as registerAmountSetter
3427
+ Cn as default
3429
3428
  };