# Fetch Pay Request

# tyro.fetchPayRequest()

Retrieves the PayRequest status, you should fetch the Pay Request and show the result to your customers.

## Response

The Pay Request object returned.


```json
{
  "$ref": "#/components/schemas/pay-request-response",
  "components": {
    "schemas": {
      "money-positive-aud": {
        "title": "Money Positive Amount",
        "type": "object",
        "properties": {
          "amount": {
            "type": "integer",
            "description": "This is the amount in smallest currency unit. e.g 12520 (in cents) is $125.20",
            "example": 12520,
            "minimum": 0
          },
          "currency": {
            "type": "string",
            "default": "AUD",
            "enum": [
              "AUD"
            ],
            "example": "AUD",
            "description": "This is always AUD"
          }
        },
        "required": [
          "amount",
          "currency"
        ]
      },
      "transaction-result": {
        "title": "Transaction Result",
        "type": "object",
        "properties": {
          "merchant": {
            "type": "string",
            "description": "Merchant for this transaction"
          },
          "authentication": {
            "type": "object",
            "description": "3ds authentication details for this transaction",
            "properties": {
              "accessControlServerEci": {
                "type": "string"
              },
              "accessControlServerTransactionId": {
                "type": "string"
              },
              "acceptVersions": {
                "type": "string"
              },
              "amount": {
                "type": "string"
              },
              "additionalInfo": {
                "type": "string"
              },
              "authenticationToken": {
                "type": "string"
              },
              "3dsServerTransactionId": {
                "type": "string"
              },
              "channel": {
                "type": "string"
              },
              "directoryServerId": {
                "type": "string"
              },
              "directoryServerTransactionId": {
                "type": "string"
              },
              "method": {
                "type": "string"
              },
              "methodCompleted": {
                "type": "string"
              },
              "methodSupported": {
                "type": "string",
                "enum": [
                  "SUPPORTED",
                  "NOT_SUPPORTED"
                ]
              },
              "payerInteraction": {
                "type": "string"
              },
              "protocolVersion": {
                "type": "string"
              },
              "redirectedDomainName": {
                "type": "string"
              },
              "requestorId": {
                "type": "string"
              },
              "requestorName": {
                "type": "string"
              },
              "statusReasonCode": {
                "type": "string"
              },
              "transactionId": {
                "type": "string"
              },
              "transactionStatus": {
                "type": "string",
                "enum": [
                  "YES",
                  "NO",
                  "UNAVAILABLE",
                  "ATTEMPTED",
                  "CHALLENGE",
                  "REJECTED",
                  "DECOUPLED",
                  "INFORMATIONAL"
                ]
              },
              "time": {
                "type": "string"
              },
              "version": {
                "type": "string"
              }
            }
          },
          "order": {
            "type": "object",
            "description": "Order for this transaction",
            "properties": {
              "id": {
                "type": "string"
              },
              "status": {
                "type": "string"
              },
              "currency": {
                "type": "string"
              },
              "reference": {
                "type": "string"
              },
              "amount": {
                "type": "number"
              },
              "authorisedAmount": {
                "type": "number"
              },
              "capturedAmount": {
                "type": "number"
              },
              "refundedAmount": {
                "type": "number"
              },
              "merchantCurrency": {
                "type": "string"
              },
              "merchantAmount": {
                "type": "number"
              },
              "createdAt": {
                "type": "string"
              },
              "updatedAt": {
                "type": "string"
              }
            }
          },
          "card": {
            "type": "object",
            "description": "Card used for this transaction",
            "properties": {
              "brand": {
                "type": "string"
              },
              "scheme": {
                "type": "string"
              },
              "expiry": {
                "type": "object",
                "properties": {
                  "month": {
                    "type": "string"
                  },
                  "year": {
                    "type": "string"
                  }
                }
              },
              "nameOnCard": {
                "type": "string"
              },
              "number": {
                "type": "string"
              },
              "fundingMethod": {
                "type": "string"
              },
              "firstSixDigits": {
                "type": "string"
              },
              "lastFourDigits": {
                "type": "string"
              }
            }
          },
          "operationResult": {
            "type": "object",
            "description": "The result of this operation",
            "properties": {
              "result": {
                "type": "string",
                "enum": [
                  "FAILURE",
                  "PENDING",
                  "SUCCESS",
                  "UNKNOWN"
                ]
              },
              "acquirerCode": {
                "type": "string"
              },
              "gatewayCode": {
                "type": "string"
              },
              "authorisationCode": {
                "type": "string"
              },
              "errorCode": {
                "type": "string"
              },
              "errorMessage": {
                "type": "string"
              }
            }
          },
          "transaction": {
            "type": "object",
            "description": "The transaction for the operation",
            "properties": {
              "id": {
                "type": "string"
              },
              "type": {
                "type": "string"
              },
              "amount": {
                "type": "number"
              },
              "currency": {
                "type": "string"
              },
              "retrievalReferenceNumber": {
                "type": "string"
              },
              "acquirer": {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "string"
                  },
                  "merchantId": {
                    "type": "string"
                  },
                  "additionalResponse": {
                    "type": "string"
                  }
                }
              }
            }
          }
        }
      },
      "pay-request-response": {
        "title": "Pay Request Response",
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "The ID of the Pay Request generated by Tyro."
          },
          "paySecret": {
            "type": "string",
            "description": "The Pay Secret associated with this Pay Request. This is used by the frontend to submit the Pay Request. Pay Secret expire after 24 hours from the time the Pay Request was created. It’s recommended to avoid logging or storing the pay secret for security reasons."
          },
          "locationId": {
            "type": "string",
            "description": "The id of the location as specified by the Tyro Connect system"
          },
          "provider": {
            "type": "object",
            "description": "Details about the provider that processed the payment.",
            "properties": {
              "name": {
                "type": "string",
                "description": "The name of the provider that processed the payment. More providers will be supported at a later date.",
                "enum": [
                  "TYRO"
                ]
              },
              "method": {
                "type": "string",
                "description": "The payment method used",
                "enum": [
                  "CARD"
                ]
              }
            }
          },
          "origin": {
            "description": "Contains information about the partner that created the Pay Request.",
            "type": "object",
            "properties": {
              "orderId": {
                "type": "string",
                "maxLength": 50,
                "description": "An identifier that has been generated by the origin. This can be used for reconciliation of orders in the app partner’s system."
              },
              "orderReference": {
                "type": "string",
                "description": "Easily identifiable reference for the order."
              },
              "name": {
                "type": "string",
                "description": "Name of the app partner that created the Pay Request."
              }
            }
          },
          "payMethod": {
            "description": "The Pay Method details for the Pay Request",
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "description": "The id of the Pay Method attached to the Pay Request."
              },
              "customerId": {
                "type": "string",
                "description": "The Tyro generated ID of the customer linked to the Pay Method."
              },
              "save": {
                "type": "boolean",
                "description": "When set to true, the pay method will be saved after a successful payment."
              }
            }
          },
          "capture": {
            "type": "object",
            "properties": {
              "method": {
                "type": "string",
                "description": "- `AUTOMATIC` (default) - captures the funds upon Pay Request submission.\n- `MANUAL` - can be used to put funds on hold and only authorise the payment, with the funds captured later.\n- `MANUAL_ESTIMATED` - can be used when you want to authorise an estimated amount, with the funds captured later. With this option, you can update the authorised amount before capture or expiration.\n",
                "enum": [
                  "AUTOMATIC",
                  "MANUAL",
                  "MANUAL_ESTIMATED"
                ]
              },
              "total": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/money-positive-aud"
                  },
                  {
                    "description": "The total amount to capture (in smallest currency unit). You cannot capture more than the authorised amount."
                  }
                ]
              }
            }
          },
          "status": {
            "type": "string",
            "description": "The current status of this Pay Request managed by Tyro.",
            "enum": [
              "AWAITING_PAYMENT_INPUT",
              "AWAITING_AUTHENTICATION",
              "PROCESSING",
              "SUCCESS",
              "FAILED",
              "VOIDED",
              "PARTIALLY_REFUNDED",
              "REFUNDED"
            ]
          },
          "supportedNetworks": {
            "type": "array",
            "description": "List of supported card type/brand/networks for this Pay Request. If null it is unrestricted.",
            "items": {
              "type": "string",
              "enum": [
                "visa",
                "mastercard",
                "amex",
                "jcb",
                "maestro",
                "diners"
              ]
            }
          },
          "total": {
            "allOf": [
              {
                "$ref": "#/components/schemas/money-positive-aud"
              },
              {
                "description": "The total amount (in smallest currency unit)"
              }
            ]
          },
          "transactionResults": {
            "type": "array",
            "description": "List of Transaction Results",
            "items": {
              "$ref": "#/components/schemas/transaction-result"
            }
          },
          "threeDSecureDetails": {
            "type": "object",
            "description": "3D Secure details for this Pay Request",
            "properties": {
              "status": {
                "type": "string",
                "description": "Current 3D Secure status for this Pay Request",
                "enum": [
                  "AWAITING_3DS_METHOD",
                  "AWAITING_AUTH",
                  "AWAITING_CHALLENGE",
                  "AWAITING_CHALLENGE_RESULT",
                  "SUCCESS",
                  "FAILED"
                ],
                "example": "AWAITING_3DS_METHOD"
              }
            }
          },
          "additionalData": {
            "type": "object",
            "description": "Additional data for this transaction",
            "properties": {
              "customerIP": {
                "type": "string",
                "example": "127.0.0.1"
              }
            }
          }
        }
      }
    }
  }
}
```

## Implementation


```javascript
// Javascript sample code
async function showPaymentResult() {
  const paySecret = new URLSearchParams(window.location.search).get(
    "paySecret"
  );

  if (!paySecret) {
    return;
  }

  const tyro = Tyro();
  await tyro.init(paySecret);

  const payRequest = await tyro.fetchPayRequest();

  switch (payRequest.status) {
    case "PROCESSING":
      return showProcessing();
    case "SUCCESS":
      return showSuccess();
    case "FAILED":
      return showFail();
    ...
  }
}
```