Authorize.net
Authorize.net payment provider by VISA
Payment-Authorizenet
Support the Payment-Authorizenet Provider - Elevate Our Medusa Community!
Dear Developers and E-commerce Enthusiasts,
Are you ready to revolutionize the world of online stores with MedusaJS? We have an exciting opportunity that will make payment processing a breeze for our beloved Medusa platform! Introducing the Payment-Authorizenet provider, a community-driven project that brings the immensely popular Authorize.net payment gateway to our MedusaJS commerce stack.
What's in it for You:
๐ Streamline Payment Processing: With Payment-Authorizenet, you can unleash the full potential of Authorizenet's features, ensuring seamless and secure payments for your customers.
๐ Global Reach: Engage with customers worldwide, as Authorizenet supports various currencies and payment methods, catering to a diverse audience.
๐ Elevate Your Medusa Store: By sponsoring this provider, you empower the entire Medusa community, driving innovation and success across the platform.
Installation Made Simple
No hassle, no fuss! Install Payment-Authorizenet effortlessly with npm:
Authorize.net an immensely popular payment gateway with a host of features. This provider enables the Authorizenet payment interface on medusa commerce stack
Installation
Use the package manager npm to install Payment-Authorizenet.
1npm install @visa/payment-anet
Usage
Register for a Authorizenet account and generate the api keys In your environment file (.env) you need to define
12API_LOGIN_ID=<your AUTHORIZE_NET_API_LOGIN_ID>TRANSACTION_KEY=<your AUTHORIZE_NET_TRANSACTION_KEY>
You need to add the provider into your medusa-config.ts as shown below
1234567891011121314151617181920module.exports = defineConfig({modules: [...{ resolve: "@medusajs/medusa/payment",options: {providers: [...{resolve: "@visa/payment-anet",id: "authorizenet",options: {api_login_id: process.env.AUTHORIZE_NET_API_LOGIN_ID,transaction_key: process.env.AUTHORIZE_NET_TRANSACTION_KEY,capture: <boolean>,},},....],} },...]
Client side configuration
For the NextJs start you need to make the following changes
- Install package to your next starter. This just makes it easier, importing all the scripts implicitly
1yarn add react-authorize-net
- Create a button for Autorizenet /src/modules/checkout/components/payment-button/authorizenet-payment-button.tsx
like below
1234567891011121314151617181920import { Button } from "@medusajs/ui"import Spinner from "@modules/common/icons/spinner"import React, { useCallback, useEffect, useState } from "react"import { HttpTypes } from "@medusajs/types"import { cancelOrder, placeOrder, waitForPaymentCompletion } from "@lib/data/cart"const AnetPaymentButton = ({ notReady }: { notReady: boolean }) => {const [submitting, setSubmitting] = useState(false)const [errorMessage, setErrorMessage] = useState<string | null>(null)const onPaymentCompleted = async () => {await placeOrder().catch((err) => {setErrorMessage(err.message)}).finally(() => {setSubmitting(false)})}
step 3.add into the payment element /src/modules/checkout/components/payment-button/index.tsx
then
1234567case isAuthorizeNet(paymentSession?.provider_id):return(<AnetPaymentButtonnotReady={notReady}data-testid={dataTestId}/>)
Step 4.
nextjs-starter-medusa/src/lib/constants.tsx add
123456789101112131415export const isAuthorizeNet = (providerId?: string) => {return providerId?.startsWith("pp_authorizenet")}// and the following to the listexport const paymentInfoMap: Record<string,{ title: string; icon: React.JSX.Element }> = {..."pp_authorizenet_authorizenet":{title: "Authorizenet",icon: <CreditCard />,},...}
Step 4. modify initiatePaymentSession in the client storefront/src/modules/checkout/components/payment/index.tsx
1234567891011121314151617181920.....const handleSubmit = async () => {setIsLoading(true)try {const response = await createToken();console.log(response);const shouldInputCard =isStripeFunc(selectedPaymentMethod) && !activeSessionconst checkActiveSession =activeSession?.provider_id === selectedPaymentMethodif (!checkActiveSession) {await initiatePaymentSession(cart, {provider_id: selectedPaymentMethod,data: {...response,
Step 5. Add a Authoirizenet Card Conatiner in storefront/src/modules/checkout/components/payment-conatiner/index.tsx
1234567891011121314151617181920import { Radio as RadioGroupOption } from "@headlessui/react"import { Text, clx } from "@medusajs/ui"import React, { useContext, useMemo, type JSX } from "react"import Radio from "@modules/common/components/radio"import { isManual ,isAuthorizeNet} from "@lib/constants"import SkeletonCardDetails from "@modules/skeletons/components/skeleton-card-details"import { CardElement } from "@stripe/react-stripe-js"import { StripeCardElementOptions } from "@stripe/stripe-js"import PaymentTest from "../payment-test"import { StripeContext } from "../payment-wrapper/stripe-wrapper"import { AuthorizeNetProvider,Card} from "react-authorize-net"type PaymentContainerProps = {paymentProviderId: stringselectedPaymentOptionId: string | nulldisabled?: booleanpaymentInfoMap: Record<string, { title: string; icon: JSX.Element }>children?: React.ReactNode,
Step 6. Add environment variables in the client
NEXT_PUBLIC_CLIENT_KEY: NEXT_PUBLIC_API_LOGIN_ID:
watch out
Step 6. Caveat the default starter template has an option which says use the same shipping and billing address please ensure you deselect this and enter the phone number manually in the billing section.
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
Untested features
These features exists, but without implementing the client it isn't possible to tests these outright
- Capture Payment
- 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.