> ## Documentation Index
> Fetch the complete documentation index at: https://docs.juicyway.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Widget Integration Guide

> Step-by-step guide to integrate the Juicyway Payment Widget

<Note>
  This guide will walk you through the process of integrating the Juicyway Payment Widget into your application.
</Note>

## Overview

The Juicyway Payment Widget provides a secure and customizable payment solution that can be easily integrated into your website or application. Follow these steps to implement the widget in your platform.

## Integration Steps

<Steps>
  <Step title="Include the Juicyway Library">
    Add the following script tag to the `<head>` section of your HTML:

    ```html theme={null}
    <script
      src="https://checkout.juicyway.com/pay.js"
      integrity="sha384-ROsbTCP6XBvgKuKoF3VSg21iu7C48d0RZHByswNEGppV+u2KkCt4rbEq9LpO3M9e"
      crossorigin="anonymous"
    ></script>
    ```
  </Step>

  <Step title="Create the Payment Function">
    Define a JavaScript function to initialize the payment widget:

    ```javascript theme={null}
    function openWidget() {
      Juicyway.PayWithJuice({
        // Configuration options detailed below
        onClose: () => {
          // Called when user closes widget
        },
        onSuccess: () => {
          // Called when payment is successful
        },
        onError: (error) => {
          // Called when payment fails
        },
        // Required parameters
        reference: "unique_ref_123",
        amount: 1000,
        currency: "USD",
        description: "Product purchase",
        isLive: true,
        key: "YOUR_API_KEY",
        order: {
          identifier: "ORDER123",
          items: [
              { 
                name: "E-book",
                type: "digital",
                qty: 1,
                amount: 1000
              }
          ]
        },
        // Optional parameters
        appName: "Your App Name",
        customer: {
          email: "customer@email.com",
          first_name: "Test",
          last_name: "Customer",
          phone_number: "+1234567890",
          billing_address: { 
              line1: "123 Main St",
              city: "San Francisco",
              state: "CA",
              zip_code: "94105",
              country: "US"
          }
        },
        paymentMethod: {
          type: "card"
        },
        order: {
            // Additional payment order
        }
      });
    }
    ```
  </Step>

  <Step title="Implement the Payment Button">
    Create a button or link that triggers the payment widget:

    ```html theme={null}
    <button onclick="openWidget()">Make Payment</button>
    ```
  </Step>
</Steps>

## Configuration Parameters

### Required Parameters

<ResponseField name="reference" type="string" required>
  A unique identifier for the payment transaction
</ResponseField>

<ResponseField name="amount" type="number" required>
  The payment amount in the smallest denomination of the currency (e.g., cents for USD)
</ResponseField>

<ResponseField name="currency" type="string" required>
  A three-letter ISO 4217 currency code (e.g., USD, NGN, CAD)
</ResponseField>

<ResponseField name="description" type="string" required>
  A short description of the payment
</ResponseField>

<ResponseField name="isLive" type="boolean" required>
  Set to `true` for production environment, `false` for sandbox testing
</ResponseField>

<ResponseField name="key" type="string" required>
  Your Juicyway API key
</ResponseField>

<ResponseField name="order" type="object" required>
  Order details object containing:

  <Expandable title="Properties">
    <ResponseField name="identifier" type="string" required>
      Unique identifier for the order
    </ResponseField>

    <ResponseField name="items" type="array" required>
      Array of items in the order

      <Expandable title="Item Properties">
        <ResponseField name="name" type="string" required>
          Name of the item
        </ResponseField>

        <ResponseField name="type" type="string" required>
          Type of item (e.g., "digital", "physical")
        </ResponseField>

        <ResponseField name="qty" type="number">
          Quantity of the item
        </ResponseField>

        <ResponseField name="amount" type="number">
          Price per item
        </ResponseField>
      </Expandable>
    </ResponseField>
  </Expandable>
</ResponseField>

### Optional Parameters

<ResponseField name="appName" type="string">
  The name of your merchant's business or application
</ResponseField>

<ResponseField name="customer" type="object">
  Customer details object containing:

  <Expandable title="Properties">
    <ResponseField name="email" type="string">
      Customer's email address
    </ResponseField>

    <ResponseField name="first_name" type="string">
      Customer's first name
    </ResponseField>

    <ResponseField name="last_name" type="string">
      Customer's last name
    </ResponseField>

    <ResponseField name="phone_number" type="string">
      Customer's phone number with country code
    </ResponseField>

    <ResponseField name="billing_address" type="object">
      <Expandable title="Address Properties">
        <ResponseField name="line1" type="string">
          Street address
        </ResponseField>

        <ResponseField name="city" type="string">
          City
        </ResponseField>

        <ResponseField name="state" type="string">
          State/Province
        </ResponseField>

        <ResponseField name="zip_code" type="string">
          Postal/ZIP code
        </ResponseField>

        <ResponseField name="country" type="string">
          Two-letter country code
        </ResponseField>
      </Expandable>
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="paymentMethod" type="object">
  Payment method configuration:

  <Expandable title="Properties">
    <ResponseField name="type" type="string">
      Payment method type: "card" | "bank\_account" | "interac"
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="order" type="object">
  Additional data related to the payment
</ResponseField>

## Callback Functions

<ResponseField name="onClose" type="function">
  Called when the user closes the payment widget
</ResponseField>

<ResponseField name="onSuccess" type="function">
  Called when the payment is successfully completed
</ResponseField>

<ResponseField name="onError" type="function">
  Called when an error occurs during payment processing
</ResponseField>

<Note>
  For security purposes, always ensure you're using the correct API key for your environment (test or live).
</Note>
