From 10f8fd0e3bf712cea05de37ac250536bdd6a634a Mon Sep 17 00:00:00 2001 From: Govind Diwakar Date: Mon, 13 Nov 2023 08:23:05 +0000 Subject: [PATCH 1/8] fix: context --- src/core/razorpay-base.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/core/razorpay-base.ts b/src/core/razorpay-base.ts index e6a01b1..eb9d2c6 100644 --- a/src/core/razorpay-base.ts +++ b/src/core/razorpay-base.ts @@ -161,6 +161,12 @@ abstract class RazorpayBase extends AbstractPaymentProcessor { ...intentRequestData, }; + if(!(customer && customer?.billing_address?.phone && customer?.phone )) + { + throw new MedusaError(MedusaError.Types.PAYMENT_AUTHORIZATION_ERROR, + "Phone number not found in context",MedusaError.Codes.CART_INCOMPATIBLE_STATE); + } + if (customer?.metadata?.razorpay_id) { intentRequest.notes!.razorpay_id = customer.metadata .razorpay_id as string; @@ -169,7 +175,7 @@ abstract class RazorpayBase extends AbstractPaymentProcessor { try { razorpayCustomer = await this.razorpay_.customers.create({ email, - contact: customer?.phone, + contact: customer?.phone ?? customer?.billing_address?.phone ?? "", gstin: customer?.metadata?.gstin as string, fail_existing: 0, name: `${customer?.last_name} ${customer?.last_name}`, From b08ce729d75425490f28795c22420e66c79503e2 Mon Sep 17 00:00:00 2001 From: Govind Diwakar Date: Mon, 13 Nov 2023 08:23:14 +0000 Subject: [PATCH 2/8] 7.0.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 12c8a7a..87d1fda 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "medusa-payment-razorpay", - "version": "7.0.1", + "version": "7.0.2", "description": "Razorpay Payment provider for Meduas Commerce", "main": "dist/index.js", "repository": { From 1d08054ef0ecf8507fd8935eba2743ff4efac380 Mon Sep 17 00:00:00 2001 From: Govind Diwakar Date: Fri, 29 Dec 2023 05:38:02 +0000 Subject: [PATCH 3/8] fix: tests for phone number in the context --- src/core/__fixtures__/data.ts | 5 ++++- src/core/razorpay-base.ts | 10 ++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/core/__fixtures__/data.ts b/src/core/__fixtures__/data.ts index 32a634b..e0c7048 100644 --- a/src/core/__fixtures__/data.ts +++ b/src/core/__fixtures__/data.ts @@ -12,20 +12,23 @@ import { PaymentIntentDataByStatus } from "../../__fixtures__/data"; export const initiatePaymentContextWithExistingCustomer = { email: EXISTING_CUSTOMER_EMAIL, + phone: "9876542321", currency_code: "inr", amount: 1000, resource_id: "test", - customer: { last_name: "test", first_name: "customer" }, + customer: { last_name: "test", first_name: "customer", phone: "9876542321" }, context: {}, paymentSessionData: {}, }; export const initiatePaymentContextWithExistingCustomerRazorpayId = { email: EXISTING_CUSTOMER_EMAIL, + currency_code: "inr", amount: 1000, resource_id: "test", customer: { + phone: "9876542321", last_name: "test", first_name: "customer", metadata: { diff --git a/src/core/razorpay-base.ts b/src/core/razorpay-base.ts index eb9d2c6..adb7838 100644 --- a/src/core/razorpay-base.ts +++ b/src/core/razorpay-base.ts @@ -161,10 +161,12 @@ abstract class RazorpayBase extends AbstractPaymentProcessor { ...intentRequestData, }; - if(!(customer && customer?.billing_address?.phone && customer?.phone )) - { - throw new MedusaError(MedusaError.Types.PAYMENT_AUTHORIZATION_ERROR, - "Phone number not found in context",MedusaError.Codes.CART_INCOMPATIBLE_STATE); + if (!(customer?.billing_address?.phone || customer?.phone)) { + throw new MedusaError( + MedusaError.Types.PAYMENT_AUTHORIZATION_ERROR, + "Phone number not found in context", + MedusaError.Codes.CART_INCOMPATIBLE_STATE + ); } if (customer?.metadata?.razorpay_id) { From 12cd2629a6a998627be6fe03f921418c25b38bbf Mon Sep 17 00:00:00 2001 From: Govind Diwakar Date: Fri, 29 Dec 2023 05:38:30 +0000 Subject: [PATCH 4/8] 7.0.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 87d1fda..1d7a115 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "medusa-payment-razorpay", - "version": "7.0.2", + "version": "7.0.3", "description": "Razorpay Payment provider for Meduas Commerce", "main": "dist/index.js", "repository": { From fa8f0613324cc8442491a4ff90ce15e954580bd0 Mon Sep 17 00:00:00 2001 From: Govind Diwakar Date: Fri, 29 Dec 2023 05:42:19 +0000 Subject: [PATCH 5/8] chore: refactored to remove unused variables and imports --- src/core/razorpay-base.ts | 46 ++------------------------------------- 1 file changed, 2 insertions(+), 44 deletions(-) diff --git a/src/core/razorpay-base.ts b/src/core/razorpay-base.ts index adb7838..3f581ff 100644 --- a/src/core/razorpay-base.ts +++ b/src/core/razorpay-base.ts @@ -8,16 +8,10 @@ import { PaymentProcessorSessionResponse, PaymentSessionStatus, } from "@medusajs/medusa"; -import { - ErrorCodes, - ErrorIntentStatus, - PaymentIntentOptions, - RazorpayOptions, -} from "../types"; +import { ErrorCodes, PaymentIntentOptions, RazorpayOptions } from "../types"; import { MedusaError } from "@medusajs/utils"; import { Orders } from "razorpay/dist/types/orders"; import crypto from "crypto"; -import { Payments } from "razorpay/dist/types/payments"; import { Refunds } from "razorpay/dist/types/refunds"; /** @@ -89,9 +83,6 @@ abstract class RazorpayBase extends AbstractPaymentProcessor { async getRazorpayPaymentStatus( paymentIntent: Orders.RazorpayOrder ): Promise { - const payments = await this.razorpay_.orders.fetchPayments( - paymentIntent.id - ); return PaymentSessionStatus.AUTHORIZED; /* if (paymentIntent.amount_due != 0) { @@ -134,17 +125,7 @@ abstract class RazorpayBase extends AbstractPaymentProcessor { context: PaymentProcessorContext ): Promise { const intentRequestData = this.getPaymentIntentOptions(); - const { - email, - context: cart_context, - currency_code, - amount, - resource_id, - customer, - } = context; - - const description = (cart_context.payment_description ?? - this.options_?.payment_description) as string; + const { email, currency_code, amount, resource_id, customer } = context; const intentRequest: Orders.RazorpayOrderCreateRequestBody = { amount: Math.round(amount), @@ -241,24 +222,6 @@ abstract class RazorpayBase extends AbstractPaymentProcessor { code: ErrorCodes.UNSUPPORTED_OPERATION, }; return error; - - /* try { - const id = paymentSessionData.id as string - return (await this.razorpay_.orders.edit( - paymentSessionData.order_id as string, - { - notes: { - status: "cancelled" - } - } - )) as unknown as PaymentProcessorSessionResponse["session_data"] - } catch (error) { - if (error.payment_intent?.status === ErrorIntentStatus.CANCELED) { - return error.payment_intent - } - - return this.buildError("An error occurred in cancelPayment", error) - }*/ } async capturePayment( @@ -390,11 +353,6 @@ abstract class RazorpayBase extends AbstractPaymentProcessor { delete sessionOrderData.id; delete sessionOrderData.created_at; - const request: Orders.RazorpayOrderCreateRequestBody = { - ...sessionOrderData, - amount: amount, - currency: currency_code?.toUpperCase() ?? sessionOrderData.currency!, - }; context.currency_code = currency_code?.toUpperCase() ?? sessionOrderData.currency!; const newPaymentSessionOrder = (await this.initiatePayment( From 08029a1b4081ab1a5ba22ba7b1df762dc486f146 Mon Sep 17 00:00:00 2001 From: Govind Diwakar Date: Fri, 29 Dec 2023 05:42:28 +0000 Subject: [PATCH 6/8] 7.0.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1d7a115..f8ee34e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "medusa-payment-razorpay", - "version": "7.0.3", + "version": "7.0.4", "description": "Razorpay Payment provider for Meduas Commerce", "main": "dist/index.js", "repository": { From 203d41caee83435f4cb935e4855f772118e60866 Mon Sep 17 00:00:00 2001 From: Govind Diwakar Date: Fri, 29 Dec 2023 05:47:08 +0000 Subject: [PATCH 7/8] chore: refactored to remove unused variables and imports --- src/core/razorpay-base.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/core/razorpay-base.ts b/src/core/razorpay-base.ts index 3f581ff..fc91985 100644 --- a/src/core/razorpay-base.ts +++ b/src/core/razorpay-base.ts @@ -83,6 +83,9 @@ abstract class RazorpayBase extends AbstractPaymentProcessor { async getRazorpayPaymentStatus( paymentIntent: Orders.RazorpayOrder ): Promise { + if (!paymentIntent) { + return PaymentSessionStatus.ERROR; + } return PaymentSessionStatus.AUTHORIZED; /* if (paymentIntent.amount_due != 0) { From 5c405c1afbfc9e207ac3ae2f2436585fa0e4786f Mon Sep 17 00:00:00 2001 From: Govind Diwakar Date: Fri, 29 Dec 2023 05:47:19 +0000 Subject: [PATCH 8/8] 7.0.5 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f8ee34e..5ef526f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "medusa-payment-razorpay", - "version": "7.0.4", + "version": "7.0.5", "description": "Razorpay Payment provider for Meduas Commerce", "main": "dist/index.js", "repository": {