@paykit-sdk/polar 1.1.8 → 1.1.91

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/README.md CHANGED
@@ -183,4 +183,4 @@ POLAR_WEBHOOK_SECRET=your-webhook-secret
183
183
 
184
184
  ## License
185
185
 
186
- ISC
186
+ GPL-3.0
package/dist/index.js CHANGED
@@ -62,16 +62,37 @@ var toPaykitSubscription = (subscription) => {
62
62
  status: toPaykitSubscriptionStatus(subscription.status),
63
63
  current_period_start: new Date(subscription.currentPeriodStart),
64
64
  current_period_end: new Date(subscription.currentPeriodEnd),
65
- metadata: (0, import_core.stringifyObjectValues)({ ...subscription.metadata ?? {}, $customFieldData: subscription.customFieldData })
65
+ metadata: (0, import_core.stringifyObjectValues)({ ...subscription.metadata ?? {} }),
66
+ custom_fields: subscription.customFieldData ?? null,
67
+ item_id: subscription.productId,
68
+ billing_interval: subscription.recurringInterval,
69
+ currency: subscription.currency,
70
+ amount: subscription.amount,
71
+ /**
72
+ * todo: fix
73
+ */
74
+ billing_interval_count: 1,
75
+ current_cycle: 0,
76
+ total_cycles: 0
66
77
  };
67
78
  };
68
79
  var toPaykitInvoice = (invoice) => {
80
+ const status = (() => {
81
+ if (invoice.status == "paid") return "paid";
82
+ return "open";
83
+ })();
69
84
  return {
70
85
  id: invoice.id,
71
- amount: invoice.totalAmount,
86
+ amount_paid: invoice.totalAmount,
72
87
  currency: invoice.currency,
73
- metadata: (0, import_core.stringifyObjectValues)({ ...invoice.metadata ?? {}, $customFieldData: invoice.customFieldData }),
74
- customer_id: invoice.customerId
88
+ metadata: (0, import_core.stringifyObjectValues)({ ...invoice.metadata ?? {} }),
89
+ customer_id: invoice.customerId,
90
+ billing_mode: invoice.billingMode,
91
+ custom_fields: invoice.customFieldData ?? null,
92
+ status,
93
+ subscription_id: invoice.subscription?.id ?? null,
94
+ paid_at: new Date(invoice.createdAt).toISOString(),
95
+ line_items: []
75
96
  };
76
97
  };
77
98
 
@@ -133,7 +154,8 @@ var PolarProvider = class {
133
154
  */
134
155
  this.handleWebhook = async (params) => {
135
156
  const { body, headers, webhookSecret } = params;
136
- const webhookHeaders = (0, import_core2.headersExtractor)(headers, ["webhook-id", "webhook-timestamp", "webhook-signature"]).reduce(
157
+ const requiredHeaders = ["webhook-id", "webhook-timestamp", "webhook-signature"];
158
+ const webhookHeaders = (0, import_core2.headersExtractor)(headers, requiredHeaders).reduce(
137
159
  (acc, kv) => {
138
160
  acc[kv.key] = Array.isArray(kv.value) ? kv.value.join(",") : kv.value;
139
161
  return acc;
@@ -154,25 +176,17 @@ var PolarProvider = class {
154
176
  type: "$invoicePaid",
155
177
  created: parseInt(timestamp),
156
178
  id,
157
- data: toPaykitInvoice({ ...data2, metadata: { ...metadata ?? {}, $mode: "payment" } })
179
+ data: toPaykitInvoice({ ...data2, metadata: { ...metadata ?? {} }, billingMode: "one_time" })
158
180
  });
159
181
  },
160
182
  "order.created": (data2) => {
161
183
  const { billingReason, metadata, status } = data2;
162
- if (billingReason == "subscription_create") {
163
- return (0, import_core2.toPaykitEvent)({
164
- type: "$invoicePaid",
165
- created: parseInt(timestamp),
166
- id,
167
- data: toPaykitInvoice({ ...data2, metadata: { ...metadata ?? {}, $mode: "subscription" } })
168
- });
169
- }
170
- if (billingReason == "subscription_cycle") {
184
+ if (["subscription_create", "subscription_cycle"].includes(billingReason)) {
171
185
  return (0, import_core2.toPaykitEvent)({
172
186
  type: "$invoicePaid",
173
187
  created: parseInt(timestamp),
174
188
  id,
175
- data: toPaykitInvoice({ ...data2, metadata: { ...metadata ?? {}, $mode: "subscription" } })
189
+ data: toPaykitInvoice({ ...data2, metadata: { ...metadata ?? {} }, billingMode: "recurring" })
176
190
  });
177
191
  }
178
192
  return null;
package/dist/index.mjs CHANGED
@@ -42,16 +42,37 @@ var toPaykitSubscription = (subscription) => {
42
42
  status: toPaykitSubscriptionStatus(subscription.status),
43
43
  current_period_start: new Date(subscription.currentPeriodStart),
44
44
  current_period_end: new Date(subscription.currentPeriodEnd),
45
- metadata: stringifyObjectValues({ ...subscription.metadata ?? {}, $customFieldData: subscription.customFieldData })
45
+ metadata: stringifyObjectValues({ ...subscription.metadata ?? {} }),
46
+ custom_fields: subscription.customFieldData ?? null,
47
+ item_id: subscription.productId,
48
+ billing_interval: subscription.recurringInterval,
49
+ currency: subscription.currency,
50
+ amount: subscription.amount,
51
+ /**
52
+ * todo: fix
53
+ */
54
+ billing_interval_count: 1,
55
+ current_cycle: 0,
56
+ total_cycles: 0
46
57
  };
47
58
  };
48
59
  var toPaykitInvoice = (invoice) => {
60
+ const status = (() => {
61
+ if (invoice.status == "paid") return "paid";
62
+ return "open";
63
+ })();
49
64
  return {
50
65
  id: invoice.id,
51
- amount: invoice.totalAmount,
66
+ amount_paid: invoice.totalAmount,
52
67
  currency: invoice.currency,
53
- metadata: stringifyObjectValues({ ...invoice.metadata ?? {}, $customFieldData: invoice.customFieldData }),
54
- customer_id: invoice.customerId
68
+ metadata: stringifyObjectValues({ ...invoice.metadata ?? {} }),
69
+ customer_id: invoice.customerId,
70
+ billing_mode: invoice.billingMode,
71
+ custom_fields: invoice.customFieldData ?? null,
72
+ status,
73
+ subscription_id: invoice.subscription?.id ?? null,
74
+ paid_at: new Date(invoice.createdAt).toISOString(),
75
+ line_items: []
55
76
  };
56
77
  };
57
78
 
@@ -113,7 +134,8 @@ var PolarProvider = class {
113
134
  */
114
135
  this.handleWebhook = async (params) => {
115
136
  const { body, headers, webhookSecret } = params;
116
- const webhookHeaders = headersExtractor(headers, ["webhook-id", "webhook-timestamp", "webhook-signature"]).reduce(
137
+ const requiredHeaders = ["webhook-id", "webhook-timestamp", "webhook-signature"];
138
+ const webhookHeaders = headersExtractor(headers, requiredHeaders).reduce(
117
139
  (acc, kv) => {
118
140
  acc[kv.key] = Array.isArray(kv.value) ? kv.value.join(",") : kv.value;
119
141
  return acc;
@@ -134,25 +156,17 @@ var PolarProvider = class {
134
156
  type: "$invoicePaid",
135
157
  created: parseInt(timestamp),
136
158
  id,
137
- data: toPaykitInvoice({ ...data2, metadata: { ...metadata ?? {}, $mode: "payment" } })
159
+ data: toPaykitInvoice({ ...data2, metadata: { ...metadata ?? {} }, billingMode: "one_time" })
138
160
  });
139
161
  },
140
162
  "order.created": (data2) => {
141
163
  const { billingReason, metadata, status } = data2;
142
- if (billingReason == "subscription_create") {
143
- return toPaykitEvent({
144
- type: "$invoicePaid",
145
- created: parseInt(timestamp),
146
- id,
147
- data: toPaykitInvoice({ ...data2, metadata: { ...metadata ?? {}, $mode: "subscription" } })
148
- });
149
- }
150
- if (billingReason == "subscription_cycle") {
164
+ if (["subscription_create", "subscription_cycle"].includes(billingReason)) {
151
165
  return toPaykitEvent({
152
166
  type: "$invoicePaid",
153
167
  created: parseInt(timestamp),
154
168
  id,
155
- data: toPaykitInvoice({ ...data2, metadata: { ...metadata ?? {}, $mode: "subscription" } })
169
+ data: toPaykitInvoice({ ...data2, metadata: { ...metadata ?? {} }, billingMode: "recurring" })
156
170
  });
157
171
  }
158
172
  return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paykit-sdk/polar",
3
- "version": "1.1.8",
3
+ "version": "1.1.91",
4
4
  "description": "Polar provider for PayKit",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",
@@ -19,12 +19,12 @@
19
19
  "typescript"
20
20
  ],
21
21
  "author": "Emmanuel Odii",
22
- "license": "ISC",
22
+ "license": "GPL-3.0",
23
23
  "dependencies": {
24
24
  "@polar-sh/sdk": "^0.33.0"
25
25
  },
26
26
  "peerDependencies": {
27
- "@paykit-sdk/core": "^1.1.6"
27
+ "@paykit-sdk/core": "^1.1.8"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@paykit-sdk/core": "workspace:*",