Docs / Payments API / Create Payment

Create a Payment

v2.0 • Stable
POST https://api.mossen.com/v1/payments

Creates a new payment charge. Use this endpoint to accept payments from your customers using various payment methods including credit/debit cards, bank transfers, and digital wallets like Apple Pay and Google Pay.

Code Examples

curl -X POST https://api.mossen.com/v1/payments \
  -u sk_live_your_secret_key: \
  -H "Content-Type: application/json" \
  -d '{
    "amount": 1000,
    "currency": "gbp",
    "description": "Premium Subscription",
    "customer": {
      "email": "[email protected]",
      "name": "John Smith"
    },
    "payment_method": {
      "type": "card",
      "card": {
        "number": "4242424242424242",
        "exp_month": 12,
        "exp_year": 2028,
        "cvc": "123"
      }
    },
    "metadata": {
      "order_id": "ord_12345"
    }
  }'

Request Parameters

Body parameters for creating a payment. All parameters are sent as JSON in the request body.

Body Parameters

Parameter Type Required Description
amount integer Required Amount intended to be collected by this payment. A positive integer representing how much to charge in the smallest currency unit (e.g., 100 pence to charge £1.00). Minimum: 50 • Maximum: 99999999
currency string Required Three-letter ISO currency code, in lowercase. Must be a supported currency. Supported: gbp, usd, eur, and more
description string Optional An arbitrary string attached to the object. Often useful for displaying to users. Max length: 255 characters
customer object Optional Customer information associated with the payment. See customer object below
payment_method object Required Payment method details for this transaction. See payment method object below
metadata object Optional Set of key-value pairs that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Max 50 keys, key names up to 40 chars, values up to 500 chars
capture boolean Optional Whether to immediately capture the payment. If false, the payment is authorized but not captured. Use the capture endpoint later to capture it. Default: true
statement_descriptor string Optional For card payments, the statement descriptor explains the charge on the customer's statement. Max 22 characters

Customer Object

Parameter Type Required Description
email string Optional Customer's email address.
name string Optional Customer's full name.
phone string Optional Customer's phone number.

Response

200 OK - Successful response

Returns a payment object if the request succeeded. If the payment fails, an error object is returned instead.

{
  "id": "pay_mossen_abc123def456",
  "object": "payment",
  "amount": 1000,
  "currency": "gbp",
  "status": "succeeded",
  "description": "Premium Subscription",
  "capture": true,
  "amount_captured": 1000,
  "statement_descriptor": "MOSSEN * SUBSCRIPTION",
  "customer": {
    "id": "cus_mossen_xyz789",
    "email": "[email protected]",
    "name": "John Smith"
  },
  "payment_method": {
    "type": "card",
    "card": {
      "brand": "visa",
      "last4": "4242",
      "exp_month": 12,
      "exp_year": 2028,
      "country": "GB"
    }
  },
  "metadata": {
    "order_id": "ord_12345"
  },
  "created": 1719820800,
  "updated": 1719820801,
  "livemode": true
}

Errors

The following errors can occur when creating a payment:

Error Code Status Description
amount_too_small 400 The payment amount is below the minimum allowed amount for the currency.
amount_too_large 400 The payment amount exceeds the maximum allowed amount.
invalid_currency 400 The specified currency is not supported.
card_declined 402 The card was declined. The card issuer may have declined the charge for various reasons.
expired_card 402 The card has expired. Ask the customer to use a different card or update their card details.
incorrect_cvc 402 The CVC number is incorrect. Ask the customer to verify their card's security code.
authentication_required 402 The payment requires 3D Secure authentication. Redirect the customer to complete authentication.
api_key_invalid 401 The API key provided is invalid or has been revoked.
rate_limit_exceeded 429 Too many requests have been made. Please wait and try again.

Error Response Example

{
  "error": {
    "code": "card_declined",
    "message": "Your card was declined.",
    "type": "card_error",
    "param": "payment_method",
    "decline_code": "generic_decline"
  }
}