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

# Customer management

**Managing customers** is an essential step when conducting transactions via the FedaPay platform. Each transaction is linked to a customer, so you must register and manage your customers in the system before initiating any transactions.

## Creating Customers

Creating a customer in FedaPay is done via an API request, allowing you to add the necessary information about your customer. This data is used during transactions to clearly identify the user.

### Required Parameters

When creating a customer, you need to provide the following information:

* **First Name (firstname)**: The customer’s first name.

* **Last Name (lastname)**: The customer’s last name.

* **Email (email)**: The customer's email address, which will be used for all communications and confirmations.

* **Phone Number (phone\_number)**: Optional, but helpful for certain transactions (must include the country code, e.g., +229 for Benin).

These details, except for the phone number, are mandatory. However, it is recommended to provide all information to enhance the tracking of customer interactions and payments.

**Example API Request for Creating a Customer**

To add a new customer, send a request to the FedaPay API. Below are examples in various programming languages:

<CodeGroup>
  ```java Curl theme={null}
   curl --request POST \
  --url https://sandbox-api.fedapay.com/v1/customers \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{
  "email": "jsmith@example.com",
  "phone_number": {
    "number": 123,
    "country": "<string>"
  },
  "firstname": "<string>",
  "lastname": "<string>"
  }'
  ```

  ```javascript NodeJs theme={null}
  const { FedaPay, Customer } = require('fedapay');
  /* Replace YOUR_SECRETE_API_KEY with your real API key */
  FedaPay.setApiKey("YOUR_SECRETE_API_KEY");
  /* Specify whether you want to run your query in test or live mode */
  FedaPay.setEnvironment('sandbox'); //or setEnvironment('live');
  /* Create customer */
  const customer = await Customer.create({
    firstname: 'John',
    lastname: 'Doe',
    email: 'john@doe.com',
    phone_number: {
      number: '90090909',
      country: 'BJ'
    }
  });
  ```

  ```Php PHP theme={null}
  /* Replace YOUR_SECRETE_API_KEY with your secret API key */
  \FedaPay\FedaPay::setApiKey("YOUR_SECRETE_API_KEY");
  /* Specify whether you want to run your query in test or live mode */
  \FedaPay\FedaPay::setEnvironment('sandbox'); //or setEnvironment('live');
  /* Create customer */
  \FedaPay\Customer::create(array(
    "firstname" => "John",
    "lastname" => "Doe",
    "email" => "John.doe@gmail.com",
    "phone_number" => [
      "number" => "+22966666600",
      "country" => 'bj' // 'bj' Benin code
    ]
  ));
  ```

  ```ruby Ruby theme={null}
  require 'fedapay';
  # configure FedaPay library
  FedaPay.api_key = '' # Your secret api key
  FedaPay.environment = '' # sandbox or live
  phone = {
    country: 'bj',
    number: '66000001'
  };
  customer = FedaPay::Customer.create(
    firstname: 'firstname',
    lastname: 'lastname',
    email: 'email@test.com',
    phone_number: phone
  );
  ```
</CodeGroup>

<Tip>
  ### Important Points

  * Be sure to replace **YOUR\_SECRET\_API\_KEY** with your actual secret API key.

  * The API endpoint may vary depending on the environment. Use **[https://api.fedapay.com/v1/customers](https://api.fedapay.com/v1/customers)** for the live environment.
</Tip>

## Tracking Customer Transactions

Once your customers are created, you can monitor their information and make updates or deletions as needed.

### Retrieve the List of Customers

To get a complete list of customers registered on your FedaPay account, send a simple request to the API. This allows you to view all available customers, review their details, and track their transactions.

**Example request to retrieve customers**

<CodeGroup>
  ```java Curl theme={null}
   curl --request GET \
  --url https://sandbox-api.fedapay.com/v1/customers/{id} \
  --header 'Authorization: Bearer <token>'
  ```

  ```javascript NodeJs theme={null}
  const { FedaPay, Customer } = require('fedapay');
  /* Replace YOUR_SECRETE_API_KEY with your real API key */
  FedaPay.setApiKey("YOUR_SECRETE_API_KEY");
  /* Specify whether you want to run your query in test or live mode */
  FedaPay.setEnvironment('sandbox'); //or setEnvironment('live');
  /* Show customers */
  const customer = await Customer.all( params = {}, headers = {} );
  ```

  ```php PHP theme={null}
  \FedaPay\Fedapay::setApiKey(MY_API_KEY);
  /**
  * @var \FedaPay\FedaPayObject
  */
  $response = \FedaPay\Customer::all();
  $customers = $response->customers;
  $meta = $response->meta;
  ```

  ```ruby Ruby theme={null}
  require 'fedapay';
  # configure FedaPay library
  FedaPay.api_key = '' # Your secret api key
  FedaPay.environment = '' # sandbox or live
  customers = FedaPay::Customer.list;
  ```
</CodeGroup>

### Updating Customer Information

Sometimes, you may need to update a customer’s information (e.g., an incorrect email address or phone number). To do this, provide the customer ID and the updated information.

**Example of Updating a Customer**

<CodeGroup>
  ```java Curl theme={null}
   curl --request PUT \
  --url https://sandbox-api.fedapay.com/v1/customers/{id} \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{
  "email": "jsmith@example.com",
  "phone_number": {
    "number": 123,
    "country": "<string>"
  },
  "firstname": "<string>",
  "lastname": "<string>"
  }'
  ```

  ```javascript NodeJs theme={null}
  const { FedaPay, Customer } = require('fedapay');
  /* Replace YOUR_SECRETE_API_KEY with your real API key */
  FedaPay.setApiKey("YOUR_SECRETE_API_KEY");
  /* Specify whether you want to run your query in test or live mode */
  FedaPay.setEnvironment('sandbox'); //or setEnvironment('live');
  /* Modify customer */
  const customer = await Customer.update(ID, params = {}, headers = {});
  ```

  ```php PHP theme={null}
  \FedaPay\Fedapay::setApiKey(MY_API_KEY);
  $customer = \FedaPay\Customer::retrieve(ID);
  $customer->firstname = "Eric";
  $customer->save();
  // Or
  $customer = \FedaPay\Customer::update(ID, [
  "firstname" => "Eric"
  ]);
  ```

  ```ruby Ruby theme={null}
  require 'fedapay';
  # configure FedaPay library
  FedaPay.api_key = '' # Your secret api key
  FedaPay.environment = '' # sandbox or live
  customer.firstname = 'My Firstname';
  customer.save;
  # or use this method below
  customer.save fistname: 'My Firstname', lastname: 'My Lastname';
  # Update a customer by id
  customer = FedaPay::Customer.update ID, email: 'myemail@test.com';
  ```
</CodeGroup>

### Deleting a Customer

If a customer is no longer active or you wish to remove their data from your FedaPay account, you can use an API request to delete their information.

**Example of Deleting a Customer**

<CodeGroup>
  ```java Curl theme={null}
   curl --request DELETE \
  --url https://sandbox-api.fedapay.com/v1/customers/{id} \
  --header 'Authorization: Bearer <token>'
  ```

  ```javascript NodeJs theme={null}
  const { FedaPay, Customer } = require('fedapay');
  /* Replace YOUR_SECRETE_API_KEY with your real API key */
  FedaPay.setApiKey("YOUR_SECRETE_API_KEY");
  /* Specify whether you want to run your query in test or live mode */
  FedaPay.setEnvironment('sandbox'); //or setEnvironment('live');
  /* Delete customer */
  const customer = await Customer.delete(ID, params = {}, headers = {});
  ```

  ```php PHP theme={null}
  \FedaPay\Fedapay::setApiKey(MY_API_KEY);
  \FedaPay\Customer::delete(ID);
  ```

  ```ruby Ruby theme={null}
  require 'fedapay';
  # configure FedaPay library
  FedaPay.api_key = '' # Your secret api key
  FedaPay.environment = '' # sandbox or live
  customer.delete;
  ```
</CodeGroup>
