0.0.4 • Published 11 months ago

hydrogenpay-reactjs v0.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

Hydrogen ReactJS SDK

Hydrogen ReactJS SDK allows you to accept payment using in your react application

Installation

Register for a merchant account on Hydrogen Merchant Dashboard to get started.

npm install --save hydrogenpay-reactjs
yarn add hydrogenpay-reactjs
pnpm add hydrogenpay-reactjs

Support

If you have any problems, questions or suggestions, create an issue here or send your inquiry to support@hydrogenpay.com

Implementation

You should already have your api key, If not, go to https://dashboard.hydrogenpay.com.

Usage 1 - As a React Hook

import { useHydrogenPayment } from "hydrogenpay-reactjs";

function App() {
  const options = {
    amount: 500, // REQUIRED
    email: "test@mail.com", // REQUIRED
    customerName: "John Doe", // REQUIRED
    meta: "ewr34we4w", // OPTIONAL
    apiKey: "PK_TEST_cca53e0b3bc7847aff94502b8a585f84", // REQUIRED
    description: "Test description", // OPTIONAL
    currency: "NGN", // REQUIRED
    frequency: 1, // OPTIONAL
    isRecurring: false, // OPTIONAL
    endDate: "2025-10-02", // OPTIONAL but (REQUIRED when isRecurring: true)
  };

  const onClose = (close) => {
    console.log(close);
  };

  const onSuccess = (response, closeModal) => {
    console.log(response);
    setTimeout(() => closeModal(), 2000);
  };

  const PayButton = () => {
    const initializePayment = useHydrogenPayment({
      ...options,
      onSuccess,
      onClose,
    });

    return <button onClick={() => initializePayment()}>Pay</button>;
  };

  return (
    <div className="...">
      <PayButton />
    </div>
  );
}

export default App;

Usage 2 - As a Button Component

import { HydrogenPaymentButton } from "hydrogenpay-reactjs";

function App() {
  const options = {
    amount: 500, // REQUIRED
    email: "test@mail.com", // REQUIRED
    customerName: "John Doe", // REQUIRED
    meta: "ewr34we4w", // OPTIONAL
    apiKey: "PK_TEST_cca53e0b3bc7847aff94502b8a585f84", // REQUIRED
    description: "Test description", // OPTIONAL
    currency: "NGN", // REQUIRED
    frequency: 1, // OPTIONAL
    isRecurring: false, // OPTIONAL
    endDate: "2025-10-02", // OPTIONAL but (REQUIRED when isRecurring: true)
  };

  const onClose = (close) => {
    console.log(close);
  };

  const onSuccess = (response, closeModal) => {
    console.log(response);
    setTimeout(() => closeModal(), 2000);
  };

  return (
    <div className="App">
      <HydrogenPaymentButton
        text="Payment"
        className="..."
        options={{ ...options, onSuccess, onClose }}
      />
    </div>
  );
}

export default App;

Options Type

NameTypeRequiredDesc
currencyStringRequiredThe currency for the transaction e.g NGN, USD
emailStringRequiredThe email of the user to be charged
descriptionStringOptionalThe transaction description
customerNameStringRequiredThe fullname of the user to be charged
amountNumberRequiredThe transaction amount
apiKeyStringRequiredYour LIVE or TEST apiKey or see above step to get yours
onSuccessFunctionOptionalCallback when transaction is successful
onCloseFunctionOptionalCallback when transaction is closed of cancel
textStringOptionalPayment Button Text. Default: Hydrogen Pay
classNameStringOptionalPayment Button style
childrenFunctionOptionalReact JSX Component
isRecurringbooleanOptionalRecurring Payment
frequencyStringOptionalRecurring Payment frequency
endDateStringOptionalRecurring Payment End Date. OPTIONAL but (REQUIRED when isRecurring = true)
0.0.4

11 months ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago