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

# mapi.php (direct create payment compatibility endpoint)

> Creates (or reuses) an order directly and returns Epay-style response fields.
For QR-style channels, response includes `qrcode` and `img`.
For redirect-style channels, response includes `payurl`.

Signature algorithm:
1. Remove `sign` and `sign_type`, and drop empty values.
2. Sort parameters by key in ascending order.
3. Join as `k=v` with `&`, append merchant API key.
4. MD5 the final string and compare in lowercase.




## OpenAPI

````yaml /openapi.yaml post /epay/mapi.php
openapi: 3.1.0
info:
  title: Kyren Pay API
  description: >
    The Kyren Pay API enables merchants to accept payments from customers
    worldwide.

    Integrate checkout sessions, manage products, track orders, and handle
    webhooks.


    **Data types**: The API uses the following types for request/response data:

    - **string**: For text, identifiers, and **all amount/price fields** (e.g.
    `price`, `amount`, `platformFee`, `available`)
      to avoid floating-point precision issues. Use decimal format like `"9.99"`.
    - **integer**: For counts, pagination, and timestamps

    - **timestamp**: Unix timestamp in milliseconds (integer) for all time
    fields (e.g. `createdAt`, `paidAt`, `expiresAt`).
      Time parameters (e.g. `startDate`, `endDate`) also use Unix milliseconds.
  version: 1.0.0
  contact:
    name: Kyren Pay Support
    email: support@kyren.top
    url: https://kyren.top
servers:
  - url: https://api.kyren.top
    description: Production
  - url: https://staging-api.kyren.top
    description: Staging, available only with credentials issued by Kyren
security:
  - ApiKeyAuth: []
tags:
  - name: Config
    description: Retrieve platform configuration such as supported currencies.
  - name: Products
    description: Create and manage products that represent the goods or services you sell.
  - name: Checkouts
    description: Create checkout sessions to collect payments from your customers.
  - name: Orders
    description: View and manage orders created from completed checkout sessions.
  - name: Balance
    description: View your account balance and transaction history.
  - name: Epay Compatibility
    description: >
      Compatibility endpoints for existing integrations built on 易支付 API
      conventions.

      These endpoints use form/query parameters with `pid + sign` verification
      (MD5), not `x-api-key` header auth.
paths:
  /epay/mapi.php:
    post:
      tags:
        - Epay Compatibility
      summary: mapi.php (direct create payment compatibility endpoint)
      description: >
        Creates (or reuses) an order directly and returns Epay-style response
        fields.

        For QR-style channels, response includes `qrcode` and `img`.

        For redirect-style channels, response includes `payurl`.


        Signature algorithm:

        1. Remove `sign` and `sign_type`, and drop empty values.

        2. Sort parameters by key in ascending order.

        3. Join as `k=v` with `&`, append merchant API key.

        4. MD5 the final string and compare in lowercase.
      operationId: createEpayMapi
      requestBody:
        required: true
        content:
          application/x-www-form-urlencoded:
            schema:
              $ref: '#/components/schemas/EpayMapiRequest'
            example:
              pid: merch_001
              type: wxpay
              out_trade_no: order_20260409002
              notify_url: https://merchant.example.com/pay/notify
              return_url: https://merchant.example.com/pay/return
              name: AI Credits 1000
              money: '9.99'
              money_type: CNY
              display_merchant_name: Campaign Store
              param: user_42
              clientip: 203.0.113.9
              device: pc
              sign: 1ce4f4f5294ec4c95f6b79ff79dbb57b
              sign_type: MD5
      responses:
        '200':
          description: Epay-compatible create payment result
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EpayMapiResponse'
              examples:
                successQr:
                  summary: QR payment response
                  value:
                    code: 1
                    trade_no: order_epay_001
                    out_trade_no: order_20260409002
                    qrcode: weixin://wxpay/bizpayurl?pr=xxxx
                    img: >-
                      https://api.qrserver.com/v1/create-qr-code/?size=240x240&data=weixin%3A%2F%2Fwxpay%2Fbizpayurl%3Fpr%3Dxxxx
                successRedirect:
                  summary: Redirect payment response
                  value:
                    code: 1
                    trade_no: order_epay_002
                    out_trade_no: order_20260409003
                    payurl: https://payment.kyren.io/epay/redirect/order_epay_002
                error:
                  summary: Error response
                  value:
                    code: 0
                    msg: 订单 order_20260409002 正在创建中，请稍后重试
      security: []
components:
  schemas:
    EpayMapiRequest:
      type: object
      required:
        - pid
        - type
        - out_trade_no
        - notify_url
        - name
        - money
        - clientip
        - sign
        - sign_type
      properties:
        pid:
          type: string
          description: Merchant ID
        type:
          $ref: '#/components/schemas/EpayPaymentType'
        out_trade_no:
          type: string
          description: Merchant order number (must be unique under one merchant)
        notify_url:
          type: string
          format: uri
          description: Merchant async callback URL
        return_url:
          type: string
          format: uri
          description: Merchant sync return URL
        name:
          type: string
          description: Product name
        money:
          type: string
          description: Order amount, decimal string, must be greater than 0
        money_type:
          type: string
          default: CNY
          description: Currency code. Defaults to CNY when omitted.
        param:
          type: string
          description: Pass-through parameter returned in callbacks and order queries
        display_merchant_name:
          type: string
          maxLength: 80
          description: >-
            Optional per-payment merchant display name shown on Kyren
            intermediate payment pages
        clientip:
          type: string
          description: Client IP address
        device:
          type: string
          default: pc
          description: Device identifier passed to gateway (e.g. pc)
        channel_param:
          type: string
          description: |
            Optional JSON string for channel-specific fields.
            Credit card mode supports fields such as:
            `cardNo`, `cardExpireMonth`, `cardExpireYear`, `cardSecurityCode`,
            `billFirstName`, `billLastName`, `billPhone`, `billAddress`,
            `billCountry`, `billState`, `billCity`, `billZip`, `email`.
        sign:
          type: string
          description: Lowercase MD5 signature
        sign_type:
          $ref: '#/components/schemas/EpaySignType'
    EpayMapiResponse:
      oneOf:
        - $ref: '#/components/schemas/EpayMapiSuccessResponse'
        - $ref: '#/components/schemas/EpaySimpleResponse'
    EpayPaymentType:
      type: string
      enum:
        - alipay
        - wxpay
        - creditcard
        - crypto
        - paynow
      description: Payment channel type in Epay compatibility mode.
    EpaySignType:
      type: string
      enum:
        - MD5
      description: Signature type. Current compatibility implementation only supports MD5.
    EpayMapiSuccessResponse:
      type: object
      properties:
        code:
          type: integer
          enum:
            - 1
        trade_no:
          type: string
          description: Platform order ID
        out_trade_no:
          type: string
          description: Merchant order number
        payurl:
          type: string
          nullable: true
          description: Redirect URL for browser/app payment flows
        qrcode:
          type: string
          nullable: true
          description: QR code payload or H5 payment URL depending on channel
        img:
          type: string
          nullable: true
          description: QR image URL generated from `qrcode`
    EpaySimpleResponse:
      type: object
      properties:
        code:
          type: integer
          enum:
            - 0
        msg:
          type: string
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key
      description: >
        Your API key. Public production API-key endpoints accept `kyren_live_*`
        keys. Staging credentials are environment-specific and must be used only
        with the staging environment for which Kyren issued them.

````