/** * PayPal Server SDKLib * * This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ). */ import { ApiResponse, RequestOptions } from '../core.js'; import { BalancesResponse, balancesResponseSchema, } from '../models/balancesResponse.js'; import { SearchResponse, searchResponseSchema, } from '../models/searchResponse.js'; import { number, optional, string } from '../schema.js'; import { BaseController } from './baseController.js'; import { DefaultError } from '../errors/defaultError.js'; import { SearchError } from '../errors/searchError.js'; export class TransactionSearchController extends BaseController { /** * Lists transactions. Specify one or more query parameters to filter the transaction that appear in * the response. Notes: If you specify one or more optional query parameters, the ending_balance * response field is empty. It takes a maximum of three hours for executed transactions to appear in * the list transactions call. This call lists transaction for the previous three years. * * @param startDate Filters the transactions in the response by a start date and time, * in [Internet date and time format](https://tools.ietf. * org/html/rfc3339#section-5.6). Seconds are required. Fractional * seconds are optional. * @param endDate Filters the transactions in the response by an end date and time, * in [Internet date and time format](https://tools.ietf. * org/html/rfc3339#section-5.6). Seconds are required. Fractional * seconds are optional. The maximum supported range is 31 days. * @param transactionId Filters the transactions in the response by a PayPal transaction * ID. A valid transaction ID is 17 characters long, except for an * order ID, which is 19 characters long. Note: A transaction ID is * not unique in the reporting system. The response can list two * transactions with the same ID. One transaction can be balance * affecting while the other is non-balance affecting. * @param transactionType Filters the transactions in the response by a PayPal transaction * event code. See [Transaction event * codes](/docs/integration/direct/transaction-search/transaction- * event-codes/). * @param transactionStatus Filters the transactions in the response by a PayPal transaction * status code. Value is: Status code Description D PayPal or * merchant rules denied the transaction. P The transaction is * pending. The transaction was created but waits for another payment * process to complete, such as an ACH transaction, before the status * changes to S. S The transaction successfully completed without a * denial and after any pending statuses. V A successful transaction * was reversed and funds were refunded to the original sender. * @param transactionAmount Filters the transactions in the response by a gross transaction * amount range. Specify the range as ` TO `, where ` ` is the lower * limit of the gross PayPal transaction amount and ` ` is the upper * limit of the gross transaction amount. Specify the amounts in * lower denominations. For example, to search for transactions from * $5.00 to $10.05, specify `[500 TO 1005]`. Note:The values must be * URL encoded. * @param transactionCurrency Filters the transactions in the response by a [three-character * ISO-4217 currency code](/api/rest/reference/currency-codes/) for * the PayPal transaction currency. * @param paymentInstrumentType Filters the transactions in the response by a payment instrument * type. Value is either: CREDITCARD. Returns a direct credit card * transaction with a corresponding value. DEBITCARD. Returns a debit * card transaction with a corresponding value. If you omit this * parameter, the API does not apply this filter. * @param storeId Filters the transactions in the response by a store ID. * @param terminalId Filters the transactions in the response by a terminal ID. * @param fields Indicates which fields appear in the response. Value is a single * field or a comma-separated list of fields. The transaction_info * value returns only the transaction details in the response. To * include all fields in the response, specify fields=all. Valid * fields are: transaction_info. The transaction information. * Includes the ID of the PayPal account of the payee, the PayPal- * generated transaction ID, the PayPal-generated base ID, the PayPal * reference ID type, the transaction event code, the date and time * when the transaction was initiated and was last updated, the * transaction amounts including the PayPal fee, any discounts, * insurance, the transaction status, and other information about the * transaction. payer_info. The payer information. Includes the * PayPal customer account ID and the payer's email address, primary * phone number, name, country code, address, and whether the payer * is verified or unverified. shipping_info. The shipping information. * Includes the recipient's name, the shipping method for this order, * the shipping address for this order, and the secondary address * associated with this order. auction_info. The auction information. * Includes the name of the auction site, the auction site URL, the * ID of the customer who makes the purchase in the auction, and the * date and time when the auction closes. cart_info. The cart * information. Includes an array of item details, whether the item * amount or the shipping amount already includes tax, and the ID of * the invoice for PayPal-generated invoices. incentive_info. An * array of incentive detail objects. Each object includes the * incentive, such as a special offer or coupon, the incentive amount, * and the incentive program code that identifies a merchant loyalty * or incentive program. store_info. The store information. Includes * the ID of the merchant store and the terminal ID for the checkout * stand in the merchant store. * @param balanceAffectingRecordsOnly Indicates whether the response includes only balance-impacting * transactions or all transactions. Value is either: Y. The default. * The response includes only balance transactions. N. The response * includes all transactions. * @param pageSize The number of items to return in the response. So, the * combination of `page=1` and `page_size=20` returns the first 20 * items. The combination of `page=2` and `page_size=20` returns the * next 20 items. * @param page The zero-relative start index of the entire list of items that * are returned in the response. So, the combination of `page=1` and * `page_size=20` returns the first 20 items. * @return Response from the API call */ async searchTransactions( { startDate, endDate, transactionId, transactionType, transactionStatus, transactionAmount, transactionCurrency, paymentInstrumentType, storeId, terminalId, fields, balanceAffectingRecordsOnly, pageSize, page, }: { startDate: string; endDate: string; transactionId?: string; transactionType?: string; transactionStatus?: string; transactionAmount?: string; transactionCurrency?: string; paymentInstrumentType?: string; storeId?: string; terminalId?: string; fields?: string; balanceAffectingRecordsOnly?: string; pageSize?: number; page?: number; }, requestOptions?: RequestOptions ): Promise> { const req = this.createRequest('GET', '/v1/reporting/transactions'); const mapped = req.prepareArgs({ startDate: [startDate, string()], endDate: [endDate, string()], transactionId: [transactionId, optional(string())], transactionType: [transactionType, optional(string())], transactionStatus: [transactionStatus, optional(string())], transactionAmount: [transactionAmount, optional(string())], transactionCurrency: [transactionCurrency, optional(string())], paymentInstrumentType: [paymentInstrumentType, optional(string())], storeId: [storeId, optional(string())], terminalId: [terminalId, optional(string())], fields: [fields, optional(string())], balanceAffectingRecordsOnly: [ balanceAffectingRecordsOnly, optional(string()), ], pageSize: [pageSize, optional(number())], page: [page, optional(number())], }); req.query('start_date', mapped.startDate); req.query('end_date', mapped.endDate); req.query('transaction_id', mapped.transactionId); req.query('transaction_type', mapped.transactionType); req.query('transaction_status', mapped.transactionStatus); req.query('transaction_amount', mapped.transactionAmount); req.query('transaction_currency', mapped.transactionCurrency); req.query('payment_instrument_type', mapped.paymentInstrumentType); req.query('store_id', mapped.storeId); req.query('terminal_id', mapped.terminalId); req.query('fields', mapped.fields); req.query( 'balance_affecting_records_only', mapped.balanceAffectingRecordsOnly ); req.query('page_size', mapped.pageSize); req.query('page', mapped.page); req.defaultToError(SearchError, 'The error response.'); req.authenticate([{ oauth2: true }]); return req.callAsJson(searchResponseSchema, requestOptions); } /** * List all balances. Specify date time to list balances for that time that appear in the response. * Notes: It takes a maximum of three hours for balances to appear in the list balances call. This call * lists balances upto the previous three years. * * @param asOfTime List balances in the response at the date time provided, will return the last * refreshed balance in the system when not provided. * @param currencyCode Filters the transactions in the response by a [three-character ISO-4217 currency * code](/api/rest/reference/currency-codes/) for the PayPal transaction currency. * @return Response from the API call */ async searchBalances( { asOfTime, currencyCode, }: { asOfTime?: string; currencyCode?: string; }, requestOptions?: RequestOptions ): Promise> { const req = this.createRequest('GET', '/v1/reporting/balances'); const mapped = req.prepareArgs({ asOfTime: [asOfTime, optional(string())], currencyCode: [currencyCode, optional(string())], }); req.query('as_of_time', mapped.asOfTime); req.query('currency_code', mapped.currencyCode); req.throwOn( 400, DefaultError, 'The request is not well-formed, is syntactically incorrect, or violates schema.' ); req.throwOn( 403, DefaultError, 'Authorization failed due to insufficient permissions.' ); req.throwOn(500, DefaultError, 'An internal server error occurred.'); req.defaultToError(DefaultError, 'The error response.'); req.authenticate([{ oauth2: true }]); return req.callAsJson(balancesResponseSchema, requestOptions); } }