Developer Docs

A-Tech Payment SDK

The verified React package for embedding A-Tech payments in your Next.js app. Install it, set a few variables, and render the checkout.

@a-tech.jo/atech_paymentDocumented version: 1.0.17View on npm

Overview

@a-tech.jo/atech_payment is the only SDK you should use to integrate with A-Tech Payment. It is a plug-and-play React package: it creates the order through the A-Tech payment backend, renders the payment provider's checkout, and lets you verify the result.

Your payment provider secrets never live in your front end. You save your gateway credentials once in the A-Tech dashboard and the SDK talks to the A-Tech backend for you.

Requirements

  • A Next.js (React 15.0.1 or later) application.
  • An approved A-Tech merchant account with an entity and completed KYC.
  • Gateway credentials saved in the dashboard under Credentials.

Installation

Install the package from npm:

bash
npm install @a-tech.jo/atech_payment

The package ships untranspiled source, so tell Next.js to compile it. Add it to transpilePackages in next.config.js:

javascript
// next.config.js
const nextConfig = {
  transpilePackages: ["@a-tech.jo/atech_payment"],
};

module.exports = nextConfig;

Configuration

The SDK picks the A-Tech backend from a single environment variable. Add it to your .env file:

env
# .env
NEXT_PUBLIC_NODE_ENV="production"   # production | staging | development
NEXT_PUBLIC_NODE_ENVA-Tech backend usedUse it for
productionhttps://payment.atech-workspace.com/apiLive payments
staginghttps://stage.payment.atech-workspace.com/apiTesting against the A-Tech staging system
developmenthttp://localhost:5000/apiA backend running on your own machine
If the variable is not set, the SDK defaults to production. HyperPay uses its live host only when the value is production; any other value uses the HyperPay test host.

Quick start: HyperPay

Render the PymentOrder component with your order. The SDK creates the checkout, loads the HyperPay widget and shows the card form.

The component is exported as PymentOrder (without the second a). Use that exact name in your imports.
jsx
"use client";
import { PymentOrder } from "@a-tech.jo/atech_payment";

export default function CheckoutPage() {
  const order = {
    entityId: "<YOUR_GATEWAY_ENTITY_ID>",
    amount: "10.00",
    currency: "USD",
    paymentType: "DB", // DB = immediate purchase
  };

  return (
    <PymentOrder
      provider="hyperpay"
      order={order}
      redirectUrl="https://your-site.com/checkout/result"
    />
  );
}

When the customer pays, HyperPay sends them to your redirectUrl with the id and resourcePath query parameters.

Verify the payment

On your result page, pass those two parameters to verifyCheckout to get the payment status from A-Tech. Always verify on the result page; never trust the redirect alone.

jsx
"use client";
import { useEffect, useState } from "react";
import { useSearchParams } from "next/navigation";
import { verifyCheckout } from "@a-tech.jo/atech_payment";

export default function ResultPage() {
  const params = useSearchParams();
  const [result, setResult] = useState(null);

  useEffect(() => {
    const id = params.get("id");
    const resourcePath = params.get("resourcePath");
    if (id && resourcePath) {
      verifyCheckout("hyperpay", id, resourcePath).then(setResult);
    }
  }, [params]);

  return <pre>{JSON.stringify(result, null, 2)}</pre>;
}

verifyCheckout returns the provider's result. Check its result code against the HyperPay result codes to decide whether the payment succeeded.

PayPal

Use provider="paypal" with your PayPal client ID. The order needs a type: "order" for a one-time payment or "subscription" for a recurring one. The remaining fields are passed to the A-Tech backend.

jsx
"use client";
import { PymentOrder } from "@a-tech.jo/atech_payment";

export default function PayPalCheckout() {
  return (
    <PymentOrder
      provider="paypal"
      clientId={process.env.NEXT_PUBLIC_PAYPAL_CLIENT_ID}
      order={{ type: "order" /* ...order fields */ }}
      onChange={({ event, data }) => console.log(event, data)}
      onStatusChange={(approved) => approved && console.log("Paid")}
    />
  );
}

onChange receives { event, data } for the createOrder and approveOrder steps. onStatusChange(true) is called once the payment is approved.

In version 1.0.17 the PayPal buttons work only when NEXT_PUBLIC_NODE_ENV is production or development. With staging they show "Invalid Env".

API reference

PymentOrder props

PropTypeDefaultDescription
provider"hyperpay" | "paypal""hyperpay"Which gateway to use: "hyperpay" or "paypal".
orderobject{}The order to create. Fields depend on the provider (see below).
clientIdstring"test"PayPal only. Your PayPal client ID.
redirectUrlstring""HyperPay only. The page the customer returns to after paying.
onChange({ event, data }) => void() => {}PayPal only. Called with { event, data } as the order progresses.
onStatusChange(approved: boolean) => void() => {}PayPal only. Called with true when the payment is approved.

verifyCheckout(provider, checkoutId, resourcePath)

Returns the payment status for a HyperPay checkout. Today only the "hyperpay" provider is supported; other providers return false.

How to fill the variables

Every value you have to provide, where it comes from, and where to find it.

VariableWhat to putWhere to get it
NEXT_PUBLIC_NODE_ENVproduction, staging or development.Choose per deployment. See the Configuration table above.
providerhyperpay or paypal.The gateway you enabled for your account. Save its credentials in the dashboard.
order.entityIdYour gateway entity ID for the environment you are in (test or live).Issued by HyperPay when your merchant account is set up. Use the test entity ID while testing.
order.amountThe amount as a string with two decimals, for example "10.00".Calculated by your application from the cart.
order.currencyA three-letter ISO code, for example USD, JOD or SAR.Must be a currency enabled on your gateway account.
order.paymentTypeDB for an immediate purchase. PA to pre-authorize and capture later.See the HyperPay parameters reference.
redirectUrlThe full URL of your result page, for example https://your-site.com/checkout/result.A page you build. It must call verifyCheckout.
clientId (PayPal)The PayPal REST app client ID.PayPal Developer Dashboard, under Apps & Credentials. Use the Sandbox tab for testing and Live for production.
order.type (PayPal)order for one-time payments, subscription for recurring.Chosen by your application.

Gateway credentials

Your gateway secrets (API keys, merchant IDs) are never put in your code. Save them in the dashboard and A-Tech uses them when the SDK creates an order.

Troubleshooting

Next.js fails to compile the package
Add "@a-tech.jo/atech_payment" to transpilePackages in next.config.js and restart the dev server.
The PayPal buttons show "Invalid Env"
Set NEXT_PUBLIC_NODE_ENV to production or development. Staging is not supported for PayPal in version 1.0.17.
The card form does not appear
Make sure order is not empty and your Content Security Policy allows scripts and frames from eu-test.oppwa.com (testing) or eu-prod.oppwa.com (live).
The page redirects to /login
The A-Tech backend rejected the request (401). Check that your account is approved and your gateway credentials are saved in the dashboard.
I am using the test host in production
HyperPay only uses its live host when NEXT_PUBLIC_NODE_ENV is exactly production.