@omnikit-js/ui 0.9.13 → 0.9.15

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.
@@ -281,7 +281,7 @@ async function setDefaultPaymentMethod(config, customerId, paymentMethodId) {
281
281
  }
282
282
  return { success: true };
283
283
  }
284
- async function createSubscription(config, customerId, priceId, paymentMethodId, taxInfo) {
284
+ async function createSubscription(config, customerId, priceId, paymentMethodId) {
285
285
  const { baseUrl, projectId } = config;
286
286
  const result = await fetchAPI(
287
287
  config,
@@ -294,12 +294,7 @@ async function createSubscription(config, customerId, priceId, paymentMethodId,
294
294
  payment_method_id: paymentMethodId || void 0,
295
295
  project_id: projectId,
296
296
  sync_to_stripe: true,
297
- test_mode: true,
298
- // Tax info for invoice
299
- tax_rate: taxInfo?.tax_rate,
300
- tax_amount: taxInfo?.tax_amount,
301
- tax_type: taxInfo?.tax_type,
302
- tax_jurisdiction: taxInfo?.tax_jurisdiction
297
+ test_mode: true
303
298
  })
304
299
  }
305
300
  );
@@ -356,6 +351,24 @@ async function calculateTax(config, params) {
356
351
  }
357
352
  return { success: true, data: result.data };
358
353
  }
354
+ async function updateCustomer(config, customerId, data) {
355
+ const { baseUrl, projectId } = config;
356
+ const result = await fetchAPI(
357
+ config,
358
+ `${baseUrl}/billing/customers/${customerId}`,
359
+ {
360
+ method: "PUT",
361
+ body: JSON.stringify({
362
+ project_id: projectId,
363
+ ...data
364
+ })
365
+ }
366
+ );
367
+ if (!result.success) {
368
+ return { success: false, error: result.error || "Failed to update customer" };
369
+ }
370
+ return { success: true, data: result.data };
371
+ }
359
372
  function UsageBar({ label, used, limit, unit = "" }) {
360
373
  const percentage = limit > 0 ? used / limit * 100 : 0;
361
374
  const isWarning = percentage > 80;
@@ -412,6 +425,22 @@ function BillingContent({
412
425
  const [upgradeSuccess, setUpgradeSuccess] = useState(false);
413
426
  const [taxInfo, setTaxInfo] = useState(initialTaxInfo || null);
414
427
  const [taxLoading, setTaxLoading] = useState(false);
428
+ const [preferencesForm, setPreferencesForm] = useState({
429
+ name: customer.name || "",
430
+ email: customer.email || "",
431
+ phone: customer.phone || "",
432
+ customer_type: customer.customer_type || "individual",
433
+ company_name: customer.company_name || "",
434
+ vat_number: customer.vat_number || "",
435
+ address_line1: customer.address?.line1 || "",
436
+ address_line2: customer.address?.line2 || "",
437
+ address_city: customer.address?.city || "",
438
+ address_state: customer.address?.state || "",
439
+ address_postal_code: customer.address?.postal_code || "",
440
+ address_country: customer.address?.country || ""
441
+ });
442
+ const [preferencesSaving, setPreferencesSaving] = useState(false);
443
+ const [preferencesSuccess, setPreferencesSuccess] = useState(false);
415
444
  useEffect(() => {
416
445
  async function loadStripeConfig() {
417
446
  setStripeLoading(true);
@@ -522,18 +551,11 @@ function BillingContent({
522
551
  setError(null);
523
552
  try {
524
553
  const paymentMethodId = selectedUpgradePaymentMethod ? paymentMethods.find((pm) => pm.id === selectedUpgradePaymentMethod)?.provider_payment_method_id || String(selectedUpgradePaymentMethod) : void 0;
525
- const taxInfoForSubscription = taxInfo ? {
526
- tax_rate: taxInfo.tax_rate,
527
- tax_amount: taxInfo.tax_amount,
528
- tax_type: taxInfo.tax_type,
529
- tax_jurisdiction: taxInfo.jurisdiction
530
- } : void 0;
531
554
  const result = await createSubscription(
532
555
  actionConfig,
533
556
  customer.id,
534
557
  selectedPlan.priceId,
535
- paymentMethodId,
536
- taxInfoForSubscription
558
+ paymentMethodId
537
559
  );
538
560
  if (!result.success) {
539
561
  setError(result.error || "Failed to create subscription");
@@ -555,6 +577,40 @@ function BillingContent({
555
577
  setSelectedUpgradePaymentMethod(null);
556
578
  setTaxInfo(null);
557
579
  };
580
+ const handleSavePreferences = async () => {
581
+ setPreferencesSaving(true);
582
+ setError(null);
583
+ setPreferencesSuccess(false);
584
+ try {
585
+ const updateData = {
586
+ name: preferencesForm.name || void 0,
587
+ email: preferencesForm.email || void 0,
588
+ phone: preferencesForm.phone || void 0,
589
+ customer_type: preferencesForm.customer_type,
590
+ company_name: preferencesForm.customer_type === "business" ? preferencesForm.company_name : void 0,
591
+ vat_number: preferencesForm.vat_number || void 0,
592
+ address: {
593
+ line1: preferencesForm.address_line1 || void 0,
594
+ line2: preferencesForm.address_line2 || void 0,
595
+ city: preferencesForm.address_city || void 0,
596
+ state: preferencesForm.address_state || void 0,
597
+ postal_code: preferencesForm.address_postal_code || void 0,
598
+ country: preferencesForm.address_country || void 0
599
+ }
600
+ };
601
+ const result = await updateCustomer(actionConfig, customer.id, updateData);
602
+ if (!result.success) {
603
+ setError(result.error || "Failed to save preferences");
604
+ } else {
605
+ setPreferencesSuccess(true);
606
+ router.refresh();
607
+ }
608
+ } catch (err) {
609
+ setError(err instanceof Error ? err.message : "An error occurred");
610
+ } finally {
611
+ setPreferencesSaving(false);
612
+ }
613
+ };
558
614
  const handleSetDefaultPaymentMethod = async (pm) => {
559
615
  setIsLoading(true);
560
616
  setError(null);
@@ -806,6 +862,256 @@ function BillingContent({
806
862
  )
807
863
  ] })
808
864
  ] }) })
865
+ },
866
+ {
867
+ id: "preferences",
868
+ label: "Preferences",
869
+ content: /* @__PURE__ */ jsx("div", { className: "mt-6", children: /* @__PURE__ */ jsxs(Card, { children: [
870
+ /* @__PURE__ */ jsx("h3", { className: "text-lg font-semibold mb-2", children: "Billing Preferences" }),
871
+ /* @__PURE__ */ jsx("p", { className: "text-sm text-gray-600 dark:text-gray-400 mb-6", children: "Manage your billing information and tax settings" }),
872
+ preferencesSuccess && /* @__PURE__ */ jsx("div", { className: "p-4 mb-6 bg-green-50 dark:bg-green-900/20 text-green-800 dark:text-green-200 rounded-lg", children: "Preferences saved successfully" }),
873
+ /* @__PURE__ */ jsxs("div", { className: "space-y-6", children: [
874
+ /* @__PURE__ */ jsxs("div", { children: [
875
+ /* @__PURE__ */ jsx("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2", children: "Customer Type" }),
876
+ /* @__PURE__ */ jsxs("div", { className: "flex gap-4", children: [
877
+ /* @__PURE__ */ jsxs("label", { className: "flex items-center gap-2", children: [
878
+ /* @__PURE__ */ jsx(
879
+ "input",
880
+ {
881
+ type: "radio",
882
+ name: "customer_type",
883
+ value: "individual",
884
+ checked: preferencesForm.customer_type === "individual",
885
+ onChange: () => setPreferencesForm({ ...preferencesForm, customer_type: "individual" }),
886
+ className: "h-4 w-4"
887
+ }
888
+ ),
889
+ /* @__PURE__ */ jsx("span", { className: "text-sm", children: "Individual" })
890
+ ] }),
891
+ /* @__PURE__ */ jsxs("label", { className: "flex items-center gap-2", children: [
892
+ /* @__PURE__ */ jsx(
893
+ "input",
894
+ {
895
+ type: "radio",
896
+ name: "customer_type",
897
+ value: "business",
898
+ checked: preferencesForm.customer_type === "business",
899
+ onChange: () => setPreferencesForm({ ...preferencesForm, customer_type: "business" }),
900
+ className: "h-4 w-4"
901
+ }
902
+ ),
903
+ /* @__PURE__ */ jsx("span", { className: "text-sm", children: "Business" })
904
+ ] })
905
+ ] })
906
+ ] }),
907
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
908
+ /* @__PURE__ */ jsxs("div", { children: [
909
+ /* @__PURE__ */ jsx("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1", children: preferencesForm.customer_type === "business" ? "Contact Name" : "Full Name" }),
910
+ /* @__PURE__ */ jsx(
911
+ "input",
912
+ {
913
+ type: "text",
914
+ value: preferencesForm.name,
915
+ onChange: (e) => setPreferencesForm({ ...preferencesForm, name: e.target.value }),
916
+ className: "w-full px-3 py-2 border border-gray-300 dark:border-neutral-600 rounded-lg bg-white dark:bg-neutral-800 text-gray-900 dark:text-gray-100",
917
+ placeholder: "John Doe"
918
+ }
919
+ )
920
+ ] }),
921
+ /* @__PURE__ */ jsxs("div", { children: [
922
+ /* @__PURE__ */ jsx("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1", children: "Email" }),
923
+ /* @__PURE__ */ jsx(
924
+ "input",
925
+ {
926
+ type: "email",
927
+ value: preferencesForm.email,
928
+ onChange: (e) => setPreferencesForm({ ...preferencesForm, email: e.target.value }),
929
+ className: "w-full px-3 py-2 border border-gray-300 dark:border-neutral-600 rounded-lg bg-white dark:bg-neutral-800 text-gray-900 dark:text-gray-100",
930
+ placeholder: "john@example.com"
931
+ }
932
+ )
933
+ ] }),
934
+ /* @__PURE__ */ jsxs("div", { children: [
935
+ /* @__PURE__ */ jsx("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1", children: "Phone" }),
936
+ /* @__PURE__ */ jsx(
937
+ "input",
938
+ {
939
+ type: "tel",
940
+ value: preferencesForm.phone,
941
+ onChange: (e) => setPreferencesForm({ ...preferencesForm, phone: e.target.value }),
942
+ className: "w-full px-3 py-2 border border-gray-300 dark:border-neutral-600 rounded-lg bg-white dark:bg-neutral-800 text-gray-900 dark:text-gray-100",
943
+ placeholder: "+1 555 123 4567"
944
+ }
945
+ )
946
+ ] }),
947
+ preferencesForm.customer_type === "business" && /* @__PURE__ */ jsxs("div", { children: [
948
+ /* @__PURE__ */ jsx("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1", children: "Company Name" }),
949
+ /* @__PURE__ */ jsx(
950
+ "input",
951
+ {
952
+ type: "text",
953
+ value: preferencesForm.company_name,
954
+ onChange: (e) => setPreferencesForm({ ...preferencesForm, company_name: e.target.value }),
955
+ className: "w-full px-3 py-2 border border-gray-300 dark:border-neutral-600 rounded-lg bg-white dark:bg-neutral-800 text-gray-900 dark:text-gray-100",
956
+ placeholder: "Acme Inc."
957
+ }
958
+ )
959
+ ] })
960
+ ] }),
961
+ preferencesForm.customer_type === "business" && /* @__PURE__ */ jsxs("div", { children: [
962
+ /* @__PURE__ */ jsx("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1", children: "VAT Number" }),
963
+ /* @__PURE__ */ jsx(
964
+ "input",
965
+ {
966
+ type: "text",
967
+ value: preferencesForm.vat_number,
968
+ onChange: (e) => setPreferencesForm({ ...preferencesForm, vat_number: e.target.value }),
969
+ className: "w-full px-3 py-2 border border-gray-300 dark:border-neutral-600 rounded-lg bg-white dark:bg-neutral-800 text-gray-900 dark:text-gray-100",
970
+ placeholder: "EU123456789"
971
+ }
972
+ ),
973
+ /* @__PURE__ */ jsx("p", { className: "mt-1 text-xs text-gray-500 dark:text-gray-400", children: "For EU businesses, provide your VAT ID to enable reverse charge" })
974
+ ] }),
975
+ /* @__PURE__ */ jsxs("div", { children: [
976
+ /* @__PURE__ */ jsx("h4", { className: "text-sm font-medium text-gray-700 dark:text-gray-300 mb-3", children: "Billing Address" }),
977
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
978
+ /* @__PURE__ */ jsxs("div", { className: "md:col-span-2", children: [
979
+ /* @__PURE__ */ jsx("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1", children: "Address Line 1" }),
980
+ /* @__PURE__ */ jsx(
981
+ "input",
982
+ {
983
+ type: "text",
984
+ value: preferencesForm.address_line1,
985
+ onChange: (e) => setPreferencesForm({ ...preferencesForm, address_line1: e.target.value }),
986
+ className: "w-full px-3 py-2 border border-gray-300 dark:border-neutral-600 rounded-lg bg-white dark:bg-neutral-800 text-gray-900 dark:text-gray-100",
987
+ placeholder: "123 Main Street"
988
+ }
989
+ )
990
+ ] }),
991
+ /* @__PURE__ */ jsxs("div", { className: "md:col-span-2", children: [
992
+ /* @__PURE__ */ jsx("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1", children: "Address Line 2" }),
993
+ /* @__PURE__ */ jsx(
994
+ "input",
995
+ {
996
+ type: "text",
997
+ value: preferencesForm.address_line2,
998
+ onChange: (e) => setPreferencesForm({ ...preferencesForm, address_line2: e.target.value }),
999
+ className: "w-full px-3 py-2 border border-gray-300 dark:border-neutral-600 rounded-lg bg-white dark:bg-neutral-800 text-gray-900 dark:text-gray-100",
1000
+ placeholder: "Apt 4B"
1001
+ }
1002
+ )
1003
+ ] }),
1004
+ /* @__PURE__ */ jsxs("div", { children: [
1005
+ /* @__PURE__ */ jsx("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1", children: "City" }),
1006
+ /* @__PURE__ */ jsx(
1007
+ "input",
1008
+ {
1009
+ type: "text",
1010
+ value: preferencesForm.address_city,
1011
+ onChange: (e) => setPreferencesForm({ ...preferencesForm, address_city: e.target.value }),
1012
+ className: "w-full px-3 py-2 border border-gray-300 dark:border-neutral-600 rounded-lg bg-white dark:bg-neutral-800 text-gray-900 dark:text-gray-100",
1013
+ placeholder: "New York"
1014
+ }
1015
+ )
1016
+ ] }),
1017
+ /* @__PURE__ */ jsxs("div", { children: [
1018
+ /* @__PURE__ */ jsx("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1", children: "State / Region" }),
1019
+ /* @__PURE__ */ jsx(
1020
+ "input",
1021
+ {
1022
+ type: "text",
1023
+ value: preferencesForm.address_state,
1024
+ onChange: (e) => setPreferencesForm({ ...preferencesForm, address_state: e.target.value }),
1025
+ className: "w-full px-3 py-2 border border-gray-300 dark:border-neutral-600 rounded-lg bg-white dark:bg-neutral-800 text-gray-900 dark:text-gray-100",
1026
+ placeholder: "NY"
1027
+ }
1028
+ )
1029
+ ] }),
1030
+ /* @__PURE__ */ jsxs("div", { children: [
1031
+ /* @__PURE__ */ jsx("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1", children: "Postal Code" }),
1032
+ /* @__PURE__ */ jsx(
1033
+ "input",
1034
+ {
1035
+ type: "text",
1036
+ value: preferencesForm.address_postal_code,
1037
+ onChange: (e) => setPreferencesForm({ ...preferencesForm, address_postal_code: e.target.value }),
1038
+ className: "w-full px-3 py-2 border border-gray-300 dark:border-neutral-600 rounded-lg bg-white dark:bg-neutral-800 text-gray-900 dark:text-gray-100",
1039
+ placeholder: "10001"
1040
+ }
1041
+ )
1042
+ ] }),
1043
+ /* @__PURE__ */ jsxs("div", { children: [
1044
+ /* @__PURE__ */ jsx("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1", children: "Country" }),
1045
+ /* @__PURE__ */ jsxs(
1046
+ "select",
1047
+ {
1048
+ value: preferencesForm.address_country,
1049
+ onChange: (e) => setPreferencesForm({ ...preferencesForm, address_country: e.target.value }),
1050
+ className: "w-full px-3 py-2 border border-gray-300 dark:border-neutral-600 rounded-lg bg-white dark:bg-neutral-800 text-gray-900 dark:text-gray-100",
1051
+ children: [
1052
+ /* @__PURE__ */ jsx("option", { value: "", children: "Select country" }),
1053
+ /* @__PURE__ */ jsx("option", { value: "US", children: "United States" }),
1054
+ /* @__PURE__ */ jsx("option", { value: "CA", children: "Canada" }),
1055
+ /* @__PURE__ */ jsx("option", { value: "GB", children: "United Kingdom" }),
1056
+ /* @__PURE__ */ jsx("option", { value: "DE", children: "Germany" }),
1057
+ /* @__PURE__ */ jsx("option", { value: "FR", children: "France" }),
1058
+ /* @__PURE__ */ jsx("option", { value: "ES", children: "Spain" }),
1059
+ /* @__PURE__ */ jsx("option", { value: "IT", children: "Italy" }),
1060
+ /* @__PURE__ */ jsx("option", { value: "NL", children: "Netherlands" }),
1061
+ /* @__PURE__ */ jsx("option", { value: "BE", children: "Belgium" }),
1062
+ /* @__PURE__ */ jsx("option", { value: "AT", children: "Austria" }),
1063
+ /* @__PURE__ */ jsx("option", { value: "CH", children: "Switzerland" }),
1064
+ /* @__PURE__ */ jsx("option", { value: "SE", children: "Sweden" }),
1065
+ /* @__PURE__ */ jsx("option", { value: "NO", children: "Norway" }),
1066
+ /* @__PURE__ */ jsx("option", { value: "DK", children: "Denmark" }),
1067
+ /* @__PURE__ */ jsx("option", { value: "FI", children: "Finland" }),
1068
+ /* @__PURE__ */ jsx("option", { value: "IE", children: "Ireland" }),
1069
+ /* @__PURE__ */ jsx("option", { value: "PT", children: "Portugal" }),
1070
+ /* @__PURE__ */ jsx("option", { value: "PL", children: "Poland" }),
1071
+ /* @__PURE__ */ jsx("option", { value: "CZ", children: "Czech Republic" }),
1072
+ /* @__PURE__ */ jsx("option", { value: "AU", children: "Australia" }),
1073
+ /* @__PURE__ */ jsx("option", { value: "NZ", children: "New Zealand" }),
1074
+ /* @__PURE__ */ jsx("option", { value: "SG", children: "Singapore" }),
1075
+ /* @__PURE__ */ jsx("option", { value: "JP", children: "Japan" }),
1076
+ /* @__PURE__ */ jsx("option", { value: "KR", children: "South Korea" }),
1077
+ /* @__PURE__ */ jsx("option", { value: "IN", children: "India" }),
1078
+ /* @__PURE__ */ jsx("option", { value: "BR", children: "Brazil" }),
1079
+ /* @__PURE__ */ jsx("option", { value: "MX", children: "Mexico" })
1080
+ ]
1081
+ }
1082
+ )
1083
+ ] })
1084
+ ] })
1085
+ ] }),
1086
+ initialTaxInfo && /* @__PURE__ */ jsxs("div", { className: "p-4 bg-gray-50 dark:bg-neutral-800 rounded-lg", children: [
1087
+ /* @__PURE__ */ jsx("h4", { className: "text-sm font-medium text-gray-700 dark:text-gray-300 mb-2", children: "Tax Information" }),
1088
+ /* @__PURE__ */ jsxs("div", { className: "text-sm text-gray-600 dark:text-gray-400", children: [
1089
+ /* @__PURE__ */ jsxs("p", { children: [
1090
+ "Jurisdiction: ",
1091
+ initialTaxInfo.jurisdiction
1092
+ ] }),
1093
+ /* @__PURE__ */ jsxs("p", { children: [
1094
+ "Tax Type: ",
1095
+ initialTaxInfo.tax_label
1096
+ ] }),
1097
+ /* @__PURE__ */ jsxs("p", { children: [
1098
+ "Tax Rate: ",
1099
+ initialTaxInfo.tax_rate,
1100
+ "%"
1101
+ ] }),
1102
+ initialTaxInfo.reverse_charge && /* @__PURE__ */ jsx("p", { className: "text-blue-600 dark:text-blue-400", children: "Reverse charge applies" })
1103
+ ] })
1104
+ ] }),
1105
+ /* @__PURE__ */ jsx("div", { className: "flex justify-end pt-4 border-t border-gray-200 dark:border-neutral-700", children: /* @__PURE__ */ jsx(
1106
+ Button,
1107
+ {
1108
+ onClick: handleSavePreferences,
1109
+ disabled: preferencesSaving,
1110
+ children: preferencesSaving ? "Saving..." : "Save Preferences"
1111
+ }
1112
+ ) })
1113
+ ] })
1114
+ ] }) })
809
1115
  }
810
1116
  ];
811
1117
  return /* @__PURE__ */ jsxs("div", { className, children: [
@@ -1101,5 +1407,5 @@ function BillingContent({
1101
1407
  }
1102
1408
 
1103
1409
  export { AddPaymentMethodForm, BillingContent, Modal };
1104
- //# sourceMappingURL=chunk-NBR3GKMR.js.map
1105
- //# sourceMappingURL=chunk-NBR3GKMR.js.map
1410
+ //# sourceMappingURL=chunk-EJC6ZIK2.js.map
1411
+ //# sourceMappingURL=chunk-EJC6ZIK2.js.map