Skip to content

Commit

Permalink
transaction initialise handle
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrudul Vajpayee authored and Mrudul Vajpayee committed Aug 29, 2024
1 parent 67f2b99 commit 32397fa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/modules/juspay/juspay-api-response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const SessionSDKPayload = z.object({
requestId: z.string(),
service: z.string(),
payload: Payload,
expiry: z.string().nullable(),
expiry: z.string().nullable().optional(),
});

export const PaymentResponseSchema = z.object({
Expand Down
15 changes: 13 additions & 2 deletions src/modules/webhooks/juspay/transaction-initialize-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,18 @@ export const TransactionInitializeSessionJuspayWebhookHandler = async (

const captureMethod =
event.action.actionType == TransactionFlowStrategyEnum.Authorization ? false : true;
const orderId = uuidv4();

function generateUniqueUUID(): string {
const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
let uuid = "";
for (let i = 0; i < 10; i++) {
const randomIndex = Math.floor(Math.random() * characters.length);
uuid += characters[randomIndex];
}
uuid += Date.now().toString(36);
return uuid;
}
const orderId = generateUniqueUUID();

const createOrderPayload: paymentsComponents["schemas"]["SessionRequest"] = {
order_id: normalizeValue(orderId),
Expand Down Expand Up @@ -144,7 +155,7 @@ export const TransactionInitializeSessionJuspayWebhookHandler = async (
shipping_address_country: normalizeValue(shippingAddress?.address?.zip),
shipping_address_postal_code: normalizeValue(shippingAddress?.address?.zip),
"metadata.JUSPAY:gateway_reference_id": requestData?.gatewayReferenceId,
"metadata.txns.auto_capture": normalizeValue(captureMethod),
"metadata.txns.auto_capture": captureMethod,
payment_filter: normalizeValue(requestData?.allowedPaymentMethods),
};
const createOrderResponse = await createJuspayPayment(createOrderPayload);
Expand Down

0 comments on commit 32397fa

Please sign in to comment.