@deiondz/better-auth-razorpay 2.0.16 → 2.0.17
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.js +17 -31
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4779,7 +4779,7 @@ var updateSubscriptionRecord = async (adapter, subscriptionRecordId, whereField,
|
|
|
4779
4779
|
const params = {
|
|
4780
4780
|
model: "subscription",
|
|
4781
4781
|
where: [{ field: whereField, value: subscriptionRecordId }],
|
|
4782
|
-
update:
|
|
4782
|
+
update: updateData
|
|
4783
4783
|
};
|
|
4784
4784
|
log("updateSubscriptionRecord call", {
|
|
4785
4785
|
subscriptionRecordId,
|
|
@@ -4799,33 +4799,21 @@ var updateSubscriptionRecord = async (adapter, subscriptionRecordId, whereField,
|
|
|
4799
4799
|
throw err;
|
|
4800
4800
|
}
|
|
4801
4801
|
};
|
|
4802
|
-
|
|
4803
|
-
if (record.id != null && record.id !== "") {
|
|
4804
|
-
return { value: record.id, field: "id" };
|
|
4805
|
-
}
|
|
4806
|
-
if (record._id != null && record._id !== "") {
|
|
4807
|
-
return { value: record._id, field: "_id" };
|
|
4808
|
-
}
|
|
4809
|
-
return { value: "", field: "id" };
|
|
4810
|
-
}
|
|
4811
|
-
var createStatusHandler = (status, extraFields) => async (adapter, _razorpaySubscriptionId, record, subscription) => {
|
|
4812
|
-
const primaryKey = getSubscriptionPrimaryKey(record);
|
|
4813
|
-
if (!primaryKey.value) {
|
|
4814
|
-
console.error("[razorpay-webhook] record has no id or _id", {
|
|
4815
|
-
recordKeys: Object.keys(record),
|
|
4816
|
-
razorpaySubscriptionId: record.razorpaySubscriptionId
|
|
4817
|
-
});
|
|
4818
|
-
throw new Error("Subscription record has no primary key (id or _id)");
|
|
4819
|
-
}
|
|
4802
|
+
var createStatusHandler = (status, extraFields) => async (adapter, razorpaySubscriptionId, _record, subscription) => {
|
|
4820
4803
|
const periodStart = subscription.current_start ? new Date(subscription.current_start * 1e3) : null;
|
|
4821
4804
|
const periodEnd = subscription.current_end ? new Date(subscription.current_end * 1e3) : null;
|
|
4822
|
-
await updateSubscriptionRecord(
|
|
4823
|
-
|
|
4824
|
-
|
|
4825
|
-
|
|
4826
|
-
|
|
4827
|
-
|
|
4828
|
-
|
|
4805
|
+
await updateSubscriptionRecord(
|
|
4806
|
+
adapter,
|
|
4807
|
+
razorpaySubscriptionId,
|
|
4808
|
+
"razorpaySubscriptionId",
|
|
4809
|
+
{
|
|
4810
|
+
status,
|
|
4811
|
+
planId: subscription.plan_id,
|
|
4812
|
+
...periodStart !== null && { periodStart },
|
|
4813
|
+
...periodEnd !== null && { periodEnd },
|
|
4814
|
+
...extraFields?.(subscription) ?? {}
|
|
4815
|
+
}
|
|
4816
|
+
);
|
|
4829
4817
|
};
|
|
4830
4818
|
var eventHandlers = {
|
|
4831
4819
|
"subscription.authenticated": createStatusHandler("pending"),
|
|
@@ -4928,12 +4916,10 @@ async function processWebhookEvent(adapter, rawBody, fallbackBody, onWebhookEven
|
|
|
4928
4916
|
message: isDev ? `Subscription record not found for ${subscriptionEntity.id}` : "Subscription record not found"
|
|
4929
4917
|
};
|
|
4930
4918
|
}
|
|
4931
|
-
const primaryKey = getSubscriptionPrimaryKey(record);
|
|
4932
4919
|
log("record found", {
|
|
4933
4920
|
event,
|
|
4934
4921
|
razorpaySubscriptionId: subscriptionEntity.id,
|
|
4935
|
-
|
|
4936
|
-
whereField: primaryKey.field,
|
|
4922
|
+
whereField: "razorpaySubscriptionId",
|
|
4937
4923
|
hasId: "id" in record && record.id != null,
|
|
4938
4924
|
has_id: "_id" in record && record._id != null,
|
|
4939
4925
|
status: record.status
|
|
@@ -4952,13 +4938,13 @@ async function processWebhookEvent(adapter, rawBody, fallbackBody, onWebhookEven
|
|
|
4952
4938
|
message: isDev ? `Unhandled event: ${event}` : "Unhandled webhook event"
|
|
4953
4939
|
};
|
|
4954
4940
|
}
|
|
4955
|
-
log("calling handler", { event,
|
|
4941
|
+
log("calling handler", { event, razorpaySubscriptionId: subscriptionEntity.id });
|
|
4956
4942
|
try {
|
|
4957
4943
|
await handler(adapter, subscriptionEntity.id, record, subscriptionEntity);
|
|
4958
4944
|
} catch (handlerError) {
|
|
4959
4945
|
console.error("[razorpay-webhook] handler failed", {
|
|
4960
4946
|
event,
|
|
4961
|
-
|
|
4947
|
+
razorpaySubscriptionId: subscriptionEntity.id,
|
|
4962
4948
|
error: handlerError instanceof Error ? handlerError.message : String(handlerError)
|
|
4963
4949
|
});
|
|
4964
4950
|
throw handlerError;
|