Overview
Icon for PhonePe

PhonePe

Power mobile wallet transactions via PhonePe

MEDUSA-PAYMENT-PHONEPE

Support the Medusa-Payment-PhonePe Plugin - Elevate Our Medusa Community!

Dear Developers and E-commerce Enthusiasts,

Are you a developer based in India ? Are you looking for a payment solutions that support UPI, and other india specific modes natively. If you are

A๐Ÿš€ Welcome to the future of web development and eCommerce! Are you ready to harness the power of seamless payments? Look no further than the Medusa Payment PhonPe plugin โ€“ your gateway to a world of convenience, efficiency, and innovation.

In today's fast-paced digital landscape, a smooth and secure payment experience is the cornerstone of success for any eCommerce platform. We understand the challenges you face as a web developer, striving to create exceptional user experiences while ensuring the highest level of trust and reliability. That's where Medusa Payment PhonPe comes in!

Imagine a plugin that effortlessly integrates PhonPe, one of the most trusted and widely-used payment gateways, into the MedusaJS ecosystem. Your users will enjoy a frictionless checkout process, while you benefit from the robustness and simplicity of our solution. No more struggling with complex payment integrations โ€“ we've got you covered!

By leveraging the Medusa Payment PhonPe plugin, you'll unlock a multitude of benefits:

โœ… Simplicity: Seamlessly integrate PhonPe payments into your Medusa-powered eCommerce platform with just a few lines of code. Our user-friendly documentation ensures a hassle-free setup.

โœ… Reliability: Trust is the currency of the digital age. With PhonPe's reputation for security and our commitment to excellence, you can rest assured that your users' transactions are in safe hands.

โœ… Speed: Time is of the essence. Our plugin ensures swift and efficient payment processing, reducing checkout friction and boosting customer satisfaction.

โœ… Flexibility: We understand that no two eCommerce platforms are alike. That's why our plugin is designed to be customizable, allowing you to tailor the payment experience to your unique requirements.

โœ… Innovation: Stay ahead of the curve. By offering PhonPe as a payment option, you're tapping into the growing trend of digital payments, meeting your users where they are and setting your platform apart from the competition.

Join the ranks of successful web developers who have already revolutionized their eCommerce platforms with Medusa Payment PhonPe. Together, let's build a future where every transaction is smooth, every customer is satisfied, and every developer has the tools they need to create magic.

Don't miss out on this opportunity to elevate your eCommerce platform to new heights. Embrace the future of payments with Medusa Payment PhonPe โ€“ because when it comes to success, every detail matters, and every payment counts! ๐Ÿ’ก๐Ÿ’ฐ

Installation Made Simple

No hassle, no fuss! Install Medusa-Payment-PhonePe effortlessly with npm:

yarn add medusa-payment-phonepe

PHONEPE an immensely popular payment gateway with a host of features. This plugin enables the phonepe payment interface on medusa commerce stack

Installation

Use the package manager yarn to install medusa-payment-phonepe.

yarn install medusa-payment-phonepe

Usage

Register for a phonepe account and generate the api keys In your environment file (.env) you need to define

PHONEPE_SALT=<your supplied SALT>
PHONEPE_MODE=<the mode to run your stack in production,uat,test>
PHONEPE_MERCHANT_ACCOUNT=<your phonepe account number/merchant id>
enabledDebugLogging?: boolean; - to enable debug logging. Enabling this might coz the vercel function to timeout
redirectUrl: string; - the URL to redirect the client to
redirectMode: "REDIRECT" | "POST";
callbackUrl: string; - the server 2 server callback path
merchantId: string; - the phonepe merchant id
salt: string; - the phonpe supplied
mode: "production" | "test" | "uat" - the mode to operate in. UAT is to test against the phone gateway, production when you want acutal money to be deducted, test.. well its just that test mode, mocked to be fully implemented. test are currently run in UAT mode.

You need to add the plugin into your medusa-config.js as shown below

const plugins = [
...,
{
resolve:`medusa-payment-phonepe`,
options: {
redirectUrl: "http://localhost:8000/api/payment-confirmed",
callbackUrl: "http://localhost:9000/phonepe/hook",
salt: process.env.PHONEPE_SALT,
merchantId:
process.env.PHONEPE_MERCHANT_ACCOUNT,
mode: process.env.PHONEPE_MODE,
redirectMode: "POST"
}
},
...]

you can replace http://localhost:8000 with your http(s)://your-client-domain you can replace http://localhost:9000 with your http(s)://your-server-hook

Client side configuration

For the nextjs start you need to make the following changes

  1. Create a route to handle post requests from phone pe by creating a route under /app/api/payment-confirmed/route.ts

in that add the following code

/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable require-jsdoc */
import { medusaClient } from "@lib/config";
import { createPostCheckSumHeader } from "@lib/util/phonepe-create-post-checksum-header";
import { sleep } from "@lib/util/sleep";
import { notFound } from "next/navigation";
import { NextRequest, NextResponse } from "next/server";
import { PaymentStatusCodeValues } from "types/phonepe-types";
export async function POST(
request: NextRequest,
_response: NextResponse
): Promise<NextResponse<unknown>> {
const urlSplit = request.url.split("//");
const base = urlSplit[1].split("/")[0];
const data = await request.formData();
const receivedChecksum = data.get("checksum");
2. additional dependencies for browser
yarn add crypto-js
3. lib functions
sleep
export const sleep = async (milliseconds: number): Promise<void> => {
await new Promise((resolve) => {
return setTimeout(resolve, milliseconds);
});
};
phonepe-create-post-checksum-header
import sha256 from "crypto-js/sha256";
export function createPostCheckSumHeader(
payload: any,
salt?: string,
apiString?: string
) {
const SALT_KEY = salt ?? "test-salt";
const payloadWithSalt = payload + `${apiString ?? ""}${SALT_KEY}`;
const encodedPayload = sha256(payloadWithSalt).toString();
const checksum = `${encodedPayload}###1`;
return { checksum, encodedBody: payload };
}
phone-pe types
export interface PhonePeOptions {
mode: "production" | "test" | "uat";
redirectUrl: string;
callbackUrl: string;
merchant_id: string;
salt: string;
/**
* Use this flag to capture payment immediately (default is false)
*/
capture?: boolean;
/**
* set `automatic_payment_methods` to `{ enabled: true }`
*/
automatic_payment_methods?: boolean;
/**
* Set a default description on the intent if the context does not provide one
*/
payment_description?: string;
}
  1. Create a button for PhonePe /src/modules/checkout/components/payment-button/phonepe-payment-button.tsx

like below

/* eslint-disable @typescript-eslint/no-explicit-any */
import { medusaClient } from "@lib/config";
import { PaymentSession } from "@medusajs/medusa";
import Button from "@modules/common/components/button";
import Spinner from "@modules/common/icons/spinner";
import { useCart, useUpdatePaymentSession } from "medusa-react";
import { useEffect, useState } from "react";
import { PaymentResponse } from "types/phonepe-types";
export const PhonePePaymentButton = ({
session,
notReady
}: {
session: PaymentSession;
notReady: boolean;
}) => {
const [disabled, setDisabled] = useState(false);
const [submitting, setSubmitting] = useState(false);
const [errorMessage, setErrorMessage] = useState<string | undefined>(
undefined

Step 3.

nextjs-starter-medusa/src/modules/checkout/components/payment-container/index.tsx add

phonepe: {
title: "PhonePe",
description: "PhonePe payment gateway",
},

&&

case "phonepe":
return (
<PhonePePaymentButton notReady={notReady} session={paymentSession} />
)

and add into the payment element

case "phonepe":
return <></>

###UAT CREDENTIALS - ONLY FOR TESTING

PHONEPE_SALT=099eb0cd-02cf-4e2a-8aca-3e6c6aff0399 PHONEPE_MERCHANT_ACCOUNT=MERCHANTUAT #FOR UAT TESTING MERCHANTUAT PHONEPE_MODE=uat #FOR testing

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

Untested features

These features exists, but without implementing the client it isn't possible to tests these outright

  1. Refund

Disclaimer

The code was tested on limited number of usage scenarios. There maybe unforseen bugs, please raise the issues as they come, or create pull requests if you'd like to submit fixes.

Support the Medusa-Payment-PhonePe Plugin - Strengthen Our Medusa Community!

Dear Medusa Enthusiasts,

I hope this message finds you all in high spirits and enthusiasm for the world of e-commerce! Today, I reach out to our vibrant Medusa community with a heartfelt appeal that will strengthen our collective journey and elevate our online stores to new heights. I am thrilled to present the Medusa-Payment-PhonePe plugin, a community-driven project designed to streamline payment processing for our beloved Medusa platform.

As a dedicated member of this community, I, have invested my time and passion into crafting this valuable plugin that bridges the gap between online retailers and their customers. It is with great humility that I invite you to participate in this open-source initiative by sponsoring the Medusa-Payment-PhonePe plugin through GitHub.

Your sponsorship, no matter the size, will make a world of difference in advancing the Medusa ecosystem. It will empower me to focus on the continuous improvement and maintenance of the Medusa-Payment-PhonePe plugin, ensuring it remains reliable, secure, and seamlessly integrated with Medusa.

Being a community plugin, perks are not the focus of this appeal. Instead, I promise to give back to the community by providing fast and efficient support via Discord or any other means. Your sponsorship will help sustain and enhance the plugin's development, allowing me to be responsive to your needs and address any concerns promptly.

Let's come together and demonstrate the power of community collaboration. By sponsoring the Medusa-Payment-PhonePe plugin on GitHub, you directly contribute to the success of not only this project but also the broader Medusa ecosystem. Your support enables us to empower developers, merchants, and entrepreneurs, facilitating growth and success in the world of e-commerce.

To show your commitment and be part of this exciting journey, kindly consider sponsoring the Medusa-Payment-PhonePe plugin on GitHub. Your contribution will amplify the impact of our community and foster a supportive environment for all.

Thank you for your time, and thank you for being an integral part of our Medusa community. Together, we will elevate our online stores and create extraordinary experiences for customers worldwide.

With warm regards,

SGFGOV

You may also like

Browse all integrations

Build your own

Develop your own custom integraiton

Build your own integration with our API to speed up your processes. Make your integration available via npm for it to be shared in our Library with the broader Medusa community.

gift card interface

Ready to build your custom commerce setup?