> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.senjaropay.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.senjaropay.com/_mcp/server.

# Create card payment

POST https://api.senjaropay.com/senjaropay/merchant/card/pay
Content-Type: application/json

Opens a hosted card checkout. Redirect the customer to data.checkout_url.
Send a new UUID in x-idempotency-key for every payment. Reuse that key only
when retrying the same create request.


Reference: https://docs.senjaropay.com/api-documentation/card-payments/create-card-payment

## Authentication

- `x-api-key` header (required) — API Key authentication via header
- `x-api-secret` header (required) — API Key authentication via header

## Request

### Headers

- `x-idempotency-key` (string, required) — Unique per payment. Generate a new UUID for each transaction (for example crypto.randomUUID() or a uuid library). Reuse the same value only to retry this exact request.

### Body (application/json)

This endpoint expects a CardPayRequest.

- `payment_type` (enum, required)
  - Allowed values: `card`
- `details` (PaymentDetails, required)
- `customer` (CardCustomer, required)
- `webhook_url` (string, required) — HTTPS endpoint that receives the payment result.

## Response

### 200

Checkout session created

- `status` (string, required)
- `code` (integer, required)
- `data` (CardPayResponseData, required)

## Errors

### 400 Bad Request Error

Validation error

- `status` (string, optional)
- `code` (integer, optional)
- `error_code` (string, optional)
- `message` (string, optional)

### 401 Unauthorized Error

Unauthorized

- `status` (string, optional)
- `code` (integer, optional)
- `error_code` (string, optional)
- `message` (string, optional)

## Types

### PaymentDetails

- `amount` (integer, required)
- `currency` (string, required)

### CardCustomer

- `firstname` (string, required)
- `lastname` (string, required)
- `phone_number` (string, required) — MSISDN in international format, digits only.
- `email` (string, required)
- `country` (string, required)
- `city` (string, required)
- `address` (string, required)

### CardPayResponseData

- `amount` (CardAmount, optional)
- `expires_at` (datetime, optional) — When the hosted checkout session stops accepting payment.
- `object` (string, optional)
- `payment_type` (string, optional)
- `reference` (string, optional) — Store this value. It is the key for webhooks and status checks.
- `status` (string, optional) — Initial checkout state. Do not fulfill an order while this is pending.
- `checkout_url` (string, optional) — Redirect the customer here to enter card details.

### CardAmount

- `currency` (string, optional)
- `value` (integer, optional)

## Examples

**Request**

```json
{
  "payment_type": "card",
  "details": {
    "amount": 1000,
    "currency": "TZS"
  },
  "customer": {
    "firstname": "John",
    "lastname": "Customer",
    "phone_number": "255740000001",
    "email": "test.customer@example.com",
    "country": "Tanzania",
    "city": "Dar es Salaam",
    "address": "Sample Street"
  },
  "webhook_url": "https://example.com/webhooks/senjaropay/mock-callback"
}
```

**Response**

```json
{
  "status": "success",
  "code": 200,
  "data": {
    "amount": {
      "currency": "TZS",
      "value": 1000
    },
    "expires_at": "2026-09-28T09:30:16.066Z",
    "object": "payment",
    "payment_type": "card",
    "reference": "CARD-CK7EVXQVK7CP",
    "status": "pending",
    "checkout_url": "https://cardpay.com/MI/payment.html?uuid=GgffdGF52eg6gA2AFd64Dchf"
  }
}
```

**SDK Code**

```python card_createCardPayment_example
import requests

url = "https://api.senjaropay.com/senjaropay/merchant/card/pay"

payload = {
    "payment_type": "card",
    "details": {
        "amount": 1000,
        "currency": "TZS"
    },
    "customer": {
        "firstname": "John",
        "lastname": "Customer",
        "phone_number": "255740000001",
        "email": "test.customer@example.com",
        "country": "Tanzania",
        "city": "Dar es Salaam",
        "address": "Sample Street"
    },
    "webhook_url": "https://example.com/webhooks/senjaropay/mock-callback"
}
headers = {
    "x-idempotency-key": "7c9e6679-7425-40de-944b-e07fc1f90ae7",
    "x-api-key": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript card_createCardPayment_example
const url = 'https://api.senjaropay.com/senjaropay/merchant/card/pay';
const options = {
  method: 'POST',
  headers: {
    'x-idempotency-key': '7c9e6679-7425-40de-944b-e07fc1f90ae7',
    'x-api-key': '<apiKey>',
    'Content-Type': 'application/json'
  },
  body: '{"payment_type":"card","details":{"amount":1000,"currency":"TZS"},"customer":{"firstname":"John","lastname":"Customer","phone_number":"255740000001","email":"test.customer@example.com","country":"Tanzania","city":"Dar es Salaam","address":"Sample Street"},"webhook_url":"https://example.com/webhooks/senjaropay/mock-callback"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go card_createCardPayment_example
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.senjaropay.com/senjaropay/merchant/card/pay"

	payload := strings.NewReader("{\n  \"payment_type\": \"card\",\n  \"details\": {\n    \"amount\": 1000,\n    \"currency\": \"TZS\"\n  },\n  \"customer\": {\n    \"firstname\": \"John\",\n    \"lastname\": \"Customer\",\n    \"phone_number\": \"255740000001\",\n    \"email\": \"test.customer@example.com\",\n    \"country\": \"Tanzania\",\n    \"city\": \"Dar es Salaam\",\n    \"address\": \"Sample Street\"\n  },\n  \"webhook_url\": \"https://example.com/webhooks/senjaropay/mock-callback\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("x-idempotency-key", "7c9e6679-7425-40de-944b-e07fc1f90ae7")
	req.Header.Add("x-api-key", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby card_createCardPayment_example
require 'uri'
require 'net/http'

url = URI("https://api.senjaropay.com/senjaropay/merchant/card/pay")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["x-idempotency-key"] = '7c9e6679-7425-40de-944b-e07fc1f90ae7'
request["x-api-key"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"payment_type\": \"card\",\n  \"details\": {\n    \"amount\": 1000,\n    \"currency\": \"TZS\"\n  },\n  \"customer\": {\n    \"firstname\": \"John\",\n    \"lastname\": \"Customer\",\n    \"phone_number\": \"255740000001\",\n    \"email\": \"test.customer@example.com\",\n    \"country\": \"Tanzania\",\n    \"city\": \"Dar es Salaam\",\n    \"address\": \"Sample Street\"\n  },\n  \"webhook_url\": \"https://example.com/webhooks/senjaropay/mock-callback\"\n}"

response = http.request(request)
puts response.read_body
```

```java card_createCardPayment_example
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.senjaropay.com/senjaropay/merchant/card/pay")
  .header("x-idempotency-key", "7c9e6679-7425-40de-944b-e07fc1f90ae7")
  .header("x-api-key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"payment_type\": \"card\",\n  \"details\": {\n    \"amount\": 1000,\n    \"currency\": \"TZS\"\n  },\n  \"customer\": {\n    \"firstname\": \"John\",\n    \"lastname\": \"Customer\",\n    \"phone_number\": \"255740000001\",\n    \"email\": \"test.customer@example.com\",\n    \"country\": \"Tanzania\",\n    \"city\": \"Dar es Salaam\",\n    \"address\": \"Sample Street\"\n  },\n  \"webhook_url\": \"https://example.com/webhooks/senjaropay/mock-callback\"\n}")
  .asString();
```

```php card_createCardPayment_example
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.senjaropay.com/senjaropay/merchant/card/pay', [
  'body' => '{
  "payment_type": "card",
  "details": {
    "amount": 1000,
    "currency": "TZS"
  },
  "customer": {
    "firstname": "John",
    "lastname": "Customer",
    "phone_number": "255740000001",
    "email": "test.customer@example.com",
    "country": "Tanzania",
    "city": "Dar es Salaam",
    "address": "Sample Street"
  },
  "webhook_url": "https://example.com/webhooks/senjaropay/mock-callback"
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'x-api-key' => '<apiKey>',
    'x-idempotency-key' => '7c9e6679-7425-40de-944b-e07fc1f90ae7',
  ],
]);

echo $response->getBody();
```

```csharp card_createCardPayment_example
using RestSharp;

var client = new RestClient("https://api.senjaropay.com/senjaropay/merchant/card/pay");
var request = new RestRequest(Method.POST);
request.AddHeader("x-idempotency-key", "7c9e6679-7425-40de-944b-e07fc1f90ae7");
request.AddHeader("x-api-key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"payment_type\": \"card\",\n  \"details\": {\n    \"amount\": 1000,\n    \"currency\": \"TZS\"\n  },\n  \"customer\": {\n    \"firstname\": \"John\",\n    \"lastname\": \"Customer\",\n    \"phone_number\": \"255740000001\",\n    \"email\": \"test.customer@example.com\",\n    \"country\": \"Tanzania\",\n    \"city\": \"Dar es Salaam\",\n    \"address\": \"Sample Street\"\n  },\n  \"webhook_url\": \"https://example.com/webhooks/senjaropay/mock-callback\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift card_createCardPayment_example
import Foundation

let headers = [
  "x-idempotency-key": "7c9e6679-7425-40de-944b-e07fc1f90ae7",
  "x-api-key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "payment_type": "card",
  "details": [
    "amount": 1000,
    "currency": "TZS"
  ],
  "customer": [
    "firstname": "John",
    "lastname": "Customer",
    "phone_number": "255740000001",
    "email": "test.customer@example.com",
    "country": "Tanzania",
    "city": "Dar es Salaam",
    "address": "Sample Street"
  ],
  "webhook_url": "https://example.com/webhooks/senjaropay/mock-callback"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.senjaropay.com/senjaropay/merchant/card/pay")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```