{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/benjipays-com/json-schema/benjipays-com-payment-method-with-mandate-schema.json",
  "title": "PaymentMethodWithMandate",
  "description": "Saved payment method with its authorization mandate",
  "x-generated": "2026-11-02",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/benjipays-com-benji-pays-merchant-api-openapi.yml#/components/schemas/PaymentMethodWithMandate",
  "type": "object",
  "properties": {
    "id": {
      "type": "string",
      "description": "Payment method identifier (profile `_id`)"
    },
    "accountingCompanyId": {
      "description": "Accounting company ID",
      "type": "string"
    },
    "customerId": {
      "description": "Accounting system customer ID this payment method belongs to",
      "type": "string"
    },
    "accountingType": {
      "description": "Accounting platform type (e.g. quickbooks, xero)",
      "type": "string"
    },
    "gatewayProcessor": {
      "description": "Payment processor identifier (public key, e.g. `benjipayments`)",
      "type": "string"
    },
    "gatewayId": {
      "description": "Gateway store identifier",
      "type": "string"
    },
    "gatewayCustomerId": {
      "description": "Processor-specific customer ID",
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "vaultToken": {
      "description": "Processor payment-method token (e.g. Moneris data key, Stripe `pm_…` id), or `null` if none. Treat as sensitive.",
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "customerName": {
      "description": "Accounting customer display name (denormalized from the linked customer onto the profile)",
      "type": "string"
    },
    "maskedPan": {
      "description": "Masked card or bank account number",
      "type": "string"
    },
    "expiryMonth": {
      "description": "Card expiry month (CC only)",
      "type": "string"
    },
    "expiryYear": {
      "description": "Card expiry year (CC only)",
      "type": "string"
    },
    "cardBrand": {
      "description": "Card brand, e.g. Visa, Mastercard (CC only)",
      "type": "string"
    },
    "paymentType": {
      "type": "string",
      "description": "Payment type, defaults to \"cc\""
    },
    "isDebitCard": {
      "description": "Whether the card is a debit card (CC only, defaults to false)",
      "type": "boolean"
    },
    "autoPayEnabled": {
      "type": "boolean",
      "description": "Whether autopay is enabled (enabled and not fuse-blown)"
    },
    "autoPayPriority": {
      "description": "Processing priority when multiple methods exist",
      "type": "number"
    },
    "benjiSurchargeEnabled": {
      "type": "boolean",
      "description": "Whether Benji surcharging is enabled (!surchargingDisabled)"
    },
    "note": {
      "type": "string"
    },
    "declineCount": {
      "type": "number",
      "description": "Number of declines, defaults to 0"
    },
    "lastDeclineDate": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "creatorIpAddress": {
      "type": "string"
    },
    "createdDate": {
      "type": "string"
    },
    "lastModifiedDate": {
      "type": "string"
    },
    "mandate": {
      "anyOf": [
        {
          "$ref": "#/$defs/Mandate"
        },
        {
          "type": "null"
        }
      ],
      "description": "Authorization mandate for this payment method, or null when none was captured"
    }
  },
  "required": [
    "id",
    "paymentType",
    "autoPayEnabled",
    "benjiSurchargeEnabled",
    "declineCount",
    "mandate"
  ],
  "additionalProperties": false,
  "$defs": {
    "Mandate": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "description": "Mandate identifier"
        },
        "acceptedAt": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "description": "When the customer accepted off-session billing authorization (ISO-8601)"
        },
        "ip": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "description": "IP address recorded at acceptance"
        },
        "type": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "description": "Where the customer agreed: `web-app`, `payment-portal`, `customer-portal`, `api`, `billing-profile`, or `advanced-notification`."
        },
        "agreement": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "description": "Authorization text the customer agreed to"
        },
        "loginName": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "description": "Portal user name, if the mandate was accepted by a logged-in portal user"
        },
        "loginEmail": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "description": "Portal user email, if the mandate was accepted by a logged-in portal user"
        }
      },
      "required": [
        "id",
        "acceptedAt",
        "ip",
        "type",
        "agreement",
        "loginName",
        "loginEmail"
      ],
      "additionalProperties": false,
      "description": "Off-session billing authorization mandate, e.g. for chargeback defense (Stripe accepted_at/IP)"
    }
  }
}