Skip to content

Initialize a New Session

The first step in the tokenization workflow is to initialize a payment session via the PayNetWorx API.

Overview

Use your server to initialize a session by making a secure API call to PayNetWorx. This involves making a POST request using secure credentials, including your API Key.

API Endpoint

text
https://{{PNX_HOSTED_PAYMENTS_URL}}/v1/payments/sessions/create

Environment URLs

Replace PNX_HOSTED_PAYMENTS_URL with the appropriate environment URL.

See QA Environment or Production Environment for specific URLs.

Request

js
// Make the api request to initialize the Payment Session
async function initializePaymentSession() {
  const headers = new Headers();
  headers.append("Content-Type", "application/json");
  headers.append("Authorization", "{{ YOUR_API_KEY }}"); // Include your provided PNX Api key in the Authorization Header

  const api_response = await fetch(
    `https://{{PNX_HOSTED_PAYMENTS_URL}}/v1/payments/sessions/create`,
    {
      method: "POST",
      headers,
      body: JSON.stringify({
        payment_session: {
          payment_session_use: "TOKENIZE",
        },
      }),
    }
  );
  return await api_response.json();
}

Optional Request Fields

  • payment_session.payment_session_metadata.payment_session_defaults.billing_address

    • Allowed Fields: postal_code (as string), country (as string)
    • Hides postal code and/or country fields if a values are provided
  • page_style.page_style_name

    • Accepts a custom theme name provided as a string.
    • Applies a custom style/theme to the iframe if present and is a valid theme name
    • If an invalid or now value is included the iframe will default to lightmode.

Optional request fields usage examples

Response

ts
// Example response object schema
{
  payment_session: {
    payment_session_id: string;
    /** Format: KSUID */
    payment_session_request_id: string;
    /** Url pointed to payment window with payment_session details */
    payment_session_url: string;
    /** Format: YYYY-MM-DD HH:MI:SS.FF3 UTC */
    expires_at: string;
  }
}

IMPORTANT

Save the payment_session_url from the response - you'll need this in the next step to embed the payment form iframe.

Next Step

Once you have the payment session initialized, proceed to embed the iFrame in your application.