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

# Query Payment

> Payment gateway checks the existing payment status.

The following input parameters are expected to be provided by the merchant to verify transaction status or to obtain more details on the payment before approving the customer’s order.

> * **Live queries are conditional.** A provider is only queried in real time when the stored status is `Pending`, `Authorized`, or `InstallmentInProgress`. For any other stored status (already `Success`, `Failed`, etc.), the last known status is returned immediately without a provider round-trip.
> * **Querying by `SessionNumber` alone returns a session-level result, not one fixed transaction.** Up to 3 pending transactions under that session are checked in order; the first one found `Success` is returned. If none are, the response reflects the session's own status with `transactionNumber: null` rather than any individual transaction.

## Errors

In addition to standard signature errors, this endpoint can return:

| Code | Name                     | Meaning                                                               |
| ---- | ------------------------ | --------------------------------------------------------------------- |
| 2010 | `TransactionNotFound`    | Neither `transactionNumber` nor `sessionNumber` resolves to a record. |
| 2014 | `ChannelNotAllowedQuery` | The transaction's channel/provider does not support status queries.   |
| 2116 | `QueryProviderError`     | The live provider query failed, timed out, or threw an error.         |


## OpenAPI

````yaml /openapi.json get /api/services/app/PaymentGateway/Query
openapi: 3.0.1
info:
  title: CommercePay API
  version: v1
  description: >
    ---

    **Credentials Accounts**


    Every account is provided with separate keys for testing and for running
    live transactions. Once the merchant application has been approved,
    developers can begin the process of integrating the CommercePay API. The
    following details will be provided to get started with the integration. 


    <a href="https://docs.commercepay.asia/docs/api/d19b0f3289ae0-get-started"
    target="_blank">Get Started</a>
  contact: {}
servers:
  - description: Staging
    url: https://staging-payments.commerce.asia
  - url: https://payments.commerce.asia
    description: Production
security: []
paths:
  /api/services/app/PaymentGateway/Query:
    get:
      tags:
        - PaymentGateway
      summary: Query Payment
      description: >-
        Payment gateway checks the existing payment status.


        The following input parameters are expected to be provided by the
        merchant to verify transaction status or to obtain more details on the
        payment before approving the customer’s order.
      operationId: ApiServicesAppPaymentgatewayQueryGet
      parameters:
        - name: TransactionNumber
          in: query
          schema:
            type: string
            maxLength: 24
          description: >-
            Unique CommercePay Transaction Number **(Conditional: If it is query
            for specific transaction in either normal transaction or session
            transaction, then need pass the transaction number)**
        - name: Timestamp
          in: query
          schema:
            type: integer
            format: int64
            example: 1621851652617
          description: new Date().getTime()
        - $ref: '#/components/parameters/AbpTenantId'
        - $ref: '#/components/parameters/Authorization'
        - $ref: '#/components/parameters/CapSignature'
        - schema:
            type: string
            maxLength: 24
          in: query
          name: SessionNumber
          description: >-
            Unique CommercePay Session Number **(Conditional: If the query is
            query the session, then need pass the session number)**
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/QueryPaymentOutputDto'
              examples:
                Example Response:
                  value:
                    transactionNumber: string
                    paymentSessionNumber: string
                    referenceCode: string
                    status: 0
                    currencyCode: MYR
                    amount: 1000
                    channelId: 1
                    providerTransactionNumber: string
                    creationTime: '2022-02-10T08:50:30.565Z'
                    remark: string
                    providerChannelId: string
                    providerPaymentMethod: string
                    providerErrorMessage: string
                    loyaltyType: 1
                    redemptionPoint: 100
                    redemptionAmount: 100
                    rewardPoint: 100
                    paidAmount: 900
                    loyaltyRedemptionStatus: 0
                    loyaltyRewardStatus: 0
            text/json:
              schema:
                $ref: '#/components/schemas/QueryPaymentOutputDto'
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorOutputDto'
              examples:
                TransactionNotFound:
                  value:
                    code: 2010
                    message: >-
                      Neither transactionNumber nor sessionNumber resolves to a
                      record.
components:
  parameters:
    AbpTenantId:
      schema:
        type: string
      in: header
      name: Abp-TenantId
      required: true
      description: Your unique Merchant ID assigned by CommercePay.
    Authorization:
      schema:
        type: string
      in: header
      name: Authorization
      required: true
      description: Your API credentials used for authentication (typically a Bearer token).
    CapSignature:
      schema:
        type: string
      in: header
      name: cap-signature
      required: true
      description: >-
        A unique security hash used to verify the integrity of the request body.
        See [Generate Signature](/docs/generate-signature) for how to generate
        this.
  schemas:
    QueryPaymentOutputDto:
      type: object
      additionalProperties: false
      x-examples: {}
      properties:
        transactionNumber:
          type: string
          description: Unique CommercePay transaction number
          maxLength: 24
          nullable: true
        paymentSessionNumber:
          type: string
          description: Unique CommercePay session number
          maxLength: 24
          nullable: true
        referenceCode:
          type: string
          description: Merchant Reference Code
          maxLength: 50
          nullable: true
        status:
          $ref: '#/components/schemas/PaymentStatus'
        settlementStatus:
          $ref: '#/components/schemas/SettlementStatus'
        currencyCode:
          type: string
          description: Currency code with a 3-letter ISO 4217 standard code
          example: MYR
          maxLength: 3
          nullable: true
        amount:
          type: integer
          format: int64
          description: |
            This is Request Amount.
          example: 100
        channelId:
          type: integer
          format: int32
          description: >-
            Refer to endpoints in [Get Channel
            List](/api-reference/get-tenant-channels-by-country)
        providerTransactionNumber:
          type: string
          description: Provider Transaction Number
          nullable: true
        creationTime:
          type: string
          format: date-time
          description: Payment Transaction Creation Time
          example: '2022-02-10T08:50:30.565Z'
        remark:
          type: string
          description: >-
            A description that additional information or clarify details for the
            transaction.
          nullable: true
        providerChannelId:
          type: string
          description: An identifier that represents the payment provider channel
          nullable: true
        providerPaymentMethod:
          type: string
          description: Provider Payment Method
          nullable: true
        providerErrorMessage:
          type: string
          description: Provider Error Message
          nullable: true
        loyaltyType:
          $ref: '#/components/schemas/LoyaltyProviderType'
        loyaltyId:
          type: integer
          format: int32
          description: >-
            **[Conditional for Loyalty Payment]** Identifier of the loyalty
            provider used for this transaction.
          nullable: true
        redemptionPoint:
          type: integer
          format: int64
          description: '**[Conditional for Loyalty Payment]** Redemption Point.'
        redemptionAmount:
          type: integer
          format: int64
          description: '**[Conditional for Loyalty Payment]** Redemption Amount.'
        rewardPoint:
          type: integer
          format: int64
          description: '**[Conditional for Loyalty Payment]** Reward Point.'
        paidAmount:
          type: integer
          format: int64
          description: "**[Conditional for Loyalty Payment]** This is Paid Amount.\r\n"
          example: 100
        loyaltyRedemptionStatus:
          $ref: '#/components/schemas/LoyaltyRedemptionStatus'
        loyaltyRewardStatus:
          $ref: '#/components/schemas/LoyaltyRewardStatus'
    ErrorOutputDto:
      type: object
      additionalProperties: false
      properties:
        code:
          type: integer
          description: See the Errors table above.
        message:
          type: string
          nullable: true
    PaymentStatus:
      enum:
        - 0
        - 1
        - 2
        - 3
        - 4
        - 5
        - 6
        - 7
        - 8
        - 9
        - 10
        - 11
        - 12
        - 13
        - 14
        - 15
        - 16
        - 17
        - 18
        - 19
        - 20
      type: integer
      format: int32
      x-enumNames:
        - Pending
        - Success
        - Failed
        - Cancelled
        - TransactionLimitExceeded
        - MinTransactionAmountNotMeet
        - InsufficientFunds
        - InvalidTransaction
        - UserCancelled
        - Authorized
        - TransactionExpired
        - Refunded
        - ProcessingRefund
        - FailedRefund
        - ProcessingTimeOut
        - Verified
        - RefundWithCharges
        - RefundReverse
        - Voided
        - Cancelling
        - InstallmentInProgress
      description: >-
        | Value | Name | Meaning |

        | ----- | ---- | ------- |

        | 0 | `Pending` | Transaction is pending. |

        | 1 | `Success` | Transaction completed successfully. |

        | 2 | `Failed` | Transaction failed. |

        | 3 | `Cancelled` | Transaction was cancelled. |

        | 4 | `TransactionLimitExceeded` | Transaction exceeded the allowed
        limit. |

        | 5 | `MinTransactionAmountNotMeet` | Transaction amount is below the
        minimum allowed. |

        | 6 | `InsufficientFunds` | Customer's account had insufficient funds. |

        | 7 | `InvalidTransaction` | Transaction is invalid. |

        | 8 | `UserCancelled` | Customer abandoned or cancelled the transaction
        at the provider. |

        | 9 | `Authorized` | Pre-auth held, not yet captured. |

        | 10 | `TransactionExpired` | Transaction expired before completion. |

        | 11 | `Refunded` | Transaction was refunded. |

        | 12 | `ProcessingRefund` | Refund is being processed. |

        | 13 | `FailedRefund` | Refund attempt failed. |

        | 14 | `ProcessingTimeOut` | Provider did not respond in time. |

        | 15 | `Verified` | Transaction was verified. |

        | 16 | `RefundWithCharges` | Refunded, but provider/processing charges
        were deducted from the refunded amount. |

        | 17 | `RefundReverse` | A previously completed refund was reversed by
        the provider. |

        | 18 | `Voided` | Transaction was voided. |

        | 19 | `Cancelling` | Cancellation is in progress. |

        | 20 | `InstallmentInProgress` | Transaction is being processed as an
        installment plan. |
    SettlementStatus:
      title: SettlementStatus
      enum:
        - 0
        - 1
        - 2
        - 3
        - 4
      description: >-
        0 = Unsettled, 1 = Settled, 2 = InProgress, 3 = Locked, 4 =
        CompleteProcessing
    LoyaltyProviderType:
      title: LoyaltyProviderType
      enum:
        - 1
      description: |-
        **[Conditional for Loyalty Payment]**

        1 = BCard
    LoyaltyRedemptionStatus:
      title: LoyaltyRedemptionStatus
      enum:
        - 0
        - 1
        - 2
        - 3
      description: |-
        **[Conditional for Loyalty Payment]**

        0 = Pending, 1 = Success, 2 = Failed, 3 = Void
    LoyaltyRewardStatus:
      title: LoyaltyRewardStatus
      enum:
        - 0
        - 1
        - 2
        - 3
      description: |-
        **[Conditional for Loyalty Payment]**

        0 = Pending, 1 = Success, 2 = Failed, 3 = Void

````